UNPKG

chain-saasui

Version:

chain-saasui

67 lines (58 loc) 2.13 kB
import MessageBox from './messagebox.vue'; // MessageBoxManager.js export default class MessageBoxManager { constructor(Vue, i18n, Component = MessageBox) { if (!Vue) throw new Error('[MessageBox] Vue instance is required'); if (!Component) throw new Error('[MessageBox] Vue component is required'); this.Vue = Vue; this.i18n = i18n; this.Component = Component; this.instance = null; } _t(key) { return this.i18n ? this.i18n.t(key) : key; } _createInstance() { const Constructor = this.Vue.extend(this.Component); this.instance = new Constructor({ el: document.createElement('div'), }); document.body.appendChild(this.instance.$el); } _getInstance() { if (!this.instance) this._createInstance(); return this.instance; } alert(options) { const instance = this._getInstance(); return instance.open({ ...options, title: options.title || this._t('deletemsg.hint'), confirmText: options.confirmText || this._t("buttonGroup.sure"), cancelText: options.cancelText || this._t("buttonGroup.cancel"), message: options.message, showCancelButton: false, }); } confirm(options) { const instance = this._getInstance(); return instance.open({ ...options, title: options.title || this._t('deletemsg.hint'), confirmText: options.confirmText || this._t("buttonGroup.sure"), cancelText: options.cancelText || this._t("buttonGroup.cancel"), message: options.message, }); } prompt(options) { const instance = this._getInstance(); return instance.open({ ...options, title: options.title || this._t('deletemsg.hint'), confirmText: options.confirmText || this._t("buttonGroup.sure"), cancelText: options.cancelText || this._t("buttonGroup.cancel"), message: options.message, showInput: true, }); } }