update dialog

This commit is contained in:
lb 2022-08-08 16:51:49 +08:00
parent a150905840
commit 32dd90969a
2 changed files with 70 additions and 4 deletions

View File

@ -1,14 +1,64 @@
<template> <template>
<el-dialog :title="isDetail ? '详情' : !dataForm.id ? '新增' : '修改'" :visible.sync="visible" @close="handleClose"> </el-dialog> <el-dialog :title="isDetail ? title.detail : !dataForm.id ? title.add : title.edit" :visible.sync="visible" @close="handleClose">
<el-form>
<!-- 如果需要更精细一点的布局可以根据配置项实现地再复杂一点但此处暂时全部采用一行两列布局 -->
</el-form>
<span slot="footer" class="dialog-footer">
<el-button v-for="(operate, index) in configs.operations" :key="`operate-${index}`" :type="btnType[operate.name]" @click="handleClick(operate)">
<!-- {{ operate.name | btnNameFilter }} -->
{{ btnName[operate.name] }}
</el-button>
</span>
</el-dialog>
</template> </template>
<script> <script>
// for i18n
const title = {
detail: '详情',
add: '新增',
edit: '编辑'
}
//
const btnType = {
save: 'success',
update: 'primary',
reset: 'text'
// add more...
}
const btnName = {
// for i18n
save: '保存',
update: '更新',
reset: '重置'
// add more...
}
//
const COLUMN_PER_ROW = 2
export default { export default {
name: 'AddOrUpdateDialog', name: 'AddOrUpdateDialog',
props: {
configs: {
/**
* type: 'dialog' | 'drawer' | 'page'
* fields: Array<string|object>
* - fields.object: { name, type: 'number'|'textarea'|'select'|'date'|.., required: boolean, validator: boolean(是否需要验证), [options]: any[], api: string(自动获取数据的接口一般为getcode接口)}
* operations: Array[object], 操作名和对应的接口地址
*/
type: Object,
default: () => ({}) // 使
}
},
data() { data() {
return { return {
title,
btnName,
btnType,
visible: false, visible: false,
isEdit: false, isEdit: false,
isDetail: false, isDetail: false,
@ -16,6 +66,12 @@ export default {
isUpdated: false isUpdated: false
} }
}, },
computed: {
rows() {
// ''
return Math.ceil(this.configs.fields.length / COLUMN_PER_ROW)
}
},
updated() { updated() {
this.isUpdated = true // emit(refreshDataList) this.isUpdated = true // emit(refreshDataList)
}, },
@ -35,6 +91,16 @@ export default {
init() { init() {
this.visible = true this.visible = true
}, },
handleClick(btn) {
switch (btn.name) {
case 'save':
break
case 'update':
break
case 'reset':
break
}
},
handleClose() { handleClose() {
if (this.isAdd || this.isUpdated) this.$emit('refreshDataList') if (this.isAdd || this.isUpdated) this.$emit('refreshDataList')
this.visible = false this.visible = false

View File

@ -127,9 +127,9 @@ const addOrUpdateConfigs = {
} }
], ],
operations: [ operations: [
{ add: 'api/product/add' }, { name: 'save', url: 'api/product/add' },
{ update: 'api/product/update' }, { name: 'update', url: 'api/product/update' },
{ reset: true } { name: 'reset', url: true }
] ]
} }