优化分类属性管理,移除description字段,统一使用name字段存储属性名称和字典类型

This commit is contained in:
WUSIJIAN
2025-12-23 16:55:31 +08:00
parent 95da8576bc
commit b910584019
3 changed files with 14 additions and 19 deletions

View File

@@ -355,7 +355,6 @@ interface CategoryAttr {
name: string;
type: string;
options?: { label: string; value: string }[];
description?: string;
}
interface RuleForm {
@@ -411,12 +410,12 @@ const isTimeSlotLimitReached = computed(() => ruleForm.serviceAssetConfig.schedu
// 获取属性的key
const getAttrKey = (attr: CategoryAttr): string => {
return attr.name || attr.description || `attr_${categoryAttrs.value.indexOf(attr)}`;
return attr.name || `attr_${categoryAttrs.value.indexOf(attr)}`;
};
// 获取属性的显示名称
const getAttrLabel = (attr: CategoryAttr): string => {
return attr.description || attr.name || '属性';
return attr.name || '属性';
};
// 图片相关
@@ -692,7 +691,7 @@ const onCategoryChange = (categoryId: string) => {
if (data?.attrs && Array.isArray(data.attrs)) {
categoryAttrs.value = data.attrs;
// 初始化属性值,确保 boolean 类型默认为 false
data.attrs.forEach((attr: CategoryAttr) => {
categoryAttrs.value.forEach((attr: CategoryAttr) => {
const key = getAttrKey(attr);
if (attr.type === 'boolean') {
ruleForm.metadata[key] = false;
@@ -789,7 +788,7 @@ const openDialog = (row?: any, edit?: boolean) => {
if (catData?.attrs && Array.isArray(catData.attrs)) {
categoryAttrs.value = catData.attrs;
// 初始化属性值,确保 boolean 类型默认为 false
catData.attrs.forEach((attr: CategoryAttr) => {
categoryAttrs.value.forEach((attr: CategoryAttr) => {
const key = getAttrKey(attr);
if (attr.type === 'boolean' && ruleForm.metadata[key] === undefined) {
ruleForm.metadata[key] = false;

View File

@@ -64,7 +64,7 @@
<el-table-column label="操作" width="200" fixed="right" align="center">
<template #default="scope">
<el-button size="small" text type="primary" @click="onEdit(scope.row)">修改</el-button>
<el-button size="small" text type="success" @click="onAddSku(scope.row)">添加SKU</el-button>
<el-button size="small" text type="success" @click="onAddSku(scope.row)">管理SKU</el-button>
<el-button size="small" text type="danger" @click="onRowDel(scope.row)">删除</el-button>
</template>
</el-table-column>

View File

@@ -37,7 +37,7 @@
placeholder="请输入属性名称"
clearable
/>
<span v-else class="dict-name">{{ attr.description || '请选择字典' }}</span>
<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)">
@@ -51,7 +51,7 @@
</div>
<div class="col col-dict">
<el-select
v-model="attr.description"
v-model="attr.name"
placeholder="选择字典"
class="w100"
:disabled="!isDictType(attr.type)"
@@ -69,7 +69,7 @@
</div>
<div class="col col-dict-value">
<el-select
v-if="isDictType(attr.type) && attr.description"
v-if="isDictType(attr.type) && attr.name"
v-model="attr.options"
multiple
placeholder="选择字典值"
@@ -79,7 +79,7 @@
:max-collapse-tags="2"
>
<el-option
v-for="(item, idx) in getDictValuesByType(attr.description)"
v-for="(item, idx) in getDictValuesByType(attr.name)"
:key="idx"
:label="item.value"
:value="item.key"
@@ -126,8 +126,7 @@ interface CategoryRow {
id: string;
name: string;
level: number;
type: string;
status: string;
options?: string[];
sort?: number;
children?: CategoryRow[] | null;
}
@@ -138,7 +137,6 @@ interface CustomAttr {
required?: boolean;
multiple?: boolean;
options?: string[];
description?: string;
sort?: number;
dictKey?: string;
dictValues?: string[];
@@ -254,7 +252,6 @@ const addAttr = () => {
ruleForm.attrs.push({
name: '',
type: 'text',
description: '',
options: [],
});
};
@@ -271,10 +268,10 @@ const onAttrTypeChange = (attr: CustomAttr) => {
if (dictTypeOptions.value.length === 0) {
fetchDictTypeOptions();
}
attr.description = '';
attr.name = '';
attr.options = [];
} else {
attr.description = '';
attr.name = '';
attr.options = [];
}
};
@@ -364,7 +361,7 @@ const formatDictOptions = (attr: CustomAttr) => {
value: opt.value ?? opt.key ?? '',
}));
}
const dictValues = getDictValuesByType(attr.description || '');
const dictValues = getDictValuesByType(attr.name || '');
return options.map((optValue: string) => {
const dictItem = dictValues.find((d: any) => d.key === optValue);
return {
@@ -383,7 +380,6 @@ const onSubmit = () => {
const processedAttrs = ruleForm.attrs.map((attr) => {
const base = {
type: attr.type,
description: attr.description || '',
required: attr.required ?? false,
multiple: attr.type === 'multi_select',
sort: attr.sort ?? 0,
@@ -392,7 +388,7 @@ const onSubmit = () => {
if (isDictType(attr.type)) {
return {
...base,
name: '',
name: attr.name || '',
options: formatDictOptions(attr),
};
}