2016-09-29 15:47:19 +08:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Modal from './modal.vue';
|
2017-06-01 12:32:00 +08:00
|
|
|
import Button from '../button/button.vue';
|
2017-03-30 16:05:20 +08:00
|
|
|
import Locale from '../../mixins/locale';
|
2016-09-29 15:47:19 +08:00
|
|
|
|
|
|
|
const prefixCls = 'ivu-modal-confirm';
|
|
|
|
|
|
|
|
Modal.newInstance = properties => {
|
|
|
|
const _props = properties || {};
|
|
|
|
|
2017-06-01 12:32:00 +08:00
|
|
|
const Instance = new Vue({
|
2017-03-30 16:05:20 +08:00
|
|
|
mixins: [ Locale ],
|
2017-06-01 12:32:00 +08:00
|
|
|
data: Object.assign({}, _props, {
|
2016-09-29 15:47:19 +08:00
|
|
|
visible: false,
|
|
|
|
width: 416,
|
|
|
|
title: '',
|
|
|
|
body: '',
|
|
|
|
iconType: '',
|
|
|
|
iconName: '',
|
2017-03-30 16:05:20 +08:00
|
|
|
okText: undefined,
|
|
|
|
cancelText: undefined,
|
2016-09-29 15:47:19 +08:00
|
|
|
showCancel: false,
|
|
|
|
loading: false,
|
2017-02-21 11:55:05 -06:00
|
|
|
buttonLoading: false,
|
2017-12-05 14:59:29 +08:00
|
|
|
scrollable: false,
|
2017-12-25 09:41:20 +08:00
|
|
|
closable: false
|
2016-09-29 15:47:19 +08:00
|
|
|
}),
|
2017-06-01 12:32:00 +08:00
|
|
|
render (h) {
|
|
|
|
let footerVNodes = [];
|
|
|
|
if (this.showCancel) {
|
|
|
|
footerVNodes.push(h(Button, {
|
|
|
|
props: {
|
|
|
|
type: 'text',
|
|
|
|
size: 'large'
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
click: this.cancel
|
|
|
|
}
|
|
|
|
}, this.localeCancelText));
|
|
|
|
}
|
|
|
|
footerVNodes.push(h(Button, {
|
|
|
|
props: {
|
|
|
|
type: 'primary',
|
|
|
|
size: 'large',
|
|
|
|
loading: this.buttonLoading
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
click: this.ok
|
|
|
|
}
|
|
|
|
}, this.localeOkText));
|
|
|
|
|
2017-06-02 10:04:49 +08:00
|
|
|
// render content
|
|
|
|
let body_render;
|
|
|
|
if (this.render) {
|
|
|
|
body_render = h('div', {
|
|
|
|
attrs: {
|
|
|
|
class: `${prefixCls}-body ${prefixCls}-body-render`
|
|
|
|
}
|
|
|
|
}, [this.render(h)]);
|
|
|
|
} else {
|
|
|
|
body_render = h('div', {
|
|
|
|
attrs: {
|
|
|
|
class: `${prefixCls}-body`
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
h('div', {
|
|
|
|
class: this.iconTypeCls
|
|
|
|
}, [
|
|
|
|
h('i', {
|
|
|
|
class: this.iconNameCls
|
|
|
|
})
|
|
|
|
]),
|
|
|
|
h('div', {
|
|
|
|
domProps: {
|
|
|
|
innerHTML: this.body
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-06-01 12:32:00 +08:00
|
|
|
return h(Modal, {
|
|
|
|
props: Object.assign({}, _props, {
|
|
|
|
width: this.width,
|
2017-12-05 14:59:29 +08:00
|
|
|
scrollable: this.scrollable,
|
|
|
|
closable: this.closable
|
2017-06-01 12:32:00 +08:00
|
|
|
}),
|
|
|
|
domProps: {
|
|
|
|
value: this.visible
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
input: (status) => {
|
|
|
|
this.visible = status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
h('div', {
|
|
|
|
attrs: {
|
|
|
|
class: prefixCls
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
h('div', {
|
|
|
|
attrs: {
|
|
|
|
class: `${prefixCls}-head`
|
|
|
|
}
|
2017-06-01 12:36:44 +08:00
|
|
|
}, [
|
|
|
|
h('div', {
|
|
|
|
attrs: {
|
|
|
|
class: `${prefixCls}-head-title`
|
|
|
|
},
|
|
|
|
domProps: {
|
|
|
|
innerHTML: this.title
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]),
|
2017-06-02 10:04:49 +08:00
|
|
|
body_render,
|
2017-06-01 12:32:00 +08:00
|
|
|
h('div', {
|
|
|
|
attrs: {
|
|
|
|
class: `${prefixCls}-footer`
|
|
|
|
}
|
|
|
|
}, footerVNodes)
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
},
|
2016-09-29 15:47:19 +08:00
|
|
|
computed: {
|
|
|
|
iconTypeCls () {
|
|
|
|
return [
|
2016-11-21 11:38:49 +08:00
|
|
|
`${prefixCls}-body-icon`,
|
|
|
|
`${prefixCls}-body-icon-${this.iconType}`
|
2016-12-25 22:49:42 +08:00
|
|
|
];
|
2016-09-29 15:47:19 +08:00
|
|
|
},
|
|
|
|
iconNameCls () {
|
|
|
|
return [
|
|
|
|
'ivu-icon',
|
|
|
|
`ivu-icon-${this.iconName}`
|
2016-12-25 22:49:42 +08:00
|
|
|
];
|
2017-03-30 16:05:20 +08:00
|
|
|
},
|
|
|
|
localeOkText () {
|
|
|
|
if (this.okText) {
|
|
|
|
return this.okText;
|
|
|
|
} else {
|
|
|
|
return this.t('i.modal.okText');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
localeCancelText () {
|
|
|
|
if (this.cancelText) {
|
|
|
|
return this.cancelText;
|
|
|
|
} else {
|
|
|
|
return this.t('i.modal.cancelText');
|
|
|
|
}
|
2016-09-29 15:47:19 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
cancel () {
|
2017-03-09 18:31:47 +08:00
|
|
|
this.$children[0].visible = false;
|
2016-09-29 15:47:19 +08:00
|
|
|
this.buttonLoading = false;
|
|
|
|
this.onCancel();
|
|
|
|
this.remove();
|
|
|
|
},
|
|
|
|
ok () {
|
|
|
|
if (this.loading) {
|
|
|
|
this.buttonLoading = true;
|
|
|
|
} else {
|
2017-03-09 18:31:47 +08:00
|
|
|
this.$children[0].visible = false;
|
2016-09-29 15:47:19 +08:00
|
|
|
this.remove();
|
|
|
|
}
|
|
|
|
this.onOk();
|
|
|
|
},
|
|
|
|
remove () {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.destroy();
|
|
|
|
}, 300);
|
|
|
|
},
|
|
|
|
destroy () {
|
|
|
|
this.$destroy();
|
2017-03-09 18:31:47 +08:00
|
|
|
document.body.removeChild(this.$el);
|
2016-09-29 15:47:19 +08:00
|
|
|
this.onRemove();
|
|
|
|
},
|
|
|
|
onOk () {},
|
|
|
|
onCancel () {},
|
|
|
|
onRemove () {}
|
|
|
|
}
|
2017-06-01 12:32:00 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const component = Instance.$mount();
|
|
|
|
document.body.appendChild(component.$el);
|
|
|
|
const modal = Instance.$children[0];
|
2016-09-29 15:47:19 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:59:29 +08:00
|
|
|
if ('closable' in props) {
|
|
|
|
modal.$parent.closable = props.closable;
|
|
|
|
}
|
|
|
|
|
2016-09-29 15:47:19 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-02-21 11:55:05 -06:00
|
|
|
if ('scrollable' in props) {
|
|
|
|
modal.$parent.scrollable = props.scrollable;
|
|
|
|
}
|
|
|
|
|
2016-09-29 15:47:19 +08:00
|
|
|
// 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
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
2016-09-29 15:47:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Modal;
|