fix: dialog animation not work

This commit is contained in:
陈嘉涵 2017-08-16 22:34:25 +08:00
parent 6b1f38a382
commit f828d14d0e
5 changed files with 70 additions and 118 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<transition name="actionsheet-float"> <transition name="actionsheet-float">
<div class="van-actionsheet" :class="[ title ? 'van-actionsheet--withtitle' : '' ]" v-show="currentValue"> <div class="van-actionsheet" :class="{ 'van-actionsheet--withtitle': title }" v-show="currentValue">
<div class="van-actionsheet__header" v-if="title"> <div class="van-actionsheet__header" v-if="title">
<h3 v-text="title"></h3> <h3 v-text="title"></h3>
<van-icon name="close" @click.stop="currentValue = false"></van-icon> <van-icon name="close" @click.stop="currentValue = false"></van-icon>
@ -17,9 +17,7 @@
<span class="van-actionsheet__name">{{ item.name }}</span> <span class="van-actionsheet__name">{{ item.name }}</span>
<span class="van-actionsheet__subname" v-if="item.subname">{{ item.subname }}</span> <span class="van-actionsheet__subname" v-if="item.subname">{{ item.subname }}</span>
</template> </template>
<template v-else> <van-loading v-else class="van-actionsheet__loading" type="circle" color="black" />
<van-loading class="van-actionsheet__loading" type="circle" color="black"></van-loading>
</template>
</li> </li>
</ul> </ul>
<a class="van-actionsheet__button" @click.stop="currentValue = false" v-if="cancelText">{{ cancelText }}</a> <a class="van-actionsheet__button" @click.stop="currentValue = false" v-if="cancelText">{{ cancelText }}</a>

View File

