2016-09-29 15:47:19 +08:00
|
|
|
import Modal from './confirm';
|
|
|
|
|
|
|
|
let modalInstance;
|
|
|
|
|
2017-06-02 10:04:49 +08:00
|
|
|
function getModalInstance (render = undefined) {
|
2016-09-29 15:47:19 +08:00
|
|
|
modalInstance = modalInstance || Modal.newInstance({
|
|
|
|
closable: false,
|
|
|
|
maskClosable: false,
|
2017-06-02 10:04:49 +08:00
|
|
|
footerHide: true,
|
|
|
|
render: render
|
2016-09-29 15:47:19 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return modalInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
function confirm (options) {
|
2017-06-02 10:04:49 +08:00
|
|
|
const render = ('render' in options) ? options.render : undefined;
|
|
|
|
let instance = getModalInstance(render);
|
2016-09-29 15:47:19 +08:00
|
|
|
|
|
|
|
options.onRemove = function () {
|
|
|
|
modalInstance = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
instance.show(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Modal.info = function (props = {}) {
|
|
|
|
props.icon = 'info';
|
|
|
|
props.showCancel = false;
|
|
|
|
return confirm(props);
|
|
|
|
};
|
|
|
|
|
|
|
|
Modal.success = function (props = {}) {
|
|
|
|
props.icon = 'success';
|
|
|
|
props.showCancel = false;
|
|
|
|
return confirm(props);
|
|
|
|
};
|
|
|
|
|
|
|
|
Modal.warning = function (props = {}) {
|
|
|
|
props.icon = 'warning';
|
|
|
|
props.showCancel = false;
|
|
|
|
return confirm(props);
|
|
|
|
};
|
|
|
|
|
|
|
|
Modal.error = function (props = {}) {
|
|
|
|
props.icon = 'error';
|
|
|
|
props.showCancel = false;
|
|
|
|
return confirm(props);
|
|
|
|
};
|
|
|
|
|
|
|
|
Modal.confirm = function (props = {}) {
|
|
|
|
props.icon = 'confirm';
|
|
|
|
props.showCancel = true;
|
|
|
|
return confirm(props);
|
|
|
|
};
|
|
|
|
|
|
|
|
Modal.remove = function () {
|
|
|
|
if (!modalInstance) { // at loading status, remove after Cancel
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const instance = getModalInstance();
|
|
|
|
|
|
|
|
instance.remove();
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Modal;
|