import { createNamespace } from '../utils'; import { BORDER_TOP, BORDER_LEFT } from '../utils/constant'; import { PopupMixin } from '../mixins/popup'; import { CloseOnPopstateMixin } from '../mixins/close-on-popstate'; import Button from '../button'; const [createComponent, bem, t] = createNamespace('dialog'); export default createComponent({ mixins: [PopupMixin, CloseOnPopstateMixin], props: { title: String, message: String, className: null, callback: Function, beforeClose: Function, messageAlign: String, cancelButtonText: String, cancelButtonColor: String, confirmButtonText: String, confirmButtonColor: String, showCancelButton: Boolean, showConfirmButton: { type: Boolean, default: true }, overlay: { 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); if (this.beforeClose) { this.loading[action] = true; this.beforeClose(action, state => { if (state !== false) { this.onClose(action); } this.loading[action] = false; }); } else { this.onClose(action); } }, onClose(action) { this.close(); if (this.callback) { this.callback(action); } } }, render() { if (!this.shouldRender) { return; } const { message, messageAlign } = this; const messageSlot = this.slots(); const title = this.slots('title') || this.title; const Title = title && (
{title}
); const Content = (messageSlot || message) && (
{messageSlot || (
)}
); const hasButtons = this.showCancelButton && this.showConfirmButton; const ButtonGroup = (
{this.showCancelButton && (
); return ( ); } });