Refactor
This commit is contained in:
parent
cece411eae
commit
c858bbf5be
45
resources/assets/src/scripts/modal.ts
Normal file
45
resources/assets/src/scripts/modal.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import $ from 'jquery'
|
||||
import Vue from 'vue'
|
||||
import Modal from '../components/Modal.vue'
|
||||
|
||||
export interface ModalOptions {
|
||||
mode?: 'alert' | 'confirm' | 'prompt'
|
||||
title?: string
|
||||
text?: string
|
||||
dangerousHTML?: string
|
||||
input?: string
|
||||
placeholder?: string
|
||||
inputType?: string
|
||||
validator?(value: any): string | boolean | void
|
||||
type?: string
|
||||
showHeader?: boolean
|
||||
center?: boolean
|
||||
okButtonText?: string
|
||||
okButtonType?: string
|
||||
cancelButtonText?: string
|
||||
cancelButtonType?: string
|
||||
flexFooter?: boolean
|
||||
}
|
||||
|
||||
export interface ModalResult {
|
||||
value: string
|
||||
}
|
||||
|
||||
export function showModal(options: ModalOptions = {}): Promise<ModalResult> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const container = document.createElement('div')
|
||||
document.body.appendChild(container)
|
||||
|
||||
const instance = new Vue({
|
||||
render: h => h(Modal, {
|
||||
props: Object.assign({ center: true }, options),
|
||||
on: {
|
||||
confirm: resolve,
|
||||
dismiss: reject,
|
||||
},
|
||||
}),
|
||||
}).$mount(container)
|
||||
|
||||
$(instance.$el).modal('show')
|
||||
})
|
||||
}
|
||||
|
|
@ -1,47 +1,5 @@
|
|||
import $ from 'jquery'
|
||||
import Vue from 'vue'
|
||||
import Modal from '../components/Modal.vue'
|
||||
|
||||
export interface ModalOptions {
|
||||
mode?: 'alert' | 'confirm' | 'prompt'
|
||||
title?: string
|
||||
text?: string
|
||||
dangerousHTML?: string
|
||||
input?: string
|
||||
placeholder?: string
|
||||
inputType?: string
|
||||
validator?(value: any): string | boolean | void
|
||||
type?: string
|
||||
showHeader?: boolean
|
||||
center?: boolean
|
||||
okButtonText?: string
|
||||
okButtonType?: string
|
||||
cancelButtonText?: string
|
||||
cancelButtonType?: string
|
||||
flexFooter?: boolean
|
||||
}
|
||||
|
||||
export interface ModalResult {
|
||||
value: string
|
||||
}
|
||||
|
||||
export function showModal(options: ModalOptions = {}): Promise<ModalResult> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const container = document.createElement('div')
|
||||
document.body.appendChild(container)
|
||||
|
||||
const instance = new Vue({
|
||||
render: h => h(Modal, {
|
||||
props: Object.assign({ center: true }, options),
|
||||
on: {
|
||||
confirm: resolve,
|
||||
dismiss: reject,
|
||||
},
|
||||
}),
|
||||
}).$mount(container)
|
||||
|
||||
$(instance.$el).modal('show')
|
||||
})
|
||||
}
|
||||
import { showModal } from './modal'
|
||||
|
||||
Object.assign(blessing, { notify: { showModal } })
|
||||
|
||||
export * from './modal'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user