update dialog

This commit is contained in:
lb 2022-08-08 16:51:49 +08:00
förälder a150905840
incheckning 32dd90969a
2 ändrade filer med 70 tillägg och 4 borttagningar

Visa fil

@ -1,14 +1,64 @@
<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>
<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 {
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() {
return {
title,
btnName,
btnType,
visible: false,
isEdit: false,
isDetail: false,
@ -16,6 +66,12 @@ export default {
isUpdated: false
}
},
computed: {
rows() {
// ''
return Math.ceil(this.configs.fields.length / COLUMN_PER_ROW)
}
},
updated() {
this.isUpdated = true // emit(refreshDataList)
},
@ -35,6 +91,16 @@ export default {
init() {
this.visible = true
},
handleClick(btn) {
switch (btn.name) {
case 'save':
break
case 'update':
break
case 'reset':
break
}
},
handleClose() {
if (this.isAdd || this.isUpdated) this.$emit('refreshDataList')
this.visible = false

Visa fil

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