微调
This commit is contained in:
@@ -33,8 +33,8 @@
|
||||
import { addDictTree, updateDictTree } from '@/api/system/dictionary/dictTree'
|
||||
import { computed, type Ref, ref } from 'vue';
|
||||
import { useDictStore } from '@/stores/modules/dict'
|
||||
import { type ResultData } from '@/api/interface';
|
||||
const dictStore = useDictStore()
|
||||
const selectedStatMethods = ref<string[]>([])
|
||||
// 定义弹出组件元信息
|
||||
const dialogFormRef = ref()
|
||||
function useMetaInfo() {
|
||||
@@ -48,7 +48,7 @@
|
||||
code: ' ',
|
||||
sort: 100,
|
||||
remark: '',
|
||||
status: 1,
|
||||
state: 0,
|
||||
children: [],
|
||||
})
|
||||
return { dialogVisible, titleType, formContent }
|
||||
@@ -59,13 +59,13 @@
|
||||
const resetFormContent = () => {
|
||||
formContent.value = {
|
||||
id: '',
|
||||
pid: '',
|
||||
pids: '',
|
||||
pid: '0',
|
||||
pids: '0',
|
||||
name: '',
|
||||
code: ' ',
|
||||
sort: 100,
|
||||
remark: '',
|
||||
status: 1,
|
||||
state: 0,
|
||||
children: [],
|
||||
}
|
||||
}
|
||||
@@ -76,8 +76,8 @@
|
||||
|
||||
// 定义表单校验规则
|
||||
const rules: Ref<Record<string, Array<FormItemRule>>> = ref({
|
||||
dataType: [{ required: true, message: '数据模型必选!', trigger: 'change' }],
|
||||
name: [{ required: true, message: '指标名称必填!', trigger: 'blur' }],
|
||||
name: [{ required: true, message: '字典名称必填!', trigger: 'blur' }],
|
||||
code: [{ required: true, message: '编码必填!', trigger: 'blur' }],
|
||||
})
|
||||
|
||||
// 关闭弹窗
|
||||
@@ -87,7 +87,6 @@
|
||||
resetFormContent()
|
||||
// 重置表单
|
||||
dialogFormRef.value?.resetFields()
|
||||
selectedStatMethods.value = []
|
||||
}
|
||||
|
||||
// 保存数据
|
||||
@@ -96,13 +95,18 @@
|
||||
dialogFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
if (formContent.value.id) {
|
||||
const result = await updateDictTree(formContent.value);
|
||||
let result: ResultData<unknown>;
|
||||
if( titleType.value == 'add'){
|
||||
result = await addDictTree(formContent.value);
|
||||
}else{
|
||||
result = await updateDictTree(formContent.value);
|
||||
}
|
||||
|
||||
if(result.code != 'A0000'){
|
||||
ElMessage.error({ message: result.message})
|
||||
}else{
|
||||
ElMessage.success({ message: `${dialogTitle.value}成功!` })
|
||||
}
|
||||
|
||||
} else {
|
||||
const result = await addDictTree(formContent.value);
|
||||
if(result.code != 'A0000'){
|
||||
@@ -126,7 +130,12 @@
|
||||
titleType.value = sign
|
||||
dialogVisible.value = true
|
||||
if (data.id) {
|
||||
formContent.value = { ...data }
|
||||
if(sign == 'add'){
|
||||
resetFormContent()
|
||||
formContent.value.pid = data.id
|
||||
}else{
|
||||
formContent.value = { ...data }
|
||||
}
|
||||
} else {
|
||||
resetFormContent()
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
ref='proTable'
|
||||
:columns='columns'
|
||||
:request-api='getDictTreeList'
|
||||
:pagination="false"
|
||||
>
|
||||
<template #tableHeader>
|
||||
<el-button type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
|
||||
</template>
|
||||
|
||||
<template #operation='scope'>
|
||||
<el-button type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
|
||||
<el-button type='primary' link :icon='CirclePlus' @click="openDialog('add',scope.row)">新增</el-button>
|
||||
<el-button type='primary' link :icon='EditPen' @click="openDialog('edit', scope.row)">编辑</el-button>
|
||||
<el-button type='primary' link :icon='Delete' @click='handleDelete(scope.row)'>删除</el-button>
|
||||
</template>
|
||||
@@ -41,42 +42,49 @@
|
||||
{
|
||||
prop: 'name',
|
||||
label: '字典名称',
|
||||
width: 180,
|
||||
|
||||
},
|
||||
{
|
||||
prop: 'code',
|
||||
label: '编码',
|
||||
width: 180,
|
||||
|
||||
},
|
||||
{
|
||||
prop: 'remark',
|
||||
label: '描述',
|
||||
width: 180,
|
||||
|
||||
},
|
||||
{
|
||||
prop: 'status',
|
||||
prop: 'state',
|
||||
label: '状态',
|
||||
width: 180,
|
||||
minWidth:30,
|
||||
enum: dictStore.getDictData('state'),
|
||||
fieldNames: { label: 'label', value: 'code' },
|
||||
render: scope => {
|
||||
return (
|
||||
<el-tag type={scope.row.state === 0 ? 'success' : (scope.row.state === 1 ? 'warning' : 'danger')}>
|
||||
{scope.row.state === 0 ? '正常' : (scope.row.state === 1 ? '停用' : '删除')}
|
||||
</el-tag>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
fixed: 'right',
|
||||
minWidth: 200,
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
// 打开 drawer(新增、编辑)
|
||||
const openDialog = (titleType: string, row: Partial<Dict.ResDictTree> = {}) => {
|
||||
treePopup.value?.open(titleType, row)
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 删除字典类型
|
||||
const handleDelete = async (params: Dict.ResDictTree) => {
|
||||
await useHandleData(deleteDictTree, [params.id], `删除【${params.name}】树形字典类型`)
|
||||
console.log(params)
|
||||
await useHandleData(deleteDictTree, params, `删除【${params.name}】树形字典类型`)
|
||||
proTable.value?.getTableList()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user