fix(ecom-dmb): 商品类目选择器改为 TreeSelect 支持选择任意层级节点

This commit is contained in:
小蟑螂
2026-04-17 17:42:57 +08:00
parent 99efd576ee
commit 834f244814
@@ -13,9 +13,9 @@ import {
Input,
InputNumber,
message,
Select,
Space,
Table,
TreeSelect,
} from 'ant-design-vue';
import dayjs from 'dayjs';
@@ -25,7 +25,7 @@ import {
getProductSpecsByIdsApi,
} from '#/api/ecommerce/product-spec/apis';
import type { ProductSpecVO } from '#/api/ecommerce/product-spec/types';
import { getCategoryListApi } from '#/api/ecommerce/category';
import { getCategoryTreeApi } from '#/api/ecommerce/category';
import { uploadFileToOss } from '#/utils/oss-upload';
interface Emits {
@@ -134,7 +134,7 @@ const formData = ref({
});
// 类目选项列表
const categoryOptions = ref<{ label: string; value: number }[]>([]);
const categoryOptions = ref<any[]>([]);
// 规格数据 - 支持创建和更新
const specs = ref<Array<ProductDTO.Spec | ProductDTO.UpdateSpec>>([]);
@@ -310,8 +310,8 @@ async function open(
// 加载类目选项
try {
const list = await getCategoryListApi();
categoryOptions.value = (list ?? []).map((c) => ({ label: c.name, value: c.id }));
const list = await getCategoryTreeApi();
categoryOptions.value = list ?? [];
} catch (error) {
console.error('加载类目列表失败:', error);
}
@@ -690,11 +690,13 @@ onUnmounted(() => {
</Form.Item>
<Form.Item label="商品类目" name="categoryId">
<Select
<TreeSelect
v-model:value="formData.categoryId"
placeholder="请选择商品类目"
:options="[{ label: '(未分类)', value: undefined }, ...categoryOptions]"
:tree-data="categoryOptions"
:field-names="{ label: 'name', value: 'id', children: 'children' }"
allow-clear
tree-default-expand-all
style="width: 100%"
/>
</Form.Item>