更改id类型为string

This commit is contained in:
2026-03-19 15:41:02 +08:00
parent bbc10ce359
commit e94204423b
14 changed files with 75 additions and 53 deletions

View File

@@ -129,7 +129,7 @@ import { getDicts } from '/@/api/system/dict/data';
import { createFormDiff } from '/@/utils/diffUtils';
interface CategoryRow {
id: number;
id: string;
name: string;
level: number;
options?: string[];
@@ -163,7 +163,7 @@ interface DictValue {
}
interface RuleForm {
id: number | '';
id: string | '';
parentId: string;
name: string;
sort: number;
@@ -324,7 +324,18 @@ const openDialog = (row?: CategoryRow | string, edit?: boolean) => {
// 获取分类树数据
getCategoryTree().then((res: any) => {
categoryData.value = res.data?.tree ?? [];
const tree = res.data?.tree ?? [];
// 递归函数将所有id字段转换为字符串
const convertIdsToString = (items: any[]): any[] => {
return items.map(item => ({
...item,
id: item.id?.toString(),
children: item.children && item.children.length > 0 ? convertIdsToString(item.children) : []
}));
};
categoryData.value = convertIdsToString(tree);
});
if (row && typeof row === 'object' && edit) {

View File

@@ -73,7 +73,7 @@ import OperationLogDialog from '../component/operationLogDialog.vue';
import { getCategoryTree, deleteCategory, updateCategoryStatus,listCategories } from '/@/api/assets/category';
interface CategoryRow {
id: number;
id: string;
name: string;
level: number;
type: string;
@@ -102,7 +102,18 @@ const getCategoryList = () => {
.then((res: any) => {
// 主类目不做展示直接取主类目的children
const tree = res.data?.tree ?? [];
tableData.data = tree.length > 0 && tree[0].children ? tree[0].children : [];
// 递归函数将所有id字段转换为字符串
const convertIdsToString = (items: any[]): any[] => {
return items.map(item => ({
...item,
id: item.id?.toString(),
children: item.children && item.children.length > 0 ? convertIdsToString(item.children) : []
}));
};
const processedTree = convertIdsToString(tree);
tableData.data = processedTree.length > 0 && processedTree[0].children ? processedTree[0].children : [];
})
.catch(() => {
tableData.data = [];