优化修改

This commit is contained in:
2026-05-27 11:24:51 +08:00
parent 95f020047d
commit 0d946c050e
6 changed files with 114 additions and 60 deletions

View File

@@ -32,22 +32,12 @@
<div class="table-body">
<div v-for="(attr, index) in ruleForm.attrs" :key="index" class="table-row">
<div class="col col-name">
<el-input
v-if="!isDictType(attr.type)"
v-model="attr.name"
placeholder="请输入属性名称"
clearable
/>
<el-input v-if="!isDictType(attr.type)" v-model="attr.name" placeholder="请输入属性名称" clearable />
<span v-else class="dict-name">{{ attr.name || '请选择字典' }}</span>
</div>
<div class="col col-type">
<el-select v-model="attr.type" placeholder="属性类型" class="w100" @change="onAttrTypeChange(attr)">
<el-option
v-for="item in attrTypeOptions"
:key="item.key"
:label="item.value"
:value="item.key"
/>
<el-option v-for="item in attrTypeOptions" :key="item.key" :label="item.value" :value="item.key" />
</el-select>
</div>
<div class="col col-required">
@@ -155,13 +145,6 @@ interface DictInfo {
remark: string;
}
interface DictValue {
key: string;
value: string;
isDefault: number;
remark: string;
}
interface RuleForm {
id: string | '';
parentId: string;
@@ -219,15 +202,11 @@ const fetchDictTypeOptions = () => {
.then((res: any) => {
const list = res.data?.list ?? [];
// 提取所有字典类型信息
dictTypeOptions.value = list
.map((item: any) => item.info)
.filter((info: DictInfo) => info && info.name);
dictTypeOptions.value = list.map((item: any) => item.info).filter((info: DictInfo) => info && info.name);
// 保存完整的字典数据列表包含info和values
dictValueOptions.value = list;
})
.catch((err: any) => {
dictTypeOptions.value = [];
dictValueOptions.value = [];
})
@@ -270,7 +249,9 @@ const isDictOptionDisabled = (dictName: string, currentAttr: CustomAttr) => {
const dictInfo = dictTypeOptions.value.find((item) => item.name === dictName);
const dictType = dictInfo?.type || '';
// 检查该字典是否已被其他属性使用(使用 dictType 判断)
return ruleForm.attrs.some((attr) => attr !== currentAttr && isDictType(attr.type) && (attr.dictType === dictType || (!attr.dictType && attr.name === dictName)));
return ruleForm.attrs.some(
(attr) => attr !== currentAttr && isDictType(attr.type) && (attr.dictType === dictType || (!attr.dictType && attr.name === dictName))
);
};
// 添加自定义属性
@@ -325,16 +306,16 @@ const openDialog = (row?: CategoryRow | string, edit?: boolean) => {
// 获取分类树数据
getCategoryTree().then((res: any) => {
const tree = res.data?.tree ?? [];
// 递归函数将所有id字段转换为字符串
const convertIdsToString = (items: any[]): any[] => {
return items.map(item => ({
return items.map((item) => ({
...item,
id: item.id?.toString(),
children: item.children && item.children.length > 0 ? convertIdsToString(item.children) : []
children: item.children && item.children.length > 0 ? convertIdsToString(item.children) : [],
}));
};
categoryData.value = convertIdsToString(tree);
});
@@ -472,7 +453,7 @@ const onSubmit = () => {
...submitData,
_originalData: originalData,
};
updateCategory(requestData)
.then(() => {
ElMessage.success('修改成功');