import { createNamespace, addUnit } from '../utils'; import { BORDER_TOP, BORDER_LEFT } from '../utils/constant'; import { PopupMixin } from '../mixins/popup'; import Button from '../button'; import GoodsAction from '../goods-action'; import GoodsActionButton from '../goods-action-button'; const [createComponent, bem, t] = createNamespace('dialog'); export default createComponent({ mixins: [PopupMixin()], props: { title: String, theme: String, width: [Number, String], message: String, className: null, callback: Function, beforeClose: Function, messageAlign: String, cancelButtonText: String, cancelButtonColor: String, confirmButtonText: String, confirmButtonColor: String, showCancelButton: Boolean, overlay: { type: Boolean, default: true, }, allowHtml: { type: Boolean, default: true, }, transition: { type: String, default: 'van-dialog-bounce', }, showConfirmButton: { type: Boolean, default: true, }, closeOnPopstate: { type: Boolean, default: true, }, closeOnClickOverlay: { type: Boolean, default: false, }, }, data() { return { loading: { confirm: false, cancel: false, }, }; }, methods: { onClickOverlay() { this.handleAction('overlay'); }, handleAction(action) { this.$emit(action); // show not trigger close event when hidden if (!this.value) { return; } if (this.beforeClose) { this.loading[action] = true; this.beforeClose(action, (state) => { if (state !== false && this.loading[action]) { this.onClose(action); } this.loading.confirm = false; this.loading.cancel = false; }); } else { this.onClose(action); } }, onClose(action) { this.close(); if (this.callback) { this.callback(action); } }, onOpened() { this.$emit('opened'); }, onClosed() { this.$emit('closed'); }, genRoundButtons() { return ( {this.showCancelButton && ( { this.handleAction('cancel'); }} /> )} {this.showConfirmButton && ( { this.handleAction('confirm'); }} /> )} ); }, genButtons() { const multiple = this.showCancelButton && this.showConfirmButton; return (
{this.showCancelButton && (
); }, genContent(hasTitle, messageSlot) { if (messageSlot) { return
{messageSlot}
; } const { message, messageAlign } = this; if (message) { const data = { class: bem('message', { 'has-title': hasTitle, [messageAlign]: messageAlign, }), domProps: { [this.allowHtml ? 'innerHTML' : 'textContent']: message, }, }; return (
); } }, }, render() { if (!this.shouldRender) { return; } const { message } = this; const messageSlot = this.slots(); const title = this.slots('title') || this.title; const Title = title && (
{title}
); return ( ); }, });