import NodesPage from './NodesPage.vue';
import type { Req } from '../../../apps/stardust/src/views/Stardust/appsModel.ts';
// äº”èŠ‚ç‚¹ä¸‰æ€æ··åˆï¼š2 æ£å¸¸(node-a/d) · 2 高负载(node-b/e,cpuRate 92/88 超阈) · 1 离线(node-c,lastActive 3 天å‰)。
// node-a 上 2 个在线应用ã€node-b 1 个ã€node-d 1 个(抽屉「应用进程ã€tab å¯ç‚¹å¼€éªŒè¯ï¼‰ã€‚
const NODES = [
{ id: 1, name: 'node-a', code: 'NA', iP: '10.0.0.1', projectName: '北京机房', oS: 'CentOS', oSVersion: '7.9', version: 'v3.9.2', framework: 'NewLife', runtime: '.NET 8', machineName: 'host-a', lastActive: new Date(Date.now() - 5000).toISOString(), alarmCpuRate: 85 },
{ id: 2, name: 'node-b', code: 'NB', iP: '10.0.0.2', projectName: '上海机房', oS: 'Ubuntu', oSVersion: '22.04', version: 'v3.9.0', framework: 'NewLife', runtime: '.NET 6', machineName: 'host-b', lastActive: new Date(Date.now() - 3000).toISOString(), alarmCpuRate: 80 },
{ id: 3, name: 'node-c', code: 'NC', iP: '10.0.0.3', projectName: '默认集群', oS: 'Debian', oSVersion: '11', version: 'v3.8.1', framework: 'NewLife', runtime: '.NET 6', machineName: 'host-c', lastActive: new Date(Date.now() - 86400_000 * 3).toISOString() },
{ id: 4, name: 'node-d', code: 'ND', iP: '10.0.0.4', projectName: '北京机房', oS: 'CentOS', oSVersion: '7.9', version: 'v3.9.2', framework: 'NewLife', runtime: '.NET 8', machineName: 'host-d', lastActive: new Date(Date.now() - 8000).toISOString(), alarmCpuRate: 85 },
{ id: 5, name: 'node-e', code: 'NE', iP: '10.0.0.5', projectName: '上海机房', oS: 'Rocky', oSVersion: '9', version: 'v3.9.0', framework: 'NewLife', runtime: '.NET 8', machineName: 'host-e', lastActive: new Date(Date.now() - 2000).toISOString(), alarmCpuRate: 85 },
];
// 在线快照(CARD-NODE-11):id=NodeOnline 会è¯ä¸»é”®ï¼ˆæ‰¹é‡ keys ç”¨å®ƒï¼Œéž Node.Id),
// nodeId=节点主键;nodeId=1 两æ¡åކå²ï¼ˆid=9 æ—§ã€id=11 æ–°ï¼‰è¦†ç›–ã€Œå– updateTime æœ€æ–°ã€æ˜ 射。
const ONLINE = [
{ id: 9, nodeID: 1, name: 'node-a', updateTime: '2026-11-08 10:00:00', cpuRate: 40, memory: 8000, memoryUsed: 4000, pingCount: 120 },
{ id: 11, nodeID: 1, name: 'node-a', updateTime: '2026-11-09 03:00:00', cpuRate: 42, memory: 8000, memoryUsed: 4100, pingCount: 120 },
{ id: 12, nodeID: 2, name: 'node-b', updateTime: '2026-11-09 02:30:00', cpuRate: 92, memory: 16000, memoryUsed: 12500, pingCount: 88 },
{ id: 14, nodeID: 4, name: 'node-d', updateTime: '2026-11-09 03:10:00', cpuRate: 30, memory: 8000, memoryUsed: 3000, pingCount: 200 },
{ id: 15, nodeID: 5, name: 'node-e', updateTime: '2026-11-09 03:12:00', cpuRate: 88, memory: 16000, memoryUsed: 9000, pingCount: 76 },
];
const APPS = [
{ id: 101, nodeId: 1, name: 'order-api', version: '1.2.0', processName: 'order-api', processId: 3210, iP: '10.0.0.1' },
{ id: 102, nodeId: 1, name: 'pay-worker', version: '0.9.3', processName: 'pay-worker', processId: 3350, iP: '10.0.0.1' },
{ id: 103, nodeId: 2, name: 'gateway', version: '2.0.1', processName: 'gateway', processId: 4100, iP: '10.0.0.2' },
{ id: 104, nodeId: 4, name: 'report', version: '1.0.0', processName: 'report', processId: 5200, iP: '10.0.0.4' },
];
// 节点命令(NODE-06 B1):载è·å½¢æ€å–自 6681 实测(camelCase æ‰å¹³æ•°ç»„,data 峿•°ç»„)。
// node-a 2 æ¡ï¼ˆä¸€æ¡æœ‰ traceId ä¸€æ¡æ— ,覆盖追踪列「—ã€ï¼‰ã€node-b 1 æ¡ã€node-d 0 æ¡ï¼ˆç©ºæ€ï¼‰ã€‚
const CMDS = [
{ id: 2, nodeID: 1, command: 'deploy/start', argument: '{"name":"order-api"}', startTime: '2026-11-09 01:00:00', expire: 3600, status: 0, times: 0, result: null, traceId: 'trc-abc-123', createUser: '星尘管ç†å¹³å° API', createUserID: 1, createTime: '2026-11-09 01:00:05', createIP: '127.0.0.1', updateUserID: 1, updateTime: '2026-11-09 01:00:05', updateIP: '127.0.0.1' },
{ id: 1, nodeID: 1, command: 'check/upgrade', argument: '', startTime: '2026-11-08 22:00:00', expire: 3600, status: 1, times: 1, result: '已是最新版本', traceId: '', createUser: '星尘管ç†å¹³å° API', createUserID: 1, createTime: '2026-11-08 22:00:05', createIP: '127.0.0.1', updateUserID: 1, updateTime: '2026-11-08 22:01:00', updateIP: '127.0.0.1' },
{ id: 3, nodeID: 2, command: 'deploy/stop', argument: '{"name":"gateway"}', startTime: '2026-11-09 00:30:00', expire: 3600, status: 2, times: 0, result: null, traceId: 'trc-def-456', createUser: 'Admin', createUserID: 2, createTime: '2026-11-09 00:30:05', createIP: '127.0.0.1', updateUserID: 2, updateTime: '2026-11-09 00:30:05', updateIP: '127.0.0.1' },
];
// 24h æ€§èƒ½é‡‡æ ·ï¼ˆCARD-NODE-07):NodeDataController åºåˆ—化形æ€ï¼ˆcamelCaseï¼Œç™¾åˆ†æ¯”å—æ®µå·²é™¤ä»¥ 100)。
// ä¹±åºä¸¤è¡Œï¼šæ¸©åº¦å…¨ç©ºï¼ˆæ˜¾éšæ–言=ä¸å‡ºçŽ°åœ¨å›¾å†…ï¼‰ï¼›ç”µé‡ä»…一行有值(null æ–点)。
const NODE_DATA = [
{ id: 1, nodeID: 1, localTime: '2026-11-09 12:00:00', cpuRate: 0.42, systemLoad: 1.2, battery: null, uplinkSpeed: 1024, temperature: null },
{ id: 2, nodeID: 1, localTime: '2026-11-09 11:00:00', cpuRate: 0.5, systemLoad: 1.0, battery: 0.85, uplinkSpeed: 2048, temperature: null },
];
// 节点历å²ï¼ˆCARD-NODE-09ï¼‰ï¼šå—æ®µ camelCase(NodeHistory 实体:id/nodeId/nodeName/action/success(bool)/
// remark/traceId/createTime/createIP)。node-a 2 æ¡ï¼ˆæˆåŠŸ+失败å„一,覆盖「是/å¦ã€åŒè‰²ä¸Žè¿½è¸ªåˆ—「—ã€ï¼‰ã€
// node-b 1 æ¡ã€node-d 0 æ¡ï¼ˆç©ºæ€ï¼‰ã€‚
const HIST = [
{ id: 21, nodeId: 1, nodeName: 'node-a', action: '登录', success: true, remark: '节点上线', traceId: 'trc-his-001', createTime: '2026-11-10T21:00:05', createIP: '10.0.0.1' },
{ id: 20, nodeId: 1, nodeName: 'node-a', action: 'å‡çº§', success: false, remark: 'å‡çº§å¤±è´¥ï¼šä¸‹è½½è¶…æ—¶', traceId: '', createTime: '2026-11-10T20:30:00', createIP: '10.0.0.1' },
{ id: 19, nodeId: 2, nodeName: 'node-b', action: '登出', success: true, remark: '节点下线', traceId: 'trc-his-002', createTime: '2026-11-10T19:00:00', createIP: '10.0.0.2' },
];
function stubReq(): Req {
return async (opts) => {
if (opts.url === '/Nodes/Node') return { data: NODES };
if (opts.url === '/Nodes/NodeOnline') return { data: ONLINE };
if (opts.url === '/Registry/AppOnline') {
const nid = opts.params?.nodeId;
if (nid !== undefined && nid !== null) return { data: APPS.filter((a) => a.nodeId === nid) };
return { data: APPS };
}
if (opts.url === '/Nodes/NodeStat') return { data: [] };
if (opts.url === '/Nodes/NodeCommand') {
const nid = opts.params?.nodeId;
return { data: CMDS.filter((c) => c.nodeID === nid) };
}
if (opts.url === '/Nodes/NodeHistory') {
// CARD-NODE-09:æ•获 success è¿‡æ»¤å‚æ•°ï¼ˆ'true'/'false' å—符串,CT æ–言用)并按值过滤
captureBatch(String(opts.url), (opts.params ?? {}) as Record<string, unknown>);
const nid = opts.params?.nodeId;
let list = HIST.filter((h) => h.nodeId === nid);
const sc = opts.params?.success;
if (sc === 'true') list = list.filter((h) => h.success === true);
if (sc === 'false') list = list.filter((h) => h.success === false);
return { code: 0, data: list };
}
if (opts.url === '/Nodes/NodeData') {
captureBatch(String(opts.url), (opts.params ?? {}) as Record<string, unknown>);
return { data: NODE_DATA };
}
return { data: [] };
};
}
function stubReqEmpty(): Req {
return async (opts) => {
if (opts.url === '/Registry/AppOnline') return { data: [] };
return { data: [] };
};
}
function stubReqFail(): Req {
return async () => {
throw new Error('stub 500');
};
}
// 列表æ£å¸¸ä½†å‘½ä»¤æŽ¥å£å¤±è´¥ï¼šèŠ‚ç‚¹è¡Œå¯ç‚¹å¼€æŠ½å±‰ï¼Œå‘½ä»¤é¡µç¾èµ°é”™è¯¯+é‡è¯•æ€ï¼ˆNODE-06 B1)
function stubReqCmdFail(): Req {
return async (opts) => {
if (opts.url === '/Nodes/NodeCommand') throw new Error('cmd stub 500');
if (opts.url === '/Nodes/Node') return { data: NODES };
if (opts.url === '/Nodes/NodeOnline') return { data: ONLINE };
if (opts.url === '/Registry/AppOnline') {
const nid = opts.params?.nodeId;
if (nid !== undefined && nid !== null) return { data: APPS.filter((a) => a.nodeId === nid) };
return { data: APPS };
}
return { data: [] };
};
}
// ---------- 批é‡è¿ç»´ï¼ˆCARD-NODE-11) ----------
// 批é‡åŠ¨ä½œè¯·æ±‚æ•获(æµè§ˆå™¨ä¾§ï¼‰ï¼šCT ä¸èƒ½ Node ä¾§ import story(会连带转译 .vue 炸 esbuild),
// 所以 stub 里把请求挂 window.__batchCalls,spec 用 page.evaluate 读å–/清空。
// keys=NodeOnline ä¼šè¯ Id(勾选 nodeId=1 → 在线快照 updateTime 最新 id=11)。
// åŽç«¯å¥‘çº¦æ ·ä¾‹ï¼ˆNodeOnlineController.cs :110/:289/:294 é€å—å½¢æ€ï¼‰
const BATCH_SUMMARY =
'æ“作æˆåŠŸï¼ä¸‹å‘1个,å“应1个,超时0个\nnode-a: 已是最新版本';
function captureBatch(url: string, params: Record<string, unknown>): void {
const w = window as unknown as { __batchCalls?: Array<{ url: string; params: Record<string, unknown> }> };
w.__batchCalls = w.__batchCalls ?? [];
w.__batchCalls.push({ url, params });
}
function stubReqBatch(): Req {
return async (opts) => {
// 框架管ç†ï¼ˆCARD-NODE-08):列表=IDictionary 键值对对象(Biz :138/:271,auto=自动首项);安装/å¸è½½æ•获并契约汇总
if (opts.url === '/Nodes/NodeFramework/GetVersionList') {
return { code: 0, message: null, data: { '8.0.11': '8.0.11', '9.0.0': '9.0.0' } };
}
if (opts.url === '/Nodes/NodeFramework/GetKindList') {
return { code: 0, message: null, data: { auto: '自动', runtime: 'è¿è¡Œæ—¶' } };
}
if (opts.url.startsWith('/Nodes/NodeFramework/InstallFramework') || opts.url.startsWith('/Nodes/NodeFramework/UninstallFramework')) {
captureBatch(String(opts.url), (opts.params ?? {}) as Record<string, unknown>);
return { code: 0, message: BATCH_SUMMARY, data: null };
}
if (opts.url.startsWith('/Nodes/NodeOnline/')) {
captureBatch(String(opts.url), (opts.params ?? {}) as Record<string, unknown>);
return { code: 0, message: BATCH_SUMMARY, data: null };
}
if (opts.url === '/Nodes/Node') return { data: NODES };
if (opts.url === '/Nodes/NodeOnline') return { data: ONLINE };
if (opts.url === '/Registry/AppOnline') return { data: [] };
if (opts.url === '/Nodes/NodeStat') return { data: [] };
if (opts.url === '/Nodes/NodeCommand') return { data: [] };
return { data: [] };
};
}
function stubReqBatchFail(): Req {
return async (opts) => {
// 框架失败æ€ï¼šå…¨è·³è¿‡æ¸…å•(NodeFrameworkController.cs :100 ã€Œæ²¡æœ‰å¯æŽ¨é€çš„节点ï¼ã€é€å—å½¢æ€ï¼‰
if (opts.url.startsWith('/Nodes/NodeFramework/InstallFramework') || opts.url.startsWith('/Nodes/NodeFramework/UninstallFramework')) {
return { code: 400, message: 'æ²¡æœ‰å¯æŽ¨é€çš„节点ï¼\nnode-c:没有匹é…的安装包', data: null };
}
if (opts.url === '/Nodes/NodeFramework/GetVersionList') {
return { code: 0, message: null, data: { '8.0.11': '8.0.11', '9.0.0': '9.0.0' } };
}
if (opts.url === '/Nodes/NodeFramework/GetKindList') {
return { code: 0, message: null, data: { auto: '自动', runtime: 'è¿è¡Œæ—¶' } };
}
if (opts.url.startsWith('/Nodes/NodeOnline/')) {
return { code: 400, message: 'æƒé™ä¸è¶³', data: null };
}
if (opts.url === '/Nodes/Node') return { data: NODES };
if (opts.url === '/Nodes/NodeOnline') return { data: ONLINE };
if (opts.url === '/Registry/AppOnline') return { data: [] };
if (opts.url === '/Nodes/NodeStat') return { data: [] };
if (opts.url === '/Nodes/NodeCommand') return { data: [] };
return { data: [] };
};
}
// 性能失败æ€ï¼ˆCARD-NODE-07):仅 NodeData 抛错,列表/抽屉/å‘½ä»¤é¡µç¾æ£å¸¸
function stubReqPerfFail(): Req {
return async (opts) => {
if (opts.url === '/Nodes/NodeData') throw new Error('stub 500');
if (opts.url === '/Nodes/Node') return { data: NODES };
if (opts.url === '/Nodes/NodeOnline') return { data: ONLINE };
if (opts.url === '/Registry/AppOnline') return { data: [] };
if (opts.url === '/Nodes/NodeStat') return { data: [] };
if (opts.url === '/Nodes/NodeCommand') return { data: [] };
return { data: [] };
};
}
export const stories = [
// äº”èŠ‚ç‚¹ä¸‰æ€æ··åˆï¼šæ˜Ÿå›¾å…‰ç‚¹ + 过滤æ¡è®¡æ•°(全部5/æ£å¸¸2/高负载2/离线1) + 8åˆ—è¡¨æ ¼
{ id: 'NodesPage/Mixed', component: NodesPage, props: { deps: { request: stubReq() } } },
// 空æ€ï¼šæ˜Ÿå›¾ã€Œè¿˜æ²¡æœ‰èŠ‚ç‚¹ã€ã€è¡¨æ ¼ã€Œæ²¡æœ‰åŒ¹é…的节点ã€ã€chip 计数全 0
{ id: 'NodesPage/Empty', component: NodesPage, props: { deps: { request: stubReqEmpty() } } },
// 失败æ€ï¼šå¯è§é”™è¯¯æ¡ + é‡è¯•按钮(ä¸å½“空æ€ï¼‰
{ id: 'NodesPage/Failed', component: NodesPage, props: { deps: { request: stubReqFail() } } },
// 命令失败æ€ï¼šåˆ—表æ£å¸¸å¯å¼€æŠ½å±‰ï¼Œå‘½ä»¤é¡µç¾æ˜¾ç¤ºé”™è¯¯ + é‡è¯•
{ id: 'NodesPage/CmdFailed', component: NodesPage, props: { deps: { request: stubReqCmdFail() } } },
// 批é‡è¿ç»´ï¼ˆCARD-NODE-11):勾选åŽäº”动作å¯ç‚¹ï¼ŒåŠ¨ä½œè¯·æ±‚è¢« batchCalls æ•获,æˆåŠŸè¿”å›žå¥‘çº¦æ±‡æ€»
{ id: 'NodesPage/Batch', component: NodesPage, props: { deps: { request: stubReqBatch() } } },
// 批é‡å¤±è´¥æ€ï¼šåŽç«¯ code 400(æƒé™ä¸è¶³ï¼‰â†’ 失败æ¡å¯è§
{ id: 'NodesPage/BatchFail', component: NodesPage, props: { deps: { request: stubReqBatchFail() } } },
// 性能失败æ€ï¼ˆCARD-NODE-07):仅 NodeData 抛错 → 性能页ç¾é”™è¯¯æ¡ + é‡è¯•
{ id: 'NodesPage/PerfFail', component: NodesPage, props: { deps: { request: stubReqPerfFail() } } },
];
|