diff --git a/packages/dialog/Dialog.js b/packages/dialog/Dialog.js new file mode 100644 index 000000000..fb9e9962c --- /dev/null +++ b/packages/dialog/Dialog.js @@ -0,0 +1,124 @@ +import { use } from '../utils'; +import Button from '../button'; +import Popup from '../mixins/popup'; + +const [sfc, bem, t] = use('dialog'); + +export default sfc({ + mixins: [Popup], + + props: { + title: String, + message: String, + callback: Function, + className: [String, Object, Array], + beforeClose: Function, + messageAlign: String, + confirmButtonText: String, + cancelButtonText: 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: { + handleAction(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.$emit('input', false); + this.$emit(action); + this.callback && this.callback(action); + } + }, + + render(h) { + if (!this.shouldRender) { + return; + } + + const { title, message, messageAlign } = this; + const children = this.$slots.default; + + const Title = title && ( +
{title}
+ ); + + const Content = (children || message) && ( +
+ {children || ( +
+ )} +
+ ); + + const hasButtons = this.showCancelButton && this.showConfirmButton; + const ButtonGroup = ( +
+
+ ); + + return ( + +
+ {Title} + {Content} + {ButtonGroup} +
+
+ ); + } +}); diff --git a/packages/dialog/Dialog.vue b/packages/dialog/Dialog.vue deleted file mode 100644 index 9f8b6c58a..000000000 --- a/packages/dialog/Dialog.vue +++ /dev/null @@ -1,119 +0,0 @@ - - - diff --git a/packages/dialog/test/__snapshots__/demo.spec.js.snap b/packages/dialog/test/__snapshots__/demo.spec.js.snap index 34fa60f02..b634a3097 100644 --- a/packages/dialog/test/__snapshots__/demo.spec.js.snap +++ b/packages/dialog/test/__snapshots__/demo.spec.js.snap @@ -14,7 +14,6 @@ exports[`renders demo correctly 1`] = ` 高级用法 - +