mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 19:09:20 +08:00
fix(ecom-dmb): 商品类目选择器改为 TreeSelect 支持选择任意层级节点
This commit is contained in:
+9
-7
@@ -13,9 +13,9 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
InputNumber,
|
InputNumber,
|
||||||
message,
|
message,
|
||||||
Select,
|
|
||||||
Space,
|
Space,
|
||||||
Table,
|
Table,
|
||||||
|
TreeSelect,
|
||||||
} from 'ant-design-vue';
|
} from 'ant-design-vue';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ import {
|
|||||||
getProductSpecsByIdsApi,
|
getProductSpecsByIdsApi,
|
||||||
} from '#/api/ecommerce/product-spec/apis';
|
} from '#/api/ecommerce/product-spec/apis';
|
||||||
import type { ProductSpecVO } from '#/api/ecommerce/product-spec/types';
|
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';
|
import { uploadFileToOss } from '#/utils/oss-upload';
|
||||||
|
|
||||||
interface Emits {
|
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>>([]);
|
const specs = ref<Array<ProductDTO.Spec | ProductDTO.UpdateSpec>>([]);
|
||||||
@@ -310,8 +310,8 @@ async function open(
|
|||||||
|
|
||||||
// 加载类目选项
|
// 加载类目选项
|
||||||
try {
|
try {
|
||||||
const list = await getCategoryListApi();
|
const list = await getCategoryTreeApi();
|
||||||
categoryOptions.value = (list ?? []).map((c) => ({ label: c.name, value: c.id }));
|
categoryOptions.value = list ?? [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载类目列表失败:', error);
|
console.error('加载类目列表失败:', error);
|
||||||
}
|
}
|
||||||
@@ -690,11 +690,13 @@ onUnmounted(() => {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item label="商品类目" name="categoryId">
|
<Form.Item label="商品类目" name="categoryId">
|
||||||
<Select
|
<TreeSelect
|
||||||
v-model:value="formData.categoryId"
|
v-model:value="formData.categoryId"
|
||||||
placeholder="请选择商品类目"
|
placeholder="请选择商品类目"
|
||||||
:options="[{ label: '(未分类)', value: undefined }, ...categoryOptions]"
|
:tree-data="categoryOptions"
|
||||||
|
:field-names="{ label: 'name', value: 'id', children: 'children' }"
|
||||||
allow-clear
|
allow-clear
|
||||||
|
tree-default-expand-all
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
Reference in New Issue
Block a user