feat: light app center and iframe refactor

This commit is contained in:
fengxiangdebaozi committed 2026-06-12 15:40:09 +08:00
1 parent 728a4b1170
commit 9d73f27146
35 files changed
+1878 -246

No files matched your search

@@ -28,10 +28,7 @@ import {
List,
ListChecks,
ListTodo,
MessageSquareCode,
Network,
NotebookPen,
Plus,
Settings,
Sparkles,
Target,
@@ -72,40 +69,6 @@ export const sidebarMenuItems: MenuItem[] = [
{ id: "qa-research", label: "课题研究", icon: FileText, path: "/page/canvas/ai-writing" },
],
},
// {
// id: "light-app-center",
// label: "轻应用",
// icon: Grid3X3,
// children: [
// {
// id: "light-app-note-management",
// label: "笔记管理",
// icon: NotebookPen,
// children: [
// {
// id: "light-app-new-note",
// label: "新建笔记",
// icon: Plus,
// path: "/page/strategy/light-app/new-note",
// },
// {
// id: "light-app-note-list",
// label: "笔记列表",
// icon: List,
// path: "/page/strategy/light-app/notes",
// },
// {
// id: "light-app-note-qa",
// label: "笔记问答",
// icon: MessageSquareCode,
// path: "/page/strategy/light-app/note-qa",
// },
// ],
// },
// { id: "light-app-square", label: "应用广场", icon: Layout },
// { id: "light-app-records", label: "运行记录", icon: History },
// ],
// },
{
id: "task-management",
label: "任务管理",
@@ -207,6 +170,26 @@ export const sidebarMenuItems: MenuItem[] = [
},
],
},
{
id: "light-app-center",
label: "轻应用中心",
icon: Grid3X3,
children: [
{
id: "light-app-management",
label: "应用管理",
icon: Layout,
path: "/page/strategy/light-app/management",
adminOnly: true,
},
{
id: "light-app-apps",
label: "应用列表",
icon: List,
path: "/page/strategy/light-app/apps",
},
],
},
{
id: "comprehensive-management",
label: "综合管理",
@@ -0,0 +1,63 @@
/**
* 侧边栏菜单合并 hook —— 把已注册的「iframe 类型」轻应用动态注入静态菜单。
*
* 静态结构来自 sidebar-menu.ts;每个启用的 iframe 应用按其 `mountLocation`(父菜单 id)
* 作为新子项注入对应分组(XK中任务 / PG中任务 / TY中任务 / 综合管理),点击进入
* iframe 宿主页 `/page/strategy/light-app/view/:appId`。
*
* 浅色 PageSidebar 与深色 PageSidebarDark 共用此 hook,保证两套皮肤同步。
*/
import { useMemo } from "react";
import { Layout } from "lucide-react";
import { useLightApps, type LightApp } from "@/strategy-components/api/light-apps";
import {
filterMenuItemsByRole,
sidebarMenuItems,
type MenuItem,
} from "./sidebar-menu";
function lightAppLeaf(app: LightApp): MenuItem {
return {
id: `light-app-${app.appId}`,
label: app.name,
icon: Layout,
path: `/page/strategy/light-app/view/${app.appId}`,
};
}
/** 在菜单树(不可变克隆)中,把 iframe 应用按 mountLocation 注入对应父节点末尾。 */
function injectLightApps(items: MenuItem[], apps: LightApp[]): MenuItem[] {
if (apps.length === 0) return items;
const byMount = new Map<string, LightApp[]>();
for (const app of apps) {
if (!app.mountLocation) continue;
const list = byMount.get(app.mountLocation) ?? [];
list.push(app);
byMount.set(app.mountLocation, list);
}
if (byMount.size === 0) return items;
const walk = (nodes: MenuItem[]): MenuItem[] =>
nodes.map((node) => {
const children = node.children ? walk(node.children) : undefined;
const extra = byMount.get(node.id);
if (!extra || extra.length === 0) {
return children ? { ...node, children } : node;
}
return { ...node, children: [...(children ?? []), ...extra.map(lightAppLeaf)] };
});
return walk(items);
}
/** 返回合并了 iframe 轻应用、并按 admin 角色过滤后的菜单。 */
export function useSidebarMenuItems(isAdmin: boolean): MenuItem[] {
const { data: iframeApps = [] } = useLightApps({ appType: "iframe", enabledOnly: true });
return useMemo(
() => filterMenuItemsByRole(injectLightApps(sidebarMenuItems, iframeApps), isAdmin),
[iframeApps, isAdmin],
);
}
@@ -27,6 +27,50 @@ export function getNetworkActorIframeUrl(): string {
return `${base}${path.startsWith("/") ? path : `/${path}`}`;
}
/** 读取并解析 localStorage 中的 userInfo(登录信息)。 */
function readUserInfo(): Record<string, unknown> {
try {
const raw = localStorage.getItem("userInfo");
if (!raw) return {};
const parsed = JSON.parse(raw);
return parsed && typeof parsed === "object" ? (parsed as Record<string, unknown>) : {};
} catch {
return {};
}
}
/** 当前登录态 accessToken(无则空串)。 */
export function getAccessToken(): string {
const value = readUserInfo().accessToken;
return value == null ? "" : String(value);
}
/**
* XK 中任务 iframe 地址。
*
* 形如 `{base}{gopath}?accessToken={token}`,其中 gopath 含 hash 路由
* (如 `#/pageIndie/pageHome/pageSwrw`)—— 每次都从 base 重建,切换 gopath 不累加。
*/
export function getXkIframeUrl(gopath: string): string {
const base = readEnv("VITE_AIPI_XKLINKTO_URL");
if (!base) return "";
return `${base}${gopath}?accessToken=${getAccessToken()}`;
}
/** PG 中任务 iframe 地址:`{base}?access_token={token}&goPath={gopath}`。 */
export function getPgIframeUrl(gopath: string): string {
const base = readEnv("VITE_AIPI_PGLINKTO_URL");
if (!base) return "";
return `${base}?access_token=${getAccessToken()}&goPath=${gopath}`;
}
/** TY 中任务 iframe 地址:`{base}/fromB/toPage?defaultPage={defaultPage}`。 */
export function getTyIframeUrl(defaultPage: string): string {
const base = trimTrailingSlash(readEnv("VITE_AIPI_B2ACTOR_URL"));
if (!base) return "";
return `${base}/fromB/toPage?defaultPage=${defaultPage}`;
}
/** 知识库 iframe 地址换取 API */
export function getKnowledgeIframeApiUrl(): string {
return readEnv("VITE_AIPI_KNOWLEDGE_IFRAME_API_URL");