import { reactive } from 'vue'; // Utils import { callInterceptor } from '../utils/interceptor'; import { createNamespace, addUnit, pick } from '../utils'; import { BORDER_TOP, BORDER_LEFT } from '../utils/constant'; // Components import Popup, { popupSharedProps } from '../popup'; import Button from '../button'; import ActionBar from '../action-bar'; import ActionBarButton from '../action-bar-button'; const [createComponent, bem, t] = createNamespace('dialog'); const popupKeys = [ ...Object.keys(popupSharedProps), 'transition', 'closeOnPopstate', ]; export default createComponent({ props: { ...popupSharedProps, title: String, theme: String, width: [Number, String], message: String, callback: Function, allowHtml: Boolean, className: null, beforeClose: Function, messageAlign: String, showCancelButton: Boolean, cancelButtonText: String, cancelButtonColor: String, confirmButtonText: String, confirmButtonColor: String, closeOnClickOverlay: Boolean, transition: { type: String, default: 'van-dialog-bounce', }, showConfirmButton: { type: Boolean, default: true, }, closeOnPopstate: { type: Boolean, default: true, }, }, emits: ['confirm', 'cancel', 'update:show'], setup(props, { emit, slots }) { const loading = reactive({ confirm: false, cancel: false, }); const onUpdateShow = (value) => { emit('update:show', value); }; const close = (action) => { onUpdateShow(false); if (props.callback) { props.callback(action); } }; const handleAction = (action) => { // should not trigger close event when hidden if (!props.show) { return; } emit(action); if (props.beforeClose) { loading[action] = true; callInterceptor({ interceptor: props.beforeClose, args: [action], done() { close(action); loading[action] = false; }, canceled() { loading[action] = false; }, }); } else { close(action); } }; const renderTitle = () => { const title = slots.title ? slots.title() : props.title; if (title) { return (