feat: 🚀 addLabelValue方法抽离

This commit is contained in:
2025-05-09 16:40:41 +08:00
parent ab003714bf
commit f2ee833412
15 changed files with 37 additions and 149 deletions

View File

@@ -88,6 +88,8 @@ import {
} from "@/api/modules/downloadClass";
//深拷贝方法
import { cloneDeep } from "lodash-es";
import { addLabelValue } from "@/utils/addLabelValue";
//表格和搜索條件
import { RULE_FORM, FORM_DATA, COLUMNS, EDIT_FORM_DATA, EDIT_RULE_FORM, RULES } from "./constant/index";
@@ -130,20 +132,6 @@ const handleSelectChangeEmits = (params: any) => {
dataStore.editRuleForm.pid = id;
};
const addLabelValue = (arr: any) => {
return arr.map((item: any) => {
// 为当前对象添加 label 和 value 属性
const newItem = { ...item };
newItem.label = newItem.name;
newItem.value = newItem.id;
// 如果有子对象,递归调用 addLabelValue 处理子对象
if (newItem.children && Array.isArray(newItem.children)) {
newItem.children = addLabelValue(newItem.children);
}
return newItem;
});
};
//分类下拉
const getCategorys = async () => {
const result = await getCategorysApi();

View File

@@ -60,6 +60,8 @@ import { Delete } from "@element-plus/icons-vue";
const $route = useRoute();
import { getCategorysApi } from "@/api/modules/downloadClass";
import { recursiveCompare } from "@/utils/recursiveCompare";
import { addLabelValue } from "@/utils/addLabelValue";
//深拷贝方法
import { cloneDeep } from "lodash-es";
import {
@@ -220,19 +222,6 @@ const handleEditAdd = () => {
file_ext: "" //文件格式
});
};
// const recursiveCompare = (item: any, targetId: any) => {
// if (typeof item === "object" && item !== null) {
// if (item.value !== undefined && item.value === targetId) {
// return true;
// }
// for (const key in item) {
// if (recursiveCompare(item[key], targetId)) {
// return true;
// }
// }
// }
// return false;
// };
//详情
const getAttachmentRead = async () => {
@@ -264,21 +253,6 @@ const handleSelectChangeEmits = (value: any) => {
}
};
const addLabelValue = (arr: any) => {
return arr.map((item: any) => {
// 为当前对象添加 label 和 value 属性
const newItem = { ...item };
newItem.label = newItem.name;
newItem.value = newItem.id;
// 如果有子对象,递归调用 addLabelValue 处理子对象
if (newItem.children && Array.isArray(newItem.children)) {
newItem.children = addLabelValue(newItem.children);
}
return newItem;
});
};
//分类
const getCategorys = async () => {
const result = await getCategorysApi({ is_show: 1 });

View File

@@ -40,6 +40,8 @@ import { getCategorysApi } from "@/api/modules/downloadClass";
import { integerRexg } from "@/utils/regexp/index";
import { messageBox } from "@/utils/messageBox";
import { useMsg } from "@/hooks/useMsg";
import { addLabelValue } from "@/utils/addLabelValue";
//深拷贝方法
import { cloneDeep } from "lodash-es";
//表格和搜索條件 FORM_DATA
@@ -151,21 +153,6 @@ const handleInput = (row: any) => {
row.sort = integerRexg(row.sort);
};
const addLabelValue = (arr: any) => {
return arr.map((item: any) => {
// 为当前对象添加 label 和 value 属性
const newItem = { ...item };
newItem.label = newItem.name;
newItem.value = newItem.id;
// 如果有子对象,递归调用 addLabelValue 处理子对象
if (newItem.children && Array.isArray(newItem.children)) {
newItem.children = addLabelValue(newItem.children);
}
return newItem;
});
};
const getCategorys = async () => {
const result = await getCategorysApi();