support Modal

support Modal
This commit is contained in:
梁灏 2017-03-09 18:31:47 +08:00
parent f97e5bb01a
commit 6259471f4c
9 changed files with 153 additions and 39 deletions

View file

@ -48,4 +48,6 @@ class 改为 className
### DatePicker ### DatePicker
使用 v-model 使用 v-model
### LoadingBar ### LoadingBar
部分 prop 移至 data 部分 prop 移至 data
### Modal
visible 改为 value使用 v-modelstyle 改为 styles$Modal 的关闭有改动,建议后面在纯 html 模式下测试

View file

@ -39,7 +39,7 @@
- [x] Card - [x] Card
- [ ] Message - [ ] Message
- [ ] Notice - [ ] Notice
- [ ] Modal - [x] Modal
- [x] Progress - [x] Progress
- [x] Badge - [x] Badge
- [x] Collapse - [x] Collapse

View file

@ -51,6 +51,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; }
<li><router-link to="/form">Form</router-link></li> <li><router-link to="/form">Form</router-link></li>
<li><router-link to="/table">Table</router-link></li> <li><router-link to="/table">Table</router-link></li>
<li><router-link to="/loading-bar">LoadingBar</router-link></li> <li><router-link to="/loading-bar">LoadingBar</router-link></li>
<li><router-link to="/modal">Modal</router-link></li>
</ul> </ul>
</nav> </nav>
<router-view></router-view> <router-view></router-view>

View file

@ -168,6 +168,10 @@ const router = new VueRouter({
{ {
path: '/loading-bar', path: '/loading-bar',
component: require('./routers/loading-bar.vue') component: require('./routers/loading-bar.vue')
},
{
path: '/modal',
component: require('./routers/modal.vue')
} }
] ]
}); });

View file

@ -0,0 +1,94 @@
<template>
<div>
<i-button @click.native="instance('info')">消息</i-button>
<i-button @click.native="instance('success')">成功</i-button>
<i-button @click.native="instance('warning')">警告</i-button>
<i-button @click.native="instance('error')">错误</i-button>
</div>
</template>
<script>
export default {
methods: {
instance (type) {
const title = '对话框的标题';
const content = '<p>一些对话框内容</p><p>一些对话框内容</p>';
switch (type) {
case 'info':
this.$Modal.info({
title: title,
content: content
});
break;
case 'success':
this.$Modal.success({
title: title,
content: content
});
break;
case 'warning':
this.$Modal.warning({
title: title,
content: content
});
break;
case 'error':
this.$Modal.error({
title: title,
content: content
});
break;
}
}
}
}
</script>
<!--<template>-->
<!--<div>-->
<!--<i-button @click.native="confirm">标准</i-button>-->
<!--<i-button @click.native="custom">自定义按钮文字</i-button>-->
<!--<i-button @click.native="async">异步关闭</i-button>-->
<!--</div>-->
<!--</template>-->
<!--<script>-->
<!--export default {-->
<!--methods: {-->
<!--confirm () {-->
<!--this.$Modal.confirm({-->
<!--title: '确认对话框标题',-->
<!--content: '<p>一些对话框内容</p><p>一些对话框内容</p>',-->
<!--onOk: () => {-->
<!--console.log('确定');-->
<!--// this.$Message.info('');-->
<!--},-->
<!--onCancel: () => {-->
<!--console.log('取消');-->
<!--// this.$Message.info('');-->
<!--}-->
<!--});-->
<!--},-->
<!--custom () {-->
<!--this.$Modal.confirm({-->
<!--title: '确认对话框标题',-->
<!--content: '<p>一些对话框内容</p><p>一些对话框内容</p>',-->
<!--okText: 'OK',-->
<!--cancelText: 'Cancel'-->
<!--});-->
<!--},-->
<!--async () {-->
<!--this.$Modal.confirm({-->
<!--title: '确认对话框标题',-->
<!--content: '<p>对话框将在 2秒 后关闭</p>',-->
<!--loading: true,-->
<!--onOk: () => {-->
<!--setTimeout(() => {-->
<!--this.$Modal.remove();-->
<!--// this.$Message.info('');-->
<!--}, 2000);-->
<!--}-->
<!--});-->
<!--}-->
<!--}-->
<!--}-->
<!--</script>-->

View file

