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

16
src/components.d.ts vendored
View File

@@ -17,9 +17,16 @@ declare module "vue" {
ElBreadcrumb: typeof import("element-plus/es")["ElBreadcrumb"];
ElBreadcrumbItem: typeof import("element-plus/es")["ElBreadcrumbItem"];
ElButton: typeof import("element-plus/es")["ElButton"];
ElCarousel: typeof import("element-plus/es")["ElCarousel"];
ElCarouselItem: typeof import("element-plus/es")["ElCarouselItem"];
ElCheckbox: typeof import("element-plus/es")["ElCheckbox"];
ElCheckboxGroup: typeof import("element-plus/es")["ElCheckboxGroup"];
ElColorPicker: typeof import("element-plus/es")["ElColorPicker"];
ElContainer: typeof import("element-plus/es")["ElContainer"];
ElDatePicker: typeof import("element-plus/es")["ElDatePicker"];
ElDialog: typeof import("element-plus/es")["ElDialog"];
ElDivider: typeof import("element-plus/es")["ElDivider"];
ElDrawer: typeof import("element-plus/es")["ElDrawer"];
ElDropdown: typeof import("element-plus/es")["ElDropdown"];
ElDropdownItem: typeof import("element-plus/es")["ElDropdownItem"];
ElDropdownMenu: typeof import("element-plus/es")["ElDropdownMenu"];
@@ -27,19 +34,28 @@ declare module "vue" {
ElFormItem: typeof import("element-plus/es")["ElFormItem"];
ElHeader: typeof import("element-plus/es")["ElHeader"];
ElIcon: typeof import("element-plus/es")["ElIcon"];
ElImage: typeof import("element-plus/es")["ElImage"];
ElInput: typeof import("element-plus/es")["ElInput"];
ElInputNumber: typeof import("element-plus/es")["ElInputNumber"];
ElMain: typeof import("element-plus/es")["ElMain"];
ElMenu: typeof import("element-plus/es")["ElMenu"];
ElMenuItem: typeof import("element-plus/es")["ElMenuItem"];
ElOption: typeof import("element-plus/es")["ElOption"];
ElPagination: typeof import("element-plus/es")["ElPagination"];
ElRadio: typeof import("element-plus/es")["ElRadio"];
ElRadioButton: typeof import("element-plus/es")["ElRadioButton"];
ElRadioGroup: typeof import("element-plus/es")["ElRadioGroup"];
ElScrollbar: typeof import("element-plus/es")["ElScrollbar"];
ElSelect: typeof import("element-plus/es")["ElSelect"];
ElSubMenu: typeof import("element-plus/es")["ElSubMenu"];
ElSwitch: typeof import("element-plus/es")["ElSwitch"];
ElTable: typeof import("element-plus/es")["ElTable"];
ElTableColumn: typeof import("element-plus/es")["ElTableColumn"];
ElTabPane: typeof import("element-plus/es")["ElTabPane"];
ElTabs: typeof import("element-plus/es")["ElTabs"];
ElTag: typeof import("element-plus/es")["ElTag"];
ElTooltip: typeof import("element-plus/es")["ElTooltip"];
ElTree: typeof import("element-plus/es")["ElTree"];
ElTreeSelect: typeof import("element-plus/es")["ElTreeSelect"];
ElUpload: typeof import("element-plus/es")["ElUpload"];
Empty: typeof import("./components/ProTable/components/Empty.vue")["default"];

View File

@@ -20,7 +20,7 @@
<el-tab-pane label="问答详细" name="third">
<div style="width: 1280px; margin: 0 auto">
<Editor v-model:value="dataStore.editRuleForm.answer" />
<Editor v-model:content="dataStore.editRuleForm.answer" />
</div>
</el-tab-pane>
</el-tabs>

View File

@@ -83,7 +83,7 @@
<script setup lang="ts" name="articleClassListIndex">
import rulesForm from "@/components/rulesForm/index.vue";
import { integerRexg } from "@/utils/regexp/index";
import { addLabelValue } from "@/utils/addLabelValue";
import { h } from "@/utils/url";
// import ProTable from "@/components/ProTable/index.vue";
import { messageBox } from "@/utils/messageBox";
@@ -146,21 +146,6 @@ const reset = () => {
getArticleClassList();
};
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 handleSelectChangeEmits = (params: any) => {
const { id } = params;
dataStore.editRuleForm.pid = id;

View File

@@ -41,7 +41,7 @@ import { recursiveCompare } from "@/utils/recursiveCompare";
import { EDIT_FORM_DATA, EDIT_RULE_FORM, RULES } from "./constant/index";
import { ref, reactive } from "vue";
import { addLabelValue } from "@/utils/addLabelValue";
import { cloneDeep } from "lodash-es";
import { useMsg } from "@/hooks/useMsg";
const formRef = ref<any>(null);
@@ -55,20 +55,6 @@ const dataStore = reactive<any>({
editFormData: cloneDeep(EDIT_FORM_DATA) //抽屉表单配置项
});
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 getArticleClassData = async () => {
const result = await getArticleClassDataApi({ is_show: 1 });

View File

@@ -43,6 +43,9 @@ import {
import { cloneDeep } from "lodash-es";
//表格和搜索條件
import { RULE_FORM, FORM_DATA, COLUMNS } from "./constant/index";
import { addLabelValue } from "@/utils/addLabelValue";
//图片地址
import { h } from "@/utils/url";
// 获取 ProTable 元素,调用其获取刷新数据方法(还能获取到当前查询参数,方便导出携带参数)
@@ -57,20 +60,7 @@ const dataStore = reactive<any>({
formData: FORM_DATA, //搜索配置项
selectRow: {} //当前选择的row
});
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 getArticleClassData = async () => {
const result = await getArticleClassDataApi();

View File

@@ -27,7 +27,7 @@
import ProTable from "@/components/ProTable/index.vue";
import { messageBox } from "@/utils/messageBox";
import { useMsg } from "@/hooks/useMsg";
import { addLabelValue } from "@/utils/addLabelValue";
import { h } from "@/utils/url";
//列表接口
import { getArticleTrashListApi, getArticleTrashDelApi, getArticleTrashRestoreApi } from "@/api/modules/articleRecycle";
@@ -66,20 +66,7 @@ const getArticleTrashDel = (id: 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 getArticleClassData = async () => {
const result = await getArticleClassDataApi();

View File

@@ -98,7 +98,8 @@ import {
getBannerListExportApi,
getBannerClassListApi
} from "@/api/modules/banner";
// import { getBannerClassListApi } from "@/api/modules/bannerClass";
import { addLabelValue } from "@/utils/addLabelValue";
import { getSystemUrlsApi } from "@/api/modules/home";
// 深拷贝方法
import { cloneDeep } from "lodash-es";
@@ -132,20 +133,7 @@ const treeProps = {
label: "label",
value: "value"
};
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 getProductCategoryList = async () => {
const result = await getProductCategoryListApi();

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();

View File

@@ -100,7 +100,7 @@ import {
getArticleCategorySortApi,
getProductClassTcoTreeApi
} from "@/api/modules/productClass";
import { addLabelValue } from "../list/utils/common/addLabelValue";
import { addLabelValue } from "@/utils/addLabelValue";
import { useMsg } from "@/hooks/useMsg";

View File

@@ -16,7 +16,7 @@
</el-tab-pane>
<el-tab-pane label="产品详情" name="third">
<div style="width: 1280px; margin: 0 auto">
<Editor v-model:value="dataStore.detail" />
<Editor v-model:content="dataStore.detail" />
</div>
</el-tab-pane>
<el-tab-pane label="相关信息" name="related">
@@ -56,7 +56,8 @@ import { messageBox } from "@/utils/messageBox";
import { useMsg } from "@/hooks/useMsg";
import { handleSubmit, handleReset, initDetailParams } from "./utils/edit/index";
import { addLabelValue } from "./utils/common/addLabelValue";
import { addLabelValue } from "@/utils/addLabelValue";
//组件引入
import basicInfo from "./components/basicInfo.vue";
import imgInfo from "./components/imgInfo.vue";

View File

@@ -63,7 +63,7 @@ import {
getProductCategoryListApi
} from "@/api/modules/productList";
// import { getProductCategoryListApi } from "@/api/modules/productClass";
import { addLabelValue } from "./utils/common/addLabelValue";
import { addLabelValue } from "@/utils/addLabelValue";
//深拷贝方法
import { cloneDeep } from "lodash-es";
@@ -153,4 +153,3 @@ const handleBtnClick = (type: any, row: any) => {
</script>
<style scoped></style>
./utils/common/addLabelValue

View File

@@ -37,6 +37,7 @@ import { useMsg } from "@/hooks/useMsg";
import { getProductCategoryListApi } from "@/api/modules/productClass";
// 获取 ProTable 元素,调用其获取刷新数据方法(还能获取到当前查询参数,方便导出携带参数)
const proTableRef = ref<any>(null);
import { addLabelValue } from "@/utils/addLabelValue";
// 数据源
const dataStore = reactive<any>({
@@ -75,20 +76,6 @@ const handleBtnClick = (type: any, row: 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 getProductCategoryList = async () => {
const result = await getProductCategoryListApi({ page: 1, size: 500 });