20260810223432

This commit is contained in:
oneao committed 2026-08-10 22:34:33 +08:00
1 parent ed5ab3885d
commit 5adbf59425
364 files changed
+7559 -4358

No files matched your search

+15 -10
View File
@@ -1,21 +1,26 @@
import * as LucideIcons from "@lucide/vue"
import * as LucideIcons from "@lucide/vue";
let iconMap: Record<string, any> | null = null
let iconMap: Record<string, any> | null = null;
function loadIcons() {
if (iconMap) return
const map: Record<string, any> = {}
if (iconMap) return;
const map: Record<string, any> = {};
for (const [key, component] of Object.entries(LucideIcons)) {
if (key !== "default" && key !== "createLucideIcon" && typeof key === "string" && key.charAt(0) === key.charAt(0).toUpperCase()) {
map[key] = component
if (
key !== "default" &&
key !== "createLucideIcon" &&
typeof key === "string" &&
key.charAt(0) === key.charAt(0).toUpperCase()
) {
map[key] = component;
}
}
iconMap = map
iconMap = map;
}
/** 同步获取图标组件,传入 null/空字符串时返回 null */
export function getIcon(name?: string | null) {
if (!iconMap) loadIcons()
if (!name || !iconMap) return null
return iconMap[name] || null
if (!iconMap) loadIcons();
if (!name || !iconMap) return null;
return iconMap[name] || null;
}
+18 -22
View File
@@ -1,5 +1,5 @@
export interface TreeNode<T> extends Record<string, unknown> {
children?: T[]
children?: T[];
}
/**
@@ -15,48 +15,44 @@ export function buildTree<T extends TreeNode<T>>(
parentKey = "b_parent_id",
childrenKey = "children",
): T[] {
const map = new Map<string, T>()
const roots: T[] = []
const map = new Map<string, T>();
const roots: T[] = [];
for (const node of list) {
map.set(String((node as any)[idKey]), node)
map.set(String((node as any)[idKey]), node);
}
for (const node of list) {
const pid = (node as any)[parentKey]
const pid = (node as any)[parentKey];
if (pid != null) {
const parent = map.get(String(pid))
const parent = map.get(String(pid));
if (parent) {
if (!(parent as any)[childrenKey]) {
;(parent as any)[childrenKey] = []
(parent as any)[childrenKey] = [];
}
;(parent as any)[childrenKey].push(node)
continue
(parent as any)[childrenKey].push(node);
continue;
}
}
roots.push(node)
roots.push(node);
}
return roots
return roots;
}
/**
* 按 b_xh 升序、b_id 升序 递归排序树。
*/
export function sortTree<T extends TreeNode<T>>(
tree: T[],
xhKey = "b_xh",
idKey = "b_id",
): T[] {
export function sortTree<T extends TreeNode<T>>(tree: T[], xhKey = "b_xh", idKey = "b_id"): T[] {
tree.sort((a: any, b: any) => {
const xhDiff = (Number(a[xhKey]) || 0) - (Number(b[xhKey]) || 0)
if (xhDiff !== 0) return xhDiff
return String(a[idKey] || "").localeCompare(String(b[idKey] || ""))
})
const xhDiff = (Number(a[xhKey]) || 0) - (Number(b[xhKey]) || 0);
if (xhDiff !== 0) return xhDiff;
return String(a[idKey] || "").localeCompare(String(b[idKey] || ""));
});
for (const node of tree) {
if (node.children?.length) {
sortTree(node.children as T[], xhKey, idKey)
sortTree(node.children as T[], xhKey, idKey);
}
}
return tree
return tree;
}