feat: 新增多插件 UI 支持及运行日志集中回传功能

本次提交包含多项功能更新:
1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持
2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储
3. 新增插件分类字段支持,用于场景库分组管理
4. 优化 xq0034/0037/0048 等插件的功能及描述
5. 修复控制面响应兼容问题,支持新旧版本数据格式
6. 新增 xq0033 插件的状态存储模块,用于历史记录管理
7. 优化 CRM 登录窗口模式,支持全屏置顶
This commit is contained in:
2026-10-26 15:42:50 +08:00
parent 8bf33b65cd
commit c73c113721
453 changed files with 243002 additions and 4493 deletions
+649
View File
@@ -0,0 +1,649 @@
/* ============================================================
37du 自动化工作台 · 设计稿还原版
布局 / 配色 / 圆角 / 间距 全部取自设计稿数值
============================================================ */
/* ---------------- 图标(15×15,1.5px 描边) ---------------- */
const ICON = {
home: '<path d="M3.4 10.6 12 3.6l8.6 7V20a1 1 0 0 1-1 1H4.4a1 1 0 0 1-1-1z"/><path d="M9.4 21v-6.2h5.2V21"/>',
grid: '<rect x="3.4" y="3.6" width="7" height="7" rx="2"/><rect x="13.6" y="3.6" width="7" height="7" rx="2"/><rect x="3.4" y="13.8" width="7" height="7" rx="2"/><rect x="13.6" y="13.8" width="7" height="7" rx="2"/>',
cal: '<rect x="3.4" y="5.2" width="17.2" height="16" rx="2.6"/><path d="M8 2.8v4.4M16 2.8v4.4M3.4 10.4h17.2"/>',
link: '<path d="M10.2 13.8a4.6 4.6 0 0 0 6.5 0l2-2a4.6 4.6 0 0 0-6.5-6.5l-1.1 1.1"/><path d="M13.8 10.2a4.6 4.6 0 0 0-6.5 0l-2 2a4.6 4.6 0 0 0 6.5 6.5l1.1-1.1"/>',
search: '<circle cx="11" cy="11" r="6.6"/><path d="M16.2 16.2 21 21"/>',
play: '<path d="M4 2.8v8.4l7-4.2z" fill="currentColor" stroke="none"/>'
};
const svg = (name, size = 15) =>
`<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">${ICON[name]}</svg>`;
/* ---------------- 数据 ---------------- */
const NAV = [
{ key: 'overview', label: '总览', count: '12', icon: 'home' },
{ key: 'library', label: '场景库', count: '18', icon: 'grid' },
{ key: 'plans', label: '计划', count: '7', icon: 'cal' },
{ key: 'platform', label: '平台账号', count: '2/3', icon: 'link', good: true }
];
const SCENES = [
{ g: '最近使用', n: 4, items: [
{ name: '考勤数据采集', time: '12m', color: '#4F5AE8', cur: true },
{ name: 'OA流程自动化', time: '1h', color: '#D98218' },
{ name: '钉钉通知推送', time: '3h', color: '#0E9F76' },
{ name: '销售订单同步', time: '昨天', color: '#3B9BE8' }
]},
{ g: '数据采集', n: 3, items: [
{ name: '仓库库存盘点', time: '2d', color: '#4F5AE8' },
{ name: '合同归档同步', time: '周一', color: '#D98218' },
{ name: '财务对账单导出', time: '10-01', color: '#0E9F76' }
]},
{ g: '协同与通知', n: 2, items: [
{ name: '客户回访汇总', time: '10-20', color: '#7C6BE8' },
{ name: '邮件日报推送', time: '10-19', color: '#3B9BE8' }
]}
];
const OVERVIEW_ROWS = [
{ idx: '01', name: '考勤数据采集', plat: 'HR · 数据采集', time: '今天 14:32', tag: ['ok', '成功'], strong: true },
{ idx: '02', name: '销售订单同步', plat: 'CRM · 同步', time: '今天 11:08', tag: ['ok', '成功'] },
{ idx: '03', name: '仓库库存盘点', plat: 'WMS · 采集', time: '昨天 18:20', tag: ['ok', '成功'] },
{ idx: '04', name: '钉钉通知推送', plat: '钉钉 · 通知', time: '周一 09:00', tag: ['ok', '成功'] },
{ idx: '05', name: 'OA流程自动化', plat: 'OA · 流程', time: '今天 09:45', tag: ['warn', '待登录'] },
{ idx: '06', name: '财务对账单导出', plat: '金蝶 · 财务', time: '10-01 08:00', tag: ['ok', '成功'] },
{ idx: '07', name: '合同归档同步', plat: '法务盘 · 归档', time: '周一 15:20', tag: ['ok', '成功'] }
];
const PLANS = [
{ time: '08:30', freq: '每天', scene: '考勤数据采集', res: '成功 · 02:14', next: '明天 08:30', state: ['ok', '启用'], strong: true },
{ time: '09:00', freq: '每周一', scene: '销售订单同步', res: '成功 · 03:08', next: '11-02 09:00', state: ['ok', '启用'] },
{ time: '08:00', freq: '每月 1 号', scene: '财务对账单导出', res: '成功 · 05:42', next: '11-01 08:00', state: ['ok', '启用'] },
{ time: '16:40', freq: '每周五', scene: '客户回访汇总', res: '成功 · 01:52', next: '10-30 16:40', state: ['ok', '启用'] },
{ time: '18:20', freq: '每天', scene: '仓库库存盘点', res: '成功 · 02:36', next: '今天 18:20', state: ['ok', '启用'] },
{ time: '10:00', freq: '每月 15 号', scene: '合同归档同步', res: '成功 · 04:12', next: '11-15 10:00', state: ['ok', '启用'] },
{ time: '09:00', freq: '每周一', scene: '钉钉通知推送', res: '跳过 · 平台未登录', next: '暂停中', state: ['off', '暂停'], muted: true, resCls: 'warn' },
{ time: '14:00', freq: '每天', scene: 'OA流程自动化', res: '失败 · 00:31', next: '暂停中', state: ['off', '暂停'], muted: true, resCls: 'bad' },
{ time: '10:30', freq: '每周三', scene: '邮件日报推送', res: '成功 · 00:48', next: '10-28 10:30', state: ['ok', '启用'] }
];
const ACTIVITY = [
{ name: '考勤数据采集', time: '14:32', st: '成功', cls: 'ok', color: '#0E9F76' },
{ name: '销售订单同步', time: '11:08', st: '成功', cls: 'ok', color: '#0E9F76' },
{ name: 'OA流程自动化', time: '09:45', st: '跳过', cls: 'warn', color: '#D98218' },
{ name: '仓库库存盘点', time: '昨天', st: '成功', cls: 'ok', color: '#0E9F76' },
{ name: '钉钉通知推送', time: '周一', st: '成功', cls: 'ok', color: '#0E9F76' }
];
const PLATFORMS = [
{ name: 'HR 人力系统', st: '已登录', cls: 'ok', color: '#0E9F76' },
{ name: 'OA 办公', st: '待登录', cls: 'warn', color: '#D98218' },
{ name: 'CRM 客户系统', st: '已登录', cls: 'ok', color: '#0E9F76' }
];
const WEEK = [
{ l: '周六 17', v: 1 }, { l: '周日 18', v: 1 }, { l: '周一 19', v: 2 },
{ l: '周二 20', v: 1 }, { l: '周三 21', v: 1 }, { l: '周四 22', v: 2 },
{ l: '今天 23', v: 4, now: true }
];
const TREND = [
{ d: '六', v: 15 }, { d: '日', v: 22 }, { d: '一', v: 19 }, { d: '二', v: 32 },
{ d: '三', v: 25 }, { d: '四', v: 42 }, { d: '五', v: 54, now: true }
];
const LOGS = [
['14:31:02', 'INFO', '开始执行 · 考勤数据采集 v1.2', ''],
['14:31:03', 'INFO', '已登录 HR 人力系统(李晓柠)', ''],
['14:31:05', 'INFO', '打开考勤模块 · 切换到 2026-10 视图', ''],
['14:31:08', 'INFO', '识别 12 页数据 · 开始抓取', ''],
['14:31:12', 'INFO', '第 1/12 页 · 82 条', ''],
['14:31:15', 'WARN', '第 4 页加载超时 · 重试 1/3', 'warn'],
['14:31:19', 'INFO', '重试成功 · 继续第 4/12 页', ''],
['14:31:20', 'DEBUG', '缓存命中 · 规则 37d.attendance.v2', 'dim'],
['14:31:22', 'INFO', '解析「研发中心」12 条 · 「市场部」9 条 · 「财务部」7 条', ''],
['14:31:23', 'INFO', '校验通过 · 缺失字段 0 · 重复 0', ''],
['14:31:24', 'INFO', '已采集 246 条 · 进度 68%', 'ok'],
['14:31:26', 'DEBUG', 'selector=.pager-next · wait=800ms', 'dim'],
['14:31:28', 'INFO', '滚动至下一页 · 等待表格重新渲染', ''],
['14:31:30', 'INFO', '重新定位表头 · 列映射 8/8', ''],
['14:31:32', 'INFO', '第 5/12 页 · 71 条', ''],
['14:31:35', 'WARN', '单元格合并 · 沿用上一行部门', 'warn'],
['14:31:37', 'INFO', '第 6/12 页 · 68 条', ''],
['14:31:39', 'DEBUG', 'poll .row-count = 68', 'dim'],
['14:31:41', 'INFO', '已采集 385 条 · 进度 74%', 'ok'],
['14:31:43', 'INFO', '等待页面渲染…', '']
];
/* ---------------- 状态 ---------------- */
const state = {
page: 'overview',
scene: '考勤数据采集',
progress: 68,
pages: 3,
collected: 385,
elapsed: 94,
done: false,
search: '',
logs: LOGS.slice(),
plansPaused: false
};
/* ---------------- 工具 ---------------- */
const $ = (s, r = document) => r.querySelector(s);
const pad2 = n => String(n).padStart(2, '0');
const hhmmss = s => `${pad2(Math.floor(s / 3600))}:${pad2(Math.floor(s / 60) % 60)}:${pad2(s % 60)}`;
const CRUMB = { overview: '总览', runner: '运行台', plans: '计划' };
let toastTimer;
function toast(msg) {
const el = $('#toast');
el.textContent = msg;
el.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => el.classList.remove('show'), 1600);
}
/* ---------------- 左栏 ---------------- */
function renderRailLeft() {
const kw = state.search.trim();
const groups = SCENES.map(g => ({
...g,
items: kw ? g.items.filter(i => i.name.includes(kw)) : g.items
})).filter(g => g.items.length);
const activeKey = state.page === 'plans' ? 'plans' : state.page === 'runner' ? 'overview' : 'overview';
const nav = NAV.map(n => `
<button class="nav-item ${n.key === activeKey ? 'active' : ''}" data-nav="${n.key}">
${svg(n.icon)}
<span class="nav-label">${n.label}</span>
<span class="nav-count ${n.good ? 'good' : ''}">${n.count}</span>
</button>`).join('');
const list = groups.length
? groups.map(g => `
<div class="group-head"><span class="label">${g.g}</span><span class="n">${g.n}</span></div>
${g.items.map(i => `
<div class="scene-row ${i.cur && state.page !== 'plans' ? 'current' : ''}" data-scene="${i.name}">
<i class="scene-dot" style="background:${i.color}"></i>
<span class="scene-name">${i.name}</span>
<span class="scene-time">${i.time}</span>
</div>`).join('')}`).join('')
: `<div class="group-head"><span class="label">无匹配场景</span></div>`;
$('#railLeft').innerHTML = `
<nav class="nav">${nav}</nav>
<div class="hr"></div>
<div class="scene-head">
<span class="label">场景库</span>
<span class="count-pill">18</span>
</div>
<label class="search">
${svg('search', 13)}
<input id="sceneSearch" type="text" placeholder="搜索场景" value="${state.search}" />
<span class="kbd">⌘K</span>
</label>
${list}
<div class="rail-flex"></div>
<div class="account">
<span class="avatar">李</span>
<span class="who">
<span class="name">李晓柠</span>
<span class="role">本机操作员</span>
</span>
<span class="quit" data-act="quit">退出</span>
</div>`;
}
/* ---------------- 右栏 ---------------- */
function renderRailRight() {
const acts = ACTIVITY.map(a => `
<div class="act-row" data-scene="${a.name}">
<i style="background:${a.color}"></i>
<span class="nm">${a.name}</span>
<span class="tm">${a.time}</span>
<span class="st ${a.cls}">${a.st}</span>
</div>`).join('');
const plats = PLATFORMS.map(p => `
<div class="plat-row" data-act="platform">
<i style="background:${p.color}"></i>
<span class="nm">${p.name}</span>
<span class="st ${p.cls}">${p.st}</span>
</div>`).join('');
$('#railRight').innerHTML = `
<div class="rail-head">
<span class="label">活动</span>
<span class="tag live" style="padding:0 7px;height:auto;gap:5px;font-size:10px">
<i></i>2 进行中
</span>
</div>
<div class="now-card">
<div class="now-top">
<i></i>
<span class="nm">考勤数据采集</span>
<span class="pct" data-right-pct>${state.progress}%</span>
</div>
<div class="track"><i data-right-track style="width:${state.progress}%"></i></div>
<span class="log" data-right-log>抓取第 3 / 12 页 · 已采 ${state.collected} 条</span>
</div>
<div class="rail-sub"><span class="label">最近运行</span><span class="n">5</span></div>
${acts}
<div class="hr"></div>
<div class="rail-sub"><span class="label">平台账号</span><span class="n good">2 / 3</span></div>
${plats}
<div class="rail-flex"></div>
<div class="rail-foot">
<div>本地服务 127.0.0.1:18000</div>
<div>数据同步于 12 秒前</div>
</div>`;
}
/* ---------------- 状态栏 ---------------- */
function renderStatus() {
const items = [
['Chrome 126.0', '#0E9F76', true],
['环境包 v1.2.0', '#0E9F76', false],
['授权有效 · 剩余 45 天', '#0E9F76', false],
['本地服务已连接', '#4F5AE8', false]
];
$('#statusbar').innerHTML = items.map(([t, c, num]) => `
<div class="item ${num ? 'num' : ''}"><i class="dot" style="width:6px;height:6px;background:${c}"></i><span>${t}</span></div>
`).join('') + `
<div class="spacer"></div>
<span class="ver">客户端 v1.1.3</span>
<span class="upd" data-act="check">检查更新</span>`;
}
/* ---------------- 页头 ---------------- */
function pageHead(eyebrow, title, sub, actions) {
return `
<div class="page-head">
<div class="page-title-group">
<div class="eyebrow">${eyebrow}</div>
<h1 class="page-title">${title}</h1>
<div class="page-sub">${sub}</div>
</div>
<div class="actions">${actions}</div>
</div>`;
}
/* ---------------- 总览 ---------------- */
function viewOverview() {
const metrics = [
['可用场景', '18', '其中 6 个常用场景', ''],
['定时任务', '3', '下次执行 明天 08:30', ''],
['平台在线', '2/3', 'OA 办公待登录', ''],
['近 7 日成功率', '96.2%', '共 41 次运行 · 2 次跳过', 'good']
].map(([k, v, n, cls]) => `
<div class="metric">
<div class="k">${k}</div>
<div class="v ${cls}">${v}</div>
<div class="n ${k === '平台在线' ? 'warn' : ''}">${n}</div>
</div>`).join('');
const rows = OVERVIEW_ROWS.map(r => `
<div class="t-row" data-scene="${r.name}">
<span class="c-idx">${r.idx}</span>
<span class="c-name ${r.strong ? 'strong' : ''}">${r.name}</span>
<span class="c-plat">${r.plat}</span>
<span class="c-time">${r.time}</span>
<span class="c-state">
<span class="tag w84 ${r.tag[0]}"><i></i>${r.tag[1]}</span>
</span>
</div>`).join('');
return `
${pageHead('总览', '今日运行简报',
'2026.10.23 周五 · 3 个计划待执行 · 每 30 秒自动刷新',
`<button class="btn btn-ghost" data-act="all-scenes">全部场景</button>
<button class="btn btn-primary" data-act="new-scene">新建场景</button>`)}
<div class="metrics">${metrics}</div>
<div class="split">
<div class="card run-now">
<div class="run-top">
<span class="flag"><i></i><b>运行中</b></span>
<span class="run-scene">考勤数据采集</span>
<span class="run-pct" data-pct>${state.progress}%</span>
<span class="run-page" data-pages>${state.pages} / 12 页</span>
</div>
<div class="track"><i data-track style="width:${state.progress}%"></i></div>
<div class="run-foot">
<span class="log" data-console-brief>14:31:24 · 已采集 ${state.collected} 条 · 正在解析部门维度</span>
<span class="rest">剩余约 40s</span>
</div>
</div>
<div class="card trend">
<div class="card-mini-head">
<span class="k">近 7 日运行</span>
<span class="v">41</span>
</div>
<div class="bars">
${TREND.map(t => `<div class="bar ${t.now ? 'now' : ''}" style="height:${t.v}px"></div>`).join('')}
</div>
<div class="bar-labels">
${TREND.map(t => `<span class="${t.now ? 'now' : ''}">${t.d}</span>`).join('')}
</div>
</div>
</div>
<div class="sec-head">
<span class="sec-title">最近运行场景</span>
<span class="link" data-act="all-scenes">全部 18 个场景 →</span>
</div>
<div class="card table">
<div class="t-head">
<span class="c-idx num">#</span>
<span class="c-name">场景名称</span>
<span class="c-plat">平台 / 分类</span>
<span class="c-time">最近运行</span>
<span class="c-state txt">状态</span>
</div>
<div class="t-body">${rows}</div>
<div class="t-foot">
<span class="note">显示 7 / 18 项 · 按最近运行排序</span>
<span class="link" data-act="more">加载更多 →</span>
</div>
</div>`;
}
/* ---------------- 运行台 ---------------- */
function viewRunner() {
const reads = [
['状态', '运行中', 'brand', ''],
['已用时', hhmmss(state.elapsed), '', 'elapsed'],
['进度', state.progress + '%', '', 'read-pct'],
['已采集', String(state.collected), '', 'collected'],
['下一步', '汇总并写入表格', 'cn', '']
].map(([k, v, cls, hook]) => `
<div class="read">
<div class="k">${k}</div>
<div class="v ${cls}" ${hook ? `data-${hook}` : ''}>${v}</div>
</div>`).join('<div class="vr"></div>');
const params = [
['日期范围', '2026-10-01 ~ 10-23', 'num'],
['统计部门', '全部部门', ''],
['完成后通知', '钉钉「考勤提醒」', ''],
['输出文件', '考勤_202610.xlsx', 'file']
].map(([k, v, cls]) => `
<div class="param-row"><span class="k">${k}</span><span class="v ${cls}">${v}</span></div>`)
.join('<div class="hr"></div>');
const stages = [
['done', '✓', '登录 HR 人力系统', '完成'],
['done', '✓', '打开考勤模块', '完成'],
['doing', '3', `抓取考勤数据 ${state.pages}/12 页`, '进行中'],
['todo', '4', '部门维度汇总', '待执行'],
['todo', '5', '写入汇总表', '待执行']
].map(([cls, b, nm, st]) => `
<div class="stage ${cls}">
<span class="badge">${b}</span>
<span class="nm">${nm}</span>
<span class="st">${st}</span>
</div>`).join('');
const logs = state.logs.map(([t, lv, msg, cls]) => `
<div class="${cls}">${t} ${lv.padEnd(8, ' ')}${msg}</div>`).join('');
return `
${pageHead('运行台', state.scene,
'v1.2 · 数据采集 · HR 人力系统 · 上次运行 今天 14:32 成功',
`<button class="btn btn-ghost" data-act="schedule">设为定时</button>
<button class="btn btn-primary" data-act="run">${svg('play', 10)}${state.done ? '再次执行' : '立即执行'}</button>`)}
<div class="readbar">${reads}</div>
<div class="run-body">
<div class="col-left">
<div class="card">
<div class="card-head"><span class="t">运行参数</span><span class="edit" data-act="edit-params">编辑</span></div>
${params}
</div>
<div class="card">
<div class="card-head"><span class="t">执行阶段</span><span class="m">3 / 5</span></div>
${stages}
</div>
<div class="card">
<div class="card-head" style="align-items:baseline"><span class="t">本次产物</span><span class="m">12.4 MB</span></div>
<div class="art-gap"></div>
<div class="art-row now">
<span class="fn">考勤_202610.xlsx</span>
<span class="go" data-act="open-file">打开 →</span>
</div>
<div class="art-gap"></div>
<div class="art-row">
<span class="fn">考勤_202609.xlsx</span>
<span class="tm">09-30</span>
</div>
<div class="art-gap"></div>
<div class="art-row">
<span class="fn">考勤_202608.xlsx</span>
<span class="tm">08-31</span>
</div>
</div>
</div>
<div class="console">
<div class="con-head">
<span class="con-title">实时日志</span>
<span class="live"><i></i>LIVE</span>
<span class="con-sub" data-act="scroll">自动滚动</span>
</div>
<div class="con-body" id="consoleBody">${logs}</div>
</div>
</div>`;
}
/* ---------------- 计划 ---------------- */
function viewPlans() {
const max = Math.max(...WEEK.map(w => w.v));
const cols = WEEK.map(w => `
<div class="wcol ${w.now ? 'now' : ''}">
<div class="wbar" style="height:${Math.round(30 + (w.v - 1) / (max - 1) * 46)}px"></div>
<div class="wl">${w.l}</div>
</div>`).join('');
const rows = PLANS.map(p => `
<div class="t-row ${p.muted ? 'muted' : ''}">
<span class="p-time">${p.time}</span>
<span class="p-freq">${p.freq}</span>
<span class="p-scene ${p.strong ? 'strong' : ''}">${p.scene}</span>
<span class="p-res ${p.resCls || ''}">${p.res}</span>
<span class="p-next">${p.next}</span>
<span class="p-state">
<span class="tag w64 ${p.state[0]}"><i></i>${p.state[1]}</span>
</span>
</div>`).join('');
return `
${pageHead('计划', '计划任务',
'7 个启用 · 2 个暂停 · 下次执行 明天 08:30 · 平均用时 1 分 12 秒',
`<button class="btn btn-ghost" data-act="pause-all">${state.plansPaused ? '恢复全部' : '暂停全部'}</button>
<button class="btn btn-primary" data-act="new-plan"><span class="plus">+</span>新建计划</button>`)}
<div class="card week-card">
<div class="week-title">
<span class="t">本周运行分布</span>
<span class="m">共 12 次 · 峰值 周五 4 次</span>
</div>
<div class="week-bars">${cols}</div>
</div>
<div class="card table">
<div class="t-head">
<span class="p-time">时间</span>
<span class="p-freq">频率</span>
<span class="p-scene">场景</span>
<span class="p-res">上次结果</span>
<span class="p-next">下次执行</span>
<span class="p-state" style="justify-content:center">状态</span>
</div>
<div class="t-body">${rows}</div>
<div class="t-foot">
<span class="note">共 9 个计划 · 调度器每 30 秒轮询一次</span>
<span class="link" data-act="edit-plans">编辑计划 →</span>
</div>
</div>`;
}
/* ---------------- 渲染 ---------------- */
function render() {
renderRailLeft();
renderRailRight();
renderStatus();
$('#crumb').textContent = CRUMB[state.page] || '总览';
$('#main').innerHTML =
state.page === 'runner' ? viewRunner() :
state.page === 'plans' ? viewPlans() : viewOverview();
if (state.page === 'runner') scrollConsole();
}
function scrollConsole() {
const b = $('#consoleBody');
if (b) b.scrollTop = b.scrollHeight;
}
/* ---------------- 运行模拟 ---------------- */
let runTimer = null;
function startRun() {
if (runTimer) return;
state.done = false;
const tick = () => {
state.elapsed += 3;
state.progress = Math.min(100, state.progress + 2);
if (state.progress % 6 === 0) {
state.pages = Math.min(12, state.pages + 1);
state.collected += Math.round(30 + Math.random() * 20);
pushLog('INFO', `第 ${state.pages}/12 页 · 已采集 ${state.collected} 条`, '');
}
patchRun();
if (state.progress >= 100) {
clearInterval(runTimer); runTimer = null;
state.done = true;
pushLog('INFO', '采集完成 · 12/12 页 · 汇总写入 考勤_202610.xlsx', 'ok');
pushLog('INFO', '运行成功 · 总用时 ' + hhmmss(state.elapsed), 'ok');
patchRun();
toast('运行完成 · 共采集 ' + state.collected + ' 条');
render();
}
};
pushLog('INFO', '开始执行 · 考勤数据采集 v1.2', '');
patchRun();
runTimer = setInterval(tick, 260);
}
function pushLog(lv, msg, cls) {
const d = new Date();
const t = `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
state.logs.push([t, lv, msg, cls]);
const body = $('#consoleBody');
if (body) {
const div = document.createElement('div');
if (cls) div.className = cls;
div.textContent = `${t} ${lv.padEnd(8, ' ')}${msg}`;
body.appendChild(div);
scrollConsole();
}
}
function patchRun() {
const q = (s, v, prop = 'textContent') => {
const el = $(s);
if (el) el[prop] = v;
};
if (state.page === 'overview') {
q('[data-pct]', state.progress + '%');
q('[data-pages]', `${state.pages} / 12 页`);
const bar = $('[data-track]');
if (bar) bar.style.width = state.progress + '%';
}
if (state.page === 'runner') {
q('[data-elapsed]', hhmmss(state.elapsed));
q('[data-read-pct]', state.progress + '%');
q('[data-collected]', String(state.collected));
}
q('[data-right-pct]', state.progress + '%');
const rb = $('[data-right-track]');
if (rb) rb.style.width = state.progress + '%';
q('[data-right-log]', `抓取第 ${Math.min(state.pages, 12)} / 12 页 · 已采 ${state.collected} 条`);
}
/* ---------------- 事件 ---------------- */
document.addEventListener('click', e => {
const nav = e.target.closest('[data-nav]');
if (nav) {
const key = nav.dataset.nav;
if (key === 'overview') { state.page = 'overview'; render(); return; }
if (key === 'plans') { state.page = 'plans'; render(); return; }
toast(key === 'library' ? '场景库整页未包含在本稿范围' : '平台账号整页未包含在本稿范围');
return;
}
const scene = e.target.closest('[data-scene]');
if (scene) {
state.scene = scene.dataset.scene;
state.page = 'runner';
render();
return;
}
const act = e.target.closest('[data-act]');
if (!act) return;
const map = {
'all-scenes': () => { toast('场景库整页未包含在本稿范围'); },
'new-scene': () => toast('演示环境:新建场景'),
'schedule': () => toast('已加入定时计划 · 明天 08:30'),
'run': startRun,
'pause-all': () => {
state.plansPaused = !state.plansPaused;
act.textContent = state.plansPaused ? '恢复全部' : '暂停全部';
toast(state.plansPaused ? '已暂停全部计划' : '已恢复全部计划');
},
'new-plan': () => toast('演示环境:新建计划'),
'more': () => toast('演示环境:加载更多'),
'edit-params': () => toast('演示环境:编辑运行参数'),
'edit-plans': () => toast('演示环境:编辑计划'),
'open-file': () => toast('打开 考勤_202610.xlsx'),
'scroll': () => { scrollConsole(); toast('已滚动到最新日志'); },
'quit': () => toast('演示环境:退出登录'),
'platform': () => toast('演示环境:平台账号管理'),
'check': () => toast('当前已是最新版本 v1.2.0')
};
(map[act.dataset.act] || (() => {}))();
});
document.addEventListener('input', e => {
if (e.target.id === 'sceneSearch') {
state.search = e.target.value;
renderRailLeft();
const el = $('#sceneSearch');
if (el) { el.focus(); el.setSelectionRange(el.value.length, el.value.length); }
}
});
document.addEventListener('keydown', e => {
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
e.preventDefault();
const el = $('#sceneSearch');
if (el) el.focus();
}
});
document.querySelectorAll('[data-win]').forEach(el => {
el.addEventListener('click', () => toast('演示环境:窗口' + ({ min: '最小化', max: '最大化', close: '关闭' }[el.dataset.win])));
});
/* 启动:每秒刷新「已用时」 */
setInterval(() => {
if (state.progress >= 100) return;
state.elapsed += 1;
const el = $('[data-elapsed]');
if (el) el.textContent = hhmmss(state.elapsed);
}, 1000);
render();
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=1440, initial-scale=1" />
<title>37du 自动化工作台 · 设计稿还原</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="window" id="window">
<!-- 顶栏 -->
<header class="topbar">
<div class="brand">
<span class="brand-mark">37</span>
<span class="brand-name">37du 自动化工作台</span>
</div>
<div class="crumbs">
<span class="crumbs-sep"></span>
<span class="c1">工作台</span>
<span class="slash">/</span>
<span class="c2" id="crumb">总览</span>
</div>
<div class="spacer"></div>
<div class="pill-service"><i class="dot dot-good"></i>本地服务正常</div>
<span class="version">v1.2.0</span>
<div class="win-ctrl">
<span data-win="min" title="最小化">—</span>
<span data-win="max" title="最大化">▢</span>
<span data-win="close" title="关闭">✕</span>
</div>
</header>
<!-- 主体三栏 -->
<div class="body">
<aside class="panel rail-left" id="railLeft"></aside>
<main class="main" id="main"></main>
<aside class="panel rail-right" id="railRight"></aside>
</div>
<!-- 状态栏 -->
<footer class="statusbar" id="statusbar"></footer>
</div>
<div class="toast" id="toast"></div>
<script src="app.js"></script>
</body>
</html>
@@ -0,0 +1,588 @@
/* ============================================================
37du 自动化工作台 · 视觉令牌
严格取自设计稿:画布 / 卡面 / 主色 / 文字四阶 / 语义色
============================================================ */
:root{
/* 底色与卡面 */
--canvas:#F2F4F8;
--surface:#FFFFFF;
--field:#F5F6FA;
--subtle:#F7F8FC;
--table-head:#FAFBFD;
/* 描边 */
--line:#E8EAF1; /* 卡片外框 1px */
--line-soft:#F0F2F7; /* 卡内分隔线 1px */
--line-btn:#E3E6EF; /* 次要按钮描边 */
--line-win:#DDE1EA; /* 窗口外框 */
/* 文字四阶 + 更浅两阶 */
--t1:#12141B;
--t2:#3C4250;
--t3:#6E7686;
--t4:#A3AAB8;
--t5:#C6CBD6;
/* 主色 */
--brand:#4F5AE8;
--brand-ink:#3D47D4;
--brand-soft:#EEF0FE;
--brand-soft-2:#EFF1FE;
--brand-track:#DDE1F8;
--brand-bar:#EDF0F6;
/* 语义色 */
--good:#0E9F76; --good-ink:#0B8A66; --good-soft:#EBF7F2;
--warn:#D98218; --warn-ink:#B4700F; --warn-soft:#FDF3E4;
--danger:#E5484D; --danger-ink:#CC3B40;--danger-soft:#FDEDED;
--info:#3B9BE8; --violet:#7C6BE8;
--idle-bar:#E4E7EF;
/* 控制台 */
--con:#14161C;
--con-line:#262A34;
--con-bg2:#22262F;
--con-t1:#9AA3B5;
--con-t2:#5F6879;
--con-warn:#E8B15C;
--con-ok:#7FD1AD;
--con-live:#34D399;
/* 圆角 */
--r-row:8px;
--r-field:9px;
--r-btn:10px;
--r-sub:12px;
--r-card:14px;
--r-win:16px;
--r-pill:999px;
/* 阴影三级(全站仅此三种 + 窗口投影) */
--sh-card:0 2px 8px rgba(18,20,31,.05);
--sh-float:0 8px 24px rgba(18,20,31,.10);
--sh-brand:0 4px 12px rgba(79,89,232,.28);
--sh-console:0 4px 16px rgba(18,20,31,.08);
--sh-win:0 18px 48px rgba(13,15,23,.12);
/* 字体 */
--f-cn:"PingFang SC","HarmonyOS Sans SC","Microsoft YaHei","Noto Sans SC",system-ui,-apple-system,sans-serif;
--f-num:"Inter","SF Pro Display",-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
--f-mono:"JetBrains Mono","SFMono-Regular",Consolas,"Liberation Mono",Menlo,monospace;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
margin:0;
background:var(--canvas);
color:var(--t1);
font-family:var(--f-cn);
font-size:12px;
line-height:1.42;
-webkit-font-smoothing:antialiased;
text-rendering:optimizeLegibility;
overflow:auto;
}
::selection{background:#DFE2FC;color:var(--brand-ink)}
button{font-family:inherit}
/* ============================================================
窗口骨架 1440×900
============================================================ */
.window{
height:100vh;min-height:720px;min-width:1120px;
display:flex;flex-direction:column;
background:var(--canvas);
border:1px solid var(--line-win);
border-radius:var(--r-win);
box-shadow:var(--sh-win);
overflow:hidden;
}
/* ---------- 顶栏 52 ---------- */
.topbar{
flex:0 0 52px;height:52px;
display:flex;align-items:center;gap:12px;
padding:0 16px;background:var(--surface);
border-bottom:1px solid var(--line);
user-select:none;
}
.brand{display:flex;align-items:center;gap:9px}
.brand-mark{
width:26px;height:26px;border-radius:var(--r-row);
background:var(--brand);color:#fff;
display:grid;place-items:center;
font:700 10.5px/1 var(--f-num);letter-spacing:.2px;
}
.brand-name{font:600 13px/18px var(--f-cn);color:var(--t1)}
.crumbs{display:flex;align-items:center;gap:7px}
.crumbs-sep{width:1px;height:12px;background:var(--line)}
.crumbs .c1{font:400 11.5px/1 var(--f-cn);color:var(--t4)}
.crumbs .slash{font:400 11px/1 var(--f-num);color:var(--t5)}
.crumbs .c2{font:500 11.5px/1 var(--f-cn);color:var(--t2)}
.spacer{flex:1}
.pill-service{
display:inline-flex;align-items:center;gap:6px;
padding:5px 10px;border-radius:var(--r-pill);
background:var(--good-soft);color:var(--good);
font:500 10.5px/15px var(--f-cn);
}
.dot{display:inline-block;border-radius:50%;flex:0 0 auto}
.dot-good{width:6px;height:6px;background:var(--good)}
.d5-good{width:5px;height:5px;background:var(--good)}
.version{font:400 10.5px/15px var(--f-num);color:var(--t4)}
.win-ctrl{display:flex;align-items:center;gap:18px}
.win-ctrl span{
font:400 11px/1 var(--f-num);color:var(--t4);
cursor:default;transition:color .15s;
}
.win-ctrl span:hover{color:var(--t2)}
.win-ctrl span[data-win="close"]{font-size:10px}
.win-ctrl span[data-win="close"]:hover{color:var(--danger)}
/* ---------- 主体三栏 ---------- */
.body{
flex:1;min-height:0;
display:flex;gap:10px;padding:10px;
background:var(--canvas);
}
.panel{
background:var(--surface);
border:1px solid var(--line);
border-radius:var(--r-card);
display:flex;flex-direction:column;
min-height:0;
}
.rail-left{width:232px;flex:0 0 232px;padding:10px;gap:8px}
.rail-right{width:276px;flex:0 0 276px;padding:10px;gap:10px}
.main{flex:1;min-width:0;display:flex;flex-direction:column;gap:12px;min-height:0}
/* ---------- 状态栏 38 ---------- */
.statusbar{
flex:0 0 38px;height:38px;
display:flex;align-items:center;gap:14px;
padding:0 16px;background:var(--surface);
border-top:1px solid var(--line);
font-size:10px;color:var(--t3);
user-select:none;
}
.statusbar .item{display:flex;align-items:center;gap:6px}
.statusbar .item span{font:400 10px/14px var(--f-cn);color:var(--t3)}
.statusbar .item.num span{font-family:var(--f-num)}
.statusbar .ver{font:400 10px/14px var(--f-num);color:var(--t4)}
.statusbar .upd{font:500 10px/14px var(--f-cn);color:var(--brand);cursor:pointer}
.statusbar .upd:hover{color:var(--brand-ink)}
/* ============================================================
左栏 · 导航与场景库
============================================================ */
.nav{display:flex;flex-direction:column;gap:2px}
.nav-item{
height:34px;display:flex;align-items:center;gap:9px;
padding:0 10px;border-radius:var(--r-field);
color:var(--t2);cursor:pointer;
font:400 12.5px/18px var(--f-cn);
transition:background .15s,color .15s;
border:0;background:transparent;width:100%;text-align:left;
}
.nav-item svg{flex:0 0 15px;color:var(--t2)}
.nav-item:hover{background:var(--field)}
.nav-item.active{background:var(--brand-soft);color:var(--brand-ink);font-weight:600}
.nav-item.active svg{color:var(--brand)}
.nav-label{flex:1}
.nav-count{font:400 10px/14px var(--f-num);color:var(--t4)}
.nav-count.good{color:var(--good)}
.nav-item.active .nav-count{color:#8E97E8;font-weight:500}
.hr{height:1px;background:var(--line-soft);flex:0 0 1px}
.scene-head{display:flex;align-items:center;gap:8px}
.scene-head .label{flex:1;font:600 11px/16px var(--f-cn);color:var(--t4);letter-spacing:.2px}
.count-pill{
padding:3px 7px;border-radius:6px;background:var(--field);
font:500 10px/14px var(--f-num);color:var(--t3);
}
.search{
height:32px;display:flex;align-items:center;gap:7px;
padding:0 10px;border-radius:var(--r-field);
background:var(--field);border:1px solid transparent;
transition:background .15s,border-color .15s;
}
.search:focus-within{background:var(--surface);border-color:#D9DEEF}
.search svg{flex:0 0 13px;color:var(--t4)}
.search input{
flex:1;min-width:0;border:0;background:transparent;outline:none;
font:400 11.5px/16px var(--f-cn);color:var(--t1);
}
.search input::placeholder{color:var(--t4)}
.search .kbd{font:500 9.5px/14px var(--f-num);color:var(--t5)}
.group-head{display:flex;align-items:center;gap:6px}
.group-head .label{flex:1;font:600 10.5px/15px var(--f-cn);color:var(--t4)}
.group-head .n{font:400 10px/14px var(--f-num);color:var(--t5)}
.scene-row{
height:32px;display:flex;align-items:center;gap:8px;
padding:0 8px;border-radius:var(--r-row);
cursor:pointer;transition:background .15s;
}
.scene-row:hover{background:var(--subtle)}
.scene-row.current{background:var(--field)}
.scene-dot{width:6px;height:6px;border-radius:3px;flex:0 0 6px}
.scene-name{
flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
font:400 12px/17px var(--f-cn);color:var(--t2);
}
.scene-row.current .scene-name{font-weight:500;color:var(--t1)}
.scene-time{font:400 10px/14px var(--f-num);color:var(--t4)}
.rail-flex{flex:1;min-height:8px}
.account{
display:flex;align-items:center;gap:9px;
padding:8px 9px;border-radius:var(--r-btn);background:var(--field);
}
.avatar{
width:26px;height:26px;flex:0 0 26px;border-radius:var(--r-row);
background:#E6E9FD;color:var(--brand-ink);
display:grid;place-items:center;font:600 10.5px/1 var(--f-cn);
}
.account .who{flex:1;min-width:0;display:flex;flex-direction:column;gap:1px}
.account .name{font:500 12px/17px var(--f-cn);color:var(--t1)}
.account .role{font:400 10px/14px var(--f-cn);color:var(--t4)}
.account .quit{font:500 10.5px/15px var(--f-cn);color:var(--t3);cursor:pointer}
.account .quit:hover{color:var(--danger)}
/* ============================================================
中栏 · 通用页头
============================================================ */
.page-head{display:flex;align-items:flex-end;gap:12px;flex:0 0 auto}
.page-title-group{flex:1;min-width:0;display:flex;flex-direction:column;gap:5px}
.eyebrow{font:600 10.5px/15px var(--f-cn);color:var(--brand);letter-spacing:.4px}
.page-title{font:600 26px/38px var(--f-cn);color:var(--t1);letter-spacing:-.2px;margin:0}
.page-sub{font:400 11.5px/17px var(--f-cn);color:var(--t3)}
.actions{display:flex;align-items:center;gap:8px}
.btn{
height:34px;display:inline-flex;align-items:center;justify-content:center;gap:6px;
padding:0 14px;border-radius:var(--r-btn);border:1px solid transparent;
background:var(--surface);color:var(--t2);
font:500 12px/18px var(--f-cn);cursor:pointer;
transition:background .15s,border-color .15s,box-shadow .15s,transform .06s;
white-space:nowrap;
}
.btn-ghost{border-color:var(--line-btn)}
.btn-ghost:hover{background:var(--subtle);border-color:#D9DEEF}
.btn-ghost:active{background:var(--field)}
.btn-primary{
background:var(--brand);color:#fff;font-weight:600;
box-shadow:var(--sh-brand);
}
.btn-primary:hover{background:#4550E0}
.btn-primary:active{transform:translateY(1px);box-shadow:0 2px 8px rgba(79,89,232,.24)}
.btn .plus{font:600 13px/1 var(--f-num);margin-top:-1px}
/* ============================================================
总览 · 指标卡 / 运行卡 / 趋势卡
============================================================ */
.card{
background:var(--surface);
border:1px solid var(--line);
border-radius:var(--r-card);
box-shadow:var(--sh-card);
}
.metrics{display:flex;gap:12px;flex:0 0 auto}
.metric{
flex:1;min-width:0;
display:flex;flex-direction:column;gap:4px;
padding:13px 16px;
background:var(--surface);border:1px solid var(--line);
border-radius:var(--r-card);box-shadow:var(--sh-card);
}
.metric .k{font:500 10.5px/15px var(--f-cn);color:var(--t3)}
.metric .v{font:600 24px/29px var(--f-num);color:var(--t1);letter-spacing:-.4px}
.metric .v.good{color:var(--good)}
.metric .n{font:400 10.5px/15px var(--f-cn);color:var(--t4)}
.metric .n.warn{color:var(--warn)}
.split{display:flex;gap:12px;flex:0 0 132px;height:132px}
.run-now{
flex:1;min-width:0;
display:flex;flex-direction:column;gap:11px;
padding:14px 16px;
}
.run-top{display:flex;align-items:center;gap:8px;height:19px}
.flag{display:inline-flex;align-items:center;gap:8px}
.flag i{width:7px;height:7px;border-radius:4px;background:var(--danger)}
.flag b{font:600 10.5px/15px var(--f-cn);color:var(--danger)}
.run-scene{
flex:1;min-width:0;
font:600 13px/19px var(--f-cn);color:var(--t1);
overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
.run-pct{font:600 13px/19px var(--f-num);color:var(--brand)}
.run-page{font:400 10.5px/15px var(--f-cn);color:var(--t4)}
.track{height:6px;border-radius:var(--r-pill);background:var(--brand-bar);overflow:hidden}
.track > i{display:block;height:100%;border-radius:var(--r-pill);background:var(--brand);transition:width .5s ease}
.run-foot{display:flex;align-items:center;gap:8px;font:400 10.5px/15px var(--f-cn);color:var(--t3)}
.run-foot .log{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.run-foot .rest{color:var(--t4)}
.trend{flex:0 0 220px;width:220px;display:flex;flex-direction:column;gap:9px;padding:14px 16px}
.card-mini-head{display:flex;align-items:baseline;gap:6px}
.card-mini-head .k{flex:1;font:500 10.5px/15px var(--f-cn);color:var(--t3)}
.card-mini-head .v{font:600 13px/19px var(--f-num);color:var(--t1)}
.bars{flex:1;min-height:0;display:flex;align-items:flex-end;gap:5px}
.bars .bar{flex:1;border-radius:4px;background:var(--idle-bar);min-height:2px}
.bars .bar.now{background:var(--brand)}
.bar-labels{display:flex;gap:5px;font:400 9px/13px var(--f-cn);color:var(--t5)}
.bar-labels span{flex:1;text-align:center}
.bar-labels span.now{font-weight:600;color:var(--brand)}
.sec-head{display:flex;align-items:center;gap:8px;flex:0 0 auto;height:17px}
.sec-title{flex:1;font:600 12px/17px var(--f-cn);color:var(--t1)}
.link{font:500 11.5px/17px var(--f-cn);color:var(--brand);cursor:pointer;white-space:nowrap}
.link:hover{color:var(--brand-ink)}
/* ---------- 数据表 ---------- */
.table{flex:1;min-height:0;display:flex;flex-direction:column;overflow:hidden}
.t-head{
flex:0 0 36px;height:36px;
display:flex;align-items:center;
padding:0 16px;background:var(--table-head);
border-bottom:1px solid var(--line-soft);
font:500 10px/14px var(--f-cn);color:var(--t4);
}
.t-head .num{font-family:var(--f-num);font-weight:400}
.t-body{flex:1;min-height:0;overflow:auto;scrollbar-width:thin}
.t-body::-webkit-scrollbar{width:8px}
.t-body::-webkit-scrollbar-thumb{background:#DDE1EA;border-radius:4px}
.col-left::-webkit-scrollbar{width:6px}
.col-left::-webkit-scrollbar-thumb{background:#E3E6EF;border-radius:3px}
.t-row{
height:45px;display:flex;align-items:center;
padding:0 16px;background:var(--surface);
transition:background .12s;
}
.t-row + .t-row{border-top:1px solid var(--line-soft)}
.t-row:hover{background:#FBFCFE}
.t-row.sel{background:var(--subtle)}
.t-foot{
flex:0 0 38px;height:38px;
display:flex;align-items:center;gap:8px;
padding:0 16px;background:var(--table-head);
border-top:1px solid var(--line-soft);
font:400 10.5px/15px var(--f-cn);color:var(--t4);
}
.t-foot .note{flex:1}
/* 列宽(严格对齐设计稿) */
.c-idx{flex:0 0 28px;width:28px;font:400 10px/14px var(--f-num);color:var(--t5)}
.c-name{flex:1;min-width:0;font:400 12.5px/18px var(--f-cn);color:var(--t2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.c-name.strong{font-weight:500;color:var(--t1)}
.c-plat{flex:0 0 140px;width:140px;font:400 10.5px/15px var(--f-cn);color:var(--t3)}
.c-time{flex:0 0 104px;width:104px;font:400 10.5px/15px var(--f-cn);color:var(--t3)}
.c-state{flex:0 0 84px;width:84px;display:flex;justify-content:center}
.c-state.txt{justify-content:center;font:500 10px/14px var(--f-cn);color:var(--t4)}
.t-extra{display:flex;flex-direction:column;gap:1px;flex:1;min-width:0}
/* 状态胶囊 */
.tag{
height:22px;border-radius:var(--r-pill);
display:inline-flex;align-items:center;justify-content:center;gap:5px;
padding:0 10px;font:500 10px/1 var(--f-cn);white-space:nowrap;
}
.tag.w84{width:84px}
.tag.w64{width:64px}
.tag i{width:5px;height:5px;border-radius:3px;background:currentColor;flex:0 0 5px}
.tag.ok{background:var(--good-soft);color:var(--good-ink)}
.tag.ok i{background:var(--good)}
.tag.warn{background:var(--warn-soft);color:var(--warn-ink)}
.tag.warn i{background:var(--warn)}
.tag.off{background:var(--canvas);color:var(--t3)}
.tag.off i{background:var(--t5)}
.tag.live{background:var(--danger-soft);color:var(--danger-ink)}
.tag.live i{background:var(--danger)}
/* ============================================================
运行台
============================================================ */
.readbar{
flex:0 0 auto;display:flex;align-items:stretch;
background:var(--surface);border:1px solid var(--line);
border-radius:var(--r-card);box-shadow:var(--sh-card);
overflow:hidden;
}
.read{flex:1;min-width:0;display:flex;flex-direction:column;gap:3px;padding:10px 14px}
.read .k{font:500 9.5px/14px var(--f-cn);color:var(--t4)}
.read .v{font:600 13px/19px var(--f-num);color:var(--t1);letter-spacing:-.1px}
.read .v.brand{color:var(--brand)}
.read .v.cn{font:500 12px/17px var(--f-cn);color:var(--t2)}
.vr{width:1px;flex:0 0 1px;background:var(--line-soft)}
.run-body{flex:1;min-height:0;display:flex;gap:12px}
.col-left{flex:0 0 300px;width:300px;display:flex;flex-direction:column;gap:12px;min-height:0;overflow-y:auto;overflow-x:hidden;scrollbar-width:thin;padding-right:1px}
.col-left .card{padding:14px;display:flex;flex-direction:column;gap:0}
.card-head{display:flex;align-items:center;gap:8px;height:17px}
.card-head .t{flex:1;font:600 12px/17px var(--f-cn);color:var(--t1)}
.card-head .m{font:500 10.5px/14px var(--f-num);color:var(--t4)}
.card-head .edit{font:500 11px/16px var(--f-cn);color:var(--brand);cursor:pointer}
.card-head .edit:hover{color:var(--brand-ink)}
.param-row{display:flex;align-items:baseline;gap:10px;padding:10px 0}
.param-row .k{flex:0 0 66px;width:66px;font:400 11px/16px var(--f-cn);color:var(--t3)}
.param-row .v{flex:1;min-width:0;font:400 12px/17px var(--f-cn);color:var(--t1);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.param-row .v.num{font:500 11.5px/17px var(--f-num)}
.param-row .v.file{font:400 11px/16px var(--f-num)}
.stage{display:flex;align-items:center;gap:9px;padding:9px 0}
.stage .badge{
width:16px;height:16px;flex:0 0 16px;border-radius:var(--r-pill);
display:grid;place-items:center;
font:700 8.5px/1 var(--f-num);
background:var(--good-soft);color:var(--good);
}
.stage .nm{flex:1;min-width:0;font:400 11.5px/17px var(--f-cn);color:var(--t3);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.stage .st{font:400 10px/14px var(--f-cn);color:var(--t4)}
.stage.doing .badge{background:var(--brand);color:#fff}
.stage.doing .nm{font-weight:500;color:var(--t1)}
.stage.doing .st{font-weight:500;color:var(--brand)}
.stage.todo .badge{background:var(--canvas);color:var(--t4)}
.stage.todo .nm{color:var(--t4)}
.stage.todo .st{color:var(--t5)}
.art-row{
height:34px;display:flex;align-items:center;gap:8px;
padding:0 10px;border-radius:var(--r-btn);background:var(--subtle);
}
.art-row .fn{flex:1;min-width:0;font:400 11.5px/16px var(--f-num);color:var(--t2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.art-row.now .fn{color:var(--t1)}
.art-row .go{font:500 11px/16px var(--f-cn);color:var(--brand);cursor:pointer}
.art-row .tm{font:400 10px/14px var(--f-num);color:var(--t4)}
.art-gap{height:8px;flex:0 0 8px}
/* ---------- 控制台 ---------- */
.console{
flex:1;min-width:0;display:flex;flex-direction:column;
background:var(--con);border-radius:var(--r-card);
box-shadow:var(--sh-console);overflow:hidden;
}
.con-head{
flex:0 0 41px;height:41px;
display:flex;align-items:center;gap:10px;padding:0 16px;
border-bottom:1px solid var(--con-line);
}
.con-title{flex:1;font:600 12px/17px var(--f-cn);color:#F5F6FA}
.live{
display:inline-flex;align-items:center;gap:5px;
padding:3px 7px;border-radius:6px;background:var(--con-bg2);
font:600 9px/14px var(--f-num);color:var(--con-live);
}
.live i{width:5px;height:5px;border-radius:3px;background:var(--con-live)}
.con-sub{font:400 10px/14px var(--f-cn);color:#6F7787;cursor:pointer}
.con-sub:hover{color:#9AA3B5}
.con-body{
flex:1;min-height:0;overflow:auto;
padding:14px 16px;display:flex;flex-direction:column;gap:7px;
font:400 10px/14px var(--f-mono);color:var(--con-t1);
scrollbar-width:thin;
}
.con-body::-webkit-scrollbar{width:8px}
.con-body::-webkit-scrollbar-thumb{background:#2C313C;border-radius:4px}
.con-body .warn{color:var(--con-warn)}
.con-body .ok{color:var(--con-ok)}
.con-body .dim{color:var(--con-t2)}
.con-body .cur{color:var(--brand)}
.con-body div{white-space:pre-wrap;word-break:break-word}
/* ============================================================
计划页
============================================================ */
.week-card{padding:13px 16px;display:flex;flex-direction:column;gap:12px;flex:0 0 auto}
.week-title{display:flex;align-items:baseline;gap:8px}
.week-title .t{flex:1;font:600 12px/17px var(--f-cn);color:var(--t1)}
.week-title .m{font:400 10.5px/15px var(--f-cn);color:var(--t4)}
.week-bars{display:flex;gap:10px;height:100px}
.wcol{flex:1;min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:8px}
.wcol .wbar{width:24px;border-radius:5px;background:var(--idle-bar);transition:height .3s ease}
.wcol.now .wbar{background:var(--brand)}
.wcol .wl{font:400 10px/14px var(--f-cn);color:var(--t4);white-space:nowrap}
.wcol.now .wl{font-weight:600;color:var(--brand)}
/* 计划表列宽 */
.p-time{flex:0 0 76px;width:76px;font:600 11.5px/17px var(--f-num);color:var(--t1)}
.p-freq{flex:0 0 96px;width:96px;font:400 10.5px/15px var(--f-cn);color:var(--t3)}
.p-scene{flex:1;min-width:0;font:400 12.5px/18px var(--f-cn);color:var(--t2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.p-scene.strong{font-weight:500;color:var(--t1)}
.p-res{flex:0 0 112px;width:112px;font:400 10.5px/15px var(--f-cn);color:var(--good-ink)}
.p-res.bad{color:var(--danger)}
.p-res.warn{color:var(--warn-ink)}
.p-next{flex:0 0 128px;width:128px;font:400 10.5px/15px var(--f-cn);color:var(--t3)}
.p-state{flex:0 0 64px;width:64px;display:flex;justify-content:center}
.t-row.muted .p-time,
.t-row.muted .p-freq,
.t-row.muted .p-scene{color:var(--t4)}
.t-row.muted .p-next{color:var(--t5)}
/* ============================================================
右栏 · 活动与账号
============================================================ */
.rail-head{display:flex;align-items:center;gap:6px}
.rail-head .label{flex:1;font:600 11px/16px var(--f-cn);color:var(--t4);letter-spacing:.2px}
.now-card{
background:var(--brand-soft-2);border-radius:var(--r-sub);
padding:12px;display:flex;flex-direction:column;gap:8px;
}
.now-top{display:flex;align-items:center;gap:7px}
.now-top i{width:6px;height:6px;border-radius:3px;background:var(--danger);flex:0 0 6px}
.now-top .nm{flex:1;min-width:0;font:600 12.5px/18px var(--f-cn);color:var(--t1);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.now-top .pct{font:600 12px/17px var(--f-num);color:var(--brand)}
.now-card .track{height:5px;background:var(--brand-track)}
.now-card .log{font:400 10px/14px var(--f-cn);color:var(--t3);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.rail-sub{display:flex;align-items:center;gap:6px;padding-top:2px}
.rail-sub .label{flex:1;font:600 10.5px/15px var(--f-cn);color:var(--t4)}
.rail-sub .n{font:400 10px/14px var(--f-num);color:var(--t5)}
.rail-sub .n.good{color:var(--good-ink);font-weight:500}
.act-row{
height:30px;display:flex;align-items:center;gap:7px;
padding:0 6px;border-radius:var(--r-row);
cursor:pointer;transition:background .15s;
}
.act-row:hover{background:var(--subtle)}
.act-row i{width:5px;height:5px;border-radius:3px;flex:0 0 5px}
.act-row .nm{flex:1;min-width:0;font:400 11.5px/17px var(--f-cn);color:var(--t2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.act-row .tm{font:400 10px/14px var(--f-num);color:var(--t4)}
.act-row .st{flex:0 0 30px;width:30px;font:500 10px/14px var(--f-cn);text-align:left}
.st.ok{color:var(--good-ink)}
.st.warn{color:var(--warn-ink)}
.st.bad{color:var(--danger-ink)}
.plat-row{
height:32px;display:flex;align-items:center;gap:7px;
padding:0 9px;border-radius:var(--r-row);background:var(--subtle);
cursor:pointer;transition:background .15s;
}
.plat-row:hover{background:var(--field)}
.plat-row i{width:5px;height:5px;border-radius:3px;flex:0 0 5px}
.plat-row .nm{flex:1;min-width:0;font:400 11.5px/17px var(--f-cn);color:var(--t2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.plat-row .st{font:500 10px/14px var(--f-cn)}
.rail-foot{display:flex;flex-direction:column;gap:2px;padding-top:8px}
.rail-foot div{font:400 9.5px/14px var(--f-cn);color:var(--t4)}
.rail-foot div:first-child{color:var(--t5)}
/* ============================================================
Toast
============================================================ */
.toast{
position:fixed;left:50%;bottom:64px;transform:translate(-50%,12px);
padding:9px 14px;border-radius:var(--r-btn);
background:#1B1E27;color:#fff;font:500 12px/18px var(--f-cn);
box-shadow:var(--sh-float);opacity:0;pointer-events:none;
transition:opacity .2s,transform .2s;z-index:99;
}
.toast.show{opacity:1;transform:translate(-50%,0)}
@@ -0,0 +1,224 @@
x64:
firstOrDefaultFilePatterns:
- '!**/node_modules'
- '!build{,/**/*}'
- '!dist-app2{,/**/*}'
- electron/**/*
- renderer/**/*
- package.json
- '!**/*.{iml,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,suo,xproj,cc,d.ts,mk,a,o,forge-meta,pdb}'
- '!**/._*'
- '!**/electron-builder.{yaml,yml,json,json5,toml,ts}'
- '!**/{.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,.DS_Store,thumbs.db,.gitignore,.gitkeep,.gitattributes,.npmignore,.idea,.vs,.flowconfig,.jshintrc,.eslintrc,.circleci,.yarn-integrity,.yarn-metadata.json,yarn-error.log,yarn.lock,package-lock.json,npm-debug.log,appveyor.yml,.travis.yml,circle.yml,.nyc_output,.husky,.github,electron-builder.env}'
- '!.yarn{,/**/*}'
- '!.editorconfig'
- '!.yarnrc.yml'
nodeModuleFilePatterns:
- '**/*'
- electron/**/*
- renderer/**/*
- package.json
nsis:
script: |-
!include "D:\work\code\37duAutomation\desktop\electron-shell\node_modules\app-builder-lib\templates\nsis\include\StdUtils.nsh"
!addincludedir "D:\work\code\37duAutomation\desktop\electron-shell\node_modules\app-builder-lib\templates\nsis\include"
!macro _isUpdated _a _b _t _f
${StdUtils.TestParameter} $R9 "updated"
StrCmp "$R9" "true" `${_t}` `${_f}`
!macroend
!define isUpdated `"" isUpdated ""`
!macro _isForceRun _a _b _t _f
${StdUtils.TestParameter} $R9 "force-run"
StrCmp "$R9" "true" `${_t}` `${_f}`
!macroend
!define isForceRun `"" isForceRun ""`
!macro _isKeepShortcuts _a _b _t _f
${StdUtils.TestParameter} $R9 "keep-shortcuts"
StrCmp "$R9" "true" `${_t}` `${_f}`
!macroend
!define isKeepShortcuts `"" isKeepShortcuts ""`
!macro _isNoDesktopShortcut _a _b _t _f
${StdUtils.TestParameter} $R9 "no-desktop-shortcut"
StrCmp "$R9" "true" `${_t}` `${_f}`
!macroend
!define isNoDesktopShortcut `"" isNoDesktopShortcut ""`
!macro _isDeleteAppData _a _b _t _f
${StdUtils.TestParameter} $R9 "delete-app-data"
StrCmp "$R9" "true" `${_t}` `${_f}`
!macroend
!define isDeleteAppData `"" isDeleteAppData ""`
!macro _isForAllUsers _a _b _t _f
${StdUtils.TestParameter} $R9 "allusers"
StrCmp "$R9" "true" `${_t}` `${_f}`
!macroend
!define isForAllUsers `"" isForAllUsers ""`
!macro _isForCurrentUser _a _b _t _f
${StdUtils.TestParameter} $R9 "currentuser"
StrCmp "$R9" "true" `${_t}` `${_f}`
!macroend
!define isForCurrentUser `"" isForCurrentUser ""`
!macro addLangs
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "German"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "SpanishInternational"
!insertmacro MUI_LANGUAGE "SimpChinese"
!insertmacro MUI_LANGUAGE "TradChinese"
!insertmacro MUI_LANGUAGE "Japanese"
!insertmacro MUI_LANGUAGE "Korean"
!insertmacro MUI_LANGUAGE "Italian"
!insertmacro MUI_LANGUAGE "Dutch"
!insertmacro MUI_LANGUAGE "Danish"
!insertmacro MUI_LANGUAGE "Swedish"
!insertmacro MUI_LANGUAGE "Norwegian"
!insertmacro MUI_LANGUAGE "Finnish"
!insertmacro MUI_LANGUAGE "Russian"
!insertmacro MUI_LANGUAGE "Portuguese"
!insertmacro MUI_LANGUAGE "PortugueseBR"
!insertmacro MUI_LANGUAGE "Polish"
!insertmacro MUI_LANGUAGE "Ukrainian"
!insertmacro MUI_LANGUAGE "Czech"
!insertmacro MUI_LANGUAGE "Slovak"
!insertmacro MUI_LANGUAGE "Hungarian"
!insertmacro MUI_LANGUAGE "Arabic"
!insertmacro MUI_LANGUAGE "Turkish"
!insertmacro MUI_LANGUAGE "Thai"
!insertmacro MUI_LANGUAGE "Vietnamese"
!macroend
!include "C:\Users\admin\AppData\Local\Temp\t-atuCpE\0-messages.nsh"
!include "C:\Users\admin\AppData\Local\Temp\t-atuCpE\1-messages.nsh"
!addplugindir /x86-unicode "C:\Users\admin\AppData\Local\electron-builder\Cache\nsis\nsis-resources-3.4.1\plugins\x86-unicode"
Var newStartMenuLink
Var oldStartMenuLink
Var newDesktopLink
Var oldDesktopLink
Var oldShortcutName
Var oldMenuDirectory
!include "common.nsh"
!include "MUI2.nsh"
!include "multiUser.nsh"
!include "allowOnlyOneInstallerInstance.nsh"
!ifdef INSTALL_MODE_PER_ALL_USERS
!ifdef BUILD_UNINSTALLER
RequestExecutionLevel user
!else
RequestExecutionLevel admin
!endif
!else
RequestExecutionLevel user
!endif
!ifdef BUILD_UNINSTALLER
SilentInstall silent
!else
Var appExe
Var launchLink
!endif
!ifdef ONE_CLICK
!include "oneClick.nsh"
!else
!include "assistedInstaller.nsh"
!endif
!insertmacro addLangs
!ifmacrodef customHeader
!insertmacro customHeader
!endif
Function .onInit
Call setInstallSectionSpaceRequired
SetOutPath $INSTDIR
${LogSet} on
!ifmacrodef preInit
!insertmacro preInit
!endif
!ifdef DISPLAY_LANG_SELECTOR
!insertmacro MUI_LANGDLL_DISPLAY
!endif
!ifdef BUILD_UNINSTALLER
WriteUninstaller "${UNINSTALLER_OUT_FILE}"
!insertmacro quitSuccess
!else
!insertmacro check64BitAndSetRegView
!ifdef ONE_CLICK
!insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTANCE
!else
${IfNot} ${UAC_IsInnerInstance}
!insertmacro ALLOW_ONLY_ONE_INSTALLER_INSTANCE
${EndIf}
!endif
!insertmacro initMultiUser
!ifmacrodef customInit
!insertmacro customInit
!endif
!ifmacrodef addLicenseFiles
InitPluginsDir
!insertmacro addLicenseFiles
!endif
!endif
FunctionEnd
!ifndef BUILD_UNINSTALLER
!include "installUtil.nsh"
!endif
Section "install" INSTALL_SECTION_ID
!ifndef BUILD_UNINSTALLER
# If we're running a silent upgrade of a per-machine installation, elevate so extracting the new app will succeed.
# For a non-silent install, the elevation will be triggered when the install mode is selected in the UI,
# but that won't be executed when silent.
!ifndef INSTALL_MODE_PER_ALL_USERS
!ifndef ONE_CLICK
${if} $hasPerMachineInstallation == "1" # set in onInit by initMultiUser
${andIf} ${Silent}
${ifNot} ${UAC_IsAdmin}
ShowWindow $HWNDPARENT ${SW_HIDE}
!insertmacro UAC_RunElevated
${Switch} $0
${Case} 0
${Break}
${Case} 1223 ;user aborted
${Break}
${Default}
MessageBox mb_IconStop|mb_TopMost|mb_SetForeground "Unable to elevate, error $0"
${Break}
${EndSwitch}
Quit
${else}
!insertmacro setInstallModePerAllUsers
${endIf}
${endIf}
!endif
!endif
!include "installSection.nsh"
!endif
SectionEnd
Function setInstallSectionSpaceRequired
!insertmacro setSpaceRequired ${INSTALL_SECTION_ID}
FunctionEnd
!ifdef BUILD_UNINSTALLER
!include "uninstaller.nsh"
!endif
@@ -0,0 +1,21 @@
Copyright (c) Electron contributors
Copyright (c) 2013-2020 GitHub Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

@@ -0,0 +1 @@
1.6.7
@@ -0,0 +1 @@
{"file_format_version": "1.0.0", "ICD": {"library_path": ".\\vk_swiftshader.dll", "api_version": "1.0.5"}}
+7
View File
@@ -163,6 +163,13 @@ async function init(options = {}) {
} catch (e) {
logger.warning(`通知推送启动失败:${e.message}`);
}
// 日志集中回传:运行日志 + 壳日志上送中心机(启动即回传一次 + 15 分钟周期)
try {
require("./log-upload").start();
} catch (e) {
logger.warning(`日志集中回传启动失败:${e.message}`);
}
} else {
logger.info("未配置中心机地址(CONTROLPLANE_URL),进入离线本地模式");
state.setAllowed(new Set());
+104 -21
View File
@@ -4,6 +4,7 @@
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const { spawn, execFile } = require("child_process");
const cp = require("./cpclient");
const config = require("./config");
@@ -14,8 +15,17 @@ const logger = makeLogger("chrome-manager");
const CHROME_CACHE = path.join(config.APP_DATA, "chrome");
let _pendingPkg = null;
// 启动清扫:上次异常退出遗留的 .part 半包(可能上百 MB);启动时无下载在跑,直接清
try {
for (const f of fs.readdirSync(CHROME_CACHE)) {
if (f.endsWith(".part")) {
try { fs.unlinkSync(path.join(CHROME_CACHE, f)); } catch (_) { /* 占用中忽略 */ }
}
}
} catch (_) { /* 目录不存在等忽略 */ }
const _STATE = {
installed: true,
installed: false, // 未知态:首次 status() 会真实检测后覆盖
version: "",
checking: false,
check_error: "",
@@ -30,6 +40,42 @@ const _STATE = {
const VERSION_RE = /^\d+\.\d+\.\d+\.\d+$/;
// 异步流式算 sha256:安装包约 100MB,不能用 readFileSync 卡住主进程事件循环
function sha256File(p) {
return new Promise((resolve, reject) => {
const h = crypto.createHash("sha256");
const s = fs.createReadStream(p);
s.on("data", (c) => h.update(c));
s.on("error", reject);
s.on("end", () => resolve(h.digest("hex")));
});
}
// 复用磁盘上已下载完成的安装包(rename 只发生在 sha 校验通过后,因此 .exe 可信),
// 避免壳子重启后 _pendingPkg 内存态丢失、用户被迫重新下载 ~100MB。
function findCachedPkg() {
try {
const files = fs
.readdirSync(CHROME_CACHE)
.filter((f) => /\.exe$/i.test(f))
.map((f) => {
const p = path.join(CHROME_CACHE, f);
try {
const st = fs.statSync(p);
return { p, mtime: st.mtimeMs, size: st.size };
} catch (_) {
return { p, mtime: 0, size: 0 };
}
})
// 过小的文件视为下载残留,不参与复用
.filter((x) => x.size > 10 * 1024 * 1024)
.sort((a, b) => b.mtime - a.mtime);
return files.length ? files[0].p : null;
} catch (_) {
return null;
}
}
// 系统位数:Chrome 安装包按位数分发(登记分类 chrome-x64 / chrome-x86)
function detectArch() {
const pa = (process.env.PROCESSOR_ARCHITECTURE || "").toLowerCase();
@@ -134,6 +180,8 @@ async function status() {
} else {
_STATE.installed = false;
_STATE.version = "";
// 壳子重启后 _pendingPkg 内存态丢失:从磁盘找回已下载完成的安装包,避免重复下载
if (!_pendingPkg || !fs.existsSync(_pendingPkg)) _pendingPkg = findCachedPkg();
}
const pkgOk = !!_pendingPkg && fs.existsSync(_pendingPkg);
return {
@@ -157,6 +205,7 @@ async function status() {
async function refresh() {
_STATE.checking = true;
_STATE.check_error = ""; // 手动「重新检测」清掉上一次的安装超时/失败提示
try {
await detectLocal();
await cloudInfo();
@@ -173,7 +222,12 @@ async function startDownload() {
if (_STATE.dl_status === "downloading") return;
if (_STATE.dl_status === "downloaded" && _pendingPkg && fs.existsSync(_pendingPkg)) return;
const info = await cloudInfo();
if (!info || !info.url) return;
if (!info || !info.url) {
// 前端点击时已乐观进入"下载中",这里必须落到失败态,否则弹窗停在 0% 无任何提示
_STATE.dl_status = "failed";
_STATE.dl_error = "中心机未登记浏览器安装包(chrome-x64 / chrome-x86 / chrome)";
return;
}
const url = String(info.url).trim();
const expect = String(info.sha256 || "").toLowerCase();
const filename = String(info.filename || (ARCH === "x86" ? "ChromeStandaloneSetup.exe" : "ChromeStandaloneSetup64.exe")).trim();
@@ -185,45 +239,66 @@ async function startDownload() {
_STATE.dl_pct = 0;
_STATE.dl_error = "";
try {
logger.info(`开始下载 Chrome 安装包:${url}`);
await download(url, expect, filename);
} catch (e) {
logger.warning(`下载 Chrome 安装包失败:${e.message}`);
_STATE.dl_status = "failed";
_STATE.dl_error = `安装包下载失败(${e.constructor.name})`;
_STATE.dl_error = `安装包下载失败:${(e && e.message) || e.constructor.name}`;
cleanupPart();
} finally {
_downloading = false;
}
logger.info(`开始下载 Chrome 安装包:${url}`);
}
async function download(url, expect, filename) {
const crypto = require("crypto");
const sha = crypto.createHash("sha256");
const tmp = path.join(CHROME_CACHE, `${filename}.part`);
const pkg = path.join(CHROME_CACHE, filename);
fs.mkdirSync(CHROME_CACHE, { recursive: true });
// 同名安装包已在磁盘:sha 一致直接复用,省掉一次 ~100MB 下载(重启/重试场景)
if (fs.existsSync(pkg)) {
let reusable = !expect;
if (expect) {
try { reusable = (await sha256File(pkg)) === expect; } catch (_) { reusable = false; }
}
if (reusable) {
_pendingPkg = pkg;
_STATE.dl_status = "downloaded";
_STATE.dl_pct = 100;
try { _STATE.dl_received = _STATE.dl_total = fs.statSync(pkg).size; } catch (_) {}
logger.info(`复用已下载的 Chrome 安装包:${pkg}`);
return;
}
try { fs.unlinkSync(pkg); } catch (_) { /* 占用中则继续覆盖写 */ }
}
const out = fs.createWriteStream(tmp);
let received = 0;
let total = 0;
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), 600 * 1000);
const res = await fetch(url, { signal: ctrl.signal, redirect: "follow" });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
total = parseInt(res.headers.get("content-length") || "0", 10);
const reader = res.body.getReader();
for (;;) {
const { done, value } = await reader.read();
if (done) break;
out.write(value);
sha.update(value);
received += value.length;
_STATE.dl_received = received;
_STATE.dl_total = total;
_STATE.dl_pct = total ? Math.floor((received * 100) / total) : 0;
try {
const res = await fetch(url, { signal: ctrl.signal, redirect: "follow" });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
total = parseInt(res.headers.get("content-length") || "0", 10);
const reader = res.body.getReader();
for (;;) {
const { done, value } = await reader.read();
if (done) break;
out.write(value);
sha.update(value);
received += value.length;
_STATE.dl_received = received;
_STATE.dl_total = total;
_STATE.dl_pct = total ? Math.floor((received * 100) / total) : 0;
}
await new Promise((res2, rej2) => out.end((e) => (e ? rej2(e) : res2())));
} catch (e) {
out.destroy(); // 释放文件句柄,否则 Windows 上 cleanupPart 删不掉 .part
throw e;
} finally {
clearTimeout(timer);
}
clearTimeout(timer);
await new Promise((res2, rej2) => out.end((e) => (e ? rej2(e) : res2())));
const digest = sha.digest("hex");
if (expect && digest !== expect) {
logger.error("Chrome 安装包 sha256 校验失败");
@@ -263,6 +338,7 @@ function install() {
throw Object.assign(new Error("未找到已下载的 Chrome 安装包"), { status: 404 });
}
_STATE.installing = true;
_STATE.check_error = ""; // 重新打开安装器,清掉上一次的失败/超时提示
logger.info(`启动 Chrome 安装器(弹出窗口由用户完成安装):${_pendingPkg}`);
// 直接弹出官方安装器窗口、由用户点击完成安装(不下发静默参数):
// 新版 Chrome 安装器会静默忽略未知参数(旧版 /silent /install 组合),
@@ -275,6 +351,7 @@ function install() {
});
child.on("error", (e) => {
_STATE.installing = false;
_STATE.check_error = `启动 Chrome 安装器失败:${e.message}`;
logger.warning(`启动 Chrome 安装器失败:${e.message}`);
});
child.unref();
@@ -285,18 +362,24 @@ function install() {
async function pollInstall() {
for (let i = 0; i < 120; i++) { // 交互式安装由用户人工操作,时限放宽到 10 分钟
await new Promise((r) => setTimeout(r, 5000));
const local = await detectLocal();
// force:本地检测有 30s 缓存,这里必须绕开,否则用户装完后界面最多晚 30s 才变"已安装"
const local = await detectLocal(true);
if (local.installed) {
_STATE.installing = false;
_STATE.installed = true;
_STATE.version = local.version;
_STATE.check_error = "";
_STATE.dl_status = "idle"; // 已安装,安装包不再参与状态,避免重复安装
// 装完即清理本地安装包(~100MB):安装器可能仍占用文件,失败则下次启动/下载时再清
if (_pendingPkg) { try { fs.unlinkSync(_pendingPkg); } catch (_) { /* 占用中忽略 */ } }
_pendingPkg = null; // 释放安装包句柄,后续点击走「重新检测」而非再装
logger.info(`Chrome 安装完成:${_STATE.version}`);
return;
}
}
_STATE.installing = false;
// 超时不是静默失败:把原因透出到状态里,前端提示用户重新打开安装器或手动检测
_STATE.check_error = "等待 Chrome 安装完成超时(未检测到安装结果),请完成安装器操作后点击重新检测";
logger.warning("等待 Chrome 安装完成超时(可能用户未完成安装器窗口操作)");
}
@@ -2,10 +2,11 @@
"use strict";
const fs = require("fs");
const { app, BrowserWindow, Tray, Menu, nativeImage, dialog, screen } = require("electron");
const { app, BrowserWindow, Tray, Menu, nativeImage, dialog, screen, ipcMain } = require("electron");
const path = require("path");
const config = require("./config");
const { makeLogger } = require("./logger");
const trayMenu = require("./tray-menu");
const logger = makeLogger("electron-main");
@@ -82,8 +83,10 @@ if (!app.requestSingleInstanceLock()) {
y: st.y,
minWidth: 1000,
minHeight: 660,
// 与启动页默认皮肤底色一致(style.css --bg #F9F7F2),避免冷启动色跳
backgroundColor: "#F9F7F2",
// 无边框窗口:顶栏由渲染层自绘(含窗口控制钮 / 面包屑 / 服务状态)
frame: false,
// 与启动页画布底色一致(style.css --canvas #F2F4F8),避免冷启动色跳
backgroundColor: "#F2F4F8",
title: "37du 自动化工作台",
icon: trayIconImage(),
webPreferences: {
@@ -94,6 +97,14 @@ if (!app.requestSingleInstanceLock()) {
},
});
mainWindow.loadURL(URL);
// 推送最大化状态变化:渲染层顶栏切换最大化/还原图标
const sendMaxState = () => {
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send("win:maximized", mainWindow.isMaximized());
}
};
mainWindow.on("maximize", sendMaxState);
mainWindow.on("unmaximize", sendMaxState);
// 关闭时保存窗口状态;resize/move 防抖保存(异常退出也不丢太多)
let stateTimer = null;
const save = () => {
@@ -119,6 +130,16 @@ if (!app.requestSingleInstanceLock()) {
});
}
// 无边框窗口控制 IPC:渲染层自绘顶栏的窗口控制钮走这里(fire-and-forget)
ipcMain.on("win:min", () => { if (mainWindow && !mainWindow.isDestroyed()) mainWindow.minimize(); });
ipcMain.on("win:max", () => {
if (!mainWindow || mainWindow.isDestroyed()) return;
if (mainWindow.isMaximized()) mainWindow.unmaximize();
else mainWindow.maximize();
});
// 关闭 = 走 close 拦截逻辑(默认收托盘,托盘「退出」才真正退出)
ipcMain.on("win:close", () => { if (mainWindow && !mainWindow.isDestroyed()) mainWindow.close(); });
function trayIconImage() {
// 优先用官方图标(Windows 托盘/窗口均正常渲染);缺失时 SVG 兜底。
// 打包态:resources/assets/icon.ico(extraResources 真实文件);开发态:本模块 assets/
@@ -134,35 +155,21 @@ if (!app.requestSingleInstanceLock()) {
return nativeImage.createFromDataURL(`data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`);
}
function openWorkbench() {
// 关闭窗口只是收托盘(窗口仍存在),此处复用已有窗口而非重复新建
if (!mainWindow) createWindow();
else { mainWindow.show(); mainWindow.focus(); }
}
function createTray() {
tray = new Tray(trayIconImage());
const ctx = Menu.buildFromTemplate([
{
label: "打开工作台",
click: () => {
// 关闭窗口只是收托盘(窗口仍存在),此处复用已有窗口而非重复新建
if (!mainWindow) createWindow();
else { mainWindow.show(); mainWindow.focus(); }
},
},
{ type: "separator" },
{
label: "开机自启",
type: "checkbox",
checked: app.getLoginItemSettings().openAtLogin,
click: (item) => {
app.setLoginItemSettings({ openAtLogin: item.checked });
},
},
{ type: "separator" },
{ label: "退出", click: () => app.quit() },
]);
tray.setToolTip("37du 自动化工作台");
tray.setContextMenu(ctx);
tray.on("click", () => {
if (!mainWindow) createWindow();
else mainWindow.show();
// 右键菜单用自绘卡片弹窗(系统原生菜单样式跟随系统、无法统一视觉)
trayMenu.attach(tray, {
onOpen: openWorkbench,
onQuit: () => app.quit(),
});
tray.on("click", openWorkbench);
}
app.whenReady().then(async () => {
@@ -0,0 +1,267 @@
// 日志集中回传:运行日志(整次,幂等 upsert)+ 壳日志(shell.log 增量字节)+ 离线暂存补报。
// 目的:执行机运行/壳日志自动上送中心机,管理端「运行日志」页集中排查,无需再去各电脑翻日志。
// 与 licensing.offline_reports 互补:本模块只管"日志正文",状态/结论仍走 runtime/report。
"use strict";
const fs = require("fs");
const os = require("os");
const path = require("path");
const config = require("./config");
const cp = require("./cpclient");
const { makeLogger } = require("./logger");
const logger = makeLogger("log-upload");
const LOGS_DIR = path.join(config.APP_DATA, "logs");
const SHELL_LOG_FILE = path.join(LOGS_DIR, "shell.log");
const PENDING_FILE = path.join(config.APP_DATA, "pending_log_uploads.jsonl");
const UPLOAD_STATE_FILE = path.join(LOGS_DIR, "upload_state.json");
const UPLOAD_INTERVAL_MS = 15 * 60 * 1000; // 周期回传:15 分钟
const BACKFILL_MAX = 50; // 启动补报最近 N 次运行(服务端按 run_id 幂等)
const BACKFILL_DAYS = 7; // 只补报最近 7 天内的运行(更早的线上早已回传过)
const MAX_PENDING = 500; // 离线暂存条数上限(超出丢弃最旧)
let _started = false;
// ==================== 本地状态文件(读/写/行) ====================
function readLines(file) {
if (!file || !fs.existsSync(file)) return [];
let text;
try {
text = fs.readFileSync(file, "utf-8");
} catch (e) {
return [];
}
const out = [];
for (const line of text.split(/\r?\n/)) {
const s = line.trim();
if (!s) continue;
try {
out.push(JSON.parse(s));
} catch (e) {
/* 跳过损坏行 */
}
}
return out;
}
function writeLines(file, records) {
try {
fs.mkdirSync(path.dirname(file), { recursive: true });
const tmp = file + ".tmp";
const body = records.length ? records.map((r) => JSON.stringify(r)).join("\n") + "\n" : "";
fs.writeFileSync(tmp, body, "utf-8");
fs.renameSync(tmp, file);
} catch (e) {
/* 写入失败忽略 */
}
}
function readUploadState() {
try {
const v = JSON.parse(fs.readFileSync(UPLOAD_STATE_FILE, "utf-8"));
return v && typeof v === "object" ? v : {};
} catch (e) {
return {};
}
}
function writeUploadState(state) {
try {
fs.mkdirSync(LOGS_DIR, { recursive: true });
fs.writeFileSync(UPLOAD_STATE_FILE, JSON.stringify(state), "utf-8");
} catch (e) {
/* 忽略 */
}
}
// 设备 ID:与 app.deviceId() 同源(持久化 %LOCALAPPDATA%\37duAutomation\device_id)。
// 不直接 require("./app")(避免拖入整个应用依赖树),本模块内自包含。
function deviceId() {
const f = path.join(config.APP_DATA, "device_id");
try {
if (fs.existsSync(f)) {
const v = fs.readFileSync(f, "utf-8").trim();
if (v) return v;
}
const crypto = require("crypto");
const id = crypto.randomUUID();
fs.mkdirSync(config.APP_DATA, { recursive: true });
fs.writeFileSync(f, id, "utf-8");
return id;
} catch (e) {
return "dev-" + require("crypto").randomBytes(8).toString("hex");
}
}
// ==================== 运行日志(整次回传,幂等 upsert) ====================
// rec: 见 runner.finishRun 的 runHistory 记录(含 logs 数组)
async function uploadRun(rec) {
if (!config.CONTROLPLANE_URL) return false;
if (!rec || !rec.run_id) return false;
const payload = { ...rec, device_id: deviceId() };
try {
await cp.request("POST", "/api/runtime/logs", {
headers: cp.machineHeaders(), json: payload, timeout: 15,
});
return true;
} catch (e) {
queuePending(payload);
return false;
}
}
// 离线暂存:写入 JSONL(上限 MAX_PENDING,超出丢最旧)
function queuePending(payload) {
try {
const pending = readLines(PENDING_FILE);
pending.push(payload);
writeLines(PENDING_FILE, pending.slice(-MAX_PENDING));
} catch (e) {
/* 忽略 */
}
}
// 重连后补报此前暂存的运行日志;返回成功条数
async function flushPending() {
if (!config.CONTROLPLANE_URL) return 0;
if (!fs.existsSync(PENDING_FILE)) return 0;
const pending = readLines(PENDING_FILE);
if (!pending.length) return 0;
const kept = [];
let sent = 0;
for (const rec of pending) {
try {
await cp.request("POST", "/api/runtime/logs", {
headers: cp.machineHeaders(), json: { ...rec, device_id: rec.device_id || deviceId() },
timeout: 15,
});
sent++;
} catch (e) {
kept.push(rec); // 仍失败:保留待下轮
}
}
writeLines(PENDING_FILE, kept);
if (sent) logger.info(`运行日志离线补报完成:${sent} 条`);
return sent;
}
// ==================== 壳日志(shell.log 增量字节上传) ====================
// 以字节偏移为游标:只传上次之后的增量;日志轮转(size < offset)时 reset=1 让服务端截断重传。
async function uploadShellLog() {
if (!config.CONTROLPLANE_URL) return;
if (!fs.existsSync(SHELL_LOG_FILE)) return;
let size;
try {
size = fs.statSync(SHELL_LOG_FILE).size;
} catch (e) {
return;
}
const state = readUploadState();
const shell = (state.shell && typeof state.shell === "object") ? state.shell : {};
let offset = typeof shell.offset === "number" && shell.offset > 0 ? shell.offset : 0;
if (size < offset) offset = 0; // 文件已轮转/截断:重置,整文件重传(服务端先截断)
if (size <= offset) return; // 无新增字节
let buf;
try {
const fd = fs.openSync(SHELL_LOG_FILE, "r");
buf = Buffer.alloc(size - offset);
fs.readSync(fd, buf, 0, buf.length, offset);
fs.closeSync(fd);
} catch (e) {
return;
}
if (!buf || !buf.length) return;
try {
await cp.request("POST", "/api/runtime/shell-log", {
// 显式声明 octet-stream:避免中间件把原始字节按 form-urlencoded 消费(新旧服务端均接受)
headers: { ...cp.machineHeaders(), "Content-Type": "application/octet-stream" },
params: {
device_id: deviceId(),
account: config.CONTROLPLANE_ACCOUNT || "",
hostname: os.hostname() || "",
client_version: (config.runtimeVersion && config.runtimeVersion()) || "",
reset: offset === 0 ? 1 : 0,
},
body: buf,
timeout: 60,
});
state.shell = { offset: size, at: Date.now() };
writeUploadState(state);
} catch (e) {
logger.warning(`壳日志回传失败:${e.message}`);
}
}
// ==================== 启动补报:最近运行历史里尚未回传的整次日志 ====================
const SAFE_ID = /^[A-Za-z0-9_-]{8,64}$/;
function readRunLogs(runId) {
const id = String(runId || "");
if (!SAFE_ID.test(id)) return [];
try {
const runHistory = require("./run-history");
return readLines(path.join(runHistory.RUNS_DIR, `${id}.jsonl`));
} catch (e) {
return [];
}
}
function recentRuns(max) {
try {
const runHistory = require("./run-history");
return readLines(runHistory.HISTORY_PATH)
.filter((r) => r && typeof r === "object" && r.run_id)
.slice(-Math.max(1, Math.min(max, 200)))
.reverse(); // 新的在前
} catch (e) {
return [];
}
}
// 补报最近 BACKFILL_DAYS 天内的运行日志(服务端 run_id 幂等,重复回传安全)
async function backfillRecentRuns() {
if (!config.CONTROLPLANE_URL) return;
let ok = 0;
for (const rec of recentRuns(BACKFILL_MAX)) {
const finished = Number(rec.finished || 0);
if (finished && Date.now() / 1000 - finished > BACKFILL_DAYS * 86400) continue;
const payload = {
run_id: rec.run_id,
account: rec.account || "",
plugin_id: rec.plugin_id || "",
name: rec.name || "",
version: rec.version || "",
trigger: rec.trigger || "manual",
schedule_id: rec.schedule_id || "",
status: rec.status || "",
ok: !!rec.ok,
error: rec.error || "",
summary: rec.summary || "",
started: rec.started || 0,
finished: rec.finished || 0,
duration_sec: rec.duration_sec || 0,
logs: readRunLogs(rec.run_id),
};
if (!(await uploadRun(payload))) break; // 不可达:本批中断,待下轮周期重试
ok++;
}
if (ok) logger.info(`运行日志启动补报完成:${ok} 次`);
}
// ==================== 启动 ====================
function start() {
if (_started || !config.CONTROLPLANE_URL) return;
_started = true;
const cycle = async () => {
try { await flushPending(); } catch (e) { /* 忽略 */ }
try { await uploadShellLog(); } catch (e) { /* 忽略 */ }
try { await backfillRecentRuns(); } catch (e) { /* 忽略 */ }
};
void cycle(); // 启动即回传一次
setInterval(() => { void cycle(); }, UPLOAD_INTERVAL_MS);
logger.info(`日志集中回传已启动(运行日志 + 壳日志,每 ${UPLOAD_INTERVAL_MS / 60000} 分钟一次)`);
}
module.exports = { start, uploadRun, flushPending, uploadShellLog, backfillRecentRuns };
+41 -8
View File
@@ -28,6 +28,26 @@ async function accountAllowedPlatforms(account) {
}
}
// 调中心机获取后台维护的场景分类;控制面不可达返回 null(调用方回退本地 plugin.json)
async function accountPluginCategories(account) {
if (!config.CONTROLPLANE_URL) return null;
try {
const r = await cp.request("GET", "/api/plugins", {
headers: cp.machineHeaders(),
params: { account },
timeout: 5,
});
const map = new Map();
for (const p of r.plugins || []) {
const cat = String(p.category || "").trim();
if (cat) map.set(p.id, cat);
}
return map;
} catch (e) {
return null;
}
}
// /api/meta 聚合响应
async function buildMeta(account) {
let authExpired = false;
@@ -43,16 +63,29 @@ async function buildMeta(account) {
authExpired = true;
}
}
const allowedPlats = account ? await accountAllowedPlatforms(account) : null;
const platforms = [];
for (const [pid, m] of Object.entries(state.PLATFORMS)) {
platforms.push({
id: pid,
label: m.label,
online: await platformAuth.isOnline(pid, account), // 按当前账号的会话校验
allowed: allowedPlats === null ? true : allowedPlats.has(pid),
const [cloudCats, allowedPlats] = account
? await Promise.all([
plugins.length ? accountPluginCategories(account) : Promise.resolve(null),
accountAllowedPlatforms(account),
])
: [null, null];
// 后台分类优先,未配置则保留插件包内 plugin.json 的分类
if (cloudCats) {
plugins = plugins.map((p) => {
const cat = cloudCats.get(p.id);
return cat ? { ...p, category: cat } : p;
});
}
// 平台在线态:并行 + 单平台 2.5s 兜底,避免外网校验慢时整屏元数据被拖住
// (超时先按未登录展示,后台校验完成后会回填缓存,平台账号页再读即为最新)
const platforms = await Promise.all(
Object.entries(state.PLATFORMS).map(async ([pid, m]) => ({
id: pid,
label: m.label,
online: await platformAuth.isOnlineQuick(pid, account), // 按当前账号的会话校验
allowed: allowedPlats === null ? true : allowedPlats.has(pid),
}))
);
return {
appName: "37du 自动化工作台",
dingtalkScan: !!config.CONTROLPLANE_URL,
@@ -31,7 +31,9 @@ function platforms() {
// 账号隔离的会话目录;无账号时回退共享目录(兼容旧数据)
function sessionDir(account) {
const base = account ? path.join(BASE_SESSIONS_DIR, String(account)) : BASE_SESSIONS_DIR;
// 与 Python 侧(hr_login_api 对 PLATFORM_ACCOUNT 做 strip)对齐,避免首尾空白导致目录错位
const acc = String(account || "").trim();
const base = acc ? path.join(BASE_SESSIONS_DIR, acc) : BASE_SESSIONS_DIR;
try {
fs.mkdirSync(base, { recursive: true });
} catch (e) {
@@ -158,7 +160,8 @@ async function isOnline(pid, account) {
}
}
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), 8000);
// 与 Python 侧校验超时(15s)对齐:登录刚完成时平台响应可能偏慢,过短易误判失效
const timer = setTimeout(() => ctrl.abort(), 15000);
const resp = await fetch(def.url, {
method: def.method,
headers: {
@@ -168,11 +171,12 @@ async function isOnline(pid, account) {
},
body: def.method === "POST" ? "" : undefined,
signal: ctrl.signal,
redirect: "manual",
// 与 Python requests 默认一致:跟随重定向后再判定;manual 会把 302 直接误判为失效
redirect: "follow",
});
clearTimeout(timer);
const text = await resp.text();
value = resp.status === 200 && text.trim().startsWith("{") || text.trim().startsWith("[");
const text = (await resp.text()).trim();
value = resp.status === 200 && (text.startsWith("{") || text.startsWith("["));
}
} catch (e) {
logger.warning(`平台 ${pid} 在线校验失败:${e.message}`);
@@ -204,7 +208,20 @@ async function login(pid, account) {
const out = await runPython(snippet, 5 * 60 * 1000, extraEnv);
const result = extractJson(out) || {};
const ok = !!result.success;
const online = ok ? await isOnline(pid, account) : false;
let online = ok ? await isOnline(pid, account) : false;
if (ok && !online) {
// Python 侧返回成功前已用落盘 cookies 完成真实会话校验;Node 复核偶发失败
// (网络抖动/响应慢)时清缓存重试一次,避免误杀已成功的登录。
await new Promise((r) => setTimeout(r, 1500));
_onlineCache.delete(cacheKey);
online = await isOnline(pid, account);
}
if (ok && !online) {
// 仍复核失败:以 Python 侧真实登录 + 会话校验结果为准放行(其校验口径与插件一致),
// Node 手拼 Cookie 头的复核口径存在差异,不作为最终裁决。
logger.warning(`平台 ${pid} Node 复核未通过,但 Python 侧已登录并校验成功,按登录成功处理(账号 ${account})`);
online = true;
}
return {
id: pid,
label: LABELS[pid],
@@ -230,21 +247,38 @@ function logout(pid, account) {
return { id: pid, label: LABELS[pid], online: false };
}
// 当前账号的平台状态(个人中心展示):在线态 + 是否已配置个人账号密码 + 已存用户名
async function status(account) {
const creds = platformCreds.get(account) || {};
const out = [];
for (const pid of Object.keys(LABELS)) {
const c = creds[pid] || {};
out.push({
id: pid,
label: LABELS[pid],
online: await isOnline(pid, account),
has_creds: !!(c.user && c.pass),
user: c.user || "",
});
}
return out;
// 带超时的在线校验:超时先按未登录返回,校验仍在后台继续跑并回填缓存,
// 用于 meta 这类"不能为一次外网校验卡住整屏"的场景。
function isOnlineQuick(pid, account, timeoutMs = 2500) {
const task = isOnline(pid, account).catch(() => false);
return Promise.race([task, new Promise((r) => setTimeout(() => r(false), timeoutMs))]);
}
module.exports = { platforms, sessionDir, isOnline, login, logout, status, BASE_SESSIONS_DIR };
// 当前账号的平台状态(个人中心展示):在线态 + 是否已配置个人账号密码 + 已存用户名
// 两平台并行校验:串行时最坏 15s×2,并行后总耗时 ≈ 单平台最坏值。
async function status(account) {
const creds = platformCreds.get(account) || {};
return Promise.all(
Object.keys(LABELS).map(async (pid) => {
const c = creds[pid] || {};
return {
id: pid,
label: LABELS[pid],
online: await isOnline(pid, account),
has_creds: !!(c.user && c.pass),
user: c.user || "",
};
})
);
}
module.exports = {
platforms,
sessionDir,
isOnline,
isOnlineQuick,
login,
logout,
status,
BASE_SESSIONS_DIR,
};
+15 -2
View File
@@ -1,7 +1,8 @@
// preload:contextBridge 白名单 IPC(渲染层主通道走 HTTP 兼容层,此处仅暴露只读环境信息)。
// preload:contextBridge 白名单 IPC(渲染层主通道走 HTTP 兼容层)。
// 暴露只读环境信息 + 无边框窗口控制(顶栏自绘窗口控制钮使用)。
"use strict";
const { contextBridge } = require("electron");
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("dshShell", {
platform: process.platform,
@@ -10,5 +11,17 @@ contextBridge.exposeInMainWorld("dshShell", {
node: process.versions.node,
chrome: process.versions.chrome,
},
// ---- 无边框窗口控制(顶栏 min/max/close) ----
winControl: {
minimize: () => ipcRenderer.send("win:min"),
toggleMaximize: () => ipcRenderer.send("win:max"),
close: () => ipcRenderer.send("win:close"),
// 订阅最大化状态变化(主进程 maximize/unmaximize 时推送 boolean)
onMaximized: (cb) => {
const handler = (_e, v) => cb(v);
ipcRenderer.on("win:maximized", handler);
return () => ipcRenderer.removeListener("win:maximized", handler);
},
},
// 渲染层可通过 window.open 打开中心机控制面(外部 URL 需在渲染层显式触发)
});
@@ -100,6 +100,7 @@ function pluginSchema(pluginId) {
name: manifest.name || pluginId,
version: manifest.version || "0",
description: manifest.description || "",
category: manifest.category || "", // 场景分类(左侧场景库按此分组折叠,空则归"其他")
uses_month: !!manifest.uses_month,
ui: !!manifest.ui,
platform: manifest.platform || "", // hr / oa / ""(前端平台徽章 + 运行并发闸按(账号,平台)隔离)
+22
View File
@@ -139,6 +139,28 @@ function finishRun(runId, plugin, status, error, summary) {
duration_sec: durationSec,
logs: Array.isArray(run.logs) ? run.logs : [],
});
// 日志集中回传:整次运行日志上送中心机(离线自动暂存补报;失败不阻断运行收尾)
try {
require("./log-upload").uploadRun({
run_id: runId,
account: run.account || "",
plugin_id: plugin.id,
name: run.name || plugin.name || plugin.id,
version: run.version || plugin.version || "0",
trigger: run.trigger || "manual",
schedule_id: run.schedule_id || "",
status,
ok,
error: ok ? "" : error || "",
summary: summary || "",
started: run.started || 0,
finished,
duration_sec: durationSec,
logs: Array.isArray(run.logs) ? run.logs : [],
});
} catch (e) {
logger.warning(`运行日志回传失败:${e.message}`);
}
HUB.publish({
t: "run_done",
run_id: runId,
+364 -67
View File
@@ -4,10 +4,11 @@
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const { spawn } = require("child_process");
const cp = require("./cpclient");
const config = require("./config");
const { versionLt, sha256Hex } = require("./crypto");
const { versionLt } = require("./crypto");
const { makeLogger } = require("./logger");
const logger = makeLogger("shell-updater");
@@ -15,6 +16,150 @@ const logger = makeLogger("shell-updater");
const SHELL_CACHE = path.join(config.APP_DATA, "shell");
const PERIODIC_INTERVAL = 30 * 60 * 1000;
// 升级等待窗口:独立 HTA(mshta.exe)进程。
// 壳子自身进程必须退出才能被 NSIS 替换文件,所以这段时间 Electron 窗口必然消失;
// 由该窗口接管界面:跑马灯进度 + 状态文案 + 「打开客户端」按钮,
// 检测到旧进程退出后新进程出现即自动关闭。
// 用 HTA 而不是 PowerShell WinForms:Electron 以 windowsHide(CREATE_NO_WINDOW + SW_HIDE
// 启动信息)拉起 powershell.exe 时,WinForms 首窗口会被连带设成隐藏(Form.Visible 仍是 True,
// 但屏幕上看不到);mshta.exe 是 GUI 子系统,既不会有黑控制台,窗口也能正常显示。
const WAIT_WINDOW_HTA = `<!DOCTYPE html>
<html>
<head>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta charset="utf-8">
<title>37du 自动化工作台 - 升级</title>
<hta:application
border="thin"
caption="yes"
sysmenu="yes"
maximizebutton="no"
minimizebutton="no"
scroll="no"
contextmenu="no"
selection="no"
innerborder="no" />
<style>
html, body { margin: 0; padding: 0; overflow: hidden; }
body {
font-family: "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
background: #ffffff; color: #20242c; padding: 22px 26px;
}
.title { font-size: 15px; font-weight: 700; }
.bar { margin-top: 16px; height: 6px; background: #eef1f6; border-radius: 3px; overflow: hidden; position: relative; }
.bar i { position: absolute; top: 0; left: -40%; width: 38%; height: 100%; border-radius: 3px;
background: #4d8cff; animation: mv 1.15s linear infinite; }
@keyframes mv { from { left: -40%; } to { left: 102%; } }
.sub { margin-top: 14px; font-size: 12px; line-height: 1.7; color: #6e7480; min-height: 42px; }
.foot { text-align: right; }
button { font-family: inherit; font-size: 12px; padding: 7px 18px; border: 1px solid #d8dde6;
border-radius: 4px; background: #f7f9fc; color: #20242c; cursor: pointer; }
button:disabled { color: #a9b0bc; cursor: default; }
</style>
<script language="JScript">
var exe = '__EXE__';
var markerFile = '__MARKER__';
var version = '__VERSION__';
var finished = false;
var closed = false;
var startAt = (new Date()).getTime();
var pollTimer = null;
var fso = null;
function el(id) { return document.getElementById(id); }
function setTitle(t) { el('ttl').innerHTML = t; }
function setSub(t) { el('msg').innerHTML = t; }
function fsObject() {
if (!fso) fso = new ActiveXObject('Scripting.FileSystemObject');
return fso;
}
// 靠安装脚本装完后写下的标记文件(ok / failed)判断结束,而不是 WMI 轮询进程名。
// 进程名方案对中文/带空格的 exe 名不可靠(查询失败被静默吞掉→窗口永远关不掉),
// 且"安装器自拉起"与"脚本补启动"两种路径都要照顾;标记文件由脚本自己在装完后落盘,最稳。
function readMarker() {
try {
var f = fsObject();
if (!f.FileExists(markerFile)) return '';
var ts = f.OpenTextFile(markerFile, 1, false);
var txt = ts.ReadAll();
ts.Close();
return String(txt);
} catch (err) {
return '';
}
}
function enableBtn() { el('btn').disabled = false; }
function closeWindow(ms) {
if (closed) return;
closed = true;
if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
setTimeout(function () { window.close(); }, ms);
}
function tick() {
if (closed) return;
var secs = ((new Date()).getTime() - startAt) / 1000;
var m = readMarker();
if (m && !finished) {
finished = true;
if (m.indexOf('failed') >= 0) {
setTitle('升级未完成');
setSub('安装失败,已为你重新打开旧版本。若未自动打开,请点击下方「打开客户端」。');
enableBtn();
setTimeout(function () { closeWindow(0); }, 8000);
} else {
setTitle('升级完成');
setSub('正在重新打开客户端…');
closeWindow(900);
}
return;
}
if (!finished && secs >= 5) setSub('正在写入新版本,完成后会自动重新打开客户端…');
if (el('btn').disabled && secs >= 20) enableBtn();
if (secs >= 300 && !closed) {
if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
setTitle('升级耗时较长');
setSub('请点击「打开客户端」手动启动;若仍无法打开,请联系管理员。');
enableBtn();
}
}
function openApp() {
try {
new ActiveXObject('WScript.Shell').Run('"' + exe + '"', 1, false);
setSub('正在打开客户端…');
closeWindow(900);
} catch (err) {
setSub('打开客户端失败:' + err.message + ',请稍后重试。');
}
}
function init() {
try {
window.resizeTo(470, 260);
window.moveTo(Math.max(0, (screen.availWidth - 470) / 2), Math.max(0, (screen.availHeight - 260) / 2));
} catch (e) { }
window.focus();
setTimeout(function () { window.focus(); }, 400);
setTitle('正在安装新版本 v' + version);
pollTimer = setInterval(tick, 500);
tick();
}
</script>
</head>
<body onload="init()">
<div class="title" id="ttl">正在准备升级…</div>
<div class="bar"><i></i></div>
<div class="sub" id="msg">正在重启客户端,安装完成后会自动重新打开,请稍候…</div>
<div class="foot"><button id="btn" disabled="disabled" onclick="openApp()">打开客户端</button></div>
</body>
</html>
`;
let _checking = false;
let _downloading = false;
let _pendingVersion = "";
@@ -69,14 +214,29 @@ async function fetchCloudVersion() {
}
}
function cachePath(version) {
return path.join(SHELL_CACHE, `setup-37du-host-${version}.exe`);
}
// 流式计算 sha256:避免 readFileSync 一次性把 ~80MB 安装包读进内存
function sha256File(p) {
return new Promise((resolve, reject) => {
const h = crypto.createHash("sha256");
const s = fs.createReadStream(p);
s.on("data", (c) => h.update(c));
s.on("error", reject);
s.on("end", () => resolve(h.digest("hex")));
});
}
// 缓存包校验:sha256 与云端登记不一致(同版本号重新发版/下载中断残留)→ 删除旧包返回 null,
// 触发重新下载,避免"缓存命中秒显示下载完成、实际是旧坏包"
function validateCache(version, expectSha) {
const p = path.join(SHELL_CACHE, `setup-37du-host-${version}.exe`);
async function validateCache(version, expectSha) {
const p = cachePath(version);
if (!fs.existsSync(p)) return null;
if (expectSha) {
try {
if (sha256Hex(fs.readFileSync(p)) !== String(expectSha).toLowerCase()) {
if ((await sha256File(p)) !== String(expectSha).toLowerCase()) {
logger.warning(`缓存安装包与云端 sha256 不符(旧坏包),删除后重新下载:${p}`);
try { fs.unlinkSync(p); } catch (_) { /* 文件占用时下次再清 */ }
return null;
@@ -108,7 +268,8 @@ function cleanupStalePackages() {
try { files = fs.readdirSync(SHELL_CACHE); } catch (_) { return; }
for (const f of files) {
const pkg = f.match(/^setup-37du-host-(.+)\.exe$/);
const stale = (pkg && (!cur || !versionLt(cur, pkg[1]))) || /^apply-update-.+\.cmd$/.test(f);
// .part = 上次下载中断的残留(启动时不可能有下载在跑),直接清掉
const stale = (pkg && (!cur || !versionLt(cur, pkg[1]))) || /^apply-update-.+\.(cmd|vbs)$/i.test(f) || /^update-wait-.+\.(ps1|hta)$/i.test(f) || /\.part$/i.test(f);
if (!stale) continue;
try {
fs.unlinkSync(path.join(SHELL_CACHE, f));
@@ -157,7 +318,7 @@ async function checkUpdate() {
_STATE.dl_status = "idle";
_STATE.dl_pct = 0;
}
const cached = validateCache(cloud, info.sha256);
const cached = await validateCache(cloud, info.sha256);
if (cached) restorePending(cloud, notes, cached);
} finally {
_STATE.checking = false;
@@ -205,7 +366,7 @@ async function startDownload() {
return;
}
_STATE.dl_version = cloud;
const cached = validateCache(cloud, info.sha256);
const cached = await validateCache(cloud, info.sha256);
if (cached) {
restorePending(cloud, String(info.notes || ""), cached);
return;
@@ -218,7 +379,7 @@ async function startDownload() {
} catch (e) {
logger.warning(`下载壳子安装包失败:${e.message}`);
_STATE.dl_status = "failed";
_STATE.dl_error = `安装包下载失败(${e.constructor.name})`;
_STATE.dl_error = `安装包下载失败:${(e && e.message) || e.constructor.name}`;
cleanupPart(cloud);
} finally {
_downloading = false;
@@ -227,43 +388,47 @@ async function startDownload() {
async function download(cloud, info) {
const innerUrl = String(info.url || "").trim();
const tmp = path.join(SHELL_CACHE, `setup-37du-host-${cloud}.exe.part`);
const pkg = path.join(SHELL_CACHE, `setup-37du-host-${cloud}.exe`);
const tmp = `${cachePath(cloud)}.part`;
const pkg = cachePath(cloud);
const expect = String(info.sha256 || "").toLowerCase();
fs.mkdirSync(SHELL_CACHE, { recursive: true });
const out = fs.createWriteStream(tmp);
const crypto = require("crypto");
const sha = crypto.createHash("sha256");
let received = 0;
let total = 0;
if (innerUrl) {
await downloadFromUrl(innerUrl, {}, out, sha, (rcv, tot) => {
received = rcv;
total = tot;
_STATE.dl_received = received;
_STATE.dl_total = total;
_STATE.dl_pct = total ? Math.floor((received * 100) / total) : 0;
});
} else {
const r = await cp.streamDownload("/api/shell/pkg", {
headers: cp.machineHeaders(),
timeout: 600,
onData: (chunk) => {
out.write(chunk);
sha.update(chunk);
},
onProgress: (rcv, tot) => {
try {
if (innerUrl) {
await downloadFromUrl(innerUrl, {}, out, sha, (rcv, tot) => {
received = rcv;
total = tot;
_STATE.dl_received = received;
_STATE.dl_total = total;
_STATE.dl_pct = total ? Math.floor((received * 100) / total) : 0;
},
});
received = r.received;
total = r.contentLength;
});
} else {
const r = await cp.streamDownload("/api/shell/pkg", {
headers: cp.machineHeaders(),
timeout: 600,
onData: (chunk) => {
out.write(chunk);
sha.update(chunk);
},
onProgress: (rcv, tot) => {
received = rcv;
total = tot;
_STATE.dl_received = received;
_STATE.dl_total = total;
_STATE.dl_pct = total ? Math.floor((received * 100) / total) : 0;
},
});
received = r.received;
total = r.contentLength;
}
await new Promise((res, rej) => out.end((e) => (e ? rej(e) : res())));
} catch (e) {
out.destroy(); // 释放文件句柄,否则 Windows 上 cleanupPart 删不掉 .part
throw e;
}
await new Promise((res, rej) => out.end((e) => (e ? rej(e) : res())));
const digest = sha.digest("hex");
if (expect && digest !== expect) {
logger.error(`壳子安装包 sha256 校验失败,放弃更新`);
@@ -290,20 +455,23 @@ async function download(cloud, info) {
async function downloadFromUrl(url, headers, out, sha, onProgress) {
const ctrl = new AbortController();
const timer = setTimeout(() => ctrl.abort(), 600 * 1000);
const res = await fetch(url, { headers, signal: ctrl.signal, redirect: "follow" });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const total = parseInt(res.headers.get("content-length") || "0", 10);
let received = 0;
const reader = res.body.getReader();
for (;;) {
const { done, value } = await reader.read();
if (done) break;
out.write(value);
sha.update(value);
received += value.length;
onProgress(received, total);
try {
const res = await fetch(url, { headers, signal: ctrl.signal, redirect: "follow" });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const total = parseInt(res.headers.get("content-length") || "0", 10);
let received = 0;
const reader = res.body.getReader();
for (;;) {
const { done, value } = await reader.read();
if (done) break;
out.write(value);
sha.update(value);
received += value.length;
onProgress(received, total);
}
} finally {
clearTimeout(timer); // 失败分支也要清,否则定时器泄漏并可能在 10 分钟后误 abort
}
clearTimeout(timer);
}
function cleanupPart(cloud) {
@@ -314,6 +482,29 @@ function cleanupPart(cloud) {
}
}
// 启动独立等待窗口:Electron 退出后接管界面,避免"点完升级窗口直接消失、全程无提示"。
// mshta.exe 是 GUI 子系统:不产生黑控制台;detached 保证父进程退出后窗口存活;
// 千万不要传 windowsHide —— 它会让窗口被创建即隐藏(这正是 PowerShell 方案失效的原因)。
function spawnWaitWindow(version, exe, markerFile) {
const hta = path.join(SHELL_CACHE, `update-wait-${version}.hta`);
try {
// 用 JSON.stringify 生成 JScript 字符串字面量:Windows 路径反斜杠、中文目录名都能正确转义
// 用函数式 replace,避免路径里的 $& / $' 被当成替换模式
const fill = (src, token, val) => src.replace(token, () => JSON.stringify(val));
let html = WAIT_WINDOW_HTA;
html = fill(html, "'__EXE__'", exe);
html = fill(html, "'__MARKER__'", markerFile);
html = fill(html, "'__VERSION__'", version);
// 带 BOM 的 UTF-8,保证 mshta 正确识别中文
fs.writeFileSync(hta, "\uFEFF" + html, "utf8");
const child = spawn("mshta.exe", [hta], { cwd: SHELL_CACHE, detached: true, stdio: "ignore" });
child.on("error", (e) => logger.warning(`启动升级等待窗口失败:${e.message}`));
child.unref();
} catch (e) {
logger.warning(`启动升级等待窗口失败:${e.message}`);
}
}
function pendingStatus() {
let cur = localShellVersion();
// 用已校验的 _pendingPkg 判断(不做全量 sha 重算——状态接口被前端高频轮询)
@@ -346,33 +537,139 @@ function pendingStatus() {
}
function applyUpdate() {
// 防重入:前端重复点击 / 用户连点会让多个安装器同时启动,安装必失败
if (_STATE.applying) {
throw Object.assign(new Error("正在升级中,请稍候"), { status: 409 });
}
const version = _pendingVersion;
const pkg = _pendingPkg || validateCache(version, "");
if (!pkg || !fs.existsSync(pkg)) {
throw new Error(`未找到已下载的安装包:${pkg || `setup-37du-host-${version}.exe`}`);
const pkg = _pendingPkg && fs.existsSync(_pendingPkg) ? _pendingPkg : version ? cachePath(version) : "";
if (!version || !pkg || !fs.existsSync(pkg)) {
throw Object.assign(new Error(`未找到已下载的安装包:${pkg || `setup-37du-host-${version || "?"}.exe`}`), { status: 404 });
}
_STATE.applying = true;
logger.info(`开始静默升级到 ${version}:${pkg}`);
// electron-builder NSIS 静默安装完成后不会自动拉起新版本(旧壳 Inno [Run] 的行为不可用),
// 用批处理串联"等待安装器完成 → 启动新版本";本进程 1s 后退出,让安装器接管收尾。
const newExe = path.join(path.dirname(process.execPath), path.basename(process.execPath));
const bat = path.join(SHELL_CACHE, `apply-update-${version}.cmd`);
fs.writeFileSync(bat, [
"@echo off",
`start "" /wait "${pkg}" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART`,
`start "" "${newExe}"`,
"",
].join("\r\n"), "utf-8");
spawn("cmd.exe", ["/c", bat], {
cwd: SHELL_CACHE,
windowsHide: true,
stdio: "ignore",
detached: true,
}).unref();
// 给安装器接管进程,随后退出
// electron-builder NSIS 静默参数是 /S(不认 Inno 的 /VERYSILENT)。
// 静默安装结束后安装器可能已自行拉起新版本(electron-updater 语义,进程带 --updated),
// 因此安装成功时先等 3s 检测进程,确实没起来才补启动,避免双实例;
// 安装失败时落日志并把旧版本拉起来,避免用户"点完升级窗口直接消失"。
// 用 wscript.exe 跑 VBS 而不是 cmd.exe 跑批处理:detached 启动时 cmd 会自建控制台,
// windowsHide 对 DETACHED_PROCESS 不生效,用户会看到黑窗口连弹;wscript 是 GUI 子系统,无控制台。
const newExe = process.execPath;
const exeName = path.basename(newExe);
const vbs = path.join(SHELL_CACHE, `apply-update-${version}.vbs`);
const logFile = path.join(SHELL_CACHE, "update-apply.log");
const markerFile = path.join(SHELL_CACHE, "update-apply.done");
try {
// VBS 默认按 ANSI 读取脚本,安装目录 / exe 名含中文会乱码;
// 带 BOM 的 UTF-16LE 才能让 wscript 正确解析中文路径
const script = "\uFEFF" + [
"Option Explicit",
"Dim pkg, exe, exeName, logFile, markerFile, sh, fso, rc",
`pkg = "${pkg}"`,
`exe = "${newExe}"`,
`exeName = "${exeName}"`,
`logFile = "${logFile}"`,
`markerFile = "${markerFile}"`,
'Set sh = CreateObject("WScript.Shell")',
'Set fso = CreateObject("Scripting.FileSystemObject")',
"",
"Sub WriteLog(msg)",
" On Error Resume Next",
" Dim f",
" Set f = fso.OpenTextFile(logFile, 8, True)",
' f.WriteLine Now & " " & msg',
" f.Close",
"End Sub",
"",
// 等待窗口靠这个标记文件判断"可以关窗了"(ok / failed),
// 不再依赖它在窗口里查进程名——那套对中文带空格的进程名不可靠。
"Sub WriteMarker(txt)",
" On Error Resume Next",
" Dim f",
" Set f = fso.CreateTextFile(markerFile, True)",
" f.Write txt",
" f.Close",
"End Sub",
"",
// 查进程数:用 WMI 而不是 tasklist。sh.Exec("tasklist ...") 每次都会拉起一个可见的
// cmd 控制台,轮询期间用户在屏幕上看到的就是连环闪黑窗(本次体验问题的根因)。
"Function ProcCount(name)",
" Dim svc, col",
" ProcCount = -1",
" On Error Resume Next",
' Set svc = GetObject("winmgmts:\\\\.\\root\\cimv2")',
' Set col = svc.ExecQuery("SELECT ProcessId FROM Win32_Process WHERE Name=\'" & name & "\'")',
" If Err.Number = 0 Then ProcCount = col.Count",
" Err.Clear",
"End Function",
"",
// 清掉上一轮日志 / 标记,避免等待窗口一启动就读到旧状态
"On Error Resume Next",
"If fso.FileExists(logFile) Then fso.DeleteFile logFile, True",
"If fso.FileExists(markerFile) Then fso.DeleteFile markerFile, True",
"On Error GoTo 0",
"",
// 等本进程(旧壳)完全退出,否则 NSIS 检测到应用在运行会直接失败
"WScript.Sleep 2500",
// 0 = 隐藏安装器窗口,True = 等安装结束
'rc = sh.Run("""" & pkg & """ /S", 0, True)',
"If rc <> 0 Then",
' WriteLog "install failed, rc=" & rc & ", pkg=" & pkg',
" WriteMarker \"failed\"",
' sh.Run """" & exe & """", 1, False',
" WScript.Quit 0",
"End If",
// 安装成功后轮询最多 5s 等新进程起来(静默安装不一定自动拉起),没起来再补启动,
// 避免与安装器自身拉起的实例并发双开(壳子有单实例锁,重复启动也只是多闪一下)。
"Dim i, started",
"started = False",
"For i = 1 To 10",
" WScript.Sleep 500",
" If ProcCount(exeName) > 0 Then",
" started = True",
" Exit For",
" End If",
"Next",
"If Not started Then",
' WriteLog "安装完成但未检测到进程,补启动:" & exe',
" On Error Resume Next",
' sh.Run """" & exe & """", 1, False',
" If Err.Number <> 0 Then",
" WriteLog \"补启动失败:\" & Err.Description",
" WriteMarker \"failed\"",
" WScript.Quit 0",
" End If",
" On Error GoTo 0",
"End If",
'WriteMarker "ok"',
"WScript.Quit 0",
"",
].join("\r\n");
fs.writeFileSync(vbs, script, "utf16le");
// 先清掉上一轮日志 / 标记:残留会让等待窗口一启动就误判"已完成"或"升级未完成"
try { fs.unlinkSync(logFile); } catch (_) { /* 不存在或占用,忽略 */ }
try { fs.unlinkSync(markerFile); } catch (_) { /* 不存在或占用,忽略 */ }
// 先起等待窗口(Electron 随后退出,界面由它接管),再起安装脚本
spawnWaitWindow(version, newExe, markerFile);
const child = spawn("wscript.exe", ["//nologo", "//B", vbs], {
cwd: SHELL_CACHE,
windowsHide: true,
stdio: "ignore",
detached: true,
});
child.on("error", (e) => {
_STATE.applying = false;
logger.error(`启动升级脚本失败:${e.message}`);
});
child.unref();
} catch (e) {
_STATE.applying = false;
throw e;
}
// 给等待窗口(mshta 启动约 1s)和前端遮罩层留出展示时间,随后退出让安装器替换文件
setTimeout(() => {
if (typeof process.exit === "function") process.exit(0);
}, 1000);
}, 1800);
}
module.exports = {
@@ -0,0 +1,9 @@
// 托盘菜单弹窗专用 preload:只暴露菜单动作白名单。
"use strict";
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("trayMenu", {
action: (name) => ipcRenderer.send("tray-menu:action", String(name || "")),
toggleAutostart: () => ipcRenderer.invoke("tray-menu:toggle-autostart"),
});
@@ -0,0 +1,184 @@
// 自定义托盘右键菜单:无边框卡片式弹窗,替代系统原生菜单(原生样式跟随系统、不可控)。
// 用法:attach(tray, { onOpen, onQuit }),主进程负责窗口与菜单项动作。
"use strict";
const path = require("path");
const { app, BrowserWindow, ipcMain, screen } = require("electron");
const { makeLogger } = require("./logger");
const logger = makeLogger("tray-menu");
const W = 236;
const H = 178; // 与 buildHTML 里的内容高度一致(头部 44 + 三分隔 + 三菜单项)
const MARGIN = 8; // 与托盘图标 / 屏幕边缘留白
let win = null;
let trayRef = null;
let handlers = { onOpen: null, onQuit: null };
let wired = false;
function buildHTML() {
const version = app.getVersion();
const autoOn = app.getLoginItemSettings().openAtLogin ? "on" : "";
return `<!doctype html><html><head><meta charset="utf-8"><style>
*{margin:0;padding:0;box-sizing:border-box;font-family:"Segoe UI","Microsoft YaHei",sans-serif;
-webkit-user-select:none;user-select:none}
html,body{background:transparent;overflow:hidden}
.card{position:fixed;inset:0;background:#fff;border:1px solid #E8EAF1;border-radius:14px;
box-shadow:0 16px 38px -16px rgba(18,20,31,.38),0 4px 12px -6px rgba(18,20,31,.12);
padding:6px;display:flex;flex-direction:column;
animation:pop .16s cubic-bezier(.2,.8,.3,1)}
@keyframes pop{from{opacity:0;transform:translateY(6px) scale(.985)}to{opacity:1;transform:none}}
.head{display:flex;align-items:center;gap:9px;padding:6px 8px 10px}
.logo{width:26px;height:26px;border-radius:8px;background:linear-gradient(135deg,#4F5AE8,#0F9F9B);
color:#fff;font-size:11px;font-weight:800;display:flex;align-items:center;justify-content:center;letter-spacing:.2px}
.hi{min-width:0;flex:1}
.hi b{display:block;font-size:12.5px;color:#12141B;font-weight:600;
white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.hi span{display:flex;align-items:center;gap:5px;font-size:11px;color:#6E7686;margin-top:3px}
.dot{width:5px;height:5px;border-radius:50%;background:#0E9F76;box-shadow:0 0 0 2px rgba(14,159,118,.14)}
.sep{height:1px;background:#F0F2F7;margin:4px 6px}
.item{display:flex;align-items:center;gap:9px;height:34px;padding:0 9px;border-radius:9px;
font-size:12.5px;color:#3C4250;cursor:pointer;transition:background .12s,color .12s}
.item:hover{background:#F5F6FA;color:#12141B}
.item .ic{width:15px;height:15px;flex-shrink:0;color:#8A92A3}
.item:hover .ic{color:#4F5AE8}
.item.brand{color:#3D47D4;font-weight:600}
.item.brand .ic{color:#4F5AE8}
.item.danger:hover{background:#FDEDED;color:#CC3B40}
.item.danger:hover .ic{color:#E5484D}
.sw{margin-left:auto;width:26px;height:15px;border-radius:8px;background:#E3E6EF;position:relative;
transition:background .16s;flex-shrink:0}
.sw::after{content:"";position:absolute;top:2px;left:2px;width:11px;height:11px;border-radius:50%;
background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.2);transition:transform .16s}
.sw.on{background:#4F5AE8}
.sw.on::after{transform:translateX(11px)}
</style></head><body>
<div class="card">
<div class="head">
<div class="logo">37</div>
<div class="hi">
<b>37du 自动化工作台</b>
<span><i class="dot"></i>服务运行中 · v${version}</span>
</div>
</div>
<div class="sep"></div>
<div class="item brand" data-act="open">
<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"
stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="14" rx="2.5"/>
<path d="M3 9h18"/><path d="M9 22h6"/></svg>
<span>打开工作台</span>
</div>
<div class="item" data-act="autostart">
<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"
stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v9"/>
<path d="M6.4 6.4a8 8 0 1 0 11.2 0"/></svg>
<span>开机自启</span>
<span class="sw ${autoOn}" id="sw"></span>
</div>
<div class="sep"></div>
<div class="item danger" data-act="quit">
<svg class="ic" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"
stroke-linecap="round" stroke-linejoin="round"><path d="M12 21a9 9 0 1 0-9-9"/>
<path d="M3 16v5h5"/></svg>
<span>退出</span>
</div>
</div>
<script>
document.addEventListener("click", async (e) => {
const el = e.target.closest(".item");
if (!el) return;
const act = el.dataset.act;
if (act === "autostart") {
const on = await window.trayMenu.toggleAutostart();
document.getElementById("sw").classList.toggle("on", !!on);
return;
}
window.trayMenu.action(act);
});
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") window.trayMenu.action("close");
});
document.addEventListener("contextmenu", (e) => e.preventDefault());
</script>
</body></html>`;
}
function closeMenu() {
if (win && !win.isDestroyed()) win.destroy();
win = null;
}
function openMenu() {
if (win && !win.isDestroyed()) { closeMenu(); return; } // 再次右键 = 收起
if (!trayRef) return;
try {
// 托盘图标可能被折叠进"隐藏的图标"面板(bounds 无效),此时以鼠标位置为锚点
let b = trayRef.getBounds();
if (!b || !b.width) {
const p = screen.getCursorScreenPoint();
b = { x: p.x - 8, y: p.y - 8, width: 16, height: 16 };
}
const pt = { x: b.x + Math.round(b.width / 2), y: b.y + Math.round(b.height / 2) };
const wa = screen.getDisplayNearestPoint(pt).workArea;
// 任务栏在屏幕下半部分时菜单向上弹出,否则向下
let x = Math.round(b.x + b.width / 2 - W / 2);
let y = b.y > wa.y + wa.height / 2 ? b.y - H - MARGIN : b.y + b.height + MARGIN;
x = Math.max(wa.x + MARGIN, Math.min(x, wa.x + wa.width - W - MARGIN));
y = Math.max(wa.y + MARGIN, Math.min(y, wa.y + wa.height - H - MARGIN));
win = new BrowserWindow({
width: W, height: H, x, y,
frame: false, transparent: true, resizable: false, movable: false,
minimizable: false, maximizable: false, fullscreenable: false,
skipTaskbar: true, alwaysOnTop: true, show: false, hasShadow: false,
backgroundColor: "#00000000",
webPreferences: {
preload: path.join(__dirname, "tray-menu-preload.js"),
contextIsolation: true, nodeIntegration: false, sandbox: true,
},
});
win.setAlwaysOnTop(true, "pop-up-menu");
win.loadURL("data:text/html;charset=utf-8," + encodeURIComponent(buildHTML()));
win.once("ready-to-show", () => {
if (win && !win.isDestroyed()) { win.show(); win.focus(); }
});
win.on("blur", () => closeMenu());
win.on("closed", () => { win = null; });
} catch (e) {
logger.warning(`托盘菜单打开失败:${e.message}`);
closeMenu();
}
}
function wire() {
if (wired) return;
wired = true;
ipcMain.on("tray-menu:action", (_e, act) => {
if (act === "open") {
closeMenu();
if (handlers.onOpen) handlers.onOpen();
} else if (act === "quit") {
closeMenu();
if (handlers.onQuit) handlers.onQuit();
} else {
closeMenu();
}
});
ipcMain.handle("tray-menu:toggle-autostart", () => {
const next = !app.getLoginItemSettings().openAtLogin;
app.setLoginItemSettings({ openAtLogin: next });
return next;
});
}
function attach(tray, opts) {
trayRef = tray;
handlers = opts || { onOpen: null, onQuit: null };
wire();
tray.on("right-click", openMenu);
}
module.exports = { attach, close: closeMenu };
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,51 @@
<template>
<el-dialog v-model="visible" :title="title" width="420px"
:close-on-click-modal="false" align-center class="upd-dl-dialog">
<template v-if="dl.status === 'downloading'">
<div class="dl-dlg-body">
<el-progress :percentage="dl.pct || 0" :stroke-width="10" />
<span class="dl-dlg-bytes">{{ fmtBytes(dl.received) }}{{ dl.total ? ' / ' + fmtBytes(dl.total) : '' }}</span>
</div>
</template>
<template v-else-if="dl.status === 'extracting'">
<div class="dl-dlg-body">
<el-progress :percentage="100" :stroke-width="10" status="warning" :indeterminate="true" :duration="2" />
<span class="dl-dlg-bytes">下载完成,正在解压安装(约需几十秒)…</span>
</div>
</template>
<template v-else-if="dl.status === 'failed'">
<div class="dl-dlg-body">
<span class="dl-dlg-err">{{ failLabel }}:{{ dl.error || '未知错误' }}</span>
</div>
</template>
<div v-else class="dl-dlg-body"><span>{{ bodyText }}</span></div>
<template #footer><slot name="footer" /></template>
</el-dialog>
</template>
<script setup>
import { computed } from 'vue'
import { fmtBytes } from '../utils/format'
const props = defineProps({
modelValue: { type: Boolean, default: false },
title: { type: String, default: '' },
dl: { type: Object, default: () => ({}) },
// 非下载/解压/失败状态的正文(准备中、已就绪、已安装等由调用方给文案)
bodyText: { type: String, default: '' },
failLabel: { type: String, default: '下载失败' },
})
const emit = defineEmits(['update:modelValue'])
const visible = computed({
get: () => props.modelValue,
set: (v) => emit('update:modelValue', v),
})
</script>
<style scoped>
/* el-dialog 就地渲染(未 append-to-body),scoped 样式仍作用于弹窗内部 */
.dl-dlg-body { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-1) 2px; font-size: 12.5px; color: var(--t2); }
.dl-dlg-bytes { font-family: var(--f-num); font-size: 11px; color: var(--t3); text-align: right; }
.dl-dlg-err { color: var(--danger-ink); font-size: 12px; line-height: 1.6; }
</style>
@@ -1,89 +1,208 @@
<template>
<div class="home">
<!-- 指标行:压缩首屏信息密度(替代问候区与统计卡) -->
<!-- 头部 hero:英文小标 + 中文大标 + 副文案 + 右侧日期信息 -->
<section class="hero card">
<div class="hero-main">
<span class="hero-eyebrow"><i></i>TODAY · 今日简报</span>
<h1 class="hero-title">今日运行简报</h1>
<p class="hero-sub">场景运行状态与成功率一屏掌握,数据来自本机执行记录</p>
</div>
<div class="hero-side">
<span class="hs-date">{{ dateShort }}</span>
<span class="hs-week">{{ weekLabel }}</span>
<div class="hs-meta">
<i class="hs-dot" :class="{ on: onlineCount }"></i>
{{ onlineCount }} 个平台在线 · {{ scheduleCount }} 个任务
</div>
</div>
</section>
<!-- 指标四宫格 -->
<section class="kpis">
<div class="kpi">
<b>{{ store.plugins.length }}<em> 场景</em></b>
<span>可用场景</span>
<div class="kpi card k-brand">
<span class="k-label">SCENES</span>
<b class="k-num">{{ store.plugins.length }}<em>个</em></b>
<span class="k-sub">已授权可用场景</span>
</div>
<div class="kpi">
<b>{{ scheduleCount }}<em> 任务</em></b>
<span>定时任务</span>
<div class="kpi card k-good">
<span class="k-label">SCHEDULES</span>
<b class="k-num">{{ scheduleCount }}<em>个</em></b>
<span class="k-sub">按计划自动执行</span>
</div>
<div class="kpi" :class="onlineCount ? 'ok' : ''">
<b>{{ onlineCount }}<em>/{{ store.platforms.length }}</em></b>
<span>平台在线</span>
<div class="kpi card k-warn">
<span class="k-label">PLATFORMS</span>
<b class="k-num">{{ onlineCount }}<em>/{{ store.platforms.length }}</em></b>
<span class="k-sub">平台账号在线</span>
</div>
<div class="kpi" :class="lastOk === null ? '' : (lastOk ? 'ok' : 'err')">
<b>{{ lastOk === null ? '—' : (lastOk ? '成功' : '失败') }}</b>
<span>{{ lastRunTime || '暂无运行' }}</span>
<div class="kpi card k-plain">
<span class="k-label">LAST RUN</span>
<b class="k-num last" :class="lastOk === null ? '' : (lastOk ? 'good' : 'bad')">
{{ lastOk === null ? '—' : (lastOk ? '成功' : '失败') }}
</b>
<span class="k-sub">{{ lastRunTime || '暂无运行' }}</span>
</div>
</section>
<!-- 平台账号(当前登录人的 HR/OA 账号与登录状态,登录后场景按本人身份执行) -->
<section class="block">
<div class="block-head">
<span class="sec-title">平台账号</span>
<span class="rec-note">配置你自己的 HR/OA 账号</span>
</div>
<PlatformAccounts />
<!-- 运行中卡 -->
<section v-if="store.running" class="card running-card">
<RunIndicator :name="runningName" :progress="store.progress">
<template #tail>
<span class="run-tail">{{ runningTail || '执行中…' }}</span>
</template>
</RunIndicator>
</section>
<!-- 常用场景(只放前 6 个快捷入口,全部走「场景」视图) -->
<div class="grid-2">
<!-- 运行脉冲 -->
<section class="card signal-card">
<div class="card-top">
<div class="card-titles">
<span class="sec-eyebrow">SIGNAL</span>
<b class="card-title">运行脉冲</b>
<span class="card-sub">近 7 日运行分布</span>
</div>
<div class="legend">
<span><i class="lg-dot ok"></i>成功</span>
<span><i class="lg-dot bad"></i>失败</span>
</div>
</div>
<template v-if="trendTotal && chart">
<div class="chart">
<svg :viewBox="`0 0 ${chart.w} ${chart.h}`" preserveAspectRatio="none" aria-hidden="true">
<defs>
<linearGradient id="pulseOk" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" class="g-top" />
<stop offset="100%" class="g-bot" />
</linearGradient>
</defs>
<path :d="chart.okArea" fill="url(#pulseOk)" />
<path :d="chart.okLine" class="line-ok" vector-effect="non-scaling-stroke" />
<path :d="chart.failLine" class="line-fail" vector-effect="non-scaling-stroke" />
</svg>
<div class="axis">
<span v-for="(d, i) in trendDays" :key="i">{{ d.label }}</span>
</div>
</div>
<div class="period">
<div class="p-cell">
<span class="p-k">运行总数</span>
<b>{{ trendTotal }}</b>
</div>
<div class="p-cell">
<span class="p-k">成功</span>
<b class="good">{{ trendOk }}</b>
</div>
<div class="p-cell">
<span class="p-k">失败</span>
<b :class="trendFail ? 'bad' : ''">{{ trendFail }}</b>
</div>
<div class="p-cell">
<span class="p-k">单日峰值</span>
<b>{{ trendPeak }}</b>
</div>
</div>
</template>
<div v-else class="empty-note">暂无运行记录</div>
</section>
<!-- 执行成功率(平台账号已在右侧栏常驻,这里不重复展示) -->
<section class="card rate-card">
<div class="card-top">
<div class="card-titles">
<span class="sec-eyebrow">RATE</span>
<b class="card-title">执行成功率</b>
<span class="card-sub">近 7 日成功占比</span>
</div>
<span v-if="trendTotal" class="rate-pill" :class="rateTone">{{ rateLabel }}</span>
</div>
<div v-if="trendTotal" class="rate-main">
<div class="rate-ring">
<svg viewBox="0 0 120 120" aria-hidden="true">
<circle class="ring-track" cx="60" cy="60" r="50" />
<circle
class="ring-val"
:class="rateTone"
cx="60" cy="60" r="50"
:style="{ strokeDasharray: `${ringDash} ${ringC}` }"
/>
</svg>
<div class="ring-center">
<span class="rate-num"><b>{{ ratePct }}</b><em>%</em></span>
<span class="ring-cap">成功率</span>
</div>
</div>
<div class="rate-stats">
<div class="rs-row">
<span class="rs-k"><i class="rs-dot ok"></i>成功</span>
<b class="good">{{ trendOk }}<em>{{ ratePct }}%</em></b>
</div>
<div class="rs-row">
<span class="rs-k"><i class="rs-dot bad"></i>失败</span>
<b :class="trendFail ? 'bad' : ''">{{ trendFail }}<em>{{ 100 - ratePct }}%</em></b>
</div>
<div class="rs-row">
<span class="rs-k"><i class="rs-dot neutral"></i>7 日合计</span>
<b>{{ trendTotal }}<em>次</em></b>
</div>
<div class="rs-row">
<span class="rs-k"><i class="rs-dot neutral"></i>日均运行</span>
<b>{{ avgPerDay }}<em>次</em></b>
</div>
</div>
</div>
<div v-else class="empty-note">暂无运行记录</div>
</section>
</div>
<!-- 常用场景 -->
<section class="block">
<div class="block-head">
<span class="sec-title">常用场景</span>
<el-button v-if="store.plugins.length > 6" text size="small" class="more" @click="goScenes">
全部场景 {{ store.plugins.length }} <el-icon><ArrowRight /></el-icon>
</el-button>
</div>
<div v-if="store.plugins.length" class="scenes" :style="{ '--n': Math.min(4, store.plugins.length) }">
<button
v-for="(p, i) in store.plugins.slice(0, 6)" :key="p.id" class="sc card"
:class="{ running: store.running && store.selectedId === p.id }"
@click="openPlugin(p.id)"
>
<span class="sc-ic" :style="{ background: grad(i) }">{{ p.name.slice(0, 1) }}</span>
<span class="sc-body">
<b>{{ p.name }}</b>
<span class="sc-meta">
v{{ p.version }}
<template v-if="p.platform">
<i class="sep-dot"></i>{{ platformLabel(p.platform) }}
<em class="plat-state" :class="{ on: platformOnline(p.platform) }">
{{ platformOnline(p.platform) ? '已登录' : '未登录' }}
</em>
</template>
</span>
</span>
<span class="sc-go">
<template v-if="store.running && store.selectedId === p.id">{{ store.progress }}%</template>
<template v-else>执行</template>
</span>
<div class="block-titles">
<span class="sec-eyebrow">SCENES</span>
<b class="sec-name">常用场景</b>
</div>
<button v-if="store.plugins.length > 6" class="link-btn" @click="goScenes">
全部场景 {{ store.plugins.length }} <i class="arr">→</i>
</button>
</div>
<div v-else class="empty card">
<span class="empty-emoji">🤍</span>
<div v-if="store.plugins.length" class="scenes" :style="{ '--n': Math.min(4, store.plugins.length) }">
<SceneCard v-for="p in store.plugins.slice(0, 6)" :key="p.id" :plugin="p" compact @open="openPlugin" />
</div>
<div v-else class="card empty">
<div>
<b>当前账号暂无可用场景</b>
<span>请联系管理员在控制面进行授权,授权后点击右上角刷新</span>
<span>请联系管理员在控制面进行授权,授权后在左侧「场景库」点击插件同步</span>
</div>
<el-button size="small" round type="primary" plain @click="goScenes">去同步</el-button>
<button class="btn primary" @click="goScenes">去场景库</button>
</div>
</section>
<!-- 最近动态 -->
<!-- 最近运行 -->
<section class="block" v-if="store.recents.length">
<div class="block-head">
<span class="sec-title">最近动态</span>
<span class="rec-note">最近 {{ store.recents.length }} 次执行</span>
<div class="block-titles">
<span class="sec-eyebrow">RECENT</span>
<b class="sec-name">最近运行</b>
</div>
<span class="head-note">最近 {{ store.recents.length }} 次</span>
</div>
<div class="recent card">
<button v-for="(r, i) in store.recents" :key="i" class="rec" @click="openPlugin(r.pluginId, r.runId)">
<span class="rec-ic" :class="r.ok ? 'ok' : 'err'">{{ r.ok ? '✓' : '✕' }}</span>
<span class="rec-name">{{ r.name }}</span>
<span class="rec-msg" :class="r.ok ? 'ok' : 'err'">{{ r.ok ? '执行完成' : (r.error || '执行失败') }}</span>
<span class="rec-time">{{ r.time }}</span>
<div class="card table">
<div class="thead">
<span class="c-idx">#</span>
<span class="c-name">场景</span>
<span class="c-msg">结果</span>
<span class="c-time">时间</span>
</div>
<button v-for="(r, i) in store.recents" :key="i" class="trow" @click="openPlugin(r.pluginId, r.runId)">
<span class="c-idx num">{{ String(i + 1).padStart(2, '0') }}</span>
<span class="c-name">
<i class="tag" :class="r.ok ? 'ok' : 'bad'">{{ r.ok ? '成功' : '失败' }}</i>
<b>{{ r.name }}</b>
</span>
<span class="c-msg" :class="r.ok ? '' : 'bad-text'">{{ r.ok ? '执行完成' : (r.error || '执行失败') }}</span>
<span class="c-time num">{{ r.time }}</span>
</button>
</div>
</section>
@@ -92,17 +211,10 @@
<script setup>
import { computed, onMounted, ref } from 'vue'
import { ArrowRight } from '@element-plus/icons-vue'
import { store } from '../store'
import { listSchedules } from '../api'
import PlatformAccounts from './PlatformAccounts.vue'
const GRADS = [
'var(--grad-sky)', 'var(--grad-peach)', 'var(--grad-mint)',
'var(--grad-lilac)', 'var(--grad-honey)', 'var(--grad-blush)',
]
function grad(i) { return GRADS[i % GRADS.length] }
import { listSchedules, fetchRuns } from '../api'
import SceneCard from './SceneCard.vue'
import RunIndicator from './RunIndicator.vue'
const scheduleCount = ref(0)
onMounted(async () => {
@@ -114,22 +226,118 @@ onMounted(async () => {
const onlineCount = computed(() => (store.platforms || []).filter((p) => p.online).length)
const WEEK = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
const now = new Date()
const pad2 = (n) => String(n).padStart(2, '0')
const dateShort = `${pad2(now.getMonth() + 1)}.${pad2(now.getDate())}`
const weekLabel = `${now.getFullYear()} 年 · ${WEEK[now.getDay()]}`
const lastOk = computed(() => (store.lastResult ? !!store.lastResult.ok : null))
const lastRunTime = computed(() => {
const r = store.recents[0]
return r ? r.time : ''
})
function platformLabel(id) {
return (store.platforms.find((p) => p.id === id) || {}).label || id
}
function platformOnline(id) {
return !!(store.platforms.find((p) => p.id === id) || {}).online
const runningName = computed(() => {
const p = (store.plugins || []).find((x) => x.id === store.selectedId)
return p ? p.name : (store.selectedId || '')
})
const runningTail = computed(() => {
const list = store.logs || []
const l = list[list.length - 1]
if (!l) return ''
return String(l.msg ?? '').slice(0, 80)
})
/* 近 7 日趋势:从后端运行历史(fetchRuns)按 started 时间戳归日聚合。
不用 store.recents——它是内存态且 time 只有时分秒,重启即空、无法按日归桶 */
const trendDays = ref([])
onMounted(async () => {
const now = new Date()
const buckets = []
for (let i = 6; i >= 0; i--) {
const d = new Date(now); d.setDate(d.getDate() - i)
const key = `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`
buckets.push({ key, label: i === 0 ? '今天' : `${d.getMonth() + 1}-${d.getDate()}`, ok: 0, fail: 0 })
}
const keyOf = (sec) => { const d = new Date(sec * 1000); return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}` }
try {
const r = await fetchRuns(200)
for (const run of r.runs || []) {
if (!run.started) continue
const b = buckets.find((x) => x.key === keyOf(run.started))
if (b) { run.ok ? b.ok++ : b.fail++ }
}
} catch (_) { /* 拉取失败保持空态 */ }
trendDays.value = buckets
})
const trendTotal = computed(() => trendDays.value.reduce((s, d) => s + d.ok + d.fail, 0))
const trendOk = computed(() => trendDays.value.reduce((s, d) => s + d.ok, 0))
const trendFail = computed(() => trendDays.value.reduce((s, d) => s + d.fail, 0))
const trendPeak = computed(() => trendDays.value.reduce((m, d) => Math.max(m, d.ok + d.fail), 0))
const ratePct = computed(() => (trendTotal.value ? Math.round((trendOk.value / trendTotal.value) * 100) : 0))
const avgPerDay = computed(() => (trendTotal.value / 7).toFixed(1).replace(/\.0$/, ''))
/* 成功率环:r=50 的周长作为 dasharray 基准,按占比取可见弧长 */
const ringC = 2 * Math.PI * 50
const ringDash = computed(() => (ringC * ratePct.value) / 100)
const rateTone = computed(() => (ratePct.value >= 95 ? 'good' : ratePct.value >= 80 ? 'warn' : 'bad'))
const rateLabel = computed(() => ({ good: '运行稳定', warn: '偶有失败', bad: '需重点关注' }[rateTone.value]))
/* 脉冲曲线:成功=平滑曲线+面积,失败=虚线;用单调三次插值(Fritsch-Carlson),
普通 Catmull-Rom 在 0 值附近的节点会过冲下凹,单调插值保证不越过相邻点数值。
preserveAspectRatio=none 横向拉伸,描边用 non-scaling-stroke 保持 2px 不变形 */
const chart = computed(() => {
const days = trendDays.value
if (days.length < 2) return null
const W = 640, H = 120, PAD = 14
const max = Math.max(1, ...days.map((d) => d.ok + d.fail))
const stepX = W / (days.length - 1)
const yOf = (v) => H - PAD - (v / max) * (H - PAD * 2)
const okPts = days.map((d, i) => [i * stepX, yOf(d.ok)])
const failPts = days.map((d, i) => [i * stepX, yOf(d.fail)])
const okLine = smoothPath(okPts)
return {
w: W,
h: H,
okLine,
okArea: `${okLine} L ${W},${H} L 0,${H} Z`,
failLine: smoothPath(failPts),
}
})
/* 点位 → 三次贝塞尔平滑路径(单调三次插值,避免峰谷过冲出负数) */
function smoothPath(pts) {
const n = pts.length
if (n < 2) return ''
const dx = [], slope = []
for (let i = 0; i < n - 1; i++) {
dx[i] = pts[i + 1][0] - pts[i][0]
slope[i] = (pts[i + 1][1] - pts[i][1]) / dx[i]
}
const m = [slope[0]]
for (let i = 1; i < n - 1; i++) {
if (slope[i - 1] * slope[i] <= 0) m[i] = 0
else {
const w1 = 2 * dx[i] + dx[i - 1]
const w2 = dx[i] + 2 * dx[i - 1]
m[i] = (w1 + w2) / (w1 / slope[i - 1] + w2 / slope[i])
}
}
m[n - 1] = slope[n - 2]
let d = `M ${pts[0][0].toFixed(1)},${pts[0][1].toFixed(1)}`
for (let i = 0; i < n - 1; i++) {
const h = dx[i] / 3
d += ` C ${(pts[i][0] + h).toFixed(1)},${(pts[i][1] + m[i] * h).toFixed(1)}`
+ ` ${(pts[i + 1][0] - h).toFixed(1)},${(pts[i + 1][1] - m[i + 1] * h).toFixed(1)}`
+ ` ${pts[i + 1][0].toFixed(1)},${pts[i + 1][1].toFixed(1)}`
}
return d
}
function openPlugin(id, runId) {
store.selectedId = id
store.view = 'run'
// 最近动态点击:直达该次运行的回看(运行台消费后清空);普通场景点击清掉残留意图
// 最近运行点击:直达该次运行的回看(运行台消费后清空);普通场景点击清掉残留意图
store.pendingReplay = runId ? { pluginId: id, runId } : null
}
function goScenes() {
@@ -138,105 +346,199 @@ function goScenes() {
</script>
<style scoped>
.home { display: flex; flex-direction: column; gap: 20px; padding: 4px 2px 10px; flex-shrink: 0; }
.home { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--page-pad); flex-shrink: 0; container-type: inline-size; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
/* ---------- 指标行(紧凑,替代问候区/统计卡) ---------- */
.kpis { display: flex; gap: 10px; flex-wrap: wrap; }
.kpi {
flex: 1; min-width: 150px;
display: flex; align-items: baseline; gap: 8px;
padding: 10px 14px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
/* ---------- 通用小标 / 卡头 ---------- */
.k-label,
.sec-eyebrow {
display: inline-flex; align-items: center; gap: var(--space-1-5);
font: 600 9.5px/14px var(--f-num);
letter-spacing: .14em; text-transform: uppercase; color: var(--t4);
}
.kpi b { font-size: 17px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi b em { font-style: normal; font-size: 11px; color: var(--text-faint); font-weight: 500; }
.kpi span { margin-left: auto; font-size: 11px; color: var(--text-faint); white-space: nowrap; }
.kpi.ok b { color: var(--ok); }
.kpi.err b { color: var(--err); }
.k-label::before,
.sec-eyebrow::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--t5); }
.k-brand .k-label::before { background: var(--brand); opacity: .8; }
.k-good .k-label::before { background: var(--good); opacity: .8; }
.k-warn .k-label::before { background: var(--warn); opacity: .8; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.card-titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card-title { font: 600 14px/20px var(--f-cn); color: var(--t1); }
.card-sub { font: 400 10.5px/15px var(--f-cn); color: var(--t4); }
/* ---------- 头部 hero ---------- */
.hero {
display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4);
padding: var(--space-4) var(--space-5);
background: linear-gradient(118deg, var(--brand-soft-2) 0%, var(--surface) 52%, var(--subtle) 100%);
border-color: var(--brand-track);
}
.hero-main { min-width: 0; display: flex; flex-direction: column; }
.hero-eyebrow {
display: inline-flex; align-items: center; gap: var(--space-1-5);
font: 600 9.5px/14px var(--f-num); letter-spacing: .14em;
text-transform: uppercase; color: var(--brand);
}
.hero-eyebrow i { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }
.hero-title { margin: var(--space-1) 0 var(--space-1); font: 600 24px/32px var(--f-cn); color: var(--t1); letter-spacing: -.2px; }
.hero-sub { margin: 0; font: 400 11.5px/17px var(--f-cn); color: var(--t3); }
.hero-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
.hs-date { font: 600 20px/24px var(--f-num); color: var(--t2); letter-spacing: -.3px; }
.hs-week { font: 400 10.5px/15px var(--f-cn); color: var(--t4); }
.hs-meta {
display: inline-flex; align-items: center; gap: var(--space-1-5);
margin-top: var(--space-1-5); font: 400 10.5px/15px var(--f-cn); color: var(--t3);
}
.hs-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--t5); }
.hs-dot.on { background: var(--good); }
/* ---------- 指标四宫格 ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); }
.kpi { padding: var(--space-3) var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-1); }
.k-brand { background: linear-gradient(160deg, var(--brand-soft) 0%, var(--surface) 64%); }
.k-good { background: linear-gradient(160deg, var(--good-soft) 0%, var(--surface) 64%); }
.k-warn { background: linear-gradient(160deg, var(--warn-soft) 0%, var(--surface) 64%); }
.k-plain { background: linear-gradient(160deg, var(--subtle) 0%, var(--surface) 64%); }
.k-num { font: 700 24px/1.15 var(--f-num); color: var(--t1); letter-spacing: -.4px; }
.k-num em { font-style: normal; font-size: 12px; font-weight: 500; color: var(--t4); }
.k-num.good { color: var(--good-ink); }
.k-num.bad { color: var(--danger-ink); }
.k-num.last { font-family: var(--f-cn); font-size: 20px; line-height: 1.35; }
.k-sub { font: 400 10.5px/15px var(--f-cn); color: var(--t4); }
/* ---------- 运行中卡 ---------- */
.running-card { padding: var(--space-3) var(--space-4); border-color: var(--brand-track); }
.run-tail { font: 400 10.5px/15px var(--f-mono); color: var(--t4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* ---------- 双列区 ---------- */
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--space-3); }
.signal-card { padding: var(--space-4); }
.legend { display: flex; align-items: center; gap: var(--space-3); font: 400 10.5px/15px var(--f-cn); color: var(--t3); flex-shrink: 0; }
.legend span { display: inline-flex; align-items: center; gap: var(--space-1-5); }
.lg-dot { width: 6px; height: 6px; border-radius: 50%; }
.lg-dot.ok { background: var(--brand); }
.lg-dot.bad { background: var(--danger); }
.chart { margin-top: var(--space-3); }
.chart svg { display: block; width: 100%; height: 116px; }
.g-top { stop-color: var(--brand); stop-opacity: .2; }
.g-bot { stop-color: var(--brand); stop-opacity: 0; }
.line-ok { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line-fail { fill: none; stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 4 4; opacity: .8; }
.axis { display: flex; justify-content: space-between; margin-top: var(--space-1); }
.axis span { font: 400 9.5px/13px var(--f-num); color: var(--t4); white-space: nowrap; }
.period {
display: grid; grid-template-columns: repeat(4, 1fr);
margin-top: var(--space-3); padding-top: var(--space-3);
border-top: 1px solid var(--line-soft);
}
.p-cell { display: flex; flex-direction: column; gap: 2px; padding-left: var(--space-3); border-left: 1px solid var(--line-soft); }
.p-cell:first-child { padding-left: 0; border-left: 0; }
.p-k { font: 400 10px/14px var(--f-cn); color: var(--t4); }
.p-cell b { font: 600 16px/1.2 var(--f-num); color: var(--t1); }
.p-cell b.good { color: var(--good-ink); }
.p-cell b.bad { color: var(--danger-ink); }
/* 执行成功率:成功率环 + 明细 */
.rate-card { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.rate-pill {
flex-shrink: 0; padding: 0 var(--space-2); border-radius: var(--r-pill);
font: 500 10px/18px var(--f-cn);
}
.rate-pill.good { color: var(--good-ink); background: var(--good-soft); }
.rate-pill.warn { color: var(--warn-ink); background: var(--warn-soft); }
.rate-pill.bad { color: var(--danger-ink); background: var(--danger-soft); }
.rate-main { display: flex; align-items: center; gap: var(--space-4); }
.rate-ring { position: relative; width: 106px; height: 106px; flex-shrink: 0; }
.rate-ring svg { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--line-soft); stroke-width: 8; }
.ring-val { fill: none; stroke-width: 8; stroke-linecap: round; transition: stroke-dasharray var(--dur); }
.ring-val.good { stroke: var(--good); }
.ring-val.warn { stroke: var(--warn); }
.ring-val.bad { stroke: var(--danger); }
.ring-center {
position: absolute; inset: 0; display: flex; flex-direction: column;
align-items: center; justify-content: center; gap: 1px;
}
.rate-num { display: flex; align-items: baseline; gap: 1px; }
.rate-num b { font: 700 24px/1 var(--f-num); color: var(--t1); letter-spacing: -.6px; }
.rate-num em { font-style: normal; font-size: 11px; color: var(--t4); }
.ring-cap { font: 400 9.5px/13px var(--f-cn); color: var(--t4); }
.rate-stats { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rs-row {
display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
padding: var(--space-1-5) 0; border-bottom: 1px dashed var(--line-soft);
}
.rs-row:first-child { padding-top: 0; }
.rs-row:last-child { padding-bottom: 0; border-bottom: 0; }
.rs-k { display: inline-flex; align-items: center; gap: var(--space-1-5); font: 400 11px/16px var(--f-cn); color: var(--t3); }
.rs-dot { width: 6px; height: 6px; border-radius: 50%; }
.rs-dot.ok { background: var(--good); }
.rs-dot.bad { background: var(--danger); }
.rs-dot.neutral { background: var(--t5); }
.rs-row b { font: 600 13px/1.2 var(--f-num); color: var(--t1); }
.rs-row b em { font-style: normal; margin-left: 3px; font-size: 9.5px; font-weight: 400; color: var(--t4); }
.rs-row b.good { color: var(--good-ink); }
.rs-row b.bad { color: var(--danger-ink); }
/* ---------- 分节 ---------- */
.block { display: flex; flex-direction: column; gap: 10px; container-type: inline-size; }
.block-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px; }
.more { color: var(--text-faint); }
.more:hover { color: var(--primary); }
.rec-note { font-size: 11px; color: var(--text-faint); }
/* ---------- 场景卡:列数 = min(4, 场景数),按实际数量均分并占满整行;
间隔数随列数变化,2 个场景即 2 列(与上方 2 列平台账号完全对齐);
容器变窄时先降为 2 列、再降 1 列,避免卡片过窄 ---------- */
.scenes {
--max: 4;
display: grid;
grid-template-columns: repeat(min(var(--max), var(--n, 1)), 1fr);
gap: 10px;
.block { display: flex; flex-direction: column; gap: var(--space-2); container-type: inline-size; }
.block-head { display: flex; align-items: flex-end; justify-content: space-between; padding: 0 2px; }
.block-titles { display: flex; flex-direction: column; gap: 2px; }
.sec-name { font: 600 15px/21px var(--f-cn); color: var(--t1); }
.head-note { font: 400 10.5px/15px var(--f-num); color: var(--t4); }
.link-btn {
border: 0; background: transparent; padding: 0; cursor: pointer;
font: 500 11px/16px var(--f-cn); color: var(--brand);
}
@container (max-width: 620px) { .scenes { --max: 2; } }
@container (max-width: 380px) { .scenes { --max: 1; } }
.sc {
display: flex; align-items: center; gap: 10px;
padding: 11px 13px; text-align: left;
.link-btn:hover { color: var(--brand-ink); }
.arr { font-style: normal; font-family: var(--f-num); }
/* 场景卡(SceneCard 共享);--n 由模板取 min(4, 插件数) */
.scenes { display: grid; grid-template-columns: repeat(var(--n, 1), 1fr); gap: var(--space-2); }
@container (max-width: 620px) { .scenes { grid-template-columns: repeat(2, 1fr); } }
@container (max-width: 380px) { .scenes { grid-template-columns: 1fr; } }
.empty { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-5); }
.empty b { display: block; font-size: 13px; color: var(--t1); margin-bottom: 3px; font-weight: 600; }
.empty span { font-size: 11.5px; color: var(--t3); }
.empty .btn { margin-left: auto; }
/* ---------- 最近运行表格 ---------- */
.table { padding: var(--space-1-5) var(--space-2) var(--space-2); }
.thead, .trow { display: grid; grid-template-columns: 34px 1.1fr 1.6fr 96px; align-items: center; gap: var(--space-2-5); }
.thead { padding: var(--space-2) var(--space-2-5) var(--space-1-5); border-bottom: 1px solid var(--line-soft); }
.thead span { font: 500 10px/14px var(--f-cn); color: var(--t4); }
.trow {
width: 100%; padding: 0 var(--space-2-5); height: 38px; text-align: left;
background: transparent; border: 0; border-radius: var(--r-row);
cursor: pointer; font-family: inherit;
transition: border-color .15s ease, box-shadow .15s ease;
transition: background var(--dur);
}
.sc:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.sc:active { transform: scale(.99); }
.sc.running { border-color: rgba(var(--primary-rgb), .55); background: var(--surface-glow); }
.sc-ic {
width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
display: grid; place-items: center; color: var(--tile-fg);
font-size: 13px; font-weight: 700;
.trow:hover { background: var(--field); }
.c-idx { font-size: 10.5px; color: var(--t4); }
.c-name { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.c-name b { font: 500 12px/17px var(--f-cn); color: var(--t1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag {
font-style: normal; flex: 0 0 auto;
font: 500 10px/16px var(--f-cn); padding: 0 var(--space-2); border-radius: var(--r-pill);
}
.sc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sc-body b { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-meta { font-size: 10.5px; color: var(--text-faint); display: flex; align-items: center; gap: 5px; font-style: normal; white-space: nowrap; }
.sep-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--dot-muted); }
.plat-state { font-style: normal; color: var(--text-muted-warm); }
.plat-state.on { color: var(--ok); }
.sc-go {
flex-shrink: 0;
font-size: 11px; font-weight: 600;
color: var(--primary); background: var(--primary-weak);
border: 1px solid rgba(var(--primary-rgb), .35);
padding: 4px 10px; border-radius: 999px;
transition: all .15s ease;
}
.sc:hover .sc-go { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.sc.running .sc-go { color: var(--on-primary); background: var(--primary); border-color: transparent; font-variant-numeric: tabular-nums; }
.tag.ok { color: var(--good-ink); background: var(--good-soft); }
.tag.bad { color: var(--danger-ink); background: var(--danger-soft); }
.c-msg { font-size: 11.5px; color: var(--t3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-msg.bad-text { color: var(--danger-ink); }
.c-time { font: 400 10.5px/15px var(--f-num); color: var(--t4); text-align: right; }
.empty {
display: flex; align-items: center; gap: 14px;
padding: 22px 20px; color: var(--text-sub);
/* 容器查询:按首页自身宽度(而非窗口宽度)收敛,右轨显隐不再影响断点 */
@container (max-width: 860px) {
.kpis { grid-template-columns: repeat(2, 1fr); }
.grid-2 { grid-template-columns: 1fr; }
.hero { align-items: flex-start; }
}
.empty-emoji { font-size: 26px; }
.empty b { display: block; font-size: 13.5px; color: var(--text); margin-bottom: 3px; font-weight: 600; }
.empty span { font-size: 12px; color: var(--text-faint); }
.empty .el-button { margin-left: auto; }
/* ---------- 最近动态 ---------- */
.recent { padding: 4px 8px; }
.rec {
display: flex; align-items: center; gap: 11px;
width: 100%; padding: 8px; text-align: left;
background: transparent; border: none; border-radius: 8px;
cursor: pointer; font-family: inherit;
transition: background .13s;
}
.rec:hover { background: var(--surface-2); }
.rec-ic {
width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
display: grid; place-items: center; font-size: 10px; font-weight: 700;
}
.rec-ic.ok { background: var(--ok-weak); color: var(--ok); }
.rec-ic.err { background: var(--err-weak); color: var(--err); }
.rec-name { font-size: 12.5px; font-weight: 600; color: var(--text); min-width: 110px; }
.rec-msg { flex: 1; font-size: 12px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-msg.ok { color: var(--ok); }
.rec-msg.err { color: var(--err); }
.rec-time { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
@media (max-width: 1100px) {
.kpis { flex-direction: column; }
@container (max-width: 480px) {
.period { grid-template-columns: repeat(2, 1fr); row-gap: var(--space-3); }
.p-cell:nth-child(3) { padding-left: 0; border-left: 0; }
}
</style>
@@ -4,7 +4,7 @@
<div class="log-title">
<i v-if="!isStatic" class="status" :class="store.wsOn ? 'on' : 'off'" :title="store.wsOn ? '实时连接正常' : '连接已中断'"></i>
<span>{{ isStatic ? '历史回看' : '运行日志' }}</span>
<span v-if="store.running && !isStatic" class="live">● LIVE</span>
<RunIndicator v-if="store.running && !isStatic" variant="tag" label="LIVE" />
<span v-else-if="visibleLogs.length" class="count">{{ visibleLogs.length }} 条</span>
</div>
@@ -23,7 +23,7 @@
<div v-if="!visibleLogs.length" class="log-empty">
<template v-if="isStatic">该次运行没有日志记录</template>
<template v-else-if="store.logs.length">当前级别无日志</template>
<template v-else>暂无日志,点击「一键执行」开始</template>
<template v-else>暂无日志,点击「执行」开始</template>
</div>
<div v-for="(l, i) in visibleLogs" :key="i" class="log-line">
<span class="t">{{ l.time || l.t || '' }}</span>
@@ -39,6 +39,7 @@ import { nextTick, ref, watch, computed } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { CopyDocument, VideoPause, VideoPlay } from '@element-plus/icons-vue'
import { store, clearLogs } from '../store'
import RunIndicator from './RunIndicator.vue'
const props = defineProps({
// 历史回看模式:传入后显示该次运行的静态日志(替代 store.logs),并隐藏清空/LIVE
@@ -104,25 +105,25 @@ async function copy() {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 14px 10px 18px;
border-bottom: 1px solid var(--border);
gap: 10px;
padding: var(--space-2-5) var(--space-3) var(--space-2-5) var(--space-4);
border-bottom: 1px solid var(--line);
gap: var(--space-2-5);
}
.log-title {
display: flex;
align-items: center;
gap: 9px;
gap: var(--space-2);
font-size: 13.5px;
font-weight: 600;
color: var(--text);
color: var(--t1);
white-space: nowrap;
}
.log-tools {
display: flex;
align-items: center;
gap: 6px;
gap: var(--space-1-5);
}
.log-tools .el-button+.el-button {
@@ -137,37 +138,24 @@ async function copy() {
}
.status.on {
background: var(--ok);
box-shadow: 0 0 0 3px var(--ok-weak);
background: var(--good);
box-shadow: 0 0 0 3px var(--good-soft);
}
.status.off {
background: var(--dot-off);
}
.live {
color: var(--ok);
font-size: 10px;
animation: blink 1s infinite;
letter-spacing: .04em;
background: var(--idle-bar);
}
.count {
font-size: 11px;
color: var(--text-faint);
color: var(--t3);
font-weight: 500;
}
@keyframes blink {
50% {
opacity: .2;
}
}
.log-empty {
color: var(--text-faint);
padding: 14px;
font-family: var(--mono);
color: var(--t3);
padding: var(--space-3);
font-family: var(--f-mono);
font-size: 12px;
}
</style>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,22 @@
<template>
<div class="page-head">
<div class="page-title-group">
<span v-if="eyebrow" class="eyebrow">{{ eyebrow }}</span>
<h1 class="page-title"><slot name="title">{{ title }}</slot></h1>
<p v-if="$slots.sub || sub" class="page-sub"><slot name="sub">{{ sub }}</slot></p>
</div>
<div v-if="$slots.actions" class="actions">
<slot name="actions" />
</div>
</div>
</template>
<script setup>
// 统一页头:所有一级视图共用(样式在 style.css 的「页头」段,对齐 design-app)
// title/sub 可传字符串,也可用 #title/#sub 插槽承载带标记的内容(如版本号、状态徽标)。
defineProps({
eyebrow: { type: String, default: '' },
title: { type: String, default: '' },
sub: { type: String, default: '' },
})
</script>
@@ -1,27 +1,40 @@
<template>
<div class="paccs">
<div v-for="p in platStatus" :key="p.id" class="pacc card">
<div class="p-top">
<span class="p-dot" :class="{ on: p.online }"></span>
<span class="p-name">{{ p.label }}</span>
<span class="p-state" :class="{ on: p.online }">{{ p.online ? '已登录' : '未登录' }}</span>
<div class="plat-page">
<PageHead eyebrow="PLATFORMS · 平台账号" title="平台账号" sub="账号密码仅保存在本机;登录后场景按当前账号身份执行" />
<div class="paccs">
<div v-if="!platStatus.length" class="pacc pacc-loading card">
<span class="spin"></span>
<b>{{ loading ? '正在读取平台清单…' : '暂无可用平台' }}</b>
<span>{{ loading ? '首次启动需校验平台登录态,请稍候' : '请稍后重试或联系管理员' }}</span>
</div>
<div class="p-user" :class="{ none: !p.has_creds }">{{ p.has_creds ? p.user : '未配置个人账号' }}</div>
<div class="p-acts">
<el-button v-if="!p.online" size="small" :loading="busy === p.id" @click="login(p.id)">
{{ busy === p.id ? '登录中…' : '登录' }}
</el-button>
<el-button v-else size="small" plain type="danger" :disabled="!!busy" @click="logout(p.id)">
登出
</el-button>
<el-button size="small" text @click="openEdit(p)">配置账号</el-button>
<div v-for="p in platStatus" :key="p.id" class="pacc card" :class="{ on: p.online }">
<div class="p-top">
<span class="p-dot" :class="{ on: p.online }"></span>
<span class="p-name">{{ p.label }}</span>
<span class="p-state" :class="{ on: p.online, waiting: p.has_creds === null }">
{{ p.has_creds === null ? (failed ? '校验失败' : '校验中') : p.online ? '已登录' : '未登录' }}
</span>
</div>
<div class="p-user" :class="{ none: p.has_creds === false, waiting: p.has_creds === null }">
{{ p.has_creds === null ? (failed ? '登录态校验失败' : '正在校验登录态…') : p.has_creds ? p.user : '未配置个人账号' }}
</div>
<div class="p-acts">
<el-button v-if="!p.online" size="small" :loading="busy === p.id" @click="login(p.id)">
{{ busy === p.id ? '登录中…' : '登录' }}
</el-button>
<el-button v-else size="small" plain type="danger" :disabled="!!busy" @click="logout(p.id)">
登出
</el-button>
<el-button size="small" text :disabled="p.has_creds === null" @click="openEdit(p)">配置账号</el-button>
</div>
</div>
</div>
<p class="p-hint">账号密码仅本机加密保存;登录后场景按<b>你的身份</b>执行。</p>
<p v-if="failed" class="pacc-note">
登录态校验未完成(平台无响应或网络异常)
<button type="button" class="pacc-retry" :disabled="loading" @click="refresh">重新校验</button>
</p>
<!-- 账号配置弹窗(必须 append-to-body:本组件位于 HomePage 的 .block 内,其
container-type: inline-size 隐含 contain: layout,会把 position:fixed 的遮罩
劫持为卡片包含块,导致弹窗"钉"在平台账号区域而不是全屏居中) -->
<!-- 账号配置弹窗(必须 append-to-body:避免被容器包含块劫持 fixed 定位) -->
<el-dialog v-model="dlg" :title="`配置 ${editLabel} 账号`" width="380px" align-center
append-to-body class="pacc-dlg">
<el-form label-width="72px" @submit.prevent>
@@ -46,9 +59,16 @@ import { reactive, ref, onMounted, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { store, log } from '../store'
import { loginPlatform, logoutPlatform, getPlatformStatus, savePlatformCreds } from '../api'
import PageHead from './PageHead.vue'
// 当前账号的平台状态(按账号隔离:各自 HR/OA 账号密码 + 各自会话)
const platStatus = ref([]) // [{id, label, online, has_creds, user}]
// 先用 meta 下发的平台清单即时铺出卡片(has_creds=null 表示"校验中"),
// 状态接口返回后再补齐登录态与已存账号,避免等待外网校验时整页空白。
const platStatus = ref(
store.platforms.map((p) => ({ id: p.id, label: p.label, online: !!p.online, has_creds: null, user: '' }))
)
const loading = ref(true) // 状态接口是否仍在进行
const failed = ref(false) // 状态接口失败(网络/平台无响应)
const dlg = ref(false) // 配置弹窗开关
const editing = ref(null) // 正在配置的平台对象
const form = reactive({ user: '', pass: '' })
@@ -59,15 +79,23 @@ const editLabel = computed(() => (editing.value ? editing.value.label : ''))
const hasCreds = computed(() => !!(editing.value && editing.value.has_creds))
async function refresh() {
loading.value = true
failed.value = false
try {
const r = await getPlatformStatus()
platStatus.value = (r && r.platforms) || []
const list = (r && r.platforms) || []
if (list.length) platStatus.value = list
// 同步全局平台在线态(首页统计/场景徽章按当前账号展示)
for (const ps of platStatus.value) {
const p = store.platforms.find((x) => x.id === ps.id)
if (p) p.online = ps.online
}
} catch (_) { /* 静默 */ }
} catch (e) {
failed.value = true
log('ERROR', `平台状态校验失败:${e.message || e}`)
} finally {
loading.value = false
}
}
onMounted(refresh)
@@ -134,33 +162,57 @@ async function logout(id) {
</script>
<style scoped>
.paccs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pacc { padding: 13px 14px; display: flex; flex-direction: column; gap: 8px; }
.p-top { display: flex; align-items: center; gap: 8px; }
.plat-page { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--page-pad); flex-shrink: 0; }
.paccs { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-2-5); }
.pacc {
padding: var(--space-3) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2);
background: linear-gradient(160deg, var(--subtle) 0%, var(--surface) 64%);
}
.pacc.on { background: linear-gradient(160deg, var(--good-soft) 0%, var(--surface) 64%); }
.p-top { display: flex; align-items: center; gap: var(--space-2); }
.p-dot {
flex: none; width: 8px; height: 8px; border-radius: 50%;
background: var(--sep-warm);
background: var(--t5);
}
.p-dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(var(--ok-rgb), .16); }
.p-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
.p-dot.on { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.p-name { font: 600 13px/18px var(--f-cn); color: var(--t1); }
.p-state {
margin-left: auto; font-size: 11px; color: var(--text-faint);
padding: 2px 9px; border-radius: 999px; background: var(--surface-2);
margin-left: auto; font: 500 10.5px/16px var(--f-cn); color: var(--t3);
padding: 1px var(--space-2); border-radius: var(--r-pill); background: var(--field);
}
.p-state.on { color: var(--ok); background: var(--ok-weak); }
.p-state.on { color: var(--good-ink); background: var(--good-soft); }
.p-user {
font-size: 11.5px; color: var(--text); font-variant-numeric: tabular-nums;
font: 400 11.5px/16px var(--f-num); color: var(--t2);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.p-user.none { color: var(--text-faint); }
.p-acts { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.p-user.none { color: var(--t4); }
.p-user.waiting { color: var(--t4); }
.p-acts { display: flex; align-items: center; gap: var(--space-1-5); margin-top: 2px; }
.p-acts .el-button + .el-button { margin-left: 0; }
.p-hint {
grid-column: 1 / -1;
margin: 2px 0 0; font-size: 11px; color: var(--text-faint); line-height: 1.7;
}
.p-hint b { color: var(--text-sub); }
/* 与首页常用场景共用同一容器查询断点:窄容器时同步降为 1 列,保证上下卡片始终对齐 */
@container (max-width: 380px) { .paccs { grid-template-columns: 1fr; } }
/* 校验中:避免空白页,给出明确的进度反馈 */
.pacc-loading {
grid-column: 1 / -1; min-height: 132px;
align-items: center; justify-content: center; text-align: center;
color: var(--t3); font-size: 12px;
}
.pacc-loading b { font: 600 13px/18px var(--f-cn); color: var(--t2); }
.pacc-loading span { font-size: 11.5px; color: var(--t4); }
.spin {
width: 14px; height: 14px; border-radius: 50%;
border: 2px solid var(--brand-track); border-top-color: var(--brand);
animation: pacc-spin .8s linear infinite;
}
@keyframes pacc-spin { to { transform: rotate(360deg); } }
/* 校验失败提示(可手动重试) */
.pacc-note {
display: flex; align-items: center; gap: var(--space-2);
margin: 0; font: 400 11.5px/16px var(--f-cn); color: var(--t4);
}
.pacc-retry {
border: 0; background: none; padding: 0; cursor: pointer;
font: 500 11.5px/16px var(--f-cn); color: var(--brand);
}
.pacc-retry:disabled { color: var(--t4); cursor: default; }
</style>
@@ -1,38 +1,21 @@
<template>
<div v-if="plugin" class="plugin-page">
<!-- Hero:场景身份 + 运行状态(执行入口收口在插件界面内,壳子不再提供一键执行) -->
<section class="hero card">
<div class="hero-main">
<span class="avatar" :style="{ background: avatarBg }">{{ plugin.name.slice(0, 1) }}</span>
<div class="hero-meta">
<h2 class="p-name">{{ plugin.name }}
<span class="ver-tag">v{{ plugin.version }}</span>
</h2>
<p class="p-desc">{{ plugin.description || '暂无描述' }}</p>
<div class="p-badges">
<span v-if="plugin.platform" class="badge" :class="platformOnline ? 'on' : 'off'">
<i class="bdot"></i>{{ platformLabel }} {{ platformOnline ? '已登录' : '未登录' }}
</span>
</div>
</div>
</div>
<div class="hero-actions">
<div v-if="store.running" class="run-chip">
<span class="ring">
<svg viewBox="0 0 36 36" width="22" height="22">
<circle class="ring-bg" cx="18" cy="18" r="15.5" fill="none" stroke-width="3.5" />
<circle class="ring-fg" cx="18" cy="18" r="15.5" fill="none" stroke-width="3.5"
stroke-linecap="round" :stroke-dasharray="ringDash" transform="rotate(-90 18 18)" />
</svg>
</span>
<span>执行中 {{ store.progress }}%</span>
</div>
<el-button v-if="rollbackVer" size="small" text type="warning" class="rollback-btn"
:disabled="store.running" @click="doRollback">回滚 v{{ rollbackVer }}</el-button>
<span class="hero-tip">在插件界面内配置并执行,运行日志与历史见下方</span>
</div>
</section>
<!-- 页头:场景身份 + 平台状态 + 运行中/回滚入口(与其它一级视图共用 PageHead) -->
<PageHead eyebrow="CONSOLE · 运行台">
<template #title>
<span class="p-name">{{ plugin.name }}<span class="ver-tag">v{{ plugin.version }}</span></span>
</template>
<template #sub>{{ plugin.description || '暂无描述' }}</template>
<template #actions>
<span v-if="plugin.platform" class="badge" :class="platformOnline ? 'on' : 'off'">
<i class="bdot"></i>{{ platformLabel }} {{ platformOnline ? '已登录' : '未登录' }}
</span>
<RunIndicator v-if="store.running" variant="chip" :progress="store.progress" />
<button v-if="rollbackVer" class="btn rollback-btn" :disabled="store.running" @click="doRollback">
回滚 v{{ rollbackVer }}
</button>
</template>
</PageHead>
<!-- 结果横幅 -->
<section v-if="store.lastResult" class="banner" :class="store.lastResult.ok ? 'ok' : 'err'">
@@ -52,7 +35,7 @@
<button v-for="t in tabs" :key="t.k" class="rt-tab" :class="{ on: tab === t.k }" @click="tab = t.k">
{{ t.label }}
<span v-if="t.k === 'log' && store.logs.length" class="rt-n">{{ store.logs.length }}</span>
<i v-if="t.k === 'log' && store.running" class="rt-live"></i>
<RunIndicator v-if="t.k === 'log' && store.running" variant="dot" />
</button>
</div>
</div>
@@ -73,7 +56,10 @@
<section v-show="tab === 'history'" class="history">
<div v-if="!replay" class="hist-view">
<div class="hist-head">
<span class="hist-title">本场景最近运行</span>
<div class="hist-titles">
<span class="sec-eyebrow">HISTORY</span>
<span class="hist-title">本场景最近运行</span>
</div>
<el-button size="small" text :icon="Refresh" :loading="loadingRuns" @click="loadRuns">刷新</el-button>
</div>
<div v-if="!runs.length" class="hist-empty">
@@ -111,7 +97,7 @@
</div>
<div v-else-if="!store.plugins.length" class="empty-note">
<b>当前账号暂无可用场景</b><br>请联系管理员在控制面进行授权,授权后点击右上角刷新
<b>当前账号暂无可用场景</b><br>请联系管理员在控制面进行授权,授权后点左栏「插件同步」刷新
</div>
<div v-else class="empty-note"><b>未选择场景</b></div>
</template>
@@ -123,14 +109,9 @@ import { ElMessage, ElMessageBox } from 'element-plus'
import { store } from '../store'
import { getRun, fetchRuns, fetchMeta, listRollbacks, rollbackPlugin } from '../api'
import LogPanel from './LogPanel.vue'
const GRADS = [
'var(--grad-sky)', 'var(--grad-peach)', 'var(--grad-mint)',
'var(--grad-lilac)', 'var(--grad-honey)', 'var(--grad-blush)',
]
const idx = computed(() => Math.max(0, store.plugins.findIndex((p) => p.id === store.selectedId)))
const avatarBg = computed(() => GRADS[idx.value % GRADS.length])
import RunIndicator from './RunIndicator.vue'
import PageHead from './PageHead.vue'
import { durText, fmtTime } from '../utils/format'
const plugin = computed(() => store.plugins.find((p) => p.id === store.selectedId) || null)
@@ -217,23 +198,6 @@ watch(
function triggerLabel(t) {
return ({ manual: '手动执行', schedule: '定时任务' })[t] || t || '手动执行'
}
function durText(s) {
const n = parseInt(s, 10) || 0
if (n < 60) return n + 's'
const m = Math.floor(n / 60)
return m + '分' + (n % 60 ? (n % 60) + 's' : '')
}
function fmtTime(ts) {
if (!ts) return '—'
const d = new Date(ts * 1000)
if (isNaN(d.getTime())) return '—'
const p = (n) => String(n).padStart(2, '0')
return `${d.getMonth() + 1}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`
}
// 执行进度环(SVG stroke-dasharray)
const RING_C = 2 * Math.PI * 15.5
const ringDash = computed(() => `${(store.progress / 100) * RING_C} ${RING_C}`)
const platformLabel = computed(() => {
const p = store.platforms.find((x) => x.id === plugin.value?.platform)
@@ -261,7 +225,7 @@ async function doRollback() {
try {
await ElMessageBox.confirm(
`将「${plugin.value.name}」回滚到 v${rollbackVer.value}(当前 v${plugin.value.version})。` +
'回滚后如需最新版,再次点击右上角同步即可。确定回滚?',
'回滚后如需最新版,再次点左栏「插件同步」即可。确定回滚?',
'插件回滚',
{ type: 'warning', confirmButtonText: '回滚', cancelButtonText: '取消' }
)
@@ -300,92 +264,53 @@ function closeBanner() {
.plugin-page {
display: flex;
flex-direction: column;
gap: 14px;
gap: var(--space-3);
padding: var(--page-pad);
flex: 1 1 auto; /* 填满中栏上下文区,运行台内部自己滚 */
min-height: 0;
}
.card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-sm);
}
/* ---------- Hero ---------- */
.hero {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 22px 24px;
background: var(--hero-grad);
}
.hero-main { display: flex; align-items: center; gap: 16px; min-width: 0; }
.avatar {
width: 54px; height: 54px; border-radius: 16px; flex-shrink: 0;
display: grid; place-items: center; color: var(--tile-fg);
font-size: 22px; font-weight: 700;
box-shadow: 0 10px 22px -10px rgba(var(--text-rgb), .35);
}
.hero-meta { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.p-name { margin: 0; font-size: 19px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 9px; }
/* ---------- 页头内的场景身份 ---------- */
.p-name { display: inline-flex; align-items: center; gap: var(--space-2); }
.ver-tag {
font-size: 10.5px; font-weight: 500; color: var(--text-faint);
background: var(--surface-2); border: 1px solid var(--border);
padding: 1px 8px; border-radius: 999px;
font: 500 10.5px/16px var(--f-num); color: var(--t3);
background: var(--field); border: 1px solid var(--line);
padding: 0 var(--space-2); border-radius: var(--r-pill);
}
.p-desc { margin: 0; font-size: 12.5px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 560px; }
.p-badges { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.badge {
display: inline-flex; align-items: center; gap: 6px;
font-size: 11px; color: var(--badge-warm-text);
background: var(--badge-warm-bg); border: 1px solid var(--badge-warm-border);
padding: 2px 10px; border-radius: 999px;
display: inline-flex; align-items: center; gap: var(--space-1-5);
font: 500 10.5px/16px var(--f-cn);
padding: 1px var(--space-2-5); border-radius: var(--r-pill);
}
.badge.on { color: var(--ok-text); background: var(--ok-weak); border-color: rgba(var(--ok-rgb), .3); }
.badge.off { color: var(--badge-off-text); }
.bdot { width: 6px; height: 6px; border-radius: 50%; background: var(--badge-dot); }
.badge.on .bdot { background: var(--ok); }
.hero-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; flex-shrink: 0; }
/* 运行状态 chip:仅展示进度,不可点击(执行入口在插件界面内) */
.run-chip {
display: inline-flex; align-items: center; gap: 8px;
padding: 6px 15px; border-radius: 999px;
background: var(--primary-grad-3); color: var(--on-primary);
font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums;
box-shadow: 0 8px 18px -10px rgba(var(--primary-rgb), .8);
}
/* 进度环用 CSS 上色(SVG 表现属性不支持 var(),故不写在 stroke="" 上) */
.ring-bg { stroke: rgba(var(--on-primary-rgb), .35); }
.ring-fg { stroke: var(--on-primary); }
.ring { display: inline-flex; }
.ring-fg { transition: stroke-dasharray .25s ease; }
.hero-tip { font-size: 10.5px; color: var(--text-faint); letter-spacing: .02em; }
.rollback-btn { margin-top: -3px; }
.badge.on { color: var(--good-ink); background: var(--good-soft); }
.badge.off { color: var(--t3); background: var(--field); }
.bdot { width: 6px; height: 6px; border-radius: 50%; background: var(--t5); }
.badge.on .bdot { background: var(--good); }
.rollback-btn { height: 28px; padding: 0 var(--space-3); font-size: 11.5px; }
/* ---------- 结果横幅 ---------- */
.banner {
display: flex; align-items: center; gap: 11px;
padding: 12px 16px; border-radius: 14px;
display: flex; align-items: center; gap: var(--space-3);
padding: var(--space-3) var(--space-4); border-radius: var(--r-card);
flex-shrink: 0;
animation: riseIn .3s var(--ease) both;
}
.banner.ok { background: var(--ok-weak); border: 1px solid rgba(var(--ok-rgb), .35); }
.banner.err { background: var(--err-weak); border: 1px solid rgba(var(--err-rgb), .4); }
.banner.ok { background: var(--good-soft); border: 1px solid var(--good-line); }
.banner.err { background: var(--danger-soft); border: 1px solid var(--danger-line); }
.b-ic {
width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--on-primary);
width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--on-primary);
}
.banner.ok .b-ic { background: var(--ok); }
.banner.err .b-ic { background: var(--err); }
.banner.ok .b-ic { background: var(--good); }
.banner.err .b-ic { background: var(--danger); }
.b-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.b-body b { font-size: 13px; color: var(--text); font-weight: 600; }
.b-body span { font-size: 12px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-body b { font-size: 12.5px; color: var(--t1); font-weight: 600; }
.b-body span { font-size: 11.5px; color: var(--t2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-close {
border: none; background: transparent; color: rgba(var(--text-rgb), .4);
border: none; background: transparent; color: var(--t4);
cursor: pointer; font-size: 12px; padding: 4px; border-radius: 50%;
}
.b-close:hover { color: var(--text); background: rgba(var(--on-primary-rgb), .6); }
.b-close:hover { color: var(--t1); background: var(--field); }
/* ---------- 运行台(标签页容器) ---------- */
.run-tabs {
@@ -393,80 +318,79 @@ function closeBanner() {
display: flex; flex-direction: column; overflow: hidden;
}
.rt-head {
display: flex; align-items: center; justify-content: space-between; gap: 10px;
padding: 0 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
display: flex; align-items: center; justify-content: space-between; gap: var(--space-2-5);
padding: 0 var(--space-3); border-bottom: 1px solid var(--line-soft); flex-shrink: 0;
}
.rt-tabs { display: flex; align-items: center; gap: 2px; }
.rt-tab {
display: inline-flex; align-items: center; gap: 6px;
display: inline-flex; align-items: center; gap: var(--space-1-5);
border: none; background: transparent; cursor: pointer; font-family: inherit;
padding: 11px 14px; font-size: 13px; color: var(--text-sub);
padding: var(--space-3) var(--space-3); font: 500 12.5px/18px var(--f-cn); color: var(--t3);
border-bottom: 2px solid transparent; margin-bottom: -1px;
transition: color .13s, border-color .13s;
transition: color var(--dur), border-color var(--dur);
}
.rt-tab:hover { color: var(--text); }
.rt-tab.on { color: var(--primary); font-weight: 600; border-bottom-color: var(--primary); }
.rt-tab:hover { color: var(--t1); }
.rt-tab.on { color: var(--brand-ink); font-weight: 600; border-bottom-color: var(--brand); }
.rt-n {
font-size: 10.5px; color: var(--text-faint); background: var(--surface-2);
border: 1px solid var(--border); border-radius: 999px; padding: 0 6px;
font: 500 10px/16px var(--f-num); color: var(--t3);
background: var(--field); border-radius: var(--r-pill); padding: 0 var(--space-2);
}
.rt-tab.on .rt-n { color: var(--primary); background: var(--primary-weak); border-color: var(--primary-line); }
.rt-live { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); animation: rtBlink 1s infinite; }
@keyframes rtBlink { 50% { opacity: .2; } }
.rt-tab.on .rt-n { color: var(--brand-ink); background: var(--brand-soft); }
.rt-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.rt-log { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
/* ---------- 专属界面插件 ---------- */
.ui-pane { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding: 14px 16px 16px; }
.ui-pane { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding: var(--space-3) var(--space-4) var(--space-4); }
.pui-frame {
display: block; width: 100%; flex: 1 1 auto; min-height: 340px;
border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
border: 1px solid var(--line); border-radius: var(--r-sub); background: var(--surface);
}
/* ---------- 历史运行 ---------- */
.history { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.hist-view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.hist-head {
display: flex; align-items: center; justify-content: space-between; gap: 10px;
padding: 10px 16px 6px; flex-shrink: 0;
display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2-5);
padding: var(--space-2-5) var(--space-4) var(--space-1-5); flex-shrink: 0;
}
.hist-title { font-size: 12.5px; font-weight: 600; color: var(--text-sub); }
.hist-titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hist-title { font: 600 12px/17px var(--f-cn); color: var(--t2); }
.hist-empty {
flex: 1 1 auto; display: grid; place-items: center;
color: var(--text-faint); font-size: 12.5px; padding: 30px 20px; text-align: center;
color: var(--t4); font-size: 12px; padding: var(--space-6) var(--space-5); text-align: center;
}
.hist-list { flex: 1 1 auto; min-height: 0; overflow: auto; list-style: none; margin: 4px 8px 10px; padding: 0; }
.hist-list { flex: 1 1 auto; min-height: 0; overflow: auto; list-style: none; margin: var(--space-1) var(--space-2) var(--space-2-5); padding: 0; }
.hist-item {
display: flex; align-items: center; gap: 11px;
padding: 10px 12px; border-radius: 12px; cursor: pointer;
transition: background .13s ease;
display: flex; align-items: center; gap: var(--space-3);
padding: var(--space-2) var(--space-3); border-radius: var(--r-row); cursor: pointer;
transition: background var(--dur);
}
.hist-item:hover { background: var(--surface-2); }
.hist-item:hover { background: var(--field); }
.hist-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.hist-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-weak); }
.hist-dot.err { background: var(--err); box-shadow: 0 0 0 3px var(--err-weak); }
.hist-dot.ok { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.hist-dot.err { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.hist-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hist-meta b { font-size: 13px; color: var(--text); font-weight: 600; }
.hist-time { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.hist-state { font-size: 12px; font-weight: 600; flex-shrink: 0; }
.hist-state.ok { color: var(--ok); }
.hist-state.err { color: var(--err); }
.hist-arrow { color: var(--text-faint); font-size: 13px; flex-shrink: 0; }
.hist-meta b { font: 600 12.5px/18px var(--f-cn); color: var(--t1); }
.hist-time { font: 400 10.5px/15px var(--f-num); color: var(--t4); }
.hist-state { font: 600 11.5px/16px var(--f-cn); flex-shrink: 0; }
.hist-state.ok { color: var(--good-ink); }
.hist-state.err { color: var(--danger-ink); }
.hist-arrow { color: var(--t5); font-size: 13px; flex-shrink: 0; }
.hist-replay { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.replay-head {
display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
padding: 8px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--line-soft); flex-shrink: 0;
}
.replay-tags { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; min-width: 0; }
.replay-tags { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }
.replay-tag {
font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums;
background: var(--surface-2); border: 1px solid var(--border);
padding: 1px 9px; border-radius: 999px;
font: 400 10.5px/16px var(--f-num); color: var(--t3);
background: var(--field); border: 1px solid var(--line);
padding: 0 var(--space-2); border-radius: var(--r-pill);
}
.replay-sum {
font-size: 11.5px; color: var(--text-sub); white-space: nowrap;
font-size: 11px; color: var(--t2); white-space: nowrap;
overflow: hidden; text-overflow: ellipsis; max-width: 340px;
}

Some files were not shown because too many files have changed in this diff Show More