来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import { pool } from '../db';
|
|
import { sanitizeMenuGroupIconSvg } from './menuGroupIconService';
|
|
|
|
export interface MenuGroupIconLibraryEntry {
|
|
label: string;
|
|
iconSvg: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface MenuGroupIconLibrary {
|
|
version: 1;
|
|
entries: Record<string, MenuGroupIconLibraryEntry>;
|
|
}
|
|
|
|
const CONFIG_KEY = 'menu_group_icon_library';
|
|
|
|
function emptyLibrary(): MenuGroupIconLibrary {
|
|
return { version: 1, entries: {} };
|
|
}
|
|
|
|
export function normalizeMenuGroupIconLabel(label: string): string {
|
|
return label.trim().replace(/\s+/g, '');
|
|
}
|
|
|
|
async function loadLibrary(): Promise<MenuGroupIconLibrary> {
|
|
const result = await pool.query(
|
|
`SELECT config_value
|
|
FROM system_configs
|
|
WHERE config_key = $1
|
|
AND branch_code IS NULL
|
|
LIMIT 1`,
|
|
[CONFIG_KEY]
|
|
);
|
|
|
|
const raw = result.rows[0]?.config_value;
|
|
if (!raw || typeof raw !== 'object') return emptyLibrary();
|
|
|
|
const entries = (raw as MenuGroupIconLibrary).entries;
|
|
if (!entries || typeof entries !== 'object') return emptyLibrary();
|
|
|
|
return {
|
|
version: 1,
|
|
entries: entries as Record<string, MenuGroupIconLibraryEntry>,
|
|
};
|
|
}
|
|
|
|
async function saveLibrary(library: MenuGroupIconLibrary): Promise<void> {
|
|
await pool.query(
|
|
`INSERT INTO system_configs (config_key, config_value, config_group, description, branch_code)
|
|
VALUES ($1, $2::jsonb, 'nav', '菜单组矢量图标库(按组名匹配复用)', NULL)
|
|
ON CONFLICT ((COALESCE(branch_code, '__GLOBAL__')), config_key)
|
|
DO UPDATE SET
|
|
config_value = EXCLUDED.config_value,
|
|
updated_at = NOW()`,
|
|
[CONFIG_KEY, JSON.stringify(library)]
|
|
);
|
|
}
|
|
|
|
export async function lookupMenuGroupIcon(label: string): Promise<string | null> {
|
|
const key = normalizeMenuGroupIconLabel(label);
|
|
if (!key) return null;
|
|
|
|
const library = await loadLibrary();
|
|
const entry = library.entries[key];
|
|
if (!entry?.iconSvg || !entry.iconSvg.includes('<svg')) return null;
|
|
return entry.iconSvg;
|
|
}
|
|
|
|
export async function saveMenuGroupIcon(label: string, iconSvg: string): Promise<void> {
|
|
const normalizedLabel = normalizeMenuGroupIconLabel(label);
|
|
const sanitized = sanitizeMenuGroupIconSvg(iconSvg);
|
|
if (!normalizedLabel || !sanitized) return;
|
|
|
|
const library = await loadLibrary();
|
|
library.entries[normalizedLabel] = {
|
|
label: label.trim(),
|
|
iconSvg: sanitized,
|
|
updatedAt: new Date().toISOString(),
|
|
};
|
|
await saveLibrary(library);
|
|
}
|
|
|
|
export async function getMenuGroupIconLibrary(): Promise<MenuGroupIconLibrary> {
|
|
return loadLibrary();
|
|
}
|