2016-09-29 15:47:19 +08:00
|
|
|
<template>
|
2017-07-19 13:58:20 +08:00
|
|
|
<div v-transfer-dom :data-transfer="transfer">
|
2017-03-31 09:26:59 +08:00
|
|
|
<transition :name="transitionNames[1]">
|
2017-03-09 18:31:47 +08:00
|
|
|
<div :class="maskClasses" v-show="visible" @click="mask"></div>
|
|
|
|
</transition>
|
|
|
|
<div :class="wrapClasses" @click="handleWrapClick">
|
2017-06-28 10:55:00 +08:00
|
|
|
<transition :name="transitionNames[0]" @after-leave="animationFinish">
|
2017-03-09 18:31:47 +08:00
|
|
|
<div :class="classes" :style="mainStyles" v-show="visible">
|
|
|
|
<div :class="[prefixCls + '-content']">
|
|
|
|
<a :class="[prefixCls + '-close']" v-if="closable" @click="close">
|
|
|
|
<slot name="close">
|
2018-06-25 21:11:42 +08:00
|
|
|
<Icon type="ios-close"></Icon>
|
2017-03-09 18:31:47 +08:00
|
|
|
</slot>
|
|
|
|
</a>
|
|
|
|
<div :class="[prefixCls + '-header']" v-if="showHead"><slot name="header"><div :class="[prefixCls + '-header-inner']">{{ title }}</div></slot></div>
|
|
|
|
<div :class="[prefixCls + '-body']"><slot></slot></div>
|
|
|
|
<div :class="[prefixCls + '-footer']" v-if="!footerHide">
|
|
|
|
<slot name="footer">
|
2017-03-30 16:05:20 +08:00
|
|
|
<i-button type="text" size="large" @click.native="cancel">{{ localeCancelText }}</i-button>
|
|
|
|
<i-button type="primary" size="large" :loading="buttonLoading" @click.native="ok">{{ localeOkText }}</i-button>
|
2017-03-09 18:31:47 +08:00
|
|
|
</slot>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-09-29 15:47:19 +08:00
|
|
|
</div>
|
2017-03-09 18:31:47 +08:00
|
|
|
</transition>
|
2016-09-29 15:47:19 +08:00
|
|
|
</div>
|
2017-04-05 11:24:00 +08:00
|
|
|
</div>
|
2016-09-29 15:47:19 +08:00
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import Icon from '../icon';
|
2016-10-28 18:27:04 +08:00
|
|
|
import iButton from '../button/button.vue';
|
2017-04-05 11:24:00 +08:00
|
|
|
import TransferDom from '../../directives/transfer-dom';
|
2017-03-30 16:05:20 +08:00
|
|
|
import Locale from '../../mixins/locale';
|
2017-04-10 09:58:51 +08:00
|
|
|
import Emitter from '../../mixins/emitter';
|
2017-09-19 14:26:46 +08:00
|
|
|
import ScrollbarMixins from './mixins-scrollbar';
|
2016-09-29 15:47:19 +08:00
|
|
|
|
|
|
|
const prefixCls = 'ivu-modal';
|
|
|
|
|
|
|
|
export default {
|
2017-03-30 16:05:20 +08:00
|
|
|
name: 'Modal',
|
2017-09-19 14:26:46 +08:00
|
|
|
mixins: [ Locale, Emitter, ScrollbarMixins ],
|
2016-10-28 18:27:04 +08:00
|
|
|
components: { Icon, iButton },
|
2017-04-05 11:24:00 +08:00
|
|
|
directives: { TransferDom },
|
2016-09-29 15:47:19 +08:00
|
|
|
props: {
|
2017-03-09 18:31:47 +08:00
|
|
|
value: {
|
2016-09-29 15:47:19 +08:00
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
closable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
maskClosable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
width: {
|
|
|
|
type: [Number, String],
|
|
|
|
default: 520
|
|
|
|
},
|
|
|
|
okText: {
|
2017-03-30 16:05:20 +08:00
|
|
|
type: String
|
2016-09-29 15:47:19 +08:00
|
|
|
},
|
|
|
|
cancelText: {
|
2017-03-30 16:05:20 +08:00
|
|
|
type: String
|
2016-09-29 15:47:19 +08:00
|
|
|
},
|
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2017-03-09 18:31:47 +08:00
|
|
|
styles: {
|
2016-09-29 15:47:19 +08:00
|
|
|
type: Object
|
|
|
|
},
|
|
|
|
className: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
// for instance
|
|
|
|
footerHide: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2017-01-24 13:36:13 -06:00
|
|
|
},
|
2017-02-05 22:58:34 -06:00
|
|
|
scrollable: {
|
2017-01-24 13:36:13 -06:00
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2017-03-31 09:26:59 +08:00
|
|
|
},
|
|
|
|
transitionNames: {
|
|
|
|
type: Array,
|
|
|
|
default () {
|
|
|
|
return ['ease', 'fade'];
|
|
|
|
}
|
2017-07-19 13:58:20 +08:00
|
|
|
},
|
|
|
|
transfer: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2016-09-29 15:47:19 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
prefixCls: prefixCls,
|
|
|
|
wrapShow: false,
|
|
|
|
showHead: true,
|
2017-03-09 18:31:47 +08:00
|
|
|
buttonLoading: false,
|
|
|
|
visible: this.value
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
2016-09-29 15:47:19 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
wrapClasses () {
|
|
|
|
return [
|
|
|
|
`${prefixCls}-wrap`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-hidden`]: !this.wrapShow,
|
|
|
|
[`${this.className}`]: !!this.className
|
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
];
|
2016-09-29 15:47:19 +08:00
|
|
|
},
|
|
|
|
maskClasses () {
|
|
|
|
return `${prefixCls}-mask`;
|
|
|
|
},
|
|
|
|
classes () {
|
|
|
|
return `${prefixCls}`;
|
|
|
|
},
|
2017-03-09 18:31:47 +08:00
|
|
|
mainStyles () {
|
2016-09-29 15:47:19 +08:00
|
|
|
let style = {};
|
|
|
|
|
2017-07-18 10:24:21 +08:00
|
|
|
const width = parseInt(this.width);
|
2016-09-29 15:47:19 +08:00
|
|
|
const styleWidth = {
|
2017-07-18 10:24:21 +08:00
|
|
|
width: width <= 100 ? `${width}%` : `${width}px`
|
2016-09-29 15:47:19 +08:00
|
|
|
};
|
|
|
|
|
2017-03-09 18:31:47 +08:00
|
|
|
const customStyle = this.styles ? this.styles : {};
|
2016-09-29 15:47:19 +08:00
|
|
|
|
|
|
|
Object.assign(style, styleWidth, customStyle);
|
|
|
|
|
|
|
|
return style;
|
2017-03-30 16:05:20 +08:00
|
|
|
},
|
|
|
|
localeOkText () {
|
|
|
|
if (this.okText === undefined) {
|
|
|
|
return this.t('i.modal.okText');
|
|
|
|
} else {
|
|
|
|
return this.okText;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
localeCancelText () {
|
|
|
|
if (this.cancelText === undefined) {
|
|
|
|
return this.t('i.modal.cancelText');
|
|
|
|
} else {
|
|
|
|
return this.cancelText;
|
|
|
|
}
|
2016-09-29 15:47:19 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
close () {
|
|
|
|
this.visible = false;
|
2017-03-09 18:31:47 +08:00
|
|
|
this.$emit('input', false);
|
2016-09-29 15:47:19 +08:00
|
|
|
this.$emit('on-cancel');
|
|
|
|
},
|
|
|
|
mask () {
|
|
|
|
if (this.maskClosable) {
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
},
|
2017-02-21 11:36:41 +08:00
|
|
|
handleWrapClick (event) {
|
|
|
|
// use indexOf,do not use === ,because ivu-modal-wrap can have other custom className
|
2017-02-22 14:39:54 +08:00
|
|
|
const className = event.target.getAttribute('class');
|
|
|
|
if (className && className.indexOf(`${prefixCls}-wrap`) > -1) this.mask();
|
2017-02-21 11:36:41 +08:00
|
|
|
},
|
2016-09-29 15:47:19 +08:00
|
|
|
cancel () {
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
ok () {
|
|
|
|
if (this.loading) {
|
|
|
|
this.buttonLoading = true;
|
|
|
|
} else {
|
|
|
|
this.visible = false;
|
2017-03-09 18:31:47 +08:00
|
|
|
this.$emit('input', false);
|
2016-09-29 15:47:19 +08:00
|
|
|
}
|
|
|
|
this.$emit('on-ok');
|
|
|
|
},
|
|
|
|
EscClose (e) {
|
|
|
|
if (this.visible && this.closable) {
|
|
|
|
if (e.keyCode === 27) {
|
2016-12-25 22:49:42 +08:00
|
|
|
this.close();
|
2016-09-29 15:47:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-06-28 10:55:00 +08:00
|
|
|
animationFinish() {
|
|
|
|
this.$emit('on-hidden');
|
2016-09-29 15:47:19 +08:00
|
|
|
}
|
|
|
|
},
|
2017-03-09 18:31:47 +08:00
|
|
|
mounted () {
|
2016-09-29 15:47:19 +08:00
|
|
|
if (this.visible) {
|
|
|
|
this.wrapShow = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let showHead = true;
|
|
|
|
|
2017-03-15 11:32:12 +08:00
|
|
|
if (this.$slots.header === undefined && !this.title) {
|
2016-09-29 15:47:19 +08:00
|
|
|
showHead = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.showHead = showHead;
|
|
|
|
|
|
|
|
// ESC close
|
|
|
|
document.addEventListener('keydown', this.EscClose);
|
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
document.removeEventListener('keydown', this.EscClose);
|
2016-11-21 18:16:31 +08:00
|
|
|
this.removeScrollEffect();
|
2016-09-29 15:47:19 +08:00
|
|
|
},
|
|
|
|
watch: {
|
2017-03-09 18:31:47 +08:00
|
|
|
value (val) {
|
|
|
|
this.visible = val;
|
|
|
|
},
|
2016-09-29 15:47:19 +08:00
|
|
|
visible (val) {
|
|
|
|
if (val === false) {
|
|
|
|
this.buttonLoading = false;
|
2017-01-13 15:35:38 +08:00
|
|
|
this.timer = setTimeout(() => {
|
2016-09-29 15:47:19 +08:00
|
|
|
this.wrapShow = false;
|
2016-11-21 09:14:38 +08:00
|
|
|
this.removeScrollEffect();
|
2016-09-29 15:47:19 +08:00
|
|
|
}, 300);
|
|
|
|
} else {
|
2017-01-13 15:35:38 +08:00
|
|
|
if (this.timer) clearTimeout(this.timer);
|
2016-09-29 15:47:19 +08:00
|
|
|
this.wrapShow = true;
|
2017-02-05 22:58:34 -06:00
|
|
|
if (!this.scrollable) {
|
2017-01-24 13:36:13 -06:00
|
|
|
this.addScrollEffect();
|
|
|
|
}
|
2016-09-29 15:47:19 +08:00
|
|
|
}
|
2017-04-10 09:58:51 +08:00
|
|
|
this.broadcast('Table', 'on-visible-change', val);
|
2018-01-23 18:14:23 +08:00
|
|
|
this.broadcast('Slider', 'on-visible-change', val); // #2852
|
2017-11-01 15:12:12 +08:00
|
|
|
this.$emit('on-visible-change', val);
|
2016-11-09 17:36:40 +08:00
|
|
|
},
|
|
|
|
loading (val) {
|
|
|
|
if (!val) {
|
|
|
|
this.buttonLoading = false;
|
|
|
|
}
|
2017-01-24 13:36:13 -06:00
|
|
|
},
|
2017-02-05 22:58:34 -06:00
|
|
|
scrollable (val) {
|
2017-01-24 13:37:35 -06:00
|
|
|
if (!val) {
|
2017-01-24 13:36:13 -06:00
|
|
|
this.addScrollEffect();
|
|
|
|
} else {
|
|
|
|
this.removeScrollEffect();
|
|
|
|
}
|
2017-04-23 23:16:19 +08:00
|
|
|
},
|
|
|
|
title (val) {
|
|
|
|
if (this.$slots.header === undefined) {
|
2017-04-25 14:08:01 +08:00
|
|
|
this.showHead = !!val;
|
2017-04-23 23:16:19 +08:00
|
|
|
}
|
2016-09-29 15:47:19 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-25 22:49:42 +08:00
|
|
|
};
|
2016-10-28 17:24:52 +08:00
|
|
|
</script>
|