@befly-addon/admin 1.1.32 → 1.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@befly-addon/admin",
3
- "version": "1.1.32",
3
+ "version": "1.1.33",
4
4
  "private": false,
5
5
  "description": "Befly - 管理后台功能组件",
6
6
  "keywords": [
@@ -65,6 +65,6 @@
65
65
  "access": "public",
66
66
  "registry": "https://registry.npmjs.org"
67
67
  },
68
- "gitHead": "0ba53d2bbdc6a7f2659ef60256cda7302fe585b0",
68
+ "gitHead": "cd0f2c4451d6ec5ead541735e6ee086611a5b3f4",
69
69
  "title": "管理后台"
70
70
  }
@@ -44,6 +44,7 @@ import { Button as TButton, Table as TTable, Tag as TTag, MessagePlugin } from "
44
44
  import ILucideRotateCw from "~icons/lucide/rotate-cw";
45
45
  import DetailPanel from "@/components/DetailPanel.vue";
46
46
  import { $Http } from "@/plugins/http";
47
+ import { arrayToTree } from "befly-vite/utils/arrayToTree";
47
48
  import { withDefaultColumns } from "befly-vite/utils/withDefaultColumns";
48
49
 
49
50
  definePage({
@@ -58,7 +59,7 @@ const $Data = $ref({
58
59
  tableData: [],
59
60
  loading: false,
60
61
  columns: withDefaultColumns([
61
- { colKey: "name", title: "菜单名称", fixed: "left" },
62
+ { colKey: "name", title: "菜单名称" },
62
63
  { colKey: "id", title: "序号" },
63
64
  { colKey: "path", title: "路由路径" },
64
65
  { colKey: "icon", title: "图标" },
@@ -79,9 +80,11 @@ const $Method = {
79
80
  async apiMenuList() {
80
81
  $Data.loading = true;
81
82
  try {
82
- const res = await $Http("/addon/admin/menu/list");
83
+ const res = await $Http("/addon/admin/menu/all");
84
+ const lists = Array.isArray(res?.data?.lists) ? res.data.lists : [];
85
+
83
86
  // 构建树形结构
84
- $Data.tableData = $Method.buildTree(res.data || []);
87
+ $Data.tableData = arrayToTree(lists);
85
88
 
86
89
  // 自动高亮第一行
87
90
  if ($Data.tableData.length > 0) {
@@ -98,43 +101,6 @@ const $Method = {
98
101
  }
99
102
  },
100
103
 
101
- // 构建树形结构
102
- buildTree(list) {
103
- const map = {};
104
- const roots = [];
105
-
106
- // 先创建所有节点的映射
107
- for (const item of list) {
108
- map[item.id] = { ...item, children: [] };
109
- }
110
-
111
- // 构建树形结构
112
- for (const item of list) {
113
- const node = map[item.id];
114
- if (item.pid === 0) {
115
- roots.push(node);
116
- } else if (map[item.pid]) {
117
- map[item.pid].children.push(node);
118
- } else {
119
- roots.push(node);
120
- }
121
- }
122
-
123
- // 移除空的 children 数组
124
- const removeEmptyChildren = (nodes) => {
125
- for (const node of nodes) {
126
- if (node.children.length === 0) {
127
- delete node.children;
128
- } else {
129
- removeEmptyChildren(node.children);
130
- }
131
- }
132
- };
133
- removeEmptyChildren(roots);
134
-
135
- return roots;
136
- },
137
-
138
104
  // 刷新
139
105
  handleRefresh() {
140
106
  $Method.apiMenuList();
@@ -59,9 +59,8 @@ const $Method = {
59
59
  async apiMenuAll() {
60
60
  try {
61
61
  const res = await $Http("/addon/admin/menu/all");
62
- // menuAll 返回的 data 直接就是菜单数组
63
- const menuList = Array.isArray(res.data) ? res.data : [];
64
- $Data.menuTreeData = arrayToTree(menuList);
62
+ const lists = Array.isArray(res?.data?.lists) ? res.data.lists : [];
63
+ $Data.menuTreeData = arrayToTree(lists);
65
64
  } catch (error) {
66
65
  MessagePlugin.error("加载菜单失败");
67
66
  }