diff --git a/src/components/dialog/confirm.js b/src/components/dialog/confirm.js deleted file mode 100644 index 05b2e63..0000000 --- a/src/components/dialog/confirm.js +++ /dev/null @@ -1,169 +0,0 @@ -import Vue from 'vue'; -import Modal from './dialog.vue'; -import Icon from '../icon/icon.vue'; -import iButton from '../button/button.vue'; -import { camelcaseToHyphen } from '../../utils/assist'; - -const prefixCls = 'ivu-modal-confirm'; - -Modal.newInstance = properties => { - const _props = properties || {}; - - let props = ''; - Object.keys(_props).forEach(prop => { - props += ' :' + camelcaseToHyphen(prop) + '=' + prop; - }); - - const div = document.createElement('div'); - div.innerHTML = ` - - - - - {{{ title }}} - - - {{{ body }}} - - - - - `; - document.body.appendChild(div); - - const modal = new Vue({ - el: div, - components: { Modal, iButton, Icon }, - data: Object.assign(_props, { - visible: false, - width: 416, - title: '', - body: '', - iconType: '', - iconName: '', - okText: '确定', - cancelText: '取消', - showCancel: false, - loading: false, - buttonLoading: false - }), - computed: { - iconTypeCls () { - return [ - `${prefixCls}-head-icon`, - `${prefixCls}-head-icon-${this.iconType}` - ] - }, - iconNameCls () { - return [ - 'ivu-icon', - `ivu-icon-${this.iconName}` - ] - } - }, - methods: { - cancel () { - this.visible = false; - this.buttonLoading = false; - this.onCancel(); - this.remove(); - }, - ok () { - if (this.loading) { - this.buttonLoading = true; - } else { - this.visible = false; - this.remove(); - } - this.onOk(); - }, - remove () { - setTimeout(() => { - this.destroy(); - }, 300); - }, - destroy () { - this.$destroy(); - document.body.removeChild(div); - this.onRemove(); - }, - onOk () {}, - onCancel () {}, - onRemove () {} - } - }).$children[0]; - - return { - show (props) { - modal.$parent.showCancel = props.showCancel; - modal.$parent.iconType = props.icon; - - switch (props.icon) { - case 'info': - modal.$parent.iconName = 'information-circled'; - break; - case 'success': - modal.$parent.iconName = 'checkmark-circled'; - break; - case 'warning': - modal.$parent.iconName = 'android-alert'; - break; - case 'error': - modal.$parent.iconName = 'close-circled'; - break; - case 'confirm': - modal.$parent.iconName = 'help-circled'; - break; - } - - if ('width' in props) { - modal.$parent.width = props.width; - } - - if ('title' in props) { - modal.$parent.title = props.title; - } - - if ('content' in props) { - modal.$parent.body = props.content; - } - - if ('okText' in props) { - modal.$parent.okText = props.okText; - } - - if ('cancelText' in props) { - modal.$parent.cancelText = props.cancelText; - } - - if ('onCancel' in props) { - modal.$parent.onCancel = props.onCancel; - } - - if ('onOk' in props) { - modal.$parent.onOk = props.onOk; - } - - // async for ok - if ('loading' in props) { - modal.$parent.loading = props.loading; - } - - // notice when component destroy - modal.$parent.onRemove = props.onRemove; - - modal.visible = true; - }, - remove () { - modal.visible = false; - modal.$parent.buttonLoading = false; - modal.$parent.remove(); - }, - component: modal - } -}; - -export default Modal; \ No newline at end of file diff --git a/src/components/dialog/dialog.vue b/src/components/dialog/dialog.vue deleted file mode 100644 index 05019ac..0000000 --- a/src/components/dialog/dialog.vue +++ /dev/null @@ -1,210 +0,0 @@ - - - - - - - - - - - {{ title }} - - - - {{ cancelText }} - {{ okText }} - - - - - - - diff --git a/src/components/dialog/index.js b/src/components/dialog/index.js deleted file mode 100644 index d79863d..0000000 --- a/src/components/dialog/index.js +++ /dev/null @@ -1,60 +0,0 @@ -import Modal from './confirm'; - -let modalInstance; - -function getModalInstance () { - modalInstance = modalInstance || Modal.newInstance({ - closable: false, - maskClosable: false, - footerHide: true - }); - - return modalInstance; -} - -function confirm (options) { - let instance = getModalInstance(); - - options.onRemove = function () { - modalInstance = null; - }; - - instance.show(options); -} - -export default { - info (props = {}) { - props.icon = 'info'; - props.showCancel = false; - return confirm(props); - }, - success (props = {}) { - props.icon = 'success'; - props.showCancel = false; - return confirm(props); - }, - warning (props = {}) { - props.icon = 'warning'; - props.showCancel = false; - return confirm(props); - }, - error (props = {}) { - props.icon = 'error'; - props.showCancel = false; - return confirm(props); - }, - confirm (props = {}) { - props.icon = 'confirm'; - props.showCancel = true; - return confirm(props); - }, - remove () { - if (!modalInstance) { // at loading status, remove after Cancel - return false; - } - - const instance = getModalInstance(); - - instance.remove(); - } -} \ No newline at end of file diff --git a/src/index.js b/src/index.js index f46877b..a3742f7 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,6 @@ import Cascader from './components/cascader'; import Checkbox from './components/checkbox'; import Circle from './components/circle'; import Collapse from './components/collapse'; -import Dialog from './components/dialog'; import Icon from './components/icon'; import Input from './components/input'; import InputNumber from './components/input-number'; @@ -82,7 +81,7 @@ const install = function (Vue) { Vue.prototype.$Loading = LoadingBar; Vue.prototype.$Message = Message; - Vue.prototype.$Modal = Dialog; + Vue.prototype.$Modal = Modal; Vue.prototype.$Notice = Notice; }; -- libgit2 0.21.4