befly-admin 3.11.0 → 3.11.2

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,7 +1,7 @@
1
1
  {
2
2
  "name": "befly-admin",
3
- "version": "3.11.0",
4
- "gitHead": "3a9dc64d2eb69e646f4fd6eebd5d8dbe6516cb69",
3
+ "version": "3.11.2",
4
+ "gitHead": "325a7282e0f03b55b77188d4b17f2ad9bd1eb6fd",
5
5
  "private": false,
6
6
  "description": "Befly Admin - 基于 Vue3 + TDesign Vue Next 的后台管理系统",
7
7
  "files": [
@@ -28,10 +28,11 @@
28
28
  "preview": "vite preview"
29
29
  },
30
30
  "dependencies": {
31
- "@befly-addon/admin": "^1.7.0",
32
- "@iconify-json/lucide": "^1.2.83",
31
+ "@befly-addon/admin": "^1.7.2",
32
+ "@iconify-json/lucide": "^1.2.85",
33
33
  "axios": "^1.13.2",
34
- "befly-vite": "^1.4.4",
34
+ "befly-shared": "1.4.2",
35
+ "befly-vite": "^1.4.5",
35
36
  "pinia": "^3.0.4",
36
37
  "tdesign-vue-next": "^1.18.0",
37
38
  "unplugin-vue-router": "^0.19.2",
@@ -76,7 +76,7 @@
76
76
 
77
77
  <script setup lang="ts">
78
78
  import { DialogPlugin } from "tdesign-vue-next";
79
- import { arrayToTree } from "@/utils/arrayToTree";
79
+ import { arrayToTree } from "befly-shared/utils/arrayToTree";
80
80
 
81
81
  const router = useRouter();
82
82
  const route = useRoute();
@@ -1,7 +1,6 @@
1
1
  import axios, { AxiosHeaders, type AxiosRequestConfig, type AxiosResponse, type InternalAxiosRequestConfig } from "axios";
2
+ import { cleanParams } from "befly-shared/utils/cleanParams";
2
3
 
3
- import { cleanParams } from "../utils/cleanParams";
4
- import { getViteEnvString } from "../utils/getViteEnvString";
5
4
  import { $Storage } from "./storage";
6
5
 
7
6
  export type HttpApiResponse<TData> = {
@@ -104,7 +103,7 @@ async function unwrapApiResponse<TData>(promise: Promise<AxiosResponse<HttpApiRe
104
103
 
105
104
  // 创建 axios 实例
106
105
  const request = axios.create({
107
- baseURL: getViteEnvString("VITE_API_BASE_URL") || "",
106
+ baseURL: (import.meta as unknown as { env?: Record<string, string> }).env?.VITE_API_BASE_URL || "",
108
107
  timeout: 10000,
109
108
  headers: {
110
109
  "Content-Type": "application/json"
@@ -3,10 +3,8 @@
3
3
  * 支持命名空间隔离,统一管理 localStorage 和 sessionStorage
4
4
  */
5
5
 
6
- import { getViteEnvString } from "../utils/getViteEnvString";
7
-
8
6
  // 获取命名空间
9
- const NAMESPACE = getViteEnvString("VITE_STORAGE_NAMESPACE") || "befly";
7
+ const NAMESPACE = (import.meta as unknown as { env?: Record<string, string> }).env?.VITE_STORAGE_NAMESPACE || "befly";
10
8
 
11
9
  class MemoryStorage implements Storage {
12
10
  private map: Map<string, string>;
@@ -14,8 +14,8 @@ declare global {
14
14
  const EffectScope: typeof import('vue').EffectScope
15
15
  const MessagePlugin: typeof import('tdesign-vue-next').MessagePlugin
16
16
  const acceptHMRUpdate: typeof import('pinia').acceptHMRUpdate
17
- const arrayToTree: typeof import('../utils/arrayToTree').arrayToTree
18
- const cleanParams: typeof import('../utils/cleanParams').cleanParams
17
+ const arrayToTree: typeof import('befly-shared/utils/arrayToTree').arrayToTree
18
+ const cleanParams: typeof import('befly-shared/utils/cleanParams').cleanParams
19
19
  const computed: typeof import('vue').computed
20
20
  const createApp: typeof import('vue').createApp
21
21
  const createPinia: typeof import('pinia').createPinia
@@ -28,7 +28,6 @@ declare global {
28
28
  const getCurrentInstance: typeof import('vue').getCurrentInstance
29
29
  const getCurrentScope: typeof import('vue').getCurrentScope
30
30
  const getCurrentWatcher: typeof import('vue').getCurrentWatcher
31
- const getViteEnvString: typeof import('../utils/getViteEnvString').getViteEnvString
32
31
  const h: typeof import('vue').h
33
32
  const inject: typeof import('vue').inject
34
33
  const isProxy: typeof import('vue').isProxy
@@ -98,9 +97,6 @@ declare global {
98
97
  export type { Component, Slot, Slots, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, ShallowRef, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue'
99
98
  import('vue')
100
99
  // @ts-ignore
101
- export type { ArrayToTreeResult } from '../utils/arrayToTree'
102
- import('../utils/arrayToTree')
103
- // @ts-ignore
104
100
  export type { BeflyAdminConfig } from '../plugins/config'
105
101
  import('../plugins/config')
106
102
  // @ts-ignore
@@ -120,8 +116,6 @@ declare module 'vue' {
120
116
  readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
121
117
  readonly MessagePlugin: UnwrapRef<typeof import('tdesign-vue-next')['MessagePlugin']>
122
118
  readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
123
- readonly arrayToTree: UnwrapRef<typeof import('../utils/arrayToTree')['arrayToTree']>
124
- readonly cleanParams: UnwrapRef<typeof import('../utils/cleanParams')['cleanParams']>
125
119
  readonly computed: UnwrapRef<typeof import('vue')['computed']>
126
120
  readonly createApp: UnwrapRef<typeof import('vue')['createApp']>
127
121
  readonly createPinia: UnwrapRef<typeof import('pinia')['createPinia']>
@@ -134,7 +128,6 @@ declare module 'vue' {
134
128
  readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
135
129
  readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
136
130
  readonly getCurrentWatcher: UnwrapRef<typeof import('vue')['getCurrentWatcher']>
137
- readonly getViteEnvString: UnwrapRef<typeof import('../utils/getViteEnvString')['getViteEnvString']>
138
131
  readonly h: UnwrapRef<typeof import('vue')['h']>
139
132
  readonly inject: UnwrapRef<typeof import('vue')['inject']>
140
133
  readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
@@ -1,135 +0,0 @@
1
- export type ArrayToTreeResult<T extends Record<string, any>> = {
2
- flat: Array<T>;
3
- tree: Array<T>;
4
- map: Map<string, T>;
5
- };
6
-
7
- /**
8
- * 将一维数组按 { id, pid } 组装为树形结构(纯函数 / 无副作用)。
9
- *
10
- * - 默认字段:id / pid / children / sort
11
- * - pid 为空字符串或父节点不存在时,视为根节点
12
- * - 内部会 clone 一份节点对象,并写入 children: []
13
- * - 默认自带递归排序:按 sort 升序;sort 缺省/非法或 < 1 视为 999999;sort 相同按 id 自然序
14
- */
15
- export function arrayToTree<T extends Record<string, any>>(items: T[], id: string = "id", pid: string = "pid", children: string = "children", sort: string = "sort"): ArrayToTreeResult<T> {
16
- const idKey = typeof id === "string" && id.length > 0 ? id : "id";
17
- const pidKey = typeof pid === "string" && pid.length > 0 ? pid : "pid";
18
- const childrenKey = typeof children === "string" && children.length > 0 ? children : "children";
19
- const sortKey = typeof sort === "string" && sort.length > 0 ? sort : "sort";
20
-
21
- const map = new Map<string, T>();
22
- const flat: T[] = [];
23
-
24
- const safeItems = Array.isArray(items) ? items : [];
25
-
26
- const normalizeKey = (value: unknown): string => {
27
- if (typeof value === "string") {
28
- return value;
29
- }
30
- if (typeof value === "number" && Number.isFinite(value)) {
31
- return String(value);
32
- }
33
- return "";
34
- };
35
-
36
- for (const item of safeItems) {
37
- const rawId = item ? (item as any)[idKey] : undefined;
38
- const rawPid = item ? (item as any)[pidKey] : undefined;
39
-
40
- const normalizedId = normalizeKey(rawId);
41
- const normalizedPid = normalizeKey(rawPid);
42
-
43
- const nextNode = Object.assign({}, item) as T;
44
- (nextNode as any)[idKey] = normalizedId;
45
- (nextNode as any)[pidKey] = normalizedPid;
46
- (nextNode as any)[childrenKey] = [];
47
-
48
- flat.push(nextNode);
49
-
50
- if (normalizedId.length > 0) {
51
- map.set(normalizedId, nextNode);
52
- }
53
- }
54
-
55
- const tree: T[] = [];
56
-
57
- for (const node of flat) {
58
- const selfId = normalizeKey(node ? (node as any)[idKey] : undefined);
59
- const parentId = normalizeKey(node ? (node as any)[pidKey] : undefined);
60
-
61
- if (parentId.length > 0 && parentId !== selfId) {
62
- const parent = map.get(parentId);
63
- if (parent && Array.isArray((parent as any)[childrenKey])) {
64
- (parent as any)[childrenKey].push(node);
65
- continue;
66
- }
67
- }
68
-
69
- tree.push(node);
70
- }
71
-
72
- const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
73
-
74
- const getSortValue = (node: T): number => {
75
- const raw = node ? (node as any)[sortKey] : undefined;
76
- if (typeof raw !== "number") {
77
- return 999999;
78
- }
79
- if (!Number.isFinite(raw)) {
80
- return 999999;
81
- }
82
- if (raw < 1) {
83
- return 999999;
84
- }
85
- return raw;
86
- };
87
-
88
- const compareNode = (a: T, b: T): number => {
89
- const aSort = getSortValue(a);
90
- const bSort = getSortValue(b);
91
-
92
- if (aSort !== bSort) {
93
- return aSort - bSort;
94
- }
95
-
96
- const aId = a ? (a as any)[idKey] : "";
97
- const bId = b ? (b as any)[idKey] : "";
98
-
99
- return collator.compare(typeof aId === "string" ? aId : "", typeof bId === "string" ? bId : "");
100
- };
101
-
102
- const sortTreeInPlace = (nodes: Array<T>, seen: WeakSet<object>): void => {
103
- if (!Array.isArray(nodes)) {
104
- return;
105
- }
106
-
107
- if (nodes.length > 1) {
108
- nodes.sort(compareNode);
109
- }
110
-
111
- for (const node of nodes) {
112
- if (typeof node !== "object" || node === null) {
113
- continue;
114
- }
115
-
116
- if (seen.has(node)) {
117
- continue;
118
- }
119
- seen.add(node);
120
-
121
- const childNodes = (node as any)[childrenKey];
122
- if (Array.isArray(childNodes) && childNodes.length > 0) {
123
- sortTreeInPlace(childNodes, seen);
124
- }
125
- }
126
- };
127
-
128
- sortTreeInPlace(tree, new WeakSet<object>());
129
-
130
- return {
131
- flat: flat,
132
- tree: tree,
133
- map: map
134
- };
135
- }
@@ -1,39 +0,0 @@
1
- export function cleanParams<TData extends Record<string, unknown>>(data: TData, dropValues?: readonly unknown[], dropKeyValue?: Record<string, readonly unknown[]>): Partial<TData> {
2
- const globalDropValues = dropValues ?? [];
3
- const perKeyDropValues = dropKeyValue ?? {};
4
-
5
- const globalDropSet = new Set<unknown>(globalDropValues);
6
-
7
- const out: Record<string, unknown> = {};
8
-
9
- for (const key of Object.keys(data)) {
10
- const value = data[key];
11
-
12
- // 默认强制移除 null / undefined
13
- if (value === null || value === undefined) {
14
- continue;
15
- }
16
-
17
- // 如果该 key 配了规则:以 key 规则为准,不再应用全局 dropValues
18
- if (Object.hasOwn(perKeyDropValues, key)) {
19
- const keyDropValues = perKeyDropValues[key] ?? [];
20
- const keyDropSet = new Set<unknown>(keyDropValues);
21
-
22
- if (keyDropSet.has(value)) {
23
- continue;
24
- }
25
-
26
- out[key] = value;
27
- continue;
28
- }
29
-
30
- // 未配置 key 规则:应用全局 dropValues
31
- if (globalDropSet.has(value)) {
32
- continue;
33
- }
34
-
35
- out[key] = value;
36
- }
37
-
38
- return out as Partial<TData>;
39
- }
@@ -1,4 +0,0 @@
1
- export function getViteEnvString(key: string): string | undefined {
2
- const env = (import.meta as unknown as { env?: Record<string, string> }).env;
3
- return env?.[key];
4
- }