@befly-addon/admin 1.0.26 → 1.0.28

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.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Befly - 管理后台功能组件",
5
5
  "type": "module",
6
6
  "private": false,
@@ -18,8 +18,9 @@
18
18
  "apis/",
19
19
  "tables/",
20
20
  "views/",
21
+ "utils/",
22
+ "types/",
21
23
  "addon.config.json",
22
- "util.ts",
23
24
  "README.md",
24
25
  "package.json",
25
26
  "menu.json"
@@ -39,7 +40,7 @@
39
40
  "url": "https://github.com/chenbimo/befly.git",
40
41
  "directory": "packages/addon-admin"
41
42
  },
42
- "gitHead": "ca96814c3b67376809086cd8bef8e7816b736483",
43
+ "gitHead": "62797bf96f317ff0e666db73b4edac4435a6ed35",
43
44
  "dependencies": {
44
45
  "befly": "3.8.12"
45
46
  }
@@ -0,0 +1,12 @@
1
+ import type { RouteRecordRaw, Component } from 'vue-router';
2
+
3
+ /**
4
+ * 布局配置接口
5
+ */
6
+ export interface LayoutConfig {
7
+ path: string;
8
+ layoutName: string;
9
+ component: Component;
10
+ children?: LayoutConfig[];
11
+ meta?: Record<string, any>;
12
+ }
@@ -1,15 +1,5 @@
1
- import type { RouteRecordRaw, Component } from 'vue-router';
2
-
3
- /**
4
- * 布局配置接口
5
- */
6
- export interface LayoutConfig {
7
- path: string;
8
- layoutName: string;
9
- component: Component;
10
- children?: LayoutConfig[];
11
- meta?: Record<string, any>;
12
- }
1
+ import type { RouteRecordRaw } from 'vue-router';
2
+ import type { LayoutConfig } from '../types/layout';
13
3
 
14
4
  /**
15
5
  * 自定义布局处理函数
@@ -28,18 +18,21 @@ export function Layouts(routes: RouteRecordRaw[], inheritLayout = ''): LayoutCon
28
18
  const pathMatch = currentPath.match(/_(\d+)$/);
29
19
  const currentLayout = pathMatch ? pathMatch[1] : inheritLayout;
30
20
 
31
- // 如果有子路由,递归处理(传递当前布局给子级)
21
+ // 如果有子路由,说明这是中间节点(目录),不包裹布局,只递归处理子路由
32
22
  if (route.children && route.children.length > 0) {
33
23
  // 清理路径:如果是 xxx_数字 格式,去掉 _数字
34
24
  const cleanPath = pathMatch ? currentPath.replace(/_\d+$/, '') : currentPath;
35
25
 
36
- result.push({
37
- path: cleanPath,
38
- layoutName: currentLayout || 'default',
39
- component: route.component!,
40
- children: Layouts(route.children, currentLayout),
41
- meta: route.meta
42
- });
26
+ // 直接递归处理子路由,不添加当前层级到结果
27
+ const childConfigs = Layouts(route.children, currentLayout);
28
+
29
+ // 将子路由的路径前缀加上当前路径
30
+ for (const child of childConfigs) {
31
+ result.push({
32
+ ...child,
33
+ path: cleanPath ? `${cleanPath}/${child.path}`.replace(/\/+/g, '/') : child.path
34
+ });
35
+ }
43
36
  continue;
44
37
  }
45
38
 
@@ -0,0 +1,43 @@
1
+ import { readdirSync, existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ /**
5
+ * 扫描所有 @befly-addon 包的 views 目录
6
+ * 用于 unplugin-vue-router 的 routesFolder 配置
7
+ * 注意:此函数只能在 vite.config.ts 中使用(Node.js 环境),不能在浏览器中使用
8
+ * @returns 路由文件夹配置数组
9
+ */
10
+ export function scanBeflyAddonViews() {
11
+ // 使用绝对路径:基于项目根目录(process.cwd())
12
+ const projectRoot = process.cwd();
13
+ const addonBasePath = join(projectRoot, 'node_modules', '@befly-addon');
14
+ const routesFolders: Array<{ src: string; path: string }> = [];
15
+
16
+ if (!existsSync(addonBasePath)) {
17
+ return routesFolders;
18
+ }
19
+
20
+ try {
21
+ const addonDirs = readdirSync(addonBasePath);
22
+
23
+ for (const addonName of addonDirs) {
24
+ const addonPath = join(addonBasePath, addonName);
25
+
26
+ // 检查是否为目录(包括符号链接)
27
+ if (!existsSync(addonPath)) continue;
28
+
29
+ const viewsPath = join(addonPath, 'views');
30
+
31
+ if (existsSync(viewsPath)) {
32
+ routesFolders.push({
33
+ src: viewsPath,
34
+ path: `addon/${addonName}/`
35
+ });
36
+ }
37
+ }
38
+ } catch (error) {
39
+ console.error('扫描 @befly-addon 目录失败:', error);
40
+ }
41
+
42
+ return routesFolders;
43
+ }