123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import Dialog from './Dialog'
- import Window from './Window'
- import Toast from './Toast'
- import Alert from './Alert'
- import Confirm from './Confirm'
- import DialogContent from './Dialog-content'
- import { mount } from '../../utils/componentHelper'
- Dialog.use = function use(app) {
- Dialog.toast = function (options) {
- if (typeof options == 'string') {
- options = {
- content: options,
- }
- }
- const { destroy, vNode, el } = mount(Toast, {
- app,
- props: {
- ...options,
- destroy,
- },
- })
- if (!Dialog.toast._destroys) {
- Dialog.toast._destroys = []
- }
- Dialog.toast._destroys.push(destroy)
- return {
- hide: function () {
- let destroy = null
- while ((destroy = Dialog.toast._destroys.shift()) && destroy) {
- destroy()
- }
- }.bind(this),
- }
- }
- Dialog.toast.hide = function () {
- if (Dialog.toast._destroys && Dialog.toast._destroys.length) {
- let destroy = Dialog.toast._destroys.pop()
- destroy && destroy()
- }
- }
- Dialog.alert = function (options) {
- if (typeof options == 'string') {
- options = {
- content: options,
- }
- }
- const { destroy } = mount(Alert, {
- app,
- props: { ...options, destroy: () => destroy() },
- })
- this.alert.hide = function () {
- destroy()
- }
- return this.alert
- }
- Dialog.confirm = function (options) {
- if (typeof options == 'string') {
- options = {
- content: options,
- }
- }
- let promise
- if (!options.func) {
- promise = new Promise(resolve => {
- options.func = result => resolve(result === 'ok')
- })
- }
- const { destroy } = mount(Confirm, {
- app,
- props: { ...options, destroy: () => destroy() },
- })
- this.confirm.hide = function () {
- destroy()
- }
- return promise || this.confirm
- }
- }
- export { Window, Toast, Alert, Confirm, DialogContent }
- export default Dialog
|