@ -6,7 +6,7 @@
</transition> </transition>
</template> </template>
<script> <script>
import { oneOf } from '../../utils/assist'; // import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-loading-bar'; const prefixCls = 'ivu-loading-bar';

View file

@ -17,18 +17,18 @@ Modal.newInstance = properties => {
const div = document.createElement('div'); const div = document.createElement('div');
div.innerHTML = ` div.innerHTML = `
<Modal${props} :visible.sync="visible" :width="width" :scrollable.sync="scrollable"> <Modal${props} v-model="visible" :width="width" :scrollable="scrollable">
<div class="${prefixCls}"> <div class="${prefixCls}">
<div class="${prefixCls}-head"> <div class="${prefixCls}-head">
<div class="${prefixCls}-head-title">{{{ title }}}</div> <div class="${prefixCls}-head-title" v-html="title"></div>
</div> </div>
<div class="${prefixCls}-body"> <div class="${prefixCls}-body">
<div :class="iconTypeCls"><i :class="iconNameCls"></i></div> <div :class="iconTypeCls"><i :class="iconNameCls"></i></div>
{{{ body }}} <div v-html="body"></div>
</div> </div>
<div class="${prefixCls}-footer"> <div class="${prefixCls}-footer">
<i-button type="text" size="large" v-if="showCancel" @click="cancel">{{ cancelText }}</i-button> <i-button type="text" size="large" v-if="showCancel" @click.native="cancel">{{ cancelText }}</i-button>
<i-button type="primary" size="large" :loading="buttonLoading" @click="ok">{{ okText }}</i-button> <i-button type="primary" size="large" :loading="buttonLoading" @click.native="ok">{{ okText }}</i-button>
</div> </div>
</div> </div>
</Modal> </Modal>
@ -68,7 +68,7 @@ Modal.newInstance = properties => {
}, },
methods: { methods: {
cancel () { cancel () {
this.visible = false; this.$children[0].visible = false;
this.buttonLoading = false; this.buttonLoading = false;
this.onCancel(); this.onCancel();
this.remove(); this.remove();
@ -77,7 +77,7 @@ Modal.newInstance = properties => {
if (this.loading) { if (this.loading) {
this.buttonLoading = true; this.buttonLoading = true;
} else { } else {
this.visible = false; this.$children[0].visible = false;
this.remove(); this.remove();
} }
this.onOk(); this.onOk();
@ -89,7 +89,7 @@ Modal.newInstance = properties => {
}, },
destroy () { destroy () {
this.$destroy(); this.$destroy();
document.body.removeChild(div); document.body.removeChild(this.$el);
this.onRemove(); this.onRemove();
}, },
onOk () {}, onOk () {},

View file

@ -1,24 +1,30 @@
<template> <template>
<div :class="maskClasses" v-show="visible" @click="mask" transition="fade"></div> <span>
<div :class="wrapClasses" @click="handleWrapClick"> <transition name="fade">
<div :class="classes" :style="styles" v-show="visible" transition="ease"> <div :class="maskClasses" v-show="visible" @click="mask"></div>
<div :class="[prefixCls + '-content']"> </transition>
<a :class="[prefixCls + '-close']" v-if="closable" @click="close"> <div :class="wrapClasses" @click="handleWrapClick">
<slot name="close"> <transition name="ease">
<Icon type="ios-close-empty"></Icon> <div :class="classes" :style="mainStyles" v-show="visible">
</slot> <div :class="[prefixCls + '-content']">
</a> <a :class="[prefixCls + '-close']" v-if="closable" @click="close">
<div :class="[prefixCls + '-header']" v-if="showHead" v-el:head><slot name="header"><div :class="[prefixCls + '-header-inner']">{{ title }}</div></slot></div> <slot name="close">
<div :class="[prefixCls + '-body']"><slot></slot></div> <Icon type="ios-close-empty"></Icon>
<div :class="[prefixCls + '-footer']" v-if="!footerHide"> </slot>
<slot name="footer"> </a>
<i-button type="text" size="large" @click="cancel">{{ cancelText }}</i-button> <div :class="[prefixCls + '-header']" v-if="showHead"><slot name="header"><div :class="[prefixCls + '-header-inner']">{{ title }}</div></slot></div>
<i-button type="primary" size="large" :loading="buttonLoading" @click="ok">{{ okText }}</i-button> <div :class="[prefixCls + '-body']"><slot></slot></div>
</slot> <div :class="[prefixCls + '-footer']" v-if="!footerHide">
<slot name="footer">
<i-button type="text" size="large" @click.native="cancel">{{ cancelText }}</i-button>
<i-button type="primary" size="large" :loading="buttonLoading" @click.native="ok">{{ okText }}</i-button>
</slot>
</div>
</div>
</div> </div>
</div> </transition>
</div> </div>
</div> </span>
</template> </template>
<script> <script>
import Icon from '../icon'; import Icon from '../icon';
@ -31,7 +37,7 @@
export default { export default {
components: { Icon, iButton }, components: { Icon, iButton },
props: { props: {
visible: { value: {
type: Boolean, type: Boolean,
default: false default: false
}, },
@ -66,7 +72,7 @@
type: Boolean, type: Boolean,
default: false default: false
}, },
style: { styles: {
type: Object type: Object
}, },
className: { className: {
@ -87,7 +93,8 @@
prefixCls: prefixCls, prefixCls: prefixCls,
wrapShow: false, wrapShow: false,
showHead: true, showHead: true,
buttonLoading: false buttonLoading: false,
visible: this.value
}; };
}, },
computed: { computed: {
@ -106,14 +113,14 @@
classes () { classes () {
return `${prefixCls}`; return `${prefixCls}`;
}, },
styles () { mainStyles () {
let style = {}; let style = {};
const styleWidth = { const styleWidth = {
width: `${this.width}px` width: `${this.width}px`
}; };
const customStyle = this.style ? this.style : {}; const customStyle = this.styles ? this.styles : {};
Object.assign(style, styleWidth, customStyle); Object.assign(style, styleWidth, customStyle);
@ -123,6 +130,7 @@
methods: { methods: {
close () { close () {
this.visible = false; this.visible = false;
this.$emit('input', false);
this.$emit('on-cancel'); this.$emit('on-cancel');
}, },
mask () { mask () {
@ -143,6 +151,7 @@
this.buttonLoading = true; this.buttonLoading = true;
} else { } else {
this.visible = false; this.visible = false;
this.$emit('input', false);
} }
this.$emit('on-ok'); this.$emit('on-ok');
}, },
@ -182,14 +191,14 @@
this.resetScrollBar(); this.resetScrollBar();
} }
}, },
ready () { mounted () {
if (this.visible) { if (this.visible) {
this.wrapShow = true; this.wrapShow = true;
} }
let showHead = true; let showHead = true;
if (this.$els.head.innerHTML == `<div class="${prefixCls}-header-inner"></div>` && !this.title) { if (this.$slots.head === undefined && !this.title) {
showHead = false; showHead = false;
} }
@ -203,6 +212,10 @@
this.removeScrollEffect(); this.removeScrollEffect();
}, },
watch: { watch: {
value (val) {
this.visible = val;
console.log(this.visible)
},
visible (val) { visible (val) {
if (val === false) { if (val === false) {
this.buttonLoading = false; this.buttonLoading = false;

View file

@ -22,7 +22,7 @@ import InputNumber from './components/input-number';
import LoadingBar from './components/loading-bar'; import LoadingBar from './components/loading-bar';
import Menu from './components/menu'; import Menu from './components/menu';
// import Message from './components/message'; // import Message from './components/message';
// import Modal from './components/modal'; import Modal from './components/modal';
// import Notice from './components/notice'; // import Notice from './components/notice';
import Page from './components/page'; import Page from './components/page';
import Poptip from './components/poptip'; import Poptip from './components/poptip';
@ -81,7 +81,7 @@ const iview = {
MenuItem: Menu.Item, MenuItem: Menu.Item,
Submenu: Menu.Sub, Submenu: Menu.Sub,
// Message, // Message,
// Modal, Modal,
// Notice, // Notice,
iOption: Option, iOption: Option,
OptionGroup, OptionGroup,
@ -123,7 +123,7 @@ const install = function (Vue, opts = {}) {
Vue.prototype.$Loading = LoadingBar; Vue.prototype.$Loading = LoadingBar;
// Vue.prototype.$Message = Message; // Vue.prototype.$Message = Message;
// Vue.prototype.$Modal = Modal; Vue.prototype.$Modal = Modal;
// Vue.prototype.$Notice = Notice; // Vue.prototype.$Notice = Notice;
}; };