diff --git a/examples/views/docs/component/schema-page.md b/examples/views/docs/component/schema-page.md index ecbe405..3520594 100644 --- a/examples/views/docs/component/schema-page.md +++ b/examples/views/docs/component/schema-page.md @@ -365,7 +365,7 @@ export default { ::: -## 弹窗类型 +## 自定义弹窗 除了本组件内置的`new`、`edit`、`detail`三种弹出框模式之外,还可以通过任意插槽打开任意自定义弹出框。也支持重新定义原有的三种弹框,同时也需要重新自定义表单校验和提交等逻辑。 @@ -485,6 +485,115 @@ export default { ::: +## 弹窗类型 + +弹出框组件默认为`el-dialog`,使用自定义弹窗时,可以设置为`el-drawer`。 + +::: snippet 通过`openDialog`的config参数配置`is: 'el-drawer'`即可改为抽屉式弹窗,`dialog-xxx-footer`可以设置抽屉固定的footer + +```html + + + + 账单 + + + 配载 + + + {{ value }} + + + 一段很长的内容 + + + + 关闭 + + + + + 关闭弹出框 + + + + + +``` + +::: + ## 按钮权限 本组件不包含自定义业务逻辑,因此配置项不包含权限判断,如果需要按钮的权限判断,可以通过`action`插槽和`operation`插槽将渲染逻辑暴露在视图模板中,然后进行自定义判断。 diff --git a/packages/schema-page/index.scss b/packages/schema-page/index.scss index 26cf857..f9c518e 100644 --- a/packages/schema-page/index.scss +++ b/packages/schema-page/index.scss @@ -96,4 +96,30 @@ margin-top: 10px; } } +} + +.z-schema-page__drawer { + .el-drawer__header { + padding-bottom: 10px; + margin-bottom: 0; + border-bottom: 1px solid #DCDFE6; + } + .el-drawer__body { + box-sizing: border-box; + height: calc(100vh - 55px); + } + &-content { + padding: 20px; + overflow-y: auto; + } + &-footer { + height: 60px; + display: flex; + align-items: center; + justify-content: center; + box-sizing: border-box; + padding: 10px; + background: #fff; + border-top: 1px solid #DCDFE6; + } } \ No newline at end of file diff --git a/packages/schema-page/index.vue b/packages/schema-page/index.vue index 2b585eb..aba7ce5 100644 --- a/packages/schema-page/index.vue +++ b/packages/schema-page/index.vue @@ -75,19 +75,32 @@ - + + + + + + + + + + + + - + - - + + - + $emit('update:value-form', e)" @@ -107,15 +120,15 @@ - + - - + + @@ -169,10 +182,10 @@ export default { layout: get(this.schema, 'pagination.layout') || 'total, sizes, prev, pager, next, jumper', total: get(this.schema, 'pagination.total') || 0, visible: this.dialogVisible, - elDialogRender: true, - elDialogType: this.dialogType || 'none', - elDialogTitle: this.dialogTitle || '', - elDialogProps: {}, + modalRender: true, + modalType: this.dialogType || 'none', + modalTitle: this.dialogTitle || '', + modalProps: {}, detailSchema: filterout(cloneDeep(this.schema.form), ['is', 'rules']), detail: this.valueDetail || {}, tableData: this.valueTable || [], @@ -201,15 +214,15 @@ export default { this.$emit('update:dialog-visible', val); }, dialogType(val) { - this.elDialogType = val; + this.modalType = val; }, - elDialogType(val) { + modalType(val) { this.$emit('update:dialog-type', val); }, dialogTitle(val) { - this.elDialogTitle = val; + this.modalTitle = val; }, - elDialogTitle(val) { + modalTitle(val) { this.$emit('update:dialog-title', val); }, valueTable(val) { @@ -238,13 +251,41 @@ export default { }, defaultScope); }, _dialogProps() { + const { is, ...other } = this.modalProps || {}; return { - 'destroy-on-close': true, - 'append-to-body': true, + title: this.modalTitle, 'lock-scroll': false, + 'append-to-body': true, + 'destroy-on-close': true, 'close-on-click-modal': false, ...(this.schema.dialog || {}), - ...this.elDialogProps, + ...other, + }; + }, + _drawerProps() { + const { is, ...other } = this.modalProps || {}; + return { + title: this.modalTitle, + size: '50%', + 'append-to-body': true, + 'destroy-on-close': true, + 'close-on-click-modal': false, + 'custom-class': 'z-schema-page__drawer', + ...(this.schema.drawer || {}), + ...other, + }; + }, + _modalComponent() { + if (this.modalProps.is === 'el-drawer') { + return 'el-drawer'; + } + return 'el-dialog'; + }, + _modalListeners() { + return { + 'update:visible': this.onVisibleUpdate, + close: this.onDialogClose, + closed: this.onDialogClosed, }; }, }, @@ -300,12 +341,12 @@ export default { } else { this.submitting = true; let submitAPI = this.apiSubmit || this.emptyPromise; - if (this.elDialogType === 'new') { + if (this.modalType === 'new') { submitAPI = this.apiNew || this.apiSubmit || this.emptyPromise; - } else if (this.elDialogType === 'edit') { + } else if (this.modalType === 'edit') { submitAPI = this.apiEdit || this.apiSubmit || this.emptyPromise; } - submitAPI(this.valueForm, { type: this.elDialogType }) + submitAPI(this.valueForm, { type: this.modalType }) .then(() => { if (this.$listeners['submit-success']) { this.$emit('submit-success'); @@ -365,10 +406,10 @@ export default { }, // 打开弹出框 openDialog(type, title, config) { - this.elDialogRender = true; - this.elDialogType = type; - this.elDialogTitle = title; - this.elDialogProps = config || {}; + this.modalRender = true; + this.modalType = type; + this.modalTitle = title; + this.modalProps = config || {}; this.visible = true; this.$emit('dialog-change', type); }, @@ -382,7 +423,7 @@ export default { }, // 弹出框关闭 onDialogClose() { - this.elDialogType = 'none'; + this.modalType = 'none'; this.$emit('dialog-change', 'none'); }, // 弹出框关闭动画结束 @@ -390,8 +431,8 @@ export default { if (this.$refs.form) { this.$refs.form.resetFields(); } - this.elDialogRender = false; - this.elDialogProps = {}; + this.modalRender = false; + this.modalProps = {}; this.$emit('update:value-form', this.cloneDeep(this.originProps).valueForm); this.$emit('update:value-detail', this.cloneDeep(this.originProps).detailValue); }, -- libgit2 0.21.0