From f5fa296f79beae3b7092a547075636d285750db5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=88=98=E6=B2=B3=E5=B9=B3?=
<14767849+liuehping@user.noreply.gitee.com>
Date: Fri, 15 Nov 2024 21:42:08 +0800
Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=93=81=E7=B1=BB=E6=B2=A1?=
=?UTF-8?q?=E6=9C=89=E5=B1=95=E7=A4=BA=E7=88=B6=E7=BA=A7=E5=93=81=E7=B1=BB?=
=?UTF-8?q?=E7=9A=84=E4=BF=A1=E6=81=AF=EF=BC=8C=E9=9C=80=E8=A6=81=E6=90=BA?=
=?UTF-8?q?=E5=B8=A6=E6=9F=A5=E8=AF=A2=E7=88=B6=E7=BA=A7=E5=93=81=E7=B1=BB?=
=?UTF-8?q?=E7=9A=84=E5=90=8D=E7=A7=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/product/category/index.vue | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/views/product/category/index.vue b/src/views/product/category/index.vue
index a7c0b48..0c03fe8 100644
--- a/src/views/product/category/index.vue
+++ b/src/views/product/category/index.vue
@@ -68,7 +68,7 @@
-
+
@@ -263,7 +263,21 @@ export default {
getList() {
this.loading = true;
listCategory(this.queryParams).then(response => {
- this.categoryList = this.handleTree(response.data, "id", "parentId");
+ const idToName = response.data.reduce((acc, node) => {
+ acc[node.id] = node.name;
+ return acc;
+ }, {});
+ console.log(idToName);
+ const updatedTreeData = response.data.map(node => {
+ // 如果 parentId 为 null,说明没有父节点,不需要替换
+ const parentName = node.parentId !== null ? idToName[node.parentId] : null;
+ console.log(parentName);
+ return {
+ ...node,
+ parentIds: parentName
+ };
+ });
+ this.categoryList = this.handleTree(updatedTreeData, "id", "parentId");
this.loading = false;
});
},