优化分类属性管理,移除description字段,统一使用name字段存储属性名称和字典类型
This commit is contained in:
@@ -355,7 +355,6 @@ interface CategoryAttr {
|
|||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
options?: { label: string; value: string }[];
|
options?: { label: string; value: string }[];
|
||||||
description?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RuleForm {
|
interface RuleForm {
|
||||||
@@ -411,12 +410,12 @@ const isTimeSlotLimitReached = computed(() => ruleForm.serviceAssetConfig.schedu
|
|||||||
|
|
||||||
// 获取属性的key
|
// 获取属性的key
|
||||||
const getAttrKey = (attr: CategoryAttr): string => {
|
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 => {
|
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)) {
|
if (data?.attrs && Array.isArray(data.attrs)) {
|
||||||
categoryAttrs.value = data.attrs;
|
categoryAttrs.value = data.attrs;
|
||||||
// 初始化属性值,确保 boolean 类型默认为 false
|
// 初始化属性值,确保 boolean 类型默认为 false
|
||||||
data.attrs.forEach((attr: CategoryAttr) => {
|
categoryAttrs.value.forEach((attr: CategoryAttr) => {
|
||||||
const key = getAttrKey(attr);
|
const key = getAttrKey(attr);
|
||||||
if (attr.type === 'boolean') {
|
if (attr.type === 'boolean') {
|
||||||
ruleForm.metadata[key] = false;
|
ruleForm.metadata[key] = false;
|
||||||
@@ -789,7 +788,7 @@ const openDialog = (row?: any, edit?: boolean) => {
|
|||||||
if (catData?.attrs && Array.isArray(catData.attrs)) {
|
if (catData?.attrs && Array.isArray(catData.attrs)) {
|
||||||
categoryAttrs.value = catData.attrs;
|
categoryAttrs.value = catData.attrs;
|
||||||
// 初始化属性值,确保 boolean 类型默认为 false
|
// 初始化属性值,确保 boolean 类型默认为 false
|
||||||
catData.attrs.forEach((attr: CategoryAttr) => {
|
categoryAttrs.value.forEach((attr: CategoryAttr) => {
|
||||||
const key = getAttrKey(attr);
|
const key = getAttrKey(attr);
|
||||||
if (attr.type === 'boolean' && ruleForm.metadata[key] === undefined) {
|
if (attr.type === 'boolean' && ruleForm.metadata[key] === undefined) {
|
||||||
ruleForm.metadata[key] = false;
|
ruleForm.metadata[key] = false;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
<el-table-column label="操作" width="200" fixed="right" align="center">
|
<el-table-column label="操作" width="200" fixed="right" align="center">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button size="small" text type="primary" @click="onEdit(scope.row)">修改</el-button>
|
<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>
|
<el-button size="small" text type="danger" @click="onRowDel(scope.row)">删除</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
placeholder="请输入属性名称"
|
placeholder="请输入属性名称"
|
||||||
clearable
|
clearable
|
||||||
/>
|
/>
|
||||||
<span v-else class="dict-name">{{ attr.description || '请选择字典' }}</span>
|
<span v-else class="dict-name">{{ attr.name || '请选择字典' }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-type">
|
<div class="col col-type">
|
||||||
<el-select v-model="attr.type" placeholder="属性类型" class="w100" @change="onAttrTypeChange(attr)">
|
<el-select v-model="attr.type" placeholder="属性类型" class="w100" @change="onAttrTypeChange(attr)">
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col col-dict">
|
<div class="col col-dict">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="attr.description"
|
v-model="attr.name"
|
||||||
placeholder="选择字典"
|
placeholder="选择字典"
|
||||||
class="w100"
|
class="w100"
|
||||||
:disabled="!isDictType(attr.type)"
|
:disabled="!isDictType(attr.type)"
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col col-dict-value">
|
<div class="col col-dict-value">
|
||||||
<el-select
|
<el-select
|
||||||
v-if="isDictType(attr.type) && attr.description"
|
v-if="isDictType(attr.type) && attr.name"
|
||||||
v-model="attr.options"
|
v-model="attr.options"
|
||||||
multiple
|
multiple
|
||||||
placeholder="选择字典值"
|
placeholder="选择字典值"
|
||||||
@@ -79,7 +79,7 @@
|
|||||||
:max-collapse-tags="2"
|
:max-collapse-tags="2"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="(item, idx) in getDictValuesByType(attr.description)"
|
v-for="(item, idx) in getDictValuesByType(attr.name)"
|
||||||
:key="idx"
|
:key="idx"
|
||||||
:label="item.value"
|
:label="item.value"
|
||||||
:value="item.key"
|
:value="item.key"
|
||||||
@@ -126,8 +126,7 @@ interface CategoryRow {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
level: number;
|
level: number;
|
||||||
type: string;
|
options?: string[];
|
||||||
status: string;
|
|
||||||
sort?: number;
|
sort?: number;
|
||||||
children?: CategoryRow[] | null;
|
children?: CategoryRow[] | null;
|
||||||
}
|
}
|
||||||
@@ -138,7 +137,6 @@ interface CustomAttr {
|
|||||||
required?: boolean;
|
required?: boolean;
|
||||||
multiple?: boolean;
|
multiple?: boolean;
|
||||||
options?: string[];
|
options?: string[];
|
||||||
description?: string;
|
|
||||||
sort?: number;
|
sort?: number;
|
||||||
dictKey?: string;
|
dictKey?: string;
|
||||||
dictValues?: string[];
|
dictValues?: string[];
|
||||||
@@ -254,7 +252,6 @@ const addAttr = () => {
|
|||||||
ruleForm.attrs.push({
|
ruleForm.attrs.push({
|
||||||
name: '',
|
name: '',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
description: '',
|
|
||||||
options: [],
|
options: [],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -271,10 +268,10 @@ const onAttrTypeChange = (attr: CustomAttr) => {
|
|||||||
if (dictTypeOptions.value.length === 0) {
|
if (dictTypeOptions.value.length === 0) {
|
||||||
fetchDictTypeOptions();
|
fetchDictTypeOptions();
|
||||||
}
|
}
|
||||||
attr.description = '';
|
attr.name = '';
|
||||||
attr.options = [];
|
attr.options = [];
|
||||||
} else {
|
} else {
|
||||||
attr.description = '';
|
attr.name = '';
|
||||||
attr.options = [];
|
attr.options = [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -364,7 +361,7 @@ const formatDictOptions = (attr: CustomAttr) => {
|
|||||||
value: opt.value ?? opt.key ?? '',
|
value: opt.value ?? opt.key ?? '',
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
const dictValues = getDictValuesByType(attr.description || '');
|
const dictValues = getDictValuesByType(attr.name || '');
|
||||||
return options.map((optValue: string) => {
|
return options.map((optValue: string) => {
|
||||||
const dictItem = dictValues.find((d: any) => d.key === optValue);
|
const dictItem = dictValues.find((d: any) => d.key === optValue);
|
||||||
return {
|
return {
|
||||||
@@ -383,7 +380,6 @@ const onSubmit = () => {
|
|||||||
const processedAttrs = ruleForm.attrs.map((attr) => {
|
const processedAttrs = ruleForm.attrs.map((attr) => {
|
||||||
const base = {
|
const base = {
|
||||||
type: attr.type,
|
type: attr.type,
|
||||||
description: attr.description || '',
|
|
||||||
required: attr.required ?? false,
|
required: attr.required ?? false,
|
||||||
multiple: attr.type === 'multi_select',
|
multiple: attr.type === 'multi_select',
|
||||||
sort: attr.sort ?? 0,
|
sort: attr.sort ?? 0,
|
||||||
@@ -392,7 +388,7 @@ const onSubmit = () => {
|
|||||||
if (isDictType(attr.type)) {
|
if (isDictType(attr.type)) {
|
||||||
return {
|
return {
|
||||||
...base,
|
...base,
|
||||||
name: '',
|
name: attr.name || '',
|
||||||
options: formatDictOptions(attr),
|
options: formatDictOptions(attr),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user