@ -1,6 +1,5 @@
import Vue from 'vue'; import Vue from 'vue';
import Dialog from './dialog.vue'; import Dialog from './dialog.vue';
import merge from '../../utils/merge';
const DialogConstructor = Vue.extend(Dialog); const DialogConstructor = Vue.extend(Dialog);
@ -20,10 +19,14 @@ const defaultCallback = action => {
}; };
const initInstance = () => { const initInstance = () => {
console.log('init instance');
instance = new DialogConstructor({ instance = new DialogConstructor({
el: document.createElement('div') el: document.createElement('div')
}); });
instance.$on('input', value => {
instance.value = value;
})
instance.callback = defaultCallback; instance.callback = defaultCallback;
}; };
@ -34,9 +37,10 @@ const showNextDialog = () => {
/* istanbul ignore else */ /* istanbul ignore else */
if (!instance.value && dialogQueue.length > 0) { if (!instance.value && dialogQueue.length > 0) {
console.log('shift instance');
currentDialog = dialogQueue.shift(); currentDialog = dialogQueue.shift();
const options = currentDialog.options; const { options } = currentDialog;
for (const prop in options) { for (const prop in options) {
/* istanbul ignore else */ /* istanbul ignore else */
@ -45,22 +49,17 @@ const showNextDialog = () => {
} }
} }
if (options.callback === undefined) { instance.callback = options.callback || defaultCallback;
instance.callback = defaultCallback;
}
document.body.appendChild(instance.$el);
Vue.nextTick(() => {
instance.value = true; instance.value = true;
}); document.body.appendChild(instance.$el);
} }
}; };
var DialogBox = options => { var DialogBox = options => {
return new Promise((resolve, reject) => { // eslint-disable-line return new Promise((resolve, reject) => { // eslint-disable-line
console.log('push instance');
dialogQueue.push({ dialogQueue.push({
options: merge({ ...options }), options: { ...options },
callback: options.callback, callback: options.callback,
resolve: resolve, resolve: resolve,
reject: reject reject: reject
@ -71,23 +70,25 @@ var DialogBox = options => {
}; };
DialogBox.alert = function(options) { DialogBox.alert = function(options) {
return DialogBox(merge({ return DialogBox({
type: 'alert', type: 'alert',
title: '', title: '',
message: '', message: '',
closeOnClickOverlay: false, closeOnClickOverlay: false,
showCancelButton: false showCancelButton: false,
}, options)); ...options
});
}; };
DialogBox.confirm = function(options) { DialogBox.confirm = function(options) {
return DialogBox(merge({ return DialogBox({
type: 'confirm', type: 'confirm',
title: '', title: '',
message: '', message: '',
closeOnClickOverlay: true, closeOnClickOverlay: true,
showCancelButton: true showCancelButton: true,
}, options)); ...options
});
}; };
DialogBox.close = function() { DialogBox.close = function() {

View File

@ -1,31 +1,29 @@
<template> <template>
<transition name="dialog-bounce"> <transition name="van-dialog-bounce">
<div class="van-dialog-wrapper">
<div class="van-dialog" v-show="value"> <div class="van-dialog" v-show="value">
<div class="van-dialog__header" v-if="title"> <div class="van-dialog__header" v-if="title" v-text="title" />
<div class="van-dialog__title" v-text="title"></div>
</div>
<div class="van-dialog__content" v-if="message"> <div class="van-dialog__content" v-if="message">
<div class="van-dialog__message" :class="{ 'van-dialog__message--notitle': !title }" v-html="message"></div> <div class="van-dialog__message" :class="{ 'van-dialog__message--withtitle': title }" v-html="message" />
</div> </div>
<div class="van-dialog__footer" :class="{ 'is-twobtn': showCancelButton && showConfirmButton }"> <div class="van-dialog__footer" :class="{ 'is-twobtn': showCancelButton && showConfirmButton }">
<button class="van-dialog__btn van-dialog__cancel" v-show="showCancelButton" @click="handleAction('cancel')">{{ cancelButtonText }}</button> <van-button size="large" class="van-dialog__cancel" v-show="showCancelButton" @click="handleAction('cancel')">{{ cancelButtonText }}</van-button>
<button class="van-dialog__btn van-dialog__confirm" v-show="showConfirmButton" @click="handleAction('confirm')">{{ confirmButtonText }}</button> <van-button size="large" class="van-dialog__confirm" v-show="showConfirmButton" @click="handleAction('confirm')">{{ confirmButtonText }}</van-button>
</div>
</div> </div>
</div> </div>
</transition> </transition>
</template> </template>
<script> <script>
import Button from '../../button';
import Popup from '../../mixins/popup'; import Popup from '../../mixins/popup';
const CANCEL_TEXT = '取消';
const CONFIRM_TEXT = '确定';
export default { export default {
name: 'van-dialog', name: 'van-dialog',
components: {
[Button.name]: Button
},
mixins: [Popup], mixins: [Popup],
props: { props: {
@ -47,38 +45,16 @@ export default {
type: '', type: '',
showConfirmButton: true, showConfirmButton: true,
showCancelButton: false, showCancelButton: false,
confirmButtonText: CONFIRM_TEXT, confirmButtonText: '确认',
cancelButtonText: CANCEL_TEXT, cancelButtonText: '取消',
callback: null callback: null
}; };
}, },
methods: { methods: {
handleAction(action) { handleAction(action) {
this.value = false; this.$emit('input', false);
this.callback && this.callback(action); this.callback && this.callback(action);
},
close() {
/* istanbul ignore if */
if (this.closing) return;
this.closing = true;
this.value = false;
/* istanbul ignore else */
if (this.lockOnScroll) {
setTimeout(() => {
if (this.overlay && this.bodyOverflow !== 'hidden') {
document.body.style.overflow = this.bodyOverflow;
}
this.bodyOverflow = null;
}, 200);
}
this.opened = false;
this.doAfterClose();
} }
} }
}; };

View File

@ -5,17 +5,19 @@
position: fixed; position: fixed;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate3d(-50%, -50%, 0);
background-color: #fff;
width: 85%; width: 85%;
border-radius: 4px;
font-size: 16px; font-size: 16px;
overflow: hidden; overflow: hidden;
backface-visibility: hidden;
transition: .2s; transition: .2s;
border-radius: 4px;
background-color: #fff;
backface-visibility: hidden;
transform: translate3d(-50%, -50%, 0);
&__header { &__header {
padding: 15px 0 0; padding: 15px 0 0;
text-align: center;
} }
&__content { &__content {
@ -27,75 +29,50 @@
} }
} }
&__title {
text-align: center;
padding-left: 0;
margin-bottom: 0;
font-size: 16px;
color: #333;
}
&__message { &__message {
color: #999;
margin: 0;
font-size: 14px;
line-height: 1.5; line-height: 1.5;
&--notitle { &--withtitle {
color: #333; color: #999;
font-size: 16px; font-size: 14px;
} }
} }
&__footer { &__footer {
font-size: 14px;
overflow: hidden; overflow: hidden;
&.is-twobtn { &.is-twobtn {
.van-dialog__btn { .van-button {
width: 50%; width: 50%;
float: left;
} }
.van-dialog__cancel { .van-dialog__cancel {
&::after {
@mixin border-retina (right);
}
}
}
}
&__btn {
font-size: 16px;
line-height: 52px;
border: 0;
padding: 0;
background-color: #fff;
float: left;
box-sizing: border-box;
text-align: center;
position: relative; position: relative;
&::before {
@mixin border-retina (right);
left: -2px;
}
}
}
} }
&__cancel { .van-button {
color: #333; border: 0;
} }
&__confirm { &__confirm {
color: #00C000; color: #00C000;
width: 100%;
} }
&-wrapper { &-bounce-enter {
position: absolute;
}
}
.dialog-bounce-enter {
opacity: 0; opacity: 0;
transform: translate3d(-50%, -50%, 0) scale(0.7); transform: translate3d(-50%, -50%, 0) scale(0.7);
} }
.dialog-bounce-leave-active { &-bounce-leave-active {
opacity: 0; opacity: 0;
transform: translate3d(-50%, -50%, 0) scale(0.9); transform: translate3d(-50%, -50%, 0) scale(0.9);
}
} }