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"]; ElBreadcrumb: typeof import("element-plus/es")["ElBreadcrumb"];
ElBreadcrumbItem: typeof import("element-plus/es")["ElBreadcrumbItem"]; ElBreadcrumbItem: typeof import("element-plus/es")["ElBreadcrumbItem"];
ElButton: typeof import("element-plus/es")["ElButton"]; 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"]; ElContainer: typeof import("element-plus/es")["ElContainer"];
ElDatePicker: typeof import("element-plus/es")["ElDatePicker"]; ElDatePicker: typeof import("element-plus/es")["ElDatePicker"];
ElDialog: typeof import("element-plus/es")["ElDialog"]; 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"]; ElDropdown: typeof import("element-plus/es")["ElDropdown"];
ElDropdownItem: typeof import("element-plus/es")["ElDropdownItem"]; ElDropdownItem: typeof import("element-plus/es")["ElDropdownItem"];
ElDropdownMenu: typeof import("element-plus/es")["ElDropdownMenu"]; ElDropdownMenu: typeof import("element-plus/es")["ElDropdownMenu"];
@@ -27,19 +34,28 @@ declare module "vue" {
ElFormItem: typeof import("element-plus/es")["ElFormItem"]; ElFormItem: typeof import("element-plus/es")["ElFormItem"];
ElHeader: typeof import("element-plus/es")["ElHeader"]; ElHeader: typeof import("element-plus/es")["ElHeader"];
ElIcon: typeof import("element-plus/es")["ElIcon"]; ElIcon: typeof import("element-plus/es")["ElIcon"];
ElImage: typeof import("element-plus/es")["ElImage"];
ElInput: typeof import("element-plus/es")["ElInput"]; ElInput: typeof import("element-plus/es")["ElInput"];
ElInputNumber: typeof import("element-plus/es")["ElInputNumber"]; ElInputNumber: typeof import("element-plus/es")["ElInputNumber"];
ElMain: typeof import("element-plus/es")["ElMain"]; ElMain: typeof import("element-plus/es")["ElMain"];
ElMenu: typeof import("element-plus/es")["ElMenu"]; ElMenu: typeof import("element-plus/es")["ElMenu"];
ElMenuItem: typeof import("element-plus/es")["ElMenuItem"]; ElMenuItem: typeof import("element-plus/es")["ElMenuItem"];
ElOption: typeof import("element-plus/es")["ElOption"]; ElOption: typeof import("element-plus/es")["ElOption"];
ElPagination: typeof import("element-plus/es")["ElPagination"];
ElRadio: typeof import("element-plus/es")["ElRadio"]; ElRadio: typeof import("element-plus/es")["ElRadio"];
ElRadioButton: typeof import("element-plus/es")["ElRadioButton"];
ElRadioGroup: typeof import("element-plus/es")["ElRadioGroup"]; ElRadioGroup: typeof import("element-plus/es")["ElRadioGroup"];
ElScrollbar: typeof import("element-plus/es")["ElScrollbar"]; ElScrollbar: typeof import("element-plus/es")["ElScrollbar"];
ElSelect: typeof import("element-plus/es")["ElSelect"]; ElSelect: typeof import("element-plus/es")["ElSelect"];
ElSubMenu: typeof import("element-plus/es")["ElSubMenu"]; 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"]; ElTabPane: typeof import("element-plus/es")["ElTabPane"];
ElTabs: typeof import("element-plus/es")["ElTabs"]; 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"]; ElTreeSelect: typeof import("element-plus/es")["ElTreeSelect"];
ElUpload: typeof import("element-plus/es")["ElUpload"]; ElUpload: typeof import("element-plus/es")["ElUpload"];
Empty: typeof import("./components/ProTable/components/Empty.vue")["default"]; Empty: typeof import("./components/ProTable/components/Empty.vue")["default"];

View File

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

View File

@@ -83,7 +83,7 @@
<script setup lang="ts" name="articleClassListIndex"> <script setup lang="ts" name="articleClassListIndex">
import rulesForm from "@/components/rulesForm/index.vue"; import rulesForm from "@/components/rulesForm/index.vue";
import { integerRexg } from "@/utils/regexp/index"; import { integerRexg } from "@/utils/regexp/index";
import { addLabelValue } from "@/utils/addLabelValue";
import { h } from "@/utils/url"; import { h } from "@/utils/url";
// import ProTable from "@/components/ProTable/index.vue"; // import ProTable from "@/components/ProTable/index.vue";
import { messageBox } from "@/utils/messageBox"; import { messageBox } from "@/utils/messageBox";
@@ -146,21 +146,6 @@ const reset = () => {
getArticleClassList(); 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 handleSelectChangeEmits = (params: any) => {
const { id } = params; const { id } = params;
dataStore.editRuleForm.pid = id; 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 { EDIT_FORM_DATA, EDIT_RULE_FORM, RULES } from "./constant/index";
import { ref, reactive } from "vue"; import { ref, reactive } from "vue";
import { addLabelValue } from "@/utils/addLabelValue";
import { cloneDeep } from "lodash-es"; import { cloneDeep } from "lodash-es";
import { useMsg } from "@/hooks/useMsg"; import { useMsg } from "@/hooks/useMsg";
const formRef = ref<any>(null); const formRef = ref<any>(null);
@@ -55,20 +55,6 @@ const dataStore = reactive<any>({
editFormData: cloneDeep(EDIT_FORM_DATA) //抽屉表单配置项 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 getArticleClassData = async () => {
const result = await getArticleClassDataApi({ is_show: 1 }); const result = await getArticleClassDataApi({ is_show: 1 });

View File

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

View File

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

View File

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

View File

@@ -88,6 +88,8 @@ import {
} from "@/api/modules/downloadClass"; } from "@/api/modules/downloadClass";
//深拷贝方法 //深拷贝方法
import { cloneDeep } from "lodash-es"; 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"; 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; 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 getCategorys = async () => {
const result = await getCategorysApi(); const result = await getCategorysApi();

View File

@@ -60,6 +60,8 @@ import { Delete } from "@element-plus/icons-vue";
const $route = useRoute(); const $route = useRoute();
import { getCategorysApi } from "@/api/modules/downloadClass"; import { getCategorysApi } from "@/api/modules/downloadClass";
import { recursiveCompare } from "@/utils/recursiveCompare"; import { recursiveCompare } from "@/utils/recursiveCompare";
import { addLabelValue } from "@/utils/addLabelValue";
//深拷贝方法 //深拷贝方法
import { cloneDeep } from "lodash-es"; import { cloneDeep } from "lodash-es";
import { import {
@@ -220,19 +222,6 @@ const handleEditAdd = () => {
file_ext: "" //文件格式 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 () => { 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 getCategorys = async () => {
const result = await getCategorysApi({ is_show: 1 }); 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 { integerRexg } from "@/utils/regexp/index";
import { messageBox } from "@/utils/messageBox"; import { messageBox } from "@/utils/messageBox";
import { useMsg } from "@/hooks/useMsg"; import { useMsg } from "@/hooks/useMsg";
import { addLabelValue } from "@/utils/addLabelValue";
//深拷贝方法 //深拷贝方法
import { cloneDeep } from "lodash-es"; import { cloneDeep } from "lodash-es";
//表格和搜索條件 FORM_DATA //表格和搜索條件 FORM_DATA
@@ -151,21 +153,6 @@ const handleInput = (row: any) => {
row.sort = integerRexg(row.sort); 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 getCategorys = async () => {
const result = await getCategorysApi(); const result = await getCategorysApi();

View File

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

View File

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

View File

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

View File

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