20260816220132

This commit is contained in:
oneao committed 2026-08-16 22:01:32 +08:00
1 parent b6f9a4c912
commit 72993ecdcd
179 files changed
+20050 -633

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
import * as LucideIcons from '@lucide/vue'
let iconMap = null
function loadIcons() {
if (iconMap) return
const map = {}
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
}
}
iconMap = map
}
/**
* 同步获取图标组件,传入 null/空字符串时返回 null。
* @param {string | null | undefined} name lucide 图标名(首字母大写),如 "LayoutGrid"
*/
export function getIcon(name) {
if (!iconMap) loadIcons()
if (!name || !iconMap) return null
return iconMap[name] || null
}
+55
View File
@@ -0,0 +1,55 @@
/**
* 根据 parentKey 将一维数组构建为树。
* @param {Array} list 原始列表
* @param {string} idKey 节点 ID 字段名,默认 "b_id"
* @param {string} parentKey 父节点关联字段名,默认 "b_parent_id"
* @param {string} childrenKey 子节点字段名,默认 "children"
*/
export function buildTree(
list,
idKey = 'b_id',
parentKey = 'b_parent_id',
childrenKey = 'children',
) {
const map = new Map()
const roots = []
for (const node of list) {
map.set(String(node[idKey]), node)
}
for (const node of list) {
const pid = node[parentKey]
if (pid != null) {
const parent = map.get(String(pid))
if (parent) {
if (!parent[childrenKey]) parent[childrenKey] = []
parent[childrenKey].push(node)
continue
}
}
roots.push(node)
}
return roots
}
/**
* 按 b_xh 升序、b_id 升序 递归排序树。
* @param {Array} tree 树形数组
* @param {string} xhKey 排序权重字段名,默认 "b_xh"
* @param {string} idKey 排序兜底字段名,默认 "b_id"
*/
export function sortTree(tree, xhKey = 'b_xh', idKey = 'b_id') {
tree.sort((a, b) => {
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, xhKey, idKey)
}
}
return tree
}