feat: 🚀 banner添加相关分类
This commit is contained in:
@@ -159,6 +159,7 @@
|
||||
show-checkbox
|
||||
check-strictly
|
||||
@change="handleSelectChange(_ruleForm[`${item.prop}`], item.prop)"
|
||||
style="max-width: 240px"
|
||||
/>
|
||||
</template>
|
||||
<template v-if="item.type === 'treeSelects'">
|
||||
|
||||
@@ -78,6 +78,14 @@ export const EDIT_FORM_DATA: FormItem[] = [
|
||||
label: "Banner分类: ",
|
||||
options: []
|
||||
},
|
||||
{
|
||||
prop: "rel_prod_cate_id",
|
||||
placeholder: "请选择",
|
||||
type: "treeSelect",
|
||||
label: "相关分类: ",
|
||||
options: []
|
||||
},
|
||||
|
||||
{
|
||||
prop: "sort",
|
||||
placeholder: "请输入",
|
||||
|
||||
@@ -84,6 +84,7 @@ import { messageBox } from "@/utils/messageBox";
|
||||
import { useMsg } from "@/hooks/useMsg";
|
||||
import { useExport } from "@/hooks/useExport";
|
||||
import { integerRexg } from "@/utils/regexp/index";
|
||||
import { getProductCategoryListApi } from "@/api/modules/productList";
|
||||
// 图片地址
|
||||
import { h } from "@/utils/url";
|
||||
// 列表接口
|
||||
@@ -131,6 +132,28 @@ 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();
|
||||
if (result?.code === 0) {
|
||||
let dataClone: any = cloneDeep(result?.data);
|
||||
dataStore.editFormData[6].options = addLabelValue(dataClone);
|
||||
}
|
||||
};
|
||||
|
||||
const buildTree = (data: any, outerLinkTo: any = "") => {
|
||||
return data.map((item: any) => {
|
||||
@@ -152,24 +175,18 @@ const buildTree = (data: any, outerLinkTo: any = "") => {
|
||||
};
|
||||
// let isFirstRequest = true;
|
||||
const handleRadioGroupEmits = (value: any) => {
|
||||
// if (value !== "video" || value !== "image") {
|
||||
// return;
|
||||
// }
|
||||
if (value === "video") {
|
||||
dataStore.editFormData = EDIT_FORM_DATA1;
|
||||
dataStore.rules = RULES1;
|
||||
getBannerClassEditList();
|
||||
}
|
||||
// getBannerClassList();
|
||||
|
||||
if (value === "image") {
|
||||
dataStore.isFirstRequest = true;
|
||||
dataStore.editFormData = EDIT_FORM_DATA;
|
||||
dataStore.rules = RULES;
|
||||
getBannerClassEditList();
|
||||
}
|
||||
|
||||
// console.log(value, "==========value==========");
|
||||
// getBannerClassEditList();
|
||||
};
|
||||
|
||||
const getSystemUrls = async (node: any, resolve: any) => {
|
||||
@@ -201,7 +218,8 @@ const getSystemUrls = async (node: any, resolve: any) => {
|
||||
const setImgOrVideo = () => {
|
||||
if (dataStore.editRuleForm.type === "image") {
|
||||
dataStore.editFormData = EDIT_FORM_DATA;
|
||||
} else {
|
||||
}
|
||||
if (dataStore.editRuleForm.type === "video") {
|
||||
dataStore.editFormData = EDIT_FORM_DATA1;
|
||||
}
|
||||
getBannerClassEditList();
|
||||
@@ -214,6 +232,7 @@ const getBannerRead = async (id: any) => {
|
||||
if (result?.code === 0) {
|
||||
dataStore.editRuleForm = result?.data;
|
||||
setImgOrVideo();
|
||||
getProductCategoryList();
|
||||
if (dataStore.editRuleForm.link && dataStore.editRuleForm.link_to) {
|
||||
let { id, name, link } = dataStore.editRuleForm.link_echo_data;
|
||||
if (!id || !name || !link) {
|
||||
@@ -262,20 +281,6 @@ const getBannerUp = async () => {
|
||||
dataStore.isFirstRequest = true;
|
||||
}
|
||||
};
|
||||
|
||||
// 分类
|
||||
const getBannerClassList = async () => {
|
||||
const result = await getBannerClassListApi();
|
||||
if (result?.code === 0) {
|
||||
let arr: any = [];
|
||||
result?.data?.forEach((item: any) => {
|
||||
arr.push({ value: item.id, label: item.name });
|
||||
});
|
||||
dataStore.formData[1].options = arr;
|
||||
// dataStore.editFormData[4].options = arr;
|
||||
}
|
||||
};
|
||||
getBannerClassList();
|
||||
//详情里的分类
|
||||
const getBannerClassEditList = async () => {
|
||||
const result = await getBannerClassListApi();
|
||||
@@ -284,10 +289,11 @@ const getBannerClassEditList = async () => {
|
||||
result?.data?.forEach((item: any) => {
|
||||
arr.push({ value: item.id, label: item.name });
|
||||
});
|
||||
dataStore.formData[1].options = arr;
|
||||
dataStore.editFormData[5].options = arr;
|
||||
}
|
||||
};
|
||||
|
||||
getBannerClassEditList();
|
||||
// 新增
|
||||
const getBannerListSave = async () => {
|
||||
const result = await getBannerListSaveApi(dataStore.editRuleForm);
|
||||
@@ -343,6 +349,8 @@ const handleAdd = () => {
|
||||
dataStore.title = "添加Banner";
|
||||
dataStore.visible = true;
|
||||
getBannerClassEditList();
|
||||
// getBannerClassList();
|
||||
getProductCategoryList();
|
||||
};
|
||||
// 抽屉关闭前的钩子
|
||||
const handleBeforeClone = () => {
|
||||
|
||||
Reference in New Issue
Block a user