761ee8be14
1. 移除 enterprise/provider/government/investor/developer 角色 2. 重写 builtinRoutes/builtinMenu 只保留三角色 3. 删除 portal 下五个孤立页面目录 4. capabilities 写入 JWT,前端统一基于 capabilities 判断 5. AuthUser 增加 account_type/account_type_label 6. Header RoleBadge 优先使用 account_type_label 7. 修复 ChatWindow 自己消息右侧、客服消息区分 8. Operator/Users 增加在线状态 9. 修复多个预存 TS 错误
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
import { useState, useEffect } from "react";
|
|
import { BRAND } from "../constants/branding";
|
|
import { authApi } from "../api/modules/auth";
|
|
import type { ConfigInfo } from "../api/modules/auth";
|
|
|
|
/**
|
|
* Header 广告词 Hook —— 运营端可配置。
|
|
*
|
|
* 配置来源优先级:
|
|
* 1. localStorage 覆盖(调试用):localStorage.setItem("headerSlogan", "自定义广告词")
|
|
* 2. 运营端系统配置:authApi.listConfig() 中的 site.header_slogan / site.header_slogan_url
|
|
* 3. 品牌默认值:BRAND.headerSlogan
|
|
*/
|
|
const STORAGE_KEY = "headerSlogan";
|
|
const CONFIG_KEY_SLOGAN = "site.header_slogan";
|
|
const CONFIG_KEY_URL = "site.header_slogan_url";
|
|
|
|
export interface HeaderSlogan {
|
|
text: string;
|
|
url: string;
|
|
}
|
|
|
|
export function useHeaderSlogan(): HeaderSlogan {
|
|
const [slogan, setSlogan] = useState<HeaderSlogan>(() => {
|
|
// 优先从 localStorage 读取(调试用),否则使用品牌默认值
|
|
try {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
if (stored) return { text: stored, url: "" };
|
|
} catch {
|
|
// ignore
|
|
}
|
|
return { text: BRAND.headerSlogan, url: "" };
|
|
});
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
|
|
async function load() {
|
|
// 如果 localStorage 有覆盖,跳过 API 请求
|
|
try {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
if (stored) return;
|
|
} catch {
|
|
// ignore
|
|
}
|
|
|
|
try {
|
|
const cfg = await authApi.listSiteConfig();
|
|
const items = cfg as ConfigInfo[];
|
|
if (!Array.isArray(items)) {
|
|
console.warn("[useHeaderSlogan] API 返回格式不是数组:", cfg);
|
|
return;
|
|
}
|
|
const sloganItem = items.find((c) => c.key === CONFIG_KEY_SLOGAN);
|
|
const urlItem = items.find((c) => c.key === CONFIG_KEY_URL);
|
|
if (!cancelled) {
|
|
setSlogan((prev) => ({
|
|
text: sloganItem?.value || prev.text,
|
|
url: urlItem?.value || "",
|
|
}));
|
|
}
|
|
} catch (e) {
|
|
console.error("[useHeaderSlogan] 加载配置失败:", e);
|
|
// API 失败时保持默认值
|
|
}
|
|
}
|
|
|
|
load();
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, []);
|
|
|
|
return slogan;
|
|
}
|
|
|
|
export default useHeaderSlogan;
|