import { createNamespace, addUnit } from '../utils'; import { BORDER_TOP, BORDER_LEFT } from '../utils/constant'; import Popup from '../popup'; import Button from '../button'; import ActionBar from '../action-bar'; import ActionBarButton from '../action-bar-button'; const [createComponent, bem, t] = createNamespace('dialog'); export default createComponent({ props: { show: Boolean, title: String, theme: String, width: [Number, String], message: String, className: null, callback: Function, lazyRender: Boolean, 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, }, }, emits: ['opened', 'closed', 'confirm', 'cancel', 'update:show'], 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.show) { 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.$emit('update:show', false); 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) { if (this.$slots.default) { return
{this.$slots.default()}
; } const { message, messageAlign } = this; if (message) { const data = { class: bem('message', { 'has-title': hasTitle, [messageAlign]: messageAlign, }), [this.allowHtml ? 'innerHTML' : 'textContent']: message, }; return (
); } }, }, render() { const { message } = this; const title = this.$slots.title ? this.$slots.title() : this.title; const Title = title && (
{title}
); return ( {Title} {this.genContent(title)} {this.theme === 'round-button' ? this.genRoundButtons() : this.genButtons()} ); }, });