feat: 新增银行卡检查插件及相关依赖与配置文件

This commit is contained in:
2026-10-29 14:21:30 +08:00
parent 0a32518060
commit c77a26cd99
494 changed files with 66923 additions and 2714 deletions
@@ -216,7 +216,7 @@ onMounted(() => {
</el-select>
</el-form-item>
<el-form-item label="关键字">
<el-input v-model="runQuery.q" placeholder="账号 / 设备 / 插件 / 名称 / 错误摘要" clearable style="width: 260px" @keyup.enter="searchRuns" />
<el-input v-model="runQuery.q" placeholder="账号 / 设备 / 插件 / 名称 / 备注 / 错误摘要" clearable style="width: 260px" @keyup.enter="searchRuns" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="searchRuns">查询</el-button>
@@ -254,6 +254,11 @@ onMounted(() => {
<el-table-column label="日志" width="80" align="center">
<template #default="{ row }">{{ row.log_count || 0 }} 条</template>
</el-table-column>
<el-table-column label="备注" min-width="140" show-overflow-tooltip>
<template #default="{ row }">
<span :class="row.note ? '' : 'text-gray-400'">{{ row.note || '-' }}</span>
</template>
</el-table-column>
<el-table-column label="摘要 / 错误" min-width="180" show-overflow-tooltip>
<template #default="{ row }">
<span :class="row.error ? 'text-red-600' : 'text-gray-400'">{{ row.error || row.summary || '-' }}</span>
@@ -0,0 +1,23 @@
-- 2026-10-29 插件备注(账号 × 插件 唯一)+ 运行备注快照
-- 背景:客户端插件页新增「运行备注」,壳子采集 → 回传中心机。
-- plugin_notes.note = 当前最新备注(可改可清空,账号×插件唯一)
-- run_logs.note = 每次执行时的备注快照(改备注不影响历史追溯)
-- 部署:在中心机 MySQL(库名见 server/.env 的 MYSQL_DATABASE)执行本文件,然后重启
-- systemctl restart 37du-controlplane-next.service
-- ⚠️ 重复执行时 ADD COLUMN 会报 "Duplicate column name",属正常(列已存在即跳过)。
ALTER TABLE `run_logs`
ADD COLUMN `note` varchar(500) NOT NULL DEFAULT '' COMMENT '本次运行备注快照(执行时插件页的备注)' AFTER `summary`;
CREATE TABLE IF NOT EXISTS `plugin_notes` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录自增ID',
`account` varchar(64) NOT NULL DEFAULT '' COMMENT '账号(工号)',
`plugin_id` varchar(64) NOT NULL DEFAULT '' COMMENT '插件ID',
`note` varchar(500) NOT NULL DEFAULT '' COMMENT '备注内容(账号对该插件的说明)',
`device_id` varchar(64) NOT NULL DEFAULT '' COMMENT '最后修改设备ID',
`created_at` datetime NOT NULL DEFAULT current_timestamp() COMMENT '创建时间',
`updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_account_plugin` (`account`,`plugin_id`),
KEY `idx_plugin_id` (`plugin_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='插件备注(账号×插件唯一)';
@@ -88,6 +88,7 @@ export * from './modules/center/controller/admin/account';
export * from './modules/center/controller/admin/auth';
export * from './modules/center/controller/admin/dict';
export * from './modules/center/controller/admin/menu';
export * from './modules/center/controller/admin/notes';
export * from './modules/center/controller/admin/ops';
export * from './modules/center/controller/admin/plugin';
export * from './modules/center/controller/admin/sys';
@@ -98,6 +99,7 @@ export * from './modules/center/controller/api/fileserver';
export * from './modules/center/controller/api/log';
export * from './modules/center/controller/api/me';
export * from './modules/center/controller/api/misc';
export * from './modules/center/controller/api/notes';
export * from './modules/center/controller/api/ping';
export * from './modules/center/controller/api/plugins';
export * from './modules/center/controller/api/shell';
@@ -0,0 +1,86 @@
import { CoolController, BaseController } from '@cool-midway/core';
import { Get, Headers, Inject, Provide, Query } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { PluginNoteEntity } from '../../entity/runtime';
import { CenterAuthService } from '../../service/auth';
import { pageBounds } from '../../comm/util';
/**
* 插件备注管理端(账号 × 插件 唯一):
* - GET /api/admin/plugin-notes 分页 + 账号/插件/关键字筛选,供管理台查看「谁给哪个插件写了什么备注」
* 注:每次执行时的备注快照看 run_logs.note(运行日志页),这里是当前最新值。
*/
@Provide()
@CoolController('/api/admin')
export class AdminPluginNotesController extends BaseController {
@Inject()
centerAuthService: CenterAuthService;
@InjectEntityModel(PluginNoteEntity)
noteRepo: Repository<PluginNoteEntity>;
/** GET /api/admin/plugin-notes */
@Get('/plugin-notes')
async notesList(
@Query('page') page: number = 1,
@Query('page_size') pageSize: number = 20,
@Query('account') account: string = '',
@Query('plugin') plugin: string = '',
@Query('q') q: string = '',
@Headers('X-Admin-Token') xAdminToken: string = '',
@Headers('X-API-Token') xApiToken: string = ''
) {
await this.centerAuthService.requirePerms(
['center:plugin:list', 'center:log:list'], xAdminToken, xApiToken
);
const [limit, offset] = pageBounds(page, pageSize);
const cond: string[] = [];
const args: any[] = [];
if ((account || '').trim()) { cond.push('n.account LIKE ?'); args.push(`%${account.trim()}%`); }
if ((plugin || '').trim()) { cond.push('n.plugin_id LIKE ?'); args.push(`%${plugin.trim()}%`); }
if ((q || '').trim()) {
cond.push('(n.note LIKE ? OR n.account LIKE ? OR n.plugin_id LIKE ? OR p.name LIKE ?)');
const kw = `%${q.trim()}%`;
args.push(kw, kw, kw, kw);
}
const where = cond.length ? ' WHERE ' + cond.join(' AND ') : '';
const m = this.noteRepo.manager;
const totalRow: any = (await m.query(
`SELECT COUNT(*) AS c FROM plugin_notes n LEFT JOIN plugins p ON p.id = n.plugin_id${where}`,
args
))[0];
const rows: any[] = await m.query(
`SELECT n.id, n.account, a.nickname, n.plugin_id, p.name AS plugin_name,
n.note, n.device_id, n.created_at, n.updated_at
FROM plugin_notes n
LEFT JOIN accounts a ON a.account = n.account
LEFT JOIN plugins p ON p.id = n.plugin_id
${where} ORDER BY n.updated_at DESC LIMIT ? OFFSET ?`,
[...args, limit, offset]
);
return {
items: rows.map((r: any) => ({
id: Number(r.id),
account: r.account || '',
nickname: r.nickname || '',
plugin_id: r.plugin_id || '',
plugin_name: r.plugin_name || '',
note: r.note || '',
device_id: r.device_id || '',
created_at: fmtStr(r.created_at),
updated_at: fmtStr(r.updated_at),
})),
total: Number(totalRow.c || 0),
};
}
}
function fmtStr(d: any): string {
if (!d) return '';
if (d instanceof Date) {
const p = (n: number) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
}
return String(d).replace('T', ' ').slice(0, 19);
}
@@ -0,0 +1,81 @@
import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Get, Headers, Inject, Post, Provide, Query } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { PluginNoteEntity } from '../../entity/runtime';
import { CenterAuthService, ApiError } from '../../service/auth';
/**
* 客户端插件备注(账号 × 插件 唯一):
* - GET /api/plugin-notes?account= 取该账号全部备注(客户端打开/切换插件时合并到本机缓存)
* - POST /api/plugin-notes 保存备注(note 为空 = 清空云端记录)
* 身份口径与 /api/plugins 一致:Bearer cloud_token 优先,兜底 account + X-API-Token。
* 备注是「当前最新值」,每次执行时的快照另存 run_logs.note(改备注不影响历史追溯)。
*/
@Provide()
@CoolController('/api')
export class ApiPluginNotesController extends BaseController {
@Inject()
centerAuthService: CenterAuthService;
@InjectEntityModel(PluginNoteEntity)
noteRepo: Repository<PluginNoteEntity>;
/** 解析账号身份;无有效身份抛 400 */
private async resolveAcct(
account: string,
xApiToken: string,
authorization: string
): Promise<string> {
let acct = await this.centerAuthService.cloudAccount(authorization);
if (!acct) {
this.centerAuthService.checkApiToken(xApiToken);
acct = (account || '').trim();
}
if (!acct) throw new ApiError(400, '缺少有效会话或 account');
return acct;
}
/** GET /api/plugin-notes?account= — 该账号全部备注 { plugin_id: {note, at} } */
@Get('/plugin-notes')
async notesOfAccount(
@Query('account') account: string = '',
@Headers('X-API-Token') xApiToken: string = '',
@Headers('Authorization') authorization: string = ''
) {
const acct = await this.resolveAcct(account, xApiToken, authorization);
const rows = await this.noteRepo.findBy({ account: acct });
const notes: Record<string, { note: string; at: number }> = {};
for (const r of rows) {
const note = String(r.note || '').trim();
if (!note) continue;
const t = r.updatedAt ? new Date(r.updatedAt).getTime() : 0;
notes[r.pluginId] = { note, at: t ? Math.floor(t / 1000) : 0 };
}
return { ok: true, account: acct, notes };
}
/** POST /api/plugin-notes — 保存/清空备注 */
@Post('/plugin-notes')
async save(
@Body() b: any,
@Headers('X-API-Token') xApiToken: string = '',
@Headers('Authorization') authorization: string = ''
) {
const acct = await this.resolveAcct(b?.account, xApiToken, authorization);
const pid = String(b?.plugin_id || '').trim();
if (!pid) throw new ApiError(400, 'plugin_id 不能为空');
const note = String(b?.note === undefined || b?.note === null ? '' : b.note).trim().slice(0, 500);
if (!note) {
await this.noteRepo.delete({ account: acct, pluginId: pid });
return { ok: true, plugin_id: pid, note: '' };
}
await this.noteRepo.manager.query(
`INSERT INTO plugin_notes(account, plugin_id, note, device_id, created_at, updated_at)
VALUES (?,?,?,?,NOW(),NOW())
ON DUPLICATE KEY UPDATE note = VALUES(note), device_id = VALUES(device_id), updated_at = NOW()`,
[acct, pid, note, String(b?.device_id || '')]
);
return { ok: true, plugin_id: pid, note };
}
}
@@ -194,6 +194,9 @@ export class RunLogEntity {
@Column({ name: 'summary', type: 'text', comment: '运行结论摘要' })
summary: string;
@Column({ name: 'note', type: 'varchar', length: 500, default: '', comment: '本次运行备注快照(执行时插件页的备注)' })
note: string;
@Column({ name: 'started', type: 'bigint', unsigned: true, default: 0, comment: '开始时间(epoch 秒)' })
started: number;
@@ -214,6 +217,35 @@ export class RunLogEntity {
uploadedAt: Date;
}
/**
* 插件备注(账号 × 插件 唯一):客户端插件页填写的长期备注,回传中心机留档。
* 与 run_logs.note 的区别:这里是「当前最新备注」(可改可清空),run_logs.note 是「那次执行时的快照」。
*/
@Entity('plugin_notes')
@Index('uk_account_plugin', ['account', 'pluginId'], { unique: true })
export class PluginNoteEntity {
@PrimaryGeneratedColumn({ name: 'id', type: 'bigint', unsigned: true, comment: '记录自增ID' })
id: number;
@Column({ name: 'account', type: 'varchar', length: 64, default: '', comment: '账号(工号)' })
account: string;
@Column({ name: 'plugin_id', type: 'varchar', length: 64, default: '', comment: '插件ID' })
pluginId: string;
@Column({ name: 'note', type: 'varchar', length: 500, default: '', comment: '备注内容(账号对该插件的说明)' })
note: string;
@Column({ name: 'device_id', type: 'varchar', length: 64, default: '', comment: '最后修改设备ID' })
deviceId: string;
@Column({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP', comment: '创建时间' })
createdAt: Date;
@Column({ name: 'updated_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP', onUpdate: 'CURRENT_TIMESTAMP', comment: '更新时间' })
updatedAt: Date;
}
/**
* 客户端壳日志元数据(内容存 logs/shell/<device_id>.log,增量追加)
*/
@@ -74,14 +74,15 @@ export class CenterLogService {
const logJson = JSON.stringify(logs);
await this.runRepo.manager.query(
`INSERT INTO run_logs(run_id, account, device_id, plugin_id, name, version, trigger_by,
schedule_id, status, ok, error, summary, started, finished, duration_sec, log_count,
schedule_id, status, ok, error, summary, note, started, finished, duration_sec, log_count,
logs, uploaded_at)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
ON DUPLICATE KEY UPDATE
account = VALUES(account), device_id = VALUES(device_id), plugin_id = VALUES(plugin_id),
name = VALUES(name), version = VALUES(version), trigger_by = VALUES(trigger_by),
schedule_id = VALUES(schedule_id), status = VALUES(status), ok = VALUES(ok),
error = VALUES(error), summary = VALUES(summary), started = VALUES(started),
error = VALUES(error), summary = VALUES(summary), note = VALUES(note),
started = VALUES(started),
finished = VALUES(finished), duration_sec = VALUES(duration_sec),
log_count = VALUES(log_count), logs = VALUES(logs), uploaded_at = NOW()`,
[
@@ -97,6 +98,7 @@ export class CenterLogService {
Number(!!payload?.ok),
String(payload?.error || ''),
String(payload?.summary || ''),
String(payload?.note || '').slice(0, 500),
Number(payload?.started || 0),
Number(payload?.finished || 0),
Number(payload?.duration_sec || 0),
@@ -126,9 +128,9 @@ export class CenterLogService {
else if (vals.length > 1) { cond.push(`status IN (${vals.map(() => '?').join(',')})`); args.push(...vals); }
}
if ((opts?.q || '').trim()) {
cond.push('(name LIKE ? OR plugin_id LIKE ? OR account LIKE ? OR device_id LIKE ? OR error LIKE ? OR summary LIKE ?)');
cond.push('(name LIKE ? OR plugin_id LIKE ? OR account LIKE ? OR device_id LIKE ? OR error LIKE ? OR summary LIKE ? OR note LIKE ?)');
const kw = `%${opts.q.trim()}%`;
args.push(kw, kw, kw, kw, kw, kw);
args.push(kw, kw, kw, kw, kw, kw, kw);
}
if (Number(opts?.days || 0) > 0) { cond.push('uploaded_at >= DATE_SUB(NOW(), INTERVAL ? DAY)'); args.push(Number(opts.days)); }
const where = cond.length ? ' WHERE ' + cond.join(' AND ') : '';
@@ -136,7 +138,7 @@ export class CenterLogService {
const totalRow: any = (await m.query(`SELECT COUNT(*) AS c FROM run_logs${where}`, args))[0];
const rows: any[] = await m.query(
`SELECT id, run_id, account, device_id, plugin_id, name, version,
trigger_by AS \`trigger\`, schedule_id, status, ok, error, summary,
trigger_by AS \`trigger\`, schedule_id, status, ok, error, summary, note,
started, finished, duration_sec, log_count, uploaded_at
FROM run_logs${where} ORDER BY id DESC LIMIT ? OFFSET ?`,
[...args, pageSize, offset]
@@ -158,7 +160,7 @@ export class CenterLogService {
if (!rid) return null;
const rows: any[] = await this.runRepo.manager.query(
`SELECT id, run_id, account, device_id, plugin_id, name, version,
trigger_by AS \`trigger\`, schedule_id, status, ok, error, summary,
trigger_by AS \`trigger\`, schedule_id, status, ok, error, summary, note,
started, finished, duration_sec, log_count, logs, uploaded_at
FROM run_logs WHERE run_id = ?`,
[rid]
@@ -171,7 +173,7 @@ export class CenterLogService {
id: Number(r.id), run_id: r.run_id, account: r.account || '', device_id: r.device_id || '',
plugin_id: r.plugin_id || '', name: r.name || '', version: r.version || '',
trigger: r.trigger || '', schedule_id: r.schedule_id || '', status: r.status || '',
ok: Number(r.ok || 0), error: r.error || '', summary: r.summary || '',
ok: Number(r.ok || 0), error: r.error || '', summary: r.summary || '', note: r.note || '',
started: Number(r.started || 0), finished: Number(r.finished || 0),
duration_sec: Number(r.duration_sec || 0), log_count: Number(r.log_count || 0),
logs: Array.isArray(logsArr) ? logsArr : [],
+46
View File
@@ -1,5 +1,51 @@
# 更新日志
## 1.9.3(2026-10-29)
### 改进
- 运行台页头场景描述优化:自动剥掉「XQxxxx 场景名:」前缀(与标题重复),副标题最多两行、
悬停可看全文;页头操作区新增「详情」按钮,弹窗按「;」拆段展示完整说明
## 1.9.2(2026-10-29)
### 改进
- 运行备注改为「一行摘要 + 查看 / 编辑」:备注可能较长,列表只显示单行预览(悬停看全文),
查看与编辑统一在弹窗里完成(弹窗内可滚动、字数上限 500、支持一键清空),保存即回传中心机
- 插件界面工具条(v3 规范)整组靠右,从左到右为:已保存时间 → 方案下拉 → 存为方案 → 删除,左侧留空
## 1.9.1(2026-10-29)
### 新增(插件运行备注,全插件统一)
- 运行台插件页新增「运行备注」输入栏:账号 × 插件唯一,本机保存并回传中心机,
切换插件分别记忆、可一键清空(输入即防抖保存,显示「已保存 时间」)
- 备注随每次执行写入运行记录:历史运行回看可见当时的备注快照;
定时任务 / 流程编排触发时自动带上该账号对该插件的长期备注
- 备注快照同步回传中心机(运行日志新增备注列,可按备注关键字搜索)
## 1.9.0(2026-10-28)
### 界面(六个一级视图统一新版样式)
- 中栏统一为「白底面板 + 描边卡 + 浅灰卡头」:总览 / 场景库 / 计划 / 流程 / 平台账号 / 运行台 视觉一致,
不再出现"面板里再套一层白卡"的嵌套
- **总览**改为今日运行简报:KPI 四宫格(可用场景 / 定时任务 / 平台在线 / 近 7 日成功率)、
运行状态卡 + 近 7 日迷你柱状图、最近运行场景表格(含状态胶囊,点击直达运行台)
- **场景库**改为竖向卡片:语义图标 + 分类徽章 + 两行描述 + 平台登录态 + 最近运行时间,
分类 chips 带数量、底部分页;卡片图标按场景名/分类关键词匹配(考勤→人形、对账→图表、采集→数据库…)
- **计划**:页头显示启用/暂停/下次执行/平均用时;本周运行分布改为按真实运行记录聚合;
计划列表改为表格(时间 / 类型 / 频率 / 场景 / 上次结果 / 下次执行 / 状态 / 操作),新增「暂停全部」
- **流程 / 平台账号**:列表卡片化,页头显示数量与登录统计
- **运行台**:tab 栏融入页面(不再是一张独立卡片);运行日志改为暗色控制台(级别配色、等宽三列、行悬停高亮);
历史运行改为表格行(触发源 / 开始时间 / 耗时 / 执行摘要 / 状态胶囊),回看页头部同步统一
### 修复
- 计划页编辑「流程类」计划时改了名字不生效(保存时只提交了定时配置,名称未提交)
- 计划表格长 cron 表达式会顶出频率列、场景列被挤压到与频率列重叠(列宽改为按比例分配)
## 1.8.1(2026-10-27)
### 修复
+155
View File
@@ -0,0 +1,155 @@
// 插件备注(账号 × 插件 唯一):本机即时可用 + 回传中心机(跨设备一致)
// 存储:%LOCALAPPDATA%\37duAutomation\plugin_notes.json
// { "<account>": { "<plugin_id>": { "note": "...", "at": 1730000000 } } }
// 回传:POST /api/plugin-notes(账号+插件 upsert,失败只记 WARN 不阻断用户操作)
// 拉取:GET /api/plugin-notes?account=(启动/切换插件时合并;本机有、云端无的顺手补报)
"use strict";
const fs = require("fs");
const path = require("path");
const config = require("./config");
const cp = require("./cpclient");
const { makeLogger } = require("./logger");
const logger = makeLogger("notes");
const NOTES_PATH = path.join(config.APP_DATA, "plugin_notes.json");
// 设备 ID:与 log-upload / app 同源(%LOCALAPPDATA%\37duAutomation\device_id),本模块自包含避免拉入应用依赖树
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 id = require("crypto").randomUUID();
fs.mkdirSync(config.APP_DATA, { recursive: true });
fs.writeFileSync(f, id, "utf-8");
return id;
} catch (e) {
return "";
}
}
// 限长:备注是"人看的说明",不是数据字段;超长只在本地截断,避免把 AI 表/日志撑爆
const MAX_NOTE_LEN = 500;
function clip(v) {
const s = String(v === undefined || v === null ? "" : v).replace(/\r\n/g, "\n").trim();
return s.length > MAX_NOTE_LEN ? s.slice(0, MAX_NOTE_LEN) : s;
}
function readAll() {
try {
const v = JSON.parse(fs.readFileSync(NOTES_PATH, "utf-8"));
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
} catch (e) {
return {}; // 文件不存在/损坏:按空处理(备注是辅助信息,永不阻断主流程)
}
}
function writeAll(obj) {
try {
fs.mkdirSync(config.APP_DATA, { recursive: true });
const tmp = NOTES_PATH + ".tmp";
fs.writeFileSync(tmp, JSON.stringify(obj), "utf-8");
fs.renameSync(tmp, NOTES_PATH);
return true;
} catch (e) {
logger.warning(`插件备注写入失败:${e.message}`);
return false;
}
}
/** 当前账号某个插件的备注(无则空串) */
function get(account, pluginId) {
const acct = String(account || "");
const pid = String(pluginId || "");
if (!acct || !pid) return "";
const row = (readAll()[acct] || {})[pid];
return row && typeof row === "object" ? String(row.note || "") : "";
}
/** 当前账号全部备注:{ plugin_id: { note, at } } */
function all(account) {
const acct = String(account || "");
if (!acct) return {};
const mine = readAll()[acct];
return mine && typeof mine === "object" ? mine : {};
}
/** 保存备注(空串 = 清空);仅落本机,不发起网络请求 */
function save(account, pluginId, note) {
const acct = String(account || "");
const pid = String(pluginId || "");
if (!acct || !pid) return "";
const text = clip(note);
const data = readAll();
const mine = data[acct] && typeof data[acct] === "object" ? data[acct] : {};
if (text) mine[pid] = { note: text, at: Math.floor(Date.now() / 1000) };
else delete mine[pid];
data[acct] = mine;
writeAll(data);
return text;
}
/** 上报中心机(异步、失败静默);note 为空表示清空云端记录 */
async function push(account, pluginId, note) {
if (!config.CONTROLPLANE_URL) return false;
const acct = String(account || "").trim();
const pid = String(pluginId || "").trim();
if (!acct || !pid) return false;
try {
await cp.request("POST", "/api/plugin-notes", {
headers: cp.machineHeaders(),
json: { account: acct, plugin_id: pid, note: clip(note), device_id: deviceId() },
timeout: 10,
});
return true;
} catch (e) {
logger.warning(`插件备注回传失败(本机已保存,下次同步补报):${e.message}`);
return false;
}
}
/** 从中心机拉取该账号全部备注并合并到本机(云端为准;本机独有的顺手补报) */
async function pull(account) {
if (!config.CONTROLPLANE_URL) return false;
const acct = String(account || "").trim();
if (!acct) return false;
let cloud = null;
try {
const r = await cp.request("GET", "/api/plugin-notes", {
headers: cp.machineHeaders(), params: { account: acct }, timeout: 10,
});
cloud = r && r.notes && typeof r.notes === "object" ? r.notes : {};
} catch (e) {
logger.warning(`插件备注拉取失败(继续用本机缓存):${e.message}`);
return false;
}
const data = readAll();
const mine = data[acct] && typeof data[acct] === "object" ? data[acct] : {};
const toPush = [];
for (const [pid, row] of Object.entries(cloud)) {
const note = clip(row && row.note);
if (note) mine[pid] = { note, at: Number((row && row.at) || 0) || Math.floor(Date.now() / 1000) };
else delete mine[pid];
}
for (const [pid, row] of Object.entries(mine)) {
if (!cloud[pid] && row && row.note) toPush.push([pid, row.note]);
}
data[acct] = mine;
writeAll(data);
// 本机独有(例如离线期间改的)补报中心机,逐条失败不影响其余
for (const [pid, note] of toPush) {
try { await cp.request("POST", "/api/plugin-notes", {
headers: cp.machineHeaders(),
json: { account: acct, plugin_id: pid, note, device_id: deviceId() },
timeout: 10,
}); } catch (_) { /* 忽略:下次 pull 再补 */ }
}
return true;
}
module.exports = { NOTES_PATH, MAX_NOTE_LEN, get, all, save, push, pull };
@@ -168,6 +168,7 @@ function brief(rec) {
finished: rec.finished || 0,
duration_sec: rec.duration_sec || 0,
summary: rec.summary || "",
note: rec.note || "",
};
}
+10
View File
@@ -14,6 +14,7 @@ const scheduler = require("./scheduler");
const queue = require("./queue");
const licensing = require("./licensing");
const runHistory = require("./run-history");
const notes = require("./notes");
const platformAuth = require("./platform-auth");
const platformCreds = require("./platform-creds");
const { HUB } = require("./hub");
@@ -214,6 +215,7 @@ function finishRun(runId, plugin, status, error, summary) {
started: run.started || 0,
finished,
duration_sec: durationSec,
note: run.note || "",
logs: Array.isArray(run.logs) ? run.logs : [],
});
// 日志集中回传:整次运行日志上送中心机(离线自动暂存补报;失败不阻断运行收尾)
@@ -233,6 +235,7 @@ function finishRun(runId, plugin, status, error, summary) {
started: run.started || 0,
finished,
duration_sec: durationSec,
note: run.note || "",
logs: Array.isArray(run.logs) ? run.logs : [],
});
} catch (e) {
@@ -251,6 +254,7 @@ function finishRun(runId, plugin, status, error, summary) {
error: ok ? "" : error || "",
duration_sec: durationSec,
summary: summary || "",
note: run.note || "",
});
// 排队任务的结束提醒(用户手动取消队列里的任务不算:应用内已有明确反馈,不再二次打扰)
if (_QUEUED_RUNS.delete(runId)) {
@@ -316,6 +320,11 @@ function submitRun(account, plugin, fields, opts) {
const enqueuedAt = Date.now() / 1000;
const name = plugin.name || plugin.id;
const version = plugin.version || "0";
// 运行备注:调用方显式传入优先;定时任务/流程编排未传时取该账号对该插件的长期备注
let note = String(o.note === undefined || o.note === null ? "" : o.note).trim();
if (!note) {
try { note = notes.get(account, plugin.id); } catch (_) { note = ""; }
}
state.registerRun(runId, {
status: "queued", // 排队中:尚未占用执行槽,started 为空
account,
@@ -323,6 +332,7 @@ function submitRun(account, plugin, fields, opts) {
name,
version,
trigger,
note,
schedule_id: o.schedule_id || "",
flow_run_id: o.flow_run_id || "",
node_id: o.node_id || "",
+29 -1
View File
@@ -19,6 +19,7 @@ const runner = require("./runner");
const queue = require("./queue");
const runHistory = require("./run-history");
const lastFields = require("./last-fields");
const notes = require("./notes");
const pluginConfigs = require("./plugin-configs");
const scheduler = require("./scheduler");
const tasks = require("./tasks");
@@ -605,8 +606,17 @@ async function route(req, res, url) {
}
// 记住本次参数(不含 password 字段),供执行台「恢复上次参数」
lastFields.remember(account, plugin.id, body.fields || {}, plugin.fields);
// 运行备注:随执行一起落运行记录并回传中心机(用户可能刚改过备注,这里顺手落本机+上报)
const noteText = String(body && body.note !== undefined && body.note !== null ? body.note : "").trim();
if (noteText) {
notes.save(account, plugin.id, noteText);
try { await notes.push(account, plugin.id, noteText); } catch (_) { /* 回传失败不阻断执行 */ }
}
// 提交即入队:返回排队位置,前端据此提示"已加入队列,第 N 位"
const r = runner.submitRun(account, plugin, body.fields || {}, { trigger: "manual" });
const r = runner.submitRun(account, plugin, body.fields || {}, {
trigger: "manual",
note: noteText || notes.get(account, plugin.id),
});
return sendJson(res, 202, {
run_id: r.run_id,
queue_position: r.queue_position,
@@ -841,6 +851,24 @@ async function route(req, res, url) {
return sendJson(res, 200, { fields: rec.fields, at: rec.at });
}
// ---------- 插件备注(账号 × 插件 唯一;本机缓存 + 回传中心机)----------
if (p === "/api/plugin-notes" && method === "GET") {
const account = session.requireLogin(cookies);
// 拉取中心机(跨设备一致):失败静默,直接用本机缓存
try { await notes.pull(account); } catch (_) { /* 离线继续用本机 */ }
return sendJson(res, 200, { ok: true, notes: notes.all(account) });
}
if (p === "/api/plugin-notes" && method === "POST") {
const account = session.requireLogin(cookies);
const body = await readJsonBody(req);
const pluginId = String((body && body.plugin_id) || "").trim();
if (!pluginId) throw Object.assign(new Error("缺少 plugin_id"), { status: 400 });
const note = notes.save(account, pluginId, body && body.note);
// 回传失败不阻断用户操作(本机已保存,下次拉取/执行时补报)
try { await notes.push(account, pluginId, note); } catch (_) { /* 离线:仅本机 */ }
return sendJson(res, 200, { ok: true, plugin_id: pluginId, note });
}
// ---------- 场景配置方案(多配置,SQLite 存储)----------
if (p === "/api/plugin-configs" && method === "GET") {
const account = session.requireLogin(cookies);
+3 -2
View File
@@ -944,10 +944,11 @@ async function logout() {
.body { flex: 1; min-height: 0; display: flex; gap: var(--space-2); padding: var(--space-2); container-type: inline-size; }
/* 中栏:上下文区。与左右轨同级的面板容器(浅底 + 细边 + 圆角),
内部卡片仍是白底,既成完整 3 栏、又不出现"卡片套卡片"的双边框 */
/* 中栏:白底面板,内部由各视图自己排布(页头 + 内容),不再在里面套第二层面板 */
.main {
flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0;
background: var(--subtle); border: 1px solid var(--line); border-radius: var(--r-card);
padding: var(--space-2-5); overflow: hidden;
background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
padding: 0; overflow: hidden;
}
/* 中栏滚动区:视图自决定内边距 */
.page-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
@@ -137,6 +137,19 @@ export async function fetchRuns(limit = 30) {
return j(`/api/runs?limit=${limit}`)
}
// ===== 插件备注(账号 × 插件 唯一;本机缓存 + 回传中心机)=====
export async function fetchPluginNotes() {
return j('/api/plugin-notes')
}
export async function savePluginNote(pluginId, note) {
return j('/api/plugin-notes', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ plugin_id: pluginId, note }),
})
}
// ===== 流程编排(DAG) =====
export async function listFlows() {
return j('/api/flows')
@@ -1,25 +1,30 @@
<template>
<div class="flow-page">
<PageHead eyebrow="FLOW · 编排" title="流程编排" sub="画布上把场景/等待/通知/确认连起来,按依赖执行;支持 cron 定时触发">
<PageHead eyebrow="流程" title="流程编排" :sub="headSub">
<template #actions>
<el-button type="primary" :icon="Plus" @click="createAndEdit">新建流程</el-button>
</template>
</PageHead>
<!-- 人工确认:流程挂起时,这里给继续/终止 -->
<div v-if="pendingConfirm" class="confirm-bar">
<i class="cb-dot"></i>
<span class="cb-txt">
流程「{{ pendingConfirm.name }}」等待确认:{{ pendingConfirm.waiting_confirm.message }}
</span>
<el-button size="small" type="primary" @click="resolveConfirm(pendingConfirm, true)">继续</el-button>
<el-button size="small" @click="resolveConfirm(pendingConfirm, false)">终止</el-button>
</div>
<div class="page-body">
<!-- 人工确认:流程挂起时,这里给继续/终止 -->
<div v-if="pendingConfirm" class="confirm-bar">
<i class="cb-dot"></i>
<span class="cb-txt">
流程「{{ pendingConfirm.name }}」等待确认:{{ pendingConfirm.waiting_confirm.message }}
</span>
<el-button size="small" type="primary" @click="resolveConfirm(pendingConfirm, true)">继续</el-button>
<el-button size="small" @click="resolveConfirm(pendingConfirm, false)">终止</el-button>
</div>
<el-empty v-if="!list.length" description="还没有流程:点「新建流程」在画布上把节点连起来" />
<div v-else class="flow-list card">
<div v-for="f in list" :key="f.id" class="flow-row">
<section class="flow-card">
<div class="fc-head">
<h2>流程列表</h2>
<span class="fc-stat">{{ list.length }} 个流程 · {{ scheduledCount }} 个已排期</span>
</div>
<div v-if="!list.length" class="fc-empty">还没有流程:点右上角「新建流程」,在画布上把节点连起来</div>
<div v-else class="flow-list">
<div v-for="f in list" :key="f.id" class="flow-row">
<div class="fr-main" @click="openEditor(f)">
<div class="fr-title">
<b>{{ f.name }}</b>
@@ -50,6 +55,8 @@
<el-button link type="danger" @click="onDelete(f)">删除</el-button>
</div>
</div>
</div>
</section>
</div>
<!-- ==================== 可视化编排(弹窗) ====================
@@ -327,6 +334,15 @@ const DOW_NAME = { 0: '周日', 1: '周一', 2: '周二', 3: '周三', 4: '周
const list = ref([])
const runs = ref([])
// 页头/列表头统计:已排期 = 配了启用中的 cron
const scheduledCount = computed(() => list.value.filter((f) => f.schedule && f.schedule.enabled).length)
const headSub = computed(() => {
const n = list.value.length
const s = scheduledCount.value
return n
? `${n} 个流程 · ${s} 个已排期 · 画布上把场景/等待/通知/确认连起来,按依赖执行`
: '画布上把场景/等待/通知/确认连起来,按依赖执行;支持 cron 定时触发'
})
const editorOpen = ref(false)
const saving = ref(false)
const runningId = ref('')
@@ -1039,7 +1055,13 @@ function nodeVisual(n) {
</script>
<style scoped>
.flow-page { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--page-pad); flex-shrink: 0; }
.flow-page { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 0; }
/* 页头固定,下面这层自己滚 */
.page-body {
flex: 1; min-height: 0; overflow-y: auto;
display: flex; flex-direction: column; gap: var(--space-3);
padding: 20px 24px 18px;
}
/* 待确认提示条 */
.confirm-bar {
@@ -1052,8 +1074,27 @@ function nodeVisual(n) {
.cb-txt { flex: 1; min-width: 0; font-size: 12px; color: var(--warn-ink); }
/* ---------- 列表 ---------- */
/* 列表卡:与总览/计划页同款(描边卡 + 浅灰头 + 分隔线行) */
.flow-card {
display: flex; flex-direction: column;
background: var(--surface); border: 1px solid var(--line);
border-radius: var(--r-sub); overflow: hidden;
}
.fc-head {
flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
gap: var(--space-3); padding: 12px 16px;
border-bottom: 1px solid var(--line); background: var(--subtle);
}
.fc-head h2 { margin: 0; font: 600 13.5px/20px var(--f-cn); color: var(--t1); }
.fc-stat { font: 400 11.5px/16px var(--f-num); color: var(--t4); }
.fc-empty { padding: 48px 20px; text-align: center; font: 400 12px/20px var(--f-cn); color: var(--t4); }
.flow-list { display: flex; flex-direction: column; }
.flow-row { display: flex; align-items: flex-start; gap: var(--space-4); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line-soft); }
.flow-row {
display: flex; align-items: flex-start; gap: var(--space-4);
padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
transition: background var(--dur);
}
.flow-row:hover { background: var(--subtle); }
.flow-row:last-child { border-bottom: 0; }
.fr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-2); cursor: pointer; }
.fr-title { display: flex; align-items: center; gap: var(--space-2); }
@@ -1,318 +1,285 @@
<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>
<header class="ov-head">
<div class="ov-titles">
<span class="ov-crumb">总览</span>
<h1 class="ov-title">今日运行简报</h1>
<p class="ov-sub">{{ dateLine }}</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 class="ov-actions">
<button class="btn-ghost" @click="goScenes">全部场景</button>
<el-button type="primary" :icon="Refresh" :loading="syncing" :disabled="store.running" @click="syncNow">
同步场景
</el-button>
</div>
</header>
<div class="ov-body">
<!-- 指标四宫格 -->
<section class="kpis">
<div class="kpi">
<span class="k-label">可用场景</span>
<b class="k-num">{{ store.plugins.length }}<em>个</em></b>
<span class="k-sub">按账号授权自动同步</span>
</div>
</div>
</section>
<!-- 指标四宫格 -->
<section class="kpis">
<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 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 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 card k-plain">
<span class="k-label">LAST RUN</span>
<b class="k-num last" :class="lastCancelled ? '' : (lastOk === null ? '' : (lastOk ? 'good' : 'bad'))">
{{ lastCancelled ? '已取消' : (lastOk === null ? '—' : (lastOk ? '成功' : '失败')) }}
</b>
<span class="k-sub">{{ lastRunTime || '暂无运行' }}</span>
</div>
</section>
<!-- 运行中卡 -->
<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>
<!-- 排队提示:一次性点了多个场景,或多个定时任务落在同一时刻 -->
<section v-if="store.queue.waiting" class="card queue-card">
<div class="qc-top">
<span class="qc-title">排队等待 {{ store.queue.waiting }} 个</span>
<span class="qc-sub">{{ store.queue.running ? `当前执行:${store.queue.running.name}` : '即将开始第一个任务' }}</span>
</div>
<div class="qc-list">
<span v-for="it in store.queue.items.slice(0, 3)" :key="it.run_id" class="qc-chip">
<i>{{ it.position }}</i>{{ it.name }}<em v-if="it.trigger === 'schedule'">定时</em>
</span>
<span v-if="store.queue.waiting > 3" class="qc-more">+{{ store.queue.waiting - 3 }}</span>
</div>
</section>
<div class="grid-2">
<!-- 近 7 日运行:趋势 + 聚合口径(成功率等不再单独画环) -->
<section class="card trend-card">
<div class="card-top">
<div class="card-titles">
<span class="sec-eyebrow">TREND</span>
<b class="card-title">近 7 日运行</b>
<span class="card-sub">成功 / 失败分布与成功率</span>
</div>
<div class="legend">
<span><i class="lg-dot ok"></i>成功</span>
<span><i class="lg-dot bad"></i>失败</span>
</div>
<div class="kpi">
<span class="k-label">定时任务</span>
<b class="k-num">{{ scheduleCount }}<em>个</em></b>
<span class="k-sub">{{ scheduleSub }}</span>
</div>
<div class="kpi">
<span class="k-label">平台在线</span>
<b class="k-num">{{ onlineCount }}<em>/{{ store.platforms.length }}</em></b>
<span class="k-sub" :class="{ warn: !!offlineText }">{{ offlineText || '全部平台已登录' }}</span>
</div>
<div class="kpi kpi-spark">
<span class="k-label">近 7 日成功率</span>
<b class="k-num">{{ ratePct }}<em>%</em></b>
<span class="k-sub">共 {{ trendTotal }} 次运行 · {{ trendFail }} 次失败</span>
<svg class="spark" viewBox="0 0 100 50" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path d="M0 40 Q 20 20, 40 30 T 80 10 T 100 20" />
</svg>
</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="trend-foot">
<span class="rate-pill" :class="rateTone">{{ rateLabel }}</span>
<span>7 日合计 <b>{{ trendTotal }}</b> 次</span>
<span>成功率 <b>{{ ratePct }}%</b></span>
<span>成功 <b class="good">{{ trendOk }}</b></span>
<span>失败 <b :class="{ bad: trendFail > 0 }">{{ trendFail }}</b></span>
<span>日均 <b>{{ avgPerDay }}</b> 次</span>
<span>峰值 <b>{{ trendPeak }}</b> 次</span>
</div>
</template>
<div v-else class="empty-note">暂无运行记录</div>
</section>
<!-- 今日概览:只讲"今天",不与左侧 7 日聚合重复 -->
<section class="card today-card">
<div class="card-top">
<div class="card-titles">
<span class="sec-eyebrow">TODAY</span>
<b class="card-title">今日概览</b>
<span class="card-sub">当前账号 · 今天</span>
<!-- 运行状态 + 近 7 日迷你柱状图 -->
<section class="status-row">
<div class="run-card" :class="{ live: store.running }">
<div class="rc-top">
<div class="rc-id">
<template v-if="store.running">
<i class="pulse"></i>
<span class="rc-tag">运行中</span>
</template>
<i v-else class="idle-dot"></i>
<b class="rc-name">{{ store.running ? runningName : '当前空闲' }}</b>
</div>
<div class="rc-pct" :class="{ muted: !store.running }">
<template v-if="store.running">{{ store.progress }}<em>%</em></template>
<template v-else>—</template>
</div>
</div>
<div v-if="store.running" class="rc-track">
<div class="rc-fill" :style="{ width: Math.max(2, Math.min(100, store.progress || 0)) + '%' }"></div>
</div>
<div v-else class="rc-hint">从左侧场景或「场景库」启动任务;定时计划到点会自动执行</div>
<div class="rc-foot">
<span class="rc-tail">{{ store.running ? (runningTail || '执行中…') : lastRunSummary }}</span>
<span v-if="store.queue.waiting" class="rc-wait">排队 {{ store.queue.waiting }} 个</span>
</div>
</div>
<div class="ts-list">
<div class="ts-row"><span class="ts-k">今日运行</span><b class="ts-v">{{ todayTotal }} 次</b></div>
<div class="ts-row">
<span class="ts-k">今日成功 / 失败</span>
<b class="ts-v"><em class="ok">{{ todayOk }}</em> / <em :class="todayFail ? 'bad' : ''">{{ todayFail }}</em></b>
<div class="chart-card">
<div class="cc-head">
<span>近 7 日运行</span>
<em>{{ trendTotal }} 次</em>
</div>
<div class="ts-row"><span class="ts-k">平均单次耗时</span><b class="ts-v">{{ avgDurText }}</b></div>
<div class="ts-row"><span class="ts-k">最近一次</span><b class="ts-v" :class="lastRunTone">{{ lastRunText }}</b></div>
<div class="bars">
<i v-for="(d, i) in trendDays" :key="i" :class="{ today: i === trendDays.length - 1 }"
:style="{ height: barHeight(d) }" :title="`${d.label} · ${d.ok + d.fail} 次`"></i>
</div>
<div class="bars-axis">
<span v-for="(d, i) in trendDays" :key="i" :class="{ today: i === trendDays.length - 1 }">{{ d.w }}</span>
</div>
</div>
</section>
<!-- 最近运行场景表格 -->
<section class="table-card">
<div class="tc-head">
<h2>最近运行场景</h2>
<button class="link" @click="goScenes">全部 {{ store.plugins.length }} 个场景 →</button>
</div>
<div class="tc-body">
<table v-if="rows.length" class="tc-table">
<thead>
<tr>
<th class="c-idx">#</th>
<th class="c-name">场景名称</th>
<th>平台 / 分类</th>
<th>最近运行</th>
<th class="c-st">状态</th>
</tr>
</thead>
<tbody>
<tr v-for="(r, i) in rows" :key="r.id" @click="openPlugin(r.id)">
<td class="c-idx">{{ String(i + 1).padStart(2, '0') }}</td>
<td class="c-name">{{ r.name }}</td>
<td class="c-meta">{{ r.meta || '—' }}</td>
<td class="c-time">{{ r.time }}</td>
<td class="c-st"><span class="badge" :class="r.tone"><i></i>{{ r.toneText }}</span></td>
</tr>
</tbody>
</table>
<div v-else class="tc-empty">
当前账号暂无可用场景,点右上角「同步场景」按账号权限拉取;仍为空请联系管理员授权
</div>
</div>
<div class="tc-foot">
<span>显示 {{ rows.length }} / {{ store.plugins.length }} 项 · 按最近运行排序</span>
</div>
</section>
</div>
<!-- 常用场景 -->
<section class="block">
<div class="block-head">
<div class="block-titles">
<span class="sec-eyebrow">SCENES</span>
<b class="sec-name">常用场景</b>
</div>
<button v-if="store.plugins.length > 4" class="link-btn" @click="goScenes">
全部场景 {{ store.plugins.length }} <i class="arr">→</i>
</button>
</div>
<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, 4)" :key="p.id" :plugin="p" compact @open="openPlugin" />
</div>
<div v-else class="card empty">
<div>
<b>当前账号暂无可用场景</b>
<span>请联系管理员在控制面进行授权,授权后在左侧「场景库」点击插件同步</span>
</div>
<button class="btn primary" @click="goScenes">去场景库</button>
</div>
</section>
<!-- 最近运行已移到右轨(常驻、只留 5 条);总览页不再重复一份完整列表 -->
</div>
</template>
<script setup>
import { computed, onMounted, ref } from 'vue'
import { Refresh } from '@element-plus/icons-vue'
import { store } from '../store'
import { listSchedules, fetchRuns } from '../api'
import { durText, fmtTime } from '../utils/format'
import SceneCard from './SceneCard.vue'
import RunIndicator from './RunIndicator.vue'
import { fmtDayTime } from '../utils/format'
import { usePluginSync } from '../composables/usePluginSync'
const { syncing, syncNow } = usePluginSync()
// ---------- 基础指标 ----------
const onlineCount = computed(() => (store.platforms || []).filter((p) => p.online).length)
// 未登录平台(KPI 副文案),只列名字,避免一行放不下
const offlineText = computed(() => {
const off = (store.platforms || []).filter((p) => !p.online)
if (!off.length) return ''
const names = off.slice(0, 2).map((p) => p.label || p.id).join('、')
return `${names}${off.length > 2 ? ` 等 ${off.length} 个` : ''} 待登录`
})
const WEEK = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
const pad2 = (n) => String(n).padStart(2, '0')
const now0 = new Date()
const dateLine = computed(() => {
const t = `${now0.getFullYear()}.${pad2(now0.getMonth() + 1)}.${pad2(now0.getDate())} ${WEEK[now0.getDay()]}`
const parts = [t, `${scheduleCount.value} 个计划待执行`]
parts.push(`${onlineCount.value}/${store.platforms.length || 0} 个平台在线`)
return parts.join(' · ')
})
// ---------- 定时任务 ----------
const schedules = ref([])
const scheduleCount = ref(0)
onMounted(async () => {
try {
const r = await listSchedules()
scheduleCount.value = (r.schedules || []).length
} catch (_) { scheduleCount.value = 0 }
schedules.value = r.schedules || []
scheduleCount.value = schedules.value.length
} catch (_) {
schedules.value = []
scheduleCount.value = 0
}
})
const scheduleSub = computed(() => {
const list = schedules.value.filter((s) => s.enabled && s.next_run_at)
if (!list.length) return scheduleCount.value ? '暂无启用中的计划' : '尚未创建定时计划'
const next = list.map((s) => String(s.next_run_at)).sort()[0]
const d = new Date(next.replace(' ', 'T'))
if (isNaN(d.getTime())) return '按计划自动执行'
const hm = `${pad2(d.getHours())}:${pad2(d.getMinutes())}`
const today0 = new Date()
today0.setHours(0, 0, 0, 0)
const diff = Math.floor((d.getTime() - today0.getTime()) / 86400000)
const day = diff === 0 ? '今天' : diff === 1 ? '明天' : `周${'日一二三四五六'[d.getDay()]}`
return `下次执行 ${day} ${hm}`
})
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))
// 取消(用户主动取消/排队超时/退出取消)不是失败:KPI 单列,不污染"失败"口径
const lastCancelled = computed(() => !!(store.lastResult && store.lastResult.cancelled))
const lastRunTime = computed(() => {
const r = store.recents[0]
return r ? r.time : ''
})
const runningName = computed(() => {
// 以运行事件登记的 plugin_id 为准(定时任务触发时 selectedId 未必是正在跑的场景)
const pid = store._runPlugins[store.currentRun] || store.selectedId
const p = (store.plugins || []).find((x) => x.id === pid)
return p ? p.name : (pid || '')
})
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 只有时分秒,重启即空、无法按日归桶 */
// ---------- 最近 7 日运行(趋势 + 成功率 + 表格)----------
const trendDays = ref([])
const runsRaw = ref([]) // 近 7 日运行(已剔除取消/中断),供"今日/耗时/最近一次"复用
const runsRaw = ref([]) // 近 7 日运行(已剔除取消/中断)
onMounted(async () => {
const now = new Date()
const base = 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 d = new Date(base)
d.setDate(d.getDate() - i)
buckets.push({
key: `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`,
label: i === 0 ? '今天' : `${d.getMonth() + 1}-${d.getDate()}`,
w: WEEK[d.getDay()].slice(-1),
ok: 0,
fail: 0,
})
}
const keyOf = (sec) => {
const d = new Date(sec * 1000)
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`
}
const keyOf = (sec) => { const d = new Date(sec * 1000); return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}` }
try {
const r = await fetchRuns(200)
// 取消/中断不是失败:趋势、耗时、最近一次都不算它们
// 取消/中断不算失败:趋势、成功率、最近运行都不计入
runsRaw.value = (r.runs || []).filter((x) => x.started && x.status !== 'cancelled' && x.status !== 'interrupted')
for (const run of runsRaw.value) {
const b = buckets.find((x) => x.key === keyOf(run.started))
if (b) { run.ok ? b.ok++ : b.fail++ }
}
} catch (_) { /* 拉取失败保持空态 */ }
} 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$/, ''))
const rateTone = computed(() => (ratePct.value >= 95 ? 'good' : ratePct.value >= 80 ? 'warn' : 'bad'))
const rateLabel = computed(() => ({ good: '运行稳定', warn: '偶有失败', bad: '需重点关注' }[rateTone.value]))
// 右侧"今日/耗时/最近一次":口径与趋势一致(已剔除取消/中断)
const todayBucket = computed(() => trendDays.value[trendDays.value.length - 1] || null)
const todayTotal = computed(() => (todayBucket.value ? todayBucket.value.ok + todayBucket.value.fail : 0))
const todayOk = computed(() => (todayBucket.value ? todayBucket.value.ok : 0))
const todayFail = computed(() => (todayBucket.value ? todayBucket.value.fail : 0))
const avgDurText = computed(() => {
const list = runsRaw.value.filter((x) => (x.duration_sec || 0) > 0)
if (!list.length) return '—'
const avg = list.reduce((s, x) => s + x.duration_sec, 0) / list.length
return durText(Math.round(avg))
})
const lastRun = computed(() => runsRaw.value[0] || null)
const lastRunText = computed(() => {
const r = lastRun.value
if (!r) return '暂无'
return `${r.ok ? '成功' : '失败'} · ${fmtTime(r.started)}`
})
const lastRunTone = computed(() => (!lastRun.value ? '' : (lastRun.value.ok ? 'ok' : 'bad')))
/* 脉冲曲线:成功=平滑曲线+面积,失败=虚线;用单调三次插值(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 barHeight(d) {
const max = Math.max(1, trendPeak.value)
return `${Math.max(8, Math.round(((d.ok + d.fail) / max) * 100))}%`
}
function openPlugin(id, runId) {
// ---------- 运行中 / 空闲 ----------
const runningName = computed(() => {
const pid = store._runPlugins[store.currentRun] || store.selectedId
const p = (store.plugins || []).find((x) => x.id === pid)
return p ? p.name : (pid || '正在执行')
})
const runningTail = computed(() => {
const list = store.logs || []
const l = list[list.length - 1]
return l ? String(l.msg ?? '').slice(0, 90) : ''
})
const lastRunSummary = computed(() => {
const r = store.recents[0]
if (!r) return '本次会话暂无运行记录'
const st = r.ok ? '成功' : (r.cancelled ? '已取消' : '失败')
return `上次 ${r.name} · ${r.time} ${st}`
})
// ---------- 最近运行场景表格 ----------
const rows = computed(() => {
const latest = new Map() // plugin_id → 最近一次运行(列表已按时间倒序)
for (const r of runsRaw.value) {
if (r.plugin_id && !latest.has(r.plugin_id)) latest.set(r.plugin_id, r)
}
return store.plugins
.map((p) => {
const r = latest.get(p.id)
const plat = (store.platforms || []).find((x) => x.id === p.platform)
const meta = [plat?.label || p.platform || '', p.category || ''].filter(Boolean).join(' · ')
let tone = 'idle'
let toneText = '未运行'
if (r) {
tone = r.ok ? 'ok' : 'bad'
toneText = r.ok ? '成功' : '失败'
} else if (p.platform && plat && !plat.online) {
tone = 'warn'
toneText = '待登录'
}
return {
id: p.id,
name: p.name,
meta,
time: r ? fmtDayTime(r.started) : '尚未运行',
started: r ? (r.started || 0) : 0,
tone,
toneText,
}
})
.sort((a, b) => b.started - a.started || a.name.localeCompare(b.name, 'zh'))
.slice(0, 8) // 只列最近 8 条,完整清单去场景库
})
function openPlugin(id) {
store.selectedId = id
store.view = 'run'
// 最近运行点击:直达该次运行的回看(运行台消费后清空);普通场景点击清掉残留意图
store.pendingReplay = runId ? { pluginId: id, runId } : null
store.pendingReplay = null
}
function goScenes() {
store.view = 'scenes'
@@ -320,170 +287,178 @@ function goScenes() {
</script>
<style scoped>
.home { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--page-pad); flex-shrink: 0; container-type: inline-size; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
.home { flex: 1; min-height: 0; display: flex; flex-direction: column; container-type: inline-size; }
/* ---------- 通用小标 / 卡头 ---------- */
.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);
/* ---------- 页头 ---------- */
.ov-head {
flex-shrink: 0; display: flex; align-items: flex-end; justify-content: space-between;
gap: var(--space-4); padding: 20px 24px;
border-bottom: 1px solid var(--line);
}
.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; }
.ov-titles { display: flex; flex-direction: column; min-width: 0; }
.ov-crumb { font: 400 12px/16px var(--f-cn); color: var(--t4); margin-bottom: 6px; }
.ov-title { margin: 0 0 4px; font: 700 24px/32px var(--f-cn); color: var(--t1); letter-spacing: -.3px; }
.ov-sub { margin: 0; font: 400 12px/17px var(--f-cn); color: var(--t3); }
.ov-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.btn-ghost {
height: 32px; padding: 0 var(--space-3);
border: 1px solid var(--line-btn); border-radius: var(--r-row);
background: var(--surface); color: var(--t2); cursor: pointer;
font: 500 12.5px/1 var(--f-cn);
transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.btn-ghost:hover { background: var(--field); color: var(--t1); }
.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 11px/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);
/* ---------- 内容滚动区 ---------- */
.ov-body {
flex: 1; min-height: 0; overflow-y: auto;
display: flex; flex-direction: column; gap: var(--space-5);
padding: 20px 24px 18px;
}
.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; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; flex-shrink: 0; }
.kpi {
position: relative; overflow: hidden;
display: flex; flex-direction: column; gap: 4px;
padding: 16px; background: var(--subtle);
border: 1px solid var(--line); border-radius: var(--r-sub);
}
.k-label { font: 400 12px/16px var(--f-cn); color: var(--t3); }
.k-num { display: flex; align-items: baseline; gap: 3px; font: 700 24px/1.2 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 11px/15px var(--f-cn); color: var(--t4); }
.k-sub { font: 400 10.5px/15px var(--f-cn); color: var(--t4); }
.k-sub.warn { color: var(--warn); }
.kpi-spark .spark {
position: absolute; right: -8px; bottom: -8px;
width: 98px; height: 50px; color: var(--good); opacity: .14; pointer-events: none;
}
/* ---------- 运行中卡 ---------- */
.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; }
/* ---------- 排队提示卡 ---------- */
.queue-card { padding: var(--space-2-5) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); border-color: var(--line-soft); }
.qc-top { display: flex; align-items: baseline; gap: var(--space-2); }
.qc-title { font-size: 12px; font-weight: 600; color: var(--t1); }
.qc-sub { flex: 1; min-width: 0; font-size: 10.5px; color: var(--t4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qc-list { display: flex; flex-wrap: wrap; gap: var(--space-1-5); }
.qc-chip {
display: inline-flex; align-items: center; gap: var(--space-1-5);
max-width: 220px; height: 22px; padding: 0 var(--space-2); border-radius: var(--r-pill);
background: var(--field); font-size: 10.5px; color: var(--t2);
/* ---------- 运行状态 + 迷你柱状 ---------- */
.status-row { display: grid; grid-template-columns: 3fr 1fr; gap: 14px; flex-shrink: 0; }
.run-card {
display: flex; flex-direction: column; justify-content: center; gap: 10px;
padding: 18px 20px; background: var(--subtle);
border: 1px solid var(--line); border-radius: var(--r-sub);
transition: background var(--dur), border-color var(--dur);
}
.run-card.live {
background: linear-gradient(160deg, var(--brand-soft) 0%, var(--surface) 72%);
border-color: var(--brand-track);
}
.rc-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.rc-id { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); flex-shrink: 0; animation: rcPulse 1.3s ease-in-out infinite; }
.idle-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--t5); flex-shrink: 0; }
@keyframes rcPulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .3; transform: scale(.7); } }
.rc-tag {
flex-shrink: 0; font: 500 10.5px/18px var(--f-cn); color: var(--t2);
background: var(--surface); border: 1px solid var(--line-btn); border-radius: 4px; padding: 0 var(--space-1-5);
}
.rc-name {
font: 600 13.5px/20px var(--f-cn); color: var(--t1);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.qc-chip i {
width: 14px; height: 14px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
border-radius: 50%; background: var(--surface); font-family: var(--f-num); font-size: 9px; font-style: normal; color: var(--t3);
.rc-pct { flex-shrink: 0; font: 700 15px/1 var(--f-num); color: var(--brand); font-variant-numeric: tabular-nums; }
.rc-pct em { font-style: normal; font-size: 11px; font-weight: 500; }
.rc-pct.muted { color: var(--t5); }
.rc-track { height: 10px; border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.rc-fill {
height: 100%; border-radius: var(--r-pill);
background: linear-gradient(90deg, var(--brand) 0%, var(--violet) 100%);
transition: width .45s var(--ease);
}
.qc-chip em { font-style: normal; font-size: 9px; color: var(--brand-ink); flex-shrink: 0; }
.qc-more { font-size: 10.5px; color: var(--t4); align-self: center; }
.rc-hint { font: 400 11.5px/17px var(--f-cn); color: var(--t4); }
.rc-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); font: 400 11px/16px var(--f-cn); color: var(--t4); }
.rc-tail { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc-wait { flex-shrink: 0; color: var(--brand-ink); }
/* ---------- 趋势 + 今日概览(两张卡并排) ---------- */
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--space-3); align-items: stretch; }
.trend-card,
.today-card { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.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-1); }
.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 10px/13px var(--f-num); color: var(--t4); white-space: nowrap; }
/* 聚合口径统一放图表下方一行(含成功率),不再单独画环 */
.trend-foot {
display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2);
margin-top: var(--space-2); font: 400 10.5px/16px var(--f-cn); color: var(--t4);
.chart-card {
display: flex; flex-direction: column; justify-content: space-between;
padding: 14px 16px; background: var(--subtle);
border: 1px solid var(--line); border-radius: var(--r-sub);
}
.trend-foot > span + span::before { content: "·"; margin-right: var(--space-2); color: var(--t5); }
.trend-foot b { font-family: var(--f-num); font-weight: 600; color: var(--t2); }
.trend-foot b.good { color: var(--good-ink); }
.trend-foot b.bad { color: var(--danger-ink); }
.cc-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.cc-head span { font: 400 12px/16px var(--f-cn); color: var(--t3); }
.cc-head em { font-style: normal; font: 400 10.5px/15px var(--f-num); color: var(--t4); }
.bars { display: flex; align-items: flex-end; gap: 5px; height: 46px; margin-top: 10px; }
.bars i { flex: 1; border-radius: 3px; background: var(--line); transition: height .3s var(--ease); }
.bars i.today { background: var(--brand); }
.bars-axis { display: flex; gap: 5px; margin-top: 6px; }
.bars-axis span { flex: 1; text-align: center; font: 400 9.5px/12px var(--f-cn); color: var(--t4); }
.bars-axis span.today { color: var(--brand); font-weight: 700; }
/* 今日概览:四行事实,撑满与左侧趋势卡同高 */
.ts-list { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.ts-row {
display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
padding: var(--space-3) 0; border-bottom: 1px dashed var(--line-soft);
/* ---------- 最近运行场景表格 ---------- */
.table-card {
flex: 1; min-height: 240px; display: flex; flex-direction: column;
background: var(--surface); border: 1px solid var(--line);
border-radius: var(--r-sub); overflow: hidden;
}
.ts-row:first-child { padding-top: var(--space-2); }
.ts-row:last-child { padding-bottom: 0; border-bottom: 0; }
.ts-k { font: 400 11px/16px var(--f-cn); color: var(--t4); white-space: nowrap; }
.ts-v { font: 600 13px/18px var(--f-num); color: var(--t1); white-space: nowrap; }
.ts-v em { font-style: normal; }
.ts-v em.ok { color: var(--good-ink); }
.ts-v em.bad { color: var(--danger-ink); }
.ts-v.ok { color: var(--good-ink); }
.ts-v.bad { color: var(--danger-ink); }
.rate-pill {
flex-shrink: 0; padding: 0 var(--space-2); border-radius: var(--r-pill);
font: 500 10px/18px var(--f-cn);
.tc-head {
flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
gap: var(--space-3); padding: 12px 16px;
border-bottom: 1px solid var(--line); background: var(--subtle);
}
.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); }
/* ---------- 分节 ---------- */
.block { display: flex; flex-direction: column; gap: var(--space-3); 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 {
.tc-head h2 { margin: 0; font: 600 13.5px/20px var(--f-cn); color: var(--t1); }
.link {
border: 0; background: transparent; padding: 0; cursor: pointer;
font: 500 11px/16px var(--f-cn); color: var(--brand);
font: 500 12px/16px var(--f-cn); color: var(--brand);
}
.link:hover { color: var(--brand-ink); }
.tc-body { flex: 1; min-height: 0; overflow-y: auto; }
.tc-table { width: 100%; border-collapse: collapse; }
.tc-table th {
position: sticky; top: 0; z-index: 1;
padding: 10px 16px; text-align: center;
font: 500 11px/16px var(--f-cn); color: var(--t3);
background: var(--surface); border-bottom: 1px solid var(--line);
}
.tc-table th.c-idx { width: 48px; }
.tc-table td {
padding: 10px 16px; border-bottom: 1px solid var(--line-soft);
text-align: center;
font: 400 12px/18px var(--f-cn); color: var(--t2);
}
.tc-table tbody tr { cursor: pointer; transition: background var(--dur); }
.tc-table tbody tr:hover { background: var(--field); }
.tc-table tbody tr:last-child td { border-bottom: 0; }
.tc-table td.c-idx { font: 400 11px/18px var(--f-num); color: var(--t4); }
/* 场景名称长短不一:这一列(含表头)左对齐,其余列居中 */
.tc-table th.c-name, .tc-table td.c-name { text-align: left; }
.tc-table td.c-name {
font-weight: 600; color: var(--t1);
max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tc-table td.c-meta, .tc-table td.c-time { color: var(--t3); white-space: nowrap; }
.badge {
display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px;
border: 1px solid transparent; border-radius: 6px;
font: 500 11px/1 var(--f-cn);
}
.badge i { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.badge.ok { color: var(--good-ink); background: var(--good-soft); border-color: var(--good-line); }
.badge.ok i { background: var(--good); }
.badge.bad { color: var(--danger-ink); background: var(--danger-soft); border-color: var(--danger-line); }
.badge.bad i { background: var(--danger); }
.badge.warn { color: var(--warn-ink); background: var(--warn-soft); border-color: var(--warn-line); }
.badge.warn i { background: var(--warn); }
.badge.idle { color: var(--t3); background: var(--field); border-color: var(--line); }
.badge.idle i { background: var(--t5); }
.tc-empty { padding: 40px 20px; text-align: center; font: 400 12px/20px var(--f-cn); color: var(--t4); }
.tc-foot {
flex-shrink: 0; display: flex; align-items: center;
gap: var(--space-3); padding: 10px 16px;
border-top: 1px solid var(--line);
font: 400 11.5px/16px var(--f-cn); color: var(--t4);
}
.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; }
/* 容器查询:按首页自身宽度(而非窗口宽度)收敛,右轨显隐不再影响断点 */
@container (max-width: 860px) {
.kpis { grid-template-columns: repeat(2, 1fr); }
.grid-2 { grid-template-columns: 1fr; }
.hero { align-items: flex-start; }
/* 窄中栏:指标两列、状态区上下堆叠 */
@container (max-width: 900px) {
.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.status-row { grid-template-columns: 1fr; }
}
@container (max-width: 560px) {
.ov-head { flex-direction: column; align-items: flex-start; }
.kpis { grid-template-columns: 1fr; }
}
</style>
@@ -21,9 +21,15 @@
</div>
<div ref="box" class="log-box">
<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-if="isStatic">
<b>该次运行没有日志记录</b><span>可能是执行过快,或插件没有输出日志</span>
</template>
<template v-else-if="store.logs.length">
<b>当前级别无日志</b><span>切换到「全部」可以看完整输出</span>
</template>
<template v-else>
<b>暂无日志</b><span>点击「一键执行」后,输出会实时滚动到这里</span>
</template>
</div>
<div v-for="(l, i) in visibleLogs" :key="i" class="log-line">
<span class="t">{{ l.time || l.t || '' }}</span>
@@ -101,25 +107,50 @@ async function copy() {
position: relative;
}
/* ---------- 头部:标题 + 级别过滤 + 工具 ---------- */
.log-head {
display: flex;
align-items: center;
justify-content: space-between;
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);
gap: var(--space-3);
padding: 0 0 10px;
border-bottom: 1px solid var(--line-soft);
flex-shrink: 0;
}
.log-title {
display: flex;
align-items: center;
gap: var(--space-2);
font-size: 13.5px;
font-weight: 600;
font: 600 13px/18px var(--f-cn);
color: var(--t1);
white-space: nowrap;
}
.status {
width: 8px;
height: 8px;
border-radius: 50%;
flex-shrink: 0;
}
.status.on {
background: var(--good);
box-shadow: 0 0 0 3px var(--good-soft);
}
.status.off {
background: var(--t5);
}
.count {
padding: 3px 8px;
border-radius: var(--r-pill);
background: var(--field);
font: 500 11px/1 var(--f-num);
color: var(--t4);
}
.log-tools {
display: flex;
align-items: center;
@@ -130,32 +161,58 @@ async function copy() {
margin-left: 0;
}
.status {
width: 9px;
height: 9px;
border-radius: 50%;
flex-shrink: 0;
}
.status.on {
background: var(--good);
box-shadow: 0 0 0 3px var(--good-soft);
}
.status.off {
background: var(--idle-bar);
}
.count {
font-size: 11px;
color: var(--t3);
font-weight: 500;
}
.log-empty {
color: var(--t3);
padding: var(--space-3);
/* ---------- 日志区:暗色控制台(壳子 --con-* 系列) ---------- */
.log-box {
flex: 1 1 auto;
min-height: 0;
overflow: auto;
margin: 12px 0 0;
padding: 10px 0;
background: var(--con);
border: 1px solid var(--con-line);
border-radius: var(--r-sub);
font-family: var(--f-mono);
font-size: 12px;
font-size: 11.5px;
line-height: 1.85;
color: var(--con-t1);
}
.log-box::-webkit-scrollbar-thumb { background: var(--con-bg2); border-radius: 3px; }
.log-line {
display: grid;
grid-template-columns: 64px 56px minmax(0, 1fr);
gap: 8px;
padding: 1px 14px;
border-left: 2px solid transparent;
}
.log-line:hover {
background: var(--con-bg2);
border-left-color: var(--brand);
}
.log-line .t { color: var(--con-t2); user-select: none; }
.log-line .lv { font-weight: 600; }
.log-line .s-INFO { color: var(--con-info); }
.log-line .s-WARN { color: var(--con-warn); }
.log-line .s-ERROR { color: var(--con-err); }
/* 空态:暗底居中,一句标题 + 一句说明 */
.log-empty {
height: 100%;
min-height: 88px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 4px;
padding: var(--space-4);
text-align: center;
font: 400 12px/18px var(--f-cn);
color: var(--con-t2);
}
.log-empty b { color: var(--con-t1); font-weight: 500; }
.log-empty span { font-size: 11.5px; }
</style>
@@ -1,38 +1,47 @@
<template>
<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 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>
<PageHead eyebrow="平台账号" title="登录状态" :sub="headSub">
<template #actions>
<button class="btn-ghost" :disabled="loading" @click="refresh">
{{ loading ? '校验中…' : '重新校验' }}
</button>
</template>
</PageHead>
<div class="page-body">
<div class="paccs">
<div v-if="!platStatus.length" class="pacc pacc-loading">
<span class="spin"></span>
<b>{{ loading ? '正在读取平台清单…' : '暂无可用平台' }}</b>
<span>{{ loading ? '首次启动需校验平台登录态,请稍候' : '请稍后重试或联系管理员' }}</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 v-for="p in platStatus" :key="p.id" class="pacc" :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 v-if="failed" class="pacc-note">
登录态校验未完成(平台无响应或网络异常)
<button type="button" class="pacc-retry" :disabled="loading" @click="refresh">重新校验</button>
</p>
</div>
<p v-if="failed" class="pacc-note">
登录态校验未完成(平台无响应或网络异常)
<button type="button" class="pacc-retry" :disabled="loading" @click="refresh">重新校验</button>
</p>
<!-- 账号配置弹窗(必须 append-to-body:避免被容器包含块劫持 fixed 定位) -->
<el-dialog v-model="dlg" :title="`配置 ${editLabel} 账号`" width="380px" align-center
@@ -77,6 +86,12 @@ const saving = ref(false)
const editLabel = computed(() => (editing.value ? editing.value.label : ''))
const hasCreds = computed(() => !!(editing.value && editing.value.has_creds))
// 页头副标题:在线数 + 一句凭证说明(与其它页统一的"统计 + 说明"格式)
const headSub = computed(() => {
const total = platStatus.value.length
const on = platStatus.value.filter((p) => p.online).length
return `${on} / ${total} 个平台已登录 · 账号密码仅保存在本机;登录后场景按当前账号身份执行`
})
async function refresh() {
loading.value = true
@@ -162,13 +177,30 @@ async function logout(id) {
</script>
<style scoped>
.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); }
.plat-page { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page-body {
flex: 1; min-height: 0; overflow-y: auto;
padding: 20px 24px 18px;
display: flex; flex-direction: column; gap: var(--space-3);
}
.btn-ghost {
height: 32px; padding: 0 var(--space-3);
border: 1px solid var(--line-btn); border-radius: var(--r-row);
background: var(--surface); color: var(--t2); cursor: pointer;
font: 500 12.5px/1 var(--f-cn);
transition: background var(--dur), color var(--dur);
}
.btn-ghost:hover:not(:disabled) { background: var(--field); color: var(--t1); }
.btn-ghost:disabled { opacity: .5; cursor: not-allowed; }
.paccs { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.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%);
padding: 16px; display: flex; flex-direction: column; gap: 10px;
background: var(--subtle); border: 1px solid var(--line); border-radius: var(--r-sub);
}
.pacc.on {
background: linear-gradient(160deg, var(--good-soft) 0%, var(--surface) 72%);
border-color: var(--good-line);
}
.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%;
@@ -192,7 +224,7 @@ async function logout(id) {
/* 校验中:避免空白页,给出明确的进度反馈 */
.pacc-loading {
grid-column: 1 / -1; min-height: 132px;
grid-column: 1 / -1; min-height: 150px;
align-items: center; justify-content: center; text-align: center;
color: var(--t3); font-size: 12px;
}
@@ -5,7 +5,10 @@
<template #title>
<span class="p-name">{{ plugin.name }}<span class="ver-tag">v{{ plugin.version }}</span></span>
</template>
<template #sub>{{ plugin.description || '暂无描述' }}</template>
<!-- 副标题:剥掉「XQxxxx 名称:」前缀,最多两行;悬停看全文,完整描述走「详情」弹窗 -->
<template #sub>
<span class="p-sub" :title="fullDesc">{{ shortDesc }}</span>
</template>
<template #actions>
<span v-if="plugin.platform" class="badge" :class="platformOnline ? 'on' : 'off'">
<i class="bdot"></i>{{ platformLabel }} {{ platformOnline ? '已登录' : '未登录' }}
@@ -17,9 +20,11 @@
<button v-if="rollbackVer" class="btn rollback-btn" :disabled="store.running" @click="doRollback">
回滚 v{{ rollbackVer }}
</button>
<button v-if="hasDesc" class="btn desc-btn" @click="descDialog = true">详情</button>
</template>
</PageHead>
<div class="page-body">
<!-- 结果横幅 -->
<section v-if="store.lastResult" class="banner"
:class="store.lastResult.ok ? 'ok' : (store.lastResult.cancelled ? 'mid' : 'err')">
@@ -31,9 +36,56 @@
<button class="b-close" @click="closeBanner" title="关闭">✕</button>
</section>
<!-- 运行备注:账号 × 插件 唯一,本机保存并回传中心机;执行时随本次运行记录上报
备注可能较长(多行),列表只放一行摘要,查看/编辑统一走弹窗 -->
<div class="note-bar">
<span class="nb-label">运行备注</span>
<span class="nb-preview" :class="{ empty: !noteText }" :title="noteText || ''">
{{ noteText || ('给 ' + (plugin.name || '当前场景') + ' 写点备注') }}
</span>
<el-button size="small" text :disabled="!noteText" @click="openNote('view')">查看</el-button>
<el-button size="small" text @click="openNote('edit')">编辑</el-button>
<span class="nb-state" :class="{ ok: noteSavedAt && !noteSaving }">
{{ noteSaving ? '保存中…' : (noteSavedAt ? '已保存 ' + noteSavedAt : '') }}
</span>
</div>
<!-- 备注弹窗:查看只读,编辑可改(保存即回传中心机,执行时随运行一起上报) -->
<el-dialog v-model="noteDialog" :title="'运行备注 · ' + (plugin.name || '当前场景')"
width="560px" append-to-body class="note-dialog">
<el-input v-if="noteEdit" v-model="noteDraft" type="textarea" :rows="8" maxlength="500"
show-word-limit resize="vertical"
:placeholder="'给 ' + (plugin.name || '当前场景') + ' 写点备注'" />
<div v-else class="note-view">{{ noteText || '暂无备注' }}</div>
<template #footer>
<div class="note-foot">
<el-button v-if="noteEdit && noteText" text type="danger" :disabled="noteSaving"
@click="clearNote">清空</el-button>
<span class="spacer" />
<el-button @click="noteDialog = false">{{ noteEdit ? '取消' : '关闭' }}</el-button>
<el-button v-if="noteEdit" type="primary" :loading="noteSaving" @click="saveNote">保存</el-button>
</div>
</template>
</el-dialog>
<!-- 场景描述详情:manifest 里的完整描述按「;」拆段展示,页头只给两行摘要 -->
<el-dialog v-model="descDialog" :title="'场景说明 · ' + (plugin.name || '当前场景')"
width="600px" append-to-body class="desc-dialog">
<div class="desc-body">
<p v-for="(row, i) in descRows" :key="i" class="desc-p">{{ row }}</p>
<p v-if="!descRows.length" class="desc-p desc-empty">该场景暂无说明</p>
</div>
<template #footer>
<div class="note-foot">
<span class="spacer" />
<el-button @click="descDialog = false">关闭</el-button>
</div>
</template>
</el-dialog>
<!-- 运行台:插件界面 / 运行日志 / 历史运行
执行与参数配置收口在插件界面内(插件自包含前端+执行);日志归属"本次运行" -->
<div class="run-tabs card">
<div class="run-tabs">
<div class="rt-head">
<div class="rt-tabs">
<button v-for="t in tabs" :key="t.k" class="rt-tab" :class="{ on: tab === t.k }" @click="tab = t.k">
@@ -61,35 +113,38 @@
<div v-if="!replay" class="hist-view">
<div class="hist-head">
<div class="hist-titles">
<span class="sec-eyebrow">HISTORY</span>
<span class="hist-title">本场景最近运行</span>
<span class="hist-sub">共 {{ runs.length }} 条 · 成功 {{ histOk }} · 失败 {{ histFail }}</span>
</div>
<el-button size="small" text :icon="Refresh" :loading="loadingRuns" @click="loadRuns">刷新</el-button>
</div>
<div v-if="!runs.length" class="hist-empty">
{{ loadingRuns ? '加载中…' : '该场景还没有运行记录,执行一次后这里可回看' }}
<b>{{ loadingRuns ? '正在加载运行记录…' : '还没有运行记录' }}</b>
<span>执行一次后,这里可以回看当时的结果与日志</span>
</div>
<ul v-else class="hist-list">
<li v-for="r in runs" :key="r.run_id" class="hist-item" @click="openReplay(r.run_id)">
<i class="hist-dot" :class="runState(r).cls"></i>
<div class="hist-meta">
<b>{{ triggerLabel(r.trigger) }}</b>
<span class="hist-time">{{ fmtTime(r.started) }} · {{ durText(r.duration_sec) }}</span>
</div>
<span class="hist-state" :class="runState(r).cls">{{ runState(r).text }}</span>
<el-icon class="hist-arrow"><ArrowRight /></el-icon>
<li v-for="r in runs" :key="r.run_id" class="hist-row" @click="openReplay(r.run_id)">
<i class="h-dot" :class="runState(r).cls"></i>
<span class="h-trig">{{ triggerLabel(r.trigger) }}</span>
<span class="h-time">{{ fmtTime(r.started) }}</span>
<span class="h-dur">{{ durText(r.duration_sec) }}</span>
<span class="h-sum" :title="runSummary(r)">{{ runSummary(r) }}</span>
<span class="tag-badge" :class="badgeCls(r)"><i></i>{{ runState(r).text }}</span>
<el-icon class="h-arrow"><ArrowRight /></el-icon>
</li>
</ul>
</div>
<!-- 回看单次运行(结论 + 该次日志) -->
<div v-else class="hist-replay">
<div class="replay-head">
<el-button size="small" text :icon="ArrowLeft" :disabled="replayBusy" @click="replay = null">返回列表</el-button>
<div class="replay-tags">
<span class="badge" :class="replay.ok ? 'on' : 'off'"><i class="bdot"></i>{{ replay.ok ? '成功' : '失败' }}</span>
<span class="tag-badge" :class="badgeCls(replay)"><i></i>{{ runState(replay).text }}</span>
<span class="replay-tag">{{ triggerLabel(replay.trigger) }}</span>
<span class="replay-tag">{{ fmtTime(replay.started) }}</span>
<span class="replay-tag">耗时 {{ durText(replay.duration_sec) }}</span>
<span v-if="replay.note" class="replay-tag">备注:{{ replay.note }}</span>
<span v-if="replay.summary" class="replay-sum">{{ replay.summary }}</span>
</div>
</div>
@@ -98,6 +153,7 @@
</section>
</div>
</div>
</div>
</div>
<div v-else-if="!store.plugins.length" class="empty-note">
@@ -111,14 +167,27 @@ import { computed, ref, watch } from 'vue'
import { Refresh, ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { store } from '../store'
import { getRun, fetchRuns, fetchMeta, listRollbacks, rollbackPlugin, fetchQueue } from '../api'
import { getRun, fetchRuns, fetchMeta, listRollbacks, rollbackPlugin, fetchQueue,
fetchPluginNotes, savePluginNote } from '../api'
import LogPanel from './LogPanel.vue'
import RunIndicator from './RunIndicator.vue'
import PageHead from './PageHead.vue'
import { durText, fmtTime } from '../utils/format'
import { durText, fmtTime, cleanDesc, splitDesc } from '../utils/format'
const plugin = computed(() => store.plugins.find((p) => p.id === store.selectedId) || null)
// ===== 场景描述(页头副标题 + 「详情」弹窗)=====
// manifest 的 description 常写成「XQ0034 续签电子签:干这个;再干那个」,页头标题已显示场景名,
// 前缀重复且正文偏长:页头只留剥掉前缀后的摘要(CSS 限两行,悬停给全文),完整内容进「详情」弹窗按句分段。
const descDialog = ref(false)
const fullDesc = computed(() => cleanDesc(plugin.value?.description) || '暂无描述')
const hasDesc = computed(() => !!cleanDesc(plugin.value?.description))
const shortDesc = computed(() => {
const s = cleanDesc(plugin.value?.description)
return s || '暂无描述'
})
const descRows = computed(() => splitDesc(plugin.value?.description))
// 运行结论三态:成功 / 已取消(用户取消、排队超时、退出取消)/ 失败 / 已中断(客户端退出遗留)
// 「取消」不能显示成「失败」——两者对用户的含义完全不同,也不该混进失败统计。
function runState(r) {
@@ -129,6 +198,26 @@ function runState(r) {
return { text: '失败', cls: 'err' }
}
// 历史列表:状态胶囊配色(成功绿 / 失败红 / 取消中断灰)
function badgeCls(r) {
if (!r) return 'idle'
if (r.ok) return 'ok'
if (r.status === 'cancelled' || r.status === 'interrupted') return 'idle'
return 'bad'
}
// 历史行摘要:优先后端 summary,其次失败原因,都没有给个占位(整行加 title 看全文)
function runSummary(r) {
if (!r) return '—'
const s = String(r.summary || '').trim()
if (s) return s
const e = String(r.error || '').trim()
if (e) return e
if (r.status === 'cancelled') return '已取消'
if (r.status === 'interrupted') return '已中断'
return r.ok ? '执行完成' : '无输出'
}
// 本场景在队列里等待的任务数:连续点了几次「一键执行」时,页头直接给出排队提示
const queuedCount = computed(() => {
const pid = plugin.value?.id
@@ -145,6 +234,91 @@ const uiSrc = computed(() => (plugin.value?.ui ? `/pui/${plugin.value.id}/` : ''
// 取消则返回 409,插件自身横幅会显示"启动执行失败:已取消加入队列…",不会误以为已经在跑。
const uiFrame = ref(null)
// ===== 运行备注(账号 × 插件 唯一;本机保存 + 回传中心机,执行时随本次运行一起上报)=====
// 备注是壳子层统一能力:17 个插件不用各自实现,新增插件自动具备。
const noteText = ref('')
const noteSavedAt = ref('')
const noteSaving = ref(false)
const noteMap = ref({}) // 本机全部备注 { plugin_id: {note, at} }
const noteDialog = ref(false)
const noteEdit = ref(false)
const noteDraft = ref('')
let notesLoaded = false
function syncNoteFromMap() {
const cur = plugin.value
if (!cur) { noteText.value = ''; noteSavedAt.value = ''; return }
const row = noteMap.value[cur.id]
noteText.value = (row && row.note) || ''
noteSavedAt.value = row && row.at
? new Date(row.at * 1000).toLocaleTimeString('zh-CN', { hour12: false })
: ''
}
async function loadNotes() {
try {
const r = await fetchPluginNotes()
noteMap.value = (r && r.notes) || {}
} catch (_) { /* 备注是辅助能力:拉取失败静默,仍可用本机缓存 */ }
syncNoteFromMap()
}
// 查看 / 编辑:备注可能多行长文本,统一在弹窗里看和改
function openNote(mode) {
if (!plugin.value) return
noteEdit.value = mode === 'edit'
noteDraft.value = noteText.value
noteDialog.value = true
}
async function saveNote() {
const cur = plugin.value
if (!cur) return
noteSaving.value = true
try {
const r = await savePluginNote(cur.id, noteDraft.value)
const note = (r && r.note) || ''
noteText.value = note
noteDraft.value = note
const m = { ...noteMap.value }
if (note) m[cur.id] = { note, at: Math.floor(Date.now() / 1000) }
else delete m[cur.id]
noteMap.value = m
noteSavedAt.value = note ? new Date().toLocaleTimeString('zh-CN', { hour12: false }) : ''
noteDialog.value = false
ElMessage.success(note ? '备注已保存' : '备注已清空')
} catch (e) {
ElMessage.warning('备注保存失败:' + (e.message || e))
} finally {
noteSaving.value = false
}
}
function clearNote() {
noteDraft.value = ''
saveNote()
}
watch(() => plugin.value?.id, (id) => {
syncNoteFromMap()
if (id && !notesLoaded) { notesLoaded = true; loadNotes() }
}, { immediate: true })
// 把备注注入插件提交的 /api/runs(插件本身无需感知备注的存在)
function withRunNote(init) {
const note = String(noteText.value || '').trim()
if (!note) return init
const opt = { ...(init || {}) }
try {
const body = typeof opt.body === 'string' ? JSON.parse(opt.body) : null
if (body && typeof body === 'object') {
body.note = note
opt.body = JSON.stringify(body)
}
} catch (_) { /* body 非 JSON:原样提交,不影响执行 */ }
return opt
}
async function queueSnapshotNow() {
try {
const snap = await fetchQueue()
@@ -215,7 +389,8 @@ function onUiLoad() {
if (String(method).toUpperCase() !== 'POST' || !/\/api\/runs\/?$/.test(url)) {
return origFetch(input, init)
}
if (await confirmEnqueue()) return origFetch(input, init)
// 放行前把壳子的「运行备注」注入请求体:备注统一由壳子采集,插件无需感知
if (await confirmEnqueue()) return origFetch(input, withRunNote(init))
const R = w.Response || Response
return new R(JSON.stringify({ detail: '已取消加入队列(当前有其他任务在执行)' }), {
status: 409,
@@ -248,6 +423,9 @@ const loadingRuns = ref(false)
const runsLoaded = ref(false) // 本场景是否已拉过(切换场景后重置)
const replay = ref(null) // 正在回看的单次运行 {brief..., logs:[...]}
const replayBusy = ref(false)
// 历史列表顶部统计(成功 / 失败;取消与中断不计入失败)
const histOk = computed(() => runs.value.filter((r) => r.ok).length)
const histFail = computed(() => runs.value.filter((r) => badgeCls(r) === 'bad').length)
async function loadRuns() {
if (!plugin.value || loadingRuns.value) return
@@ -370,11 +548,19 @@ function closeBanner() {
.plugin-page {
display: flex;
flex-direction: column;
gap: var(--space-3);
padding: var(--page-pad);
gap: 0;
padding: 0;
flex: 1 1 auto; /* 填满中栏上下文区,运行台内部自己滚 */
min-height: 0;
}
/* 页头固定,下面这层才滚动。
左右内边距与页头一致(24px),tab 栏 / 内容都贴同一条基线,看起来是一整块 */
.page-body {
flex: 1 1 auto; min-height: 0;
display: flex; flex-direction: column; gap: 0;
padding: 0 24px 18px;
}
.banner { margin: 14px 0 12px; }
/* ---------- 页头内的场景身份 ---------- */
.p-name { display: inline-flex; align-items: center; gap: var(--space-2); }
@@ -393,6 +579,19 @@ function closeBanner() {
.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; }
/* 场景说明:页头摘要(限两行,悬停看全文)+「详情」入口(全文按「;」拆段) */
.p-sub { display: block; }
.desc-btn { height: 28px; padding: 0 var(--space-3); font-size: 11.5px; color: var(--t3); }
.desc-btn:hover { color: var(--t1); }
.desc-body { max-height: 52vh; overflow-y: auto; }
.desc-p {
margin: 0 0 10px; padding-left: 10px;
border-left: 2px solid var(--line);
font: 400 12.5px/1.7 var(--f-cn); color: var(--t2);
word-break: break-word;
}
.desc-p:last-child { margin-bottom: 0; }
.desc-empty { color: var(--t3); border-left-color: var(--line); }
/* 本场景排队中:与运行中的进度胶囊并列,点击去看右侧队列明细 */
.qchip {
display: inline-flex; align-items: center; height: 20px; padding: 0 var(--space-2);
@@ -426,20 +625,59 @@ function closeBanner() {
}
.b-close:hover { color: var(--t1); background: var(--field); }
/* ---------- 运行台(标签页容器) ---------- */
/* ---------- 运行备注(账号 × 插件 唯一,随运行回传中心机) ---------- */
.note-bar {
display: flex; align-items: center; gap: var(--space-2-5);
margin: 14px 0 2px; flex-shrink: 0;
}
.nb-label {
flex: 0 0 auto; font: 600 11.5px/1 var(--f-cn); color: var(--t3);
letter-spacing: .5px;
}
.nb-preview {
flex: 1 1 auto; min-width: 0;
height: 30px; display: flex; align-items: center;
padding: 0 10px;
background: var(--field); border: 1px solid var(--line);
border-radius: var(--r-field);
font: 400 12px/1.5 var(--f-cn); color: var(--t2);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nb-preview.empty { color: var(--t4); }
.nb-state {
flex: 0 0 auto; min-width: 74px; text-align: right;
font: 500 11px/1 var(--f-num); color: var(--t4);
}
.nb-state.ok { color: var(--good-ink); }
/* 备注弹窗:查看态用可滚动的等宽留白块,编辑态用 textarea */
.note-view {
min-height: 130px; max-height: 320px; overflow: auto;
padding: 10px 12px;
background: var(--field); border: 1px solid var(--line);
border-radius: var(--r-field);
font: 400 12.5px/1.75 var(--f-cn); color: var(--t2);
white-space: pre-wrap; word-break: break-word;
}
.note-foot { display: flex; align-items: center; gap: var(--space-2); }
.note-foot .spacer { flex: 1; }
/* ---------- 运行台:不套框,tab 栏直接贴在中栏里(只留一条细分隔线) ---------- */
.run-tabs {
flex: 1 1 auto; min-height: 300px;
display: flex; flex-direction: column; overflow: hidden;
background: transparent;
}
.rt-head {
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;
padding: 0; flex-shrink: 0;
border-bottom: 1px solid var(--line-soft);
}
.rt-tabs { display: flex; align-items: center; gap: 2px; }
.rt-tabs { display: flex; align-items: center; gap: 20px; }
.rt-tab {
display: inline-flex; align-items: center; gap: var(--space-1-5);
border: none; background: transparent; cursor: pointer; font-family: inherit;
padding: var(--space-3) var(--space-3); font: 500 12.5px/18px var(--f-cn); color: var(--t3);
padding: 12px 0; font: 500 12.5px/18px var(--f-cn); color: var(--t3);
border-bottom: 2px solid transparent; margin-bottom: -1px;
transition: color var(--dur), border-color var(--dur);
}
@@ -452,52 +690,75 @@ function closeBanner() {
.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; }
.rt-log { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding-top: 14px; }
/* ---------- 专属界面插件 ---------- */
.ui-pane { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding: var(--space-3) var(--space-4) var(--space-4); }
/* ---------- 专属界面插件:不再给 iframe 描边(插件界面自己带边界会显得"框套框") ---------- */
.ui-pane { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding: 14px 0 0; }
.pui-frame {
display: block; width: 100%; flex: 1 1 auto; min-height: 340px;
border: 1px solid var(--line); border-radius: var(--r-sub); background: var(--surface);
border: 0; border-radius: 0; 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: 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;
display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
padding: 14px 0 10px; flex-shrink: 0;
border-bottom: 1px solid var(--line-soft);
}
.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-title { font: 600 13px/18px var(--f-cn); color: var(--t1); }
.hist-sub { font: 400 11.5px/16px var(--f-cn); color: var(--t4); }
.hist-empty {
flex: 1 1 auto; display: grid; place-items: center;
color: var(--t4); font-size: 12px; padding: var(--space-6) var(--space-5); text-align: center;
flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
padding: var(--space-6) var(--space-5); text-align: center;
color: var(--t4); font: 400 12px/18px var(--f-cn);
}
.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: var(--space-3);
padding: var(--space-2) var(--space-3); border-radius: var(--r-row); cursor: pointer;
.hist-empty b { color: var(--t2); font: 600 13px/19px var(--f-cn); }
.hist-list { flex: 1 1 auto; min-height: 0; overflow: auto; list-style: none; margin: 0; padding: 6px 0 8px; }
/* 行:状态点 / 触发源 / 开始时间 / 耗时 / 摘要(占满剩余宽度)/ 状态胶囊 / 箭头 */
.hist-row {
display: grid;
grid-template-columns: 8px 92px 150px 74px minmax(0, 1fr) 88px 14px;
align-items: center; gap: var(--space-3);
padding: 9px 12px; border-radius: var(--r-row); cursor: pointer;
transition: background var(--dur);
}
.hist-item:hover { background: var(--field); }
.hist-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.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-dot.mid { background: var(--t4); box-shadow: 0 0 0 3px var(--field); }
.hist-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.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-state.mid { color: var(--t4); }
.hist-arrow { color: var(--t5); font-size: 13px; flex-shrink: 0; }
.hist-row:hover { background: var(--field); }
.h-dot { width: 8px; height: 8px; border-radius: 50%; }
.h-dot.ok { background: var(--good); }
.h-dot.err { background: var(--danger); }
.h-dot.mid { background: var(--t4); }
.h-trig { font: 500 12px/16px var(--f-cn); color: var(--t2); white-space: nowrap; }
.h-time { font: 400 11.5px/16px var(--f-num); color: var(--t3); font-variant-numeric: tabular-nums; }
.h-dur { font: 400 11.5px/16px var(--f-num); color: var(--t4); font-variant-numeric: tabular-nums; }
.h-sum {
min-width: 0; font: 400 11.5px/16px var(--f-cn); color: var(--t4);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.h-arrow { color: var(--t5); font-size: 12px; }
/* 状态胶囊(与壳子表格状态列同款) */
.tag-badge {
display: inline-flex; align-items: center; gap: 5px;
height: 22px; padding: 0 9px;
border: 1px solid transparent; border-radius: 6px;
font: 500 11px/1 var(--f-cn); white-space: nowrap;
}
.tag-badge i { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.tag-badge.ok { color: var(--good-ink); background: var(--good-soft); border-color: var(--good-line); }
.tag-badge.ok i { background: var(--good); }
.tag-badge.bad { color: var(--danger-ink); background: var(--danger-soft); border-color: var(--danger-line); }
.tag-badge.bad i { background: var(--danger); }
.tag-badge.idle { color: var(--t3); background: var(--field); border-color: var(--line); }
.tag-badge.idle i { background: var(--t5); }
.hist-replay { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.replay-head {
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;
padding: 12px 0 10px; border-bottom: 1px solid var(--line-soft); flex-shrink: 0;
}
.replay-tags { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }
.replay-tag {
@@ -1,28 +1,71 @@
<template>
<button class="scene-card card" :class="{ running, compact }" @click="$emit('open', plugin.id)">
<span v-if="compact" class="sc-dot" :style="{ background: dotColor }"></span>
<span v-else class="sc-ic" :style="{ color: dotColor, background: tileBg }">{{ initial }}</span>
<span class="sc-body">
<span class="sc-head">
<!-- 左栏「场景」紧凑态:色点 + 名称 + 版本 + 箭头(保持原样) -->
<template v-if="compact">
<span class="sc-dot" :style="{ background: dotColor }"></span>
<span class="sc-body">
<b class="sc-name">{{ plugin.name }}</b>
<em v-if="!compact && plugin.category" class="sc-cat">{{ plugin.category }}</em>
</span>
<span v-if="!compact" class="sc-desc">{{ plugin.description || '暂无描述' }}</span>
<span class="sc-meta">
<em class="ver">v{{ plugin.version }}</em>
<span v-if="plugin.platform" class="plat" :class="platformOnline ? 'on' : 'off'"
:title="`${platformLabel} ${platformOnline ? '已登录' : '未登录,请先在运行台登录'}`">
<i class="dot"></i>{{ platformLabel }} · {{ platformOnline ? '已登录' : '未登录' }}
<span class="sc-meta">
<em class="ver">v{{ plugin.version }}</em>
<span v-if="plugin.platform" class="plat" :class="platformOnline ? 'on' : 'off'"
:title="`${platformTip} ${platformOnline ? '已登录' : '未登录,请先在运行台登录'}`">
<i class="dot"></i>{{ platformTip }} · {{ platformOnline ? '已登录' : '未登录' }}
</span>
</span>
</span>
</span>
<span class="sc-go" :class="{ busy: running }">
<template v-if="running">{{ store.progress }}%</template>
<svg v-else width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M4 12h16" /><path d="m13 5 7 7-7 7" />
</svg>
</span>
<span class="sc-go" :class="{ busy: running }">
<template v-if="running">{{ store.progress }}%</template>
<svg v-else width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M4 12h16" /><path d="m13 5 7 7-7 7" />
</svg>
</span>
</template>
<!-- 场景库卡:竖向排版(图标块 + 分类胶囊 → 标题 → 两行描述 → 标签 → 底部最近运行/配置运行) -->
<template v-else>
<span class="sc-top">
<span class="sc-tile" :style="{ color: dotColor, background: tileBg }">
<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path :d="iconPath" />
</svg>
</span>
<em v-if="plugin.category" class="sc-cat">{{ plugin.category }}</em>
</span>
<b class="sc-name">{{ plugin.name }}</b>
<span class="sc-desc">{{ plugin.description || '暂无描述' }}</span>
<span class="sc-tags">
<em class="sc-tag ver">v{{ plugin.version }}</em>
<em v-if="plugin.platform" class="sc-tag plat" :class="platformOnline ? 'on' : 'off'"
:title="`${platformTip} ${platformOnline ? '已登录' : '未登录,请先在运行台登录'}`">
<i class="dot"></i><span class="tx">{{ platformText }}</span>
</em>
</span>
<span class="sc-foot">
<span class="sc-when" :class="{ live: running }" :title="running ? '正在执行' : `最近一次运行:${whenText}`">
<i v-if="running" class="live-dot"></i>
<svg v-else width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<circle cx="12" cy="12" r="8.4" /><path d="M12 7.6V12l3 1.8" />
</svg>
{{ running ? '正在执行' : whenText }}
</span>
<span class="sc-cta" :class="{ busy: running }">
<template v-if="running">{{ store.progress }}%</template>
<template v-else>
配置运行
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="m9 5 7 7-7 7" />
</svg>
</template>
</span>
</span>
</template>
</button>
</template>
@@ -31,20 +74,62 @@ import { computed } from 'vue'
import { store } from '../store'
import { sceneDotColor } from '../utils/theme'
// 场景卡:首页「常用场景」(compact,无描述)与场景库共用。
// 场景卡:首页「常用场景」(compact,无描述)与场景库(竖向卡)共用。
// 色点按插件在总清单中的位置取色,搜索/筛选/分组后颜色仍稳定。
const props = defineProps({
plugin: { type: Object, required: true },
compact: { type: Boolean, default: false },
// 最近一次运行时间(场景库页用 /api/runs 汇总后传入),空 = 尚未运行
lastRun: { type: String, default: '' },
})
defineEmits(['open'])
const dotColor = computed(() => sceneDotColor(store.plugins.findIndex((p) => p.id === props.plugin.id)))
const tileBg = computed(() => `color-mix(in srgb, ${dotColor.value} 13%, var(--surface))`)
const initial = computed(() => (props.plugin.name || '·').trim().slice(0, 1))
const pluginIndex = computed(() => Math.max(0, store.plugins.findIndex((p) => p.id === props.plugin.id)))
// ---- 场景图标:按名称/分类关键词挑语义化线性图标(24×24 描边 path)----
const ICONS = {
user: 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8z M5 20a7 7 0 0 1 14 0',
chart: 'M4 19V5 M4 19h16 M8 16v-4 M12 16V8 M16 16v-6',
sync: 'M4 9a8 8 0 0 1 13.2-3.4L20 8 M20 5v4h-4 M20 15a8 8 0 0 1-13.2 3.4L4 16 M4 19v-4h4',
bell: 'M15 17h5l-1.4-1.4A2 2 0 0 1 18 14.2V11a6 6 0 0 0-4-5.7V5a2 2 0 1 0-4 0v.3C7.7 6.2 6 8.4 6 11v3.2c0 .5-.2 1-.6 1.4L4 17h5 M15 17v1a3 3 0 1 1-6 0v-1',
doc: 'M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8l-5-5z M14 3v5h5 M9 13h6 M9 17h4',
globe: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18z M3.6 9h16.8 M3.6 15h16.8 M12 3a15 15 0 0 1 0 18 15 15 0 0 1 0-18z',
table: 'M4 5h16v14H4z M4 10h16 M4 15h16 M10 5v14',
mail: 'M4 6h16v12H4z M4 7l8 6 8-6',
check: 'M9 12l2 2 4-4 M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18z',
clock: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18z M12 7.5V12l3 2',
box: 'M12 3l8 4.5v9L12 21l-8-4.5v-9L12 3z M4 7.5l8 4.5 8-4.5 M12 12v9',
db: 'M4 6c0-1.7 3.6-3 8-3s8 1.3 8 3-3.6 3-8 3-8-1.3-8-3z M4 6v6c0 1.7 3.6 3 8 3s8-1.3 8-3V6 M4 12v6c0 1.7 3.6 3 8 3s8-1.3 8-3v-6',
}
const ICON_RULES = [
{ keys: ['考勤', '花名册', '人员', '员工', '人资', '社保', '招聘'], icon: ICONS.user },
{ keys: ['对账', '报表', '统计', '月报', '汇总', '分析', '台账'], icon: ICONS.chart },
{ keys: ['同步', '导入', '导出', '上传', '下载', '迁移', '入库'], icon: ICONS.sync },
{ keys: ['通知', '推送', '钉钉', '企微', '企业微信', '消息', '邮件'], icon: ICONS.bell },
{ keys: ['采集', '抓取', '爬取', '监控', '竞品', '数据'], icon: ICONS.db },
{ keys: ['审批', '流程', '工单', '待办', '签批'], icon: ICONS.doc },
{ keys: ['网页', '网站', '系统', '平台', '登录'], icon: ICONS.globe },
{ keys: ['excel', 'wps', '表格', '清单', '明细'], icon: ICONS.table },
{ keys: ['检查', '校验', '审核', '核对', '核验', '封存'], icon: ICONS.check },
{ keys: ['计划', '定时', '调度', '排班'], icon: ICONS.clock },
{ keys: ['库存', '物料', '订单', '采购', '仓库', '发货'], icon: ICONS.box },
]
const ICON_POOL = Object.values(ICONS)
// 关键词命中优先;都没命中时按清单序号从图标池轮取(同一场景始终同一个图标,不会乱跳)
const iconPath = computed(() => {
const text = `${props.plugin.name || ''} ${props.plugin.category || ''}`.toLowerCase()
const hit = ICON_RULES.find((r) => r.keys.some((k) => text.includes(k.toLowerCase())))
return hit ? hit.icon : ICON_POOL[pluginIndex.value % ICON_POOL.length]
})
const platform = computed(() => store.platforms.find((p) => p.id === props.plugin.platform) || null)
const platformLabel = computed(() => platform.value?.label || props.plugin.platform || '')
const platformTip = computed(() => platform.value?.label || props.plugin.platform || '')
const platformOnline = computed(() => !!platform.value?.online)
// 已登录只留平台名(绿点即状态),未登录显式标出,避免"点进去才发现要登录"
const platformText = computed(() => (platformOnline.value ? platformTip.value : `${platformTip.value} · 未登录`))
// 最近运行时间由父级(场景库页)按 /api/runs 汇总后传入,空 = 尚未运行
const whenText = computed(() => props.lastRun || '尚未运行')
const running = computed(() => store.running && store.selectedId === props.plugin.id)
</script>
@@ -70,43 +155,24 @@ const running = computed(() => store.running && store.selectedId === props.plugi
.scene-card.compact:hover { transform: none; box-shadow: var(--sh-card); }
.sc-dot { width: 6px; height: 6px; border-radius: 3px; flex-shrink: 0; }
.sc-ic {
width: 42px; height: 42px; border-radius: var(--r-sub); flex-shrink: 0;
display: grid; place-items: center; background: var(--brand-soft);
font: 600 16px/1 var(--f-cn);
}
.sc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.sc-head { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.sc-name {
min-width: 0; font: 600 13px/18px var(--f-cn); color: var(--t1);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 场景库(非 compact):标题更大、描述两行,卡片撑起来后一页不会半屏空 */
.scene-card:not(.compact) .sc-name { font: 600 14.5px/21px var(--f-cn); }
.sc-cat {
flex-shrink: 0; font-style: normal; font: 500 9.5px/15px var(--f-cn);
color: var(--brand-ink); background: var(--brand-soft);
border: 1px solid var(--brand-track); border-radius: var(--r-pill);
padding: 0 var(--space-2);
}
.sc-desc {
font-size: 12px; line-height: 17px; color: var(--t4);
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
overflow: hidden; white-space: normal;
}
.sc-meta { display: flex; align-items: center; gap: var(--space-2); margin-top: 1px; }
.scene-card:not(.compact) .sc-meta { margin-top: auto; }
.ver { font-style: normal; font: 400 10.5px/15px var(--f-num); color: var(--t4); flex-shrink: 0; }
.plat {
/* 紧凑态平台登录态(首页常用场景用):限定在 compact 内,避免污染场景库卡的标签色 */
.scene-card.compact .plat {
display: inline-flex; align-items: center; gap: 5px;
font-size: 10.5px; color: var(--t3);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.plat .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--t5); flex-shrink: 0; }
.plat.on { color: var(--good-ink); }
.plat.on .dot { background: var(--good); }
.plat.off { color: var(--warn-ink); }
.plat.off .dot { background: var(--warn); }
.scene-card.compact .plat .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--t5); flex-shrink: 0; }
.scene-card.compact .plat.on { color: var(--good-ink); }
.scene-card.compact .plat.on .dot { background: var(--good); }
.scene-card.compact .plat.off { color: var(--warn-ink); }
.scene-card.compact .plat.off .dot { background: var(--warn); }
.sc-go {
flex-shrink: 0; width: 26px; height: 26px; display: grid; place-items: center;
@@ -118,6 +184,92 @@ const running = computed(() => store.running && store.selectedId === props.plugi
.sc-go.busy { font-size: 9.5px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.scene-card.compact .sc-go { width: 22px; height: 22px; font-size: 11px; }
.scene-card.compact .sc-go.busy { font-size: 8.5px; }
.scene-card:hover .sc-go { background: var(--brand); color: var(--on-primary); border-color: transparent; box-shadow: var(--sh-brand-sm); }
.scene-card.running .sc-go { background: var(--brand); color: var(--on-primary); border-color: transparent; }
.scene-card.compact:hover .sc-go { background: var(--brand); color: var(--on-primary); border-color: transparent; box-shadow: var(--sh-brand-sm); }
.scene-card.compact.running .sc-go { background: var(--brand); color: var(--on-primary); border-color: transparent; }
/* ================= 场景库竖向卡(对齐设计稿:图标块 + 右上徽章 → 标题 → 两行描述 → 标签 → 底栏) ================= */
.scene-card:not(.compact) {
flex-direction: column; align-items: stretch; gap: 0;
height: 100%; min-height: 0; padding: var(--space-4);
background: var(--surface); border-radius: var(--r-sub); overflow: hidden;
}
/* 设计稿 hover:只加阴影 + 描边转品牌色,卡片不上浮 */
.scene-card:not(.compact):hover { transform: none; box-shadow: var(--sh-float); border-color: var(--brand-track); }
.scene-card:not(.compact):active { transform: none; }
.scene-card:not(.compact).running { background: linear-gradient(160deg, var(--brand-soft) 0%, var(--surface) 62%); }
/* 顶部:图标块(40×40)+ 右上分类徽章 */
.sc-top {
display: flex; align-items: flex-start; justify-content: space-between;
gap: var(--space-2); margin-bottom: 10px; flex-shrink: 0;
}
.sc-tile {
width: 40px; height: 40px; border-radius: 8px; flex-shrink: 0;
display: grid; place-items: center;
}
.sc-tile svg { display: block; }
.sc-cat {
flex-shrink: 0; font-style: normal; font: 500 10px/17px var(--f-cn);
color: var(--t3); background: var(--field); border: 1px solid var(--line);
border-radius: var(--r-pill); padding: 0 var(--space-2);
max-width: 118px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.scene-card:not(.compact) .sc-name {
flex-shrink: 0; font: 700 14px/20px var(--f-cn);
margin-bottom: 4px; transition: color var(--dur);
}
.scene-card:not(.compact):hover .sc-name { color: var(--brand); }
.sc-desc {
flex-shrink: 0; margin-bottom: 12px; color: var(--t3);
font-size: 12px; line-height: 18px;
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
overflow: hidden; white-space: normal;
}
/* 标签行:版本 / 平台登录态(设计稿的灰底小标签,状态只靠圆点表达) */
.sc-tags { flex-shrink: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }
.sc-tag {
display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
font-style: normal; font: 500 10px/17px var(--f-cn); color: var(--t3);
background: var(--field); border: 1px solid var(--line);
border-radius: 4px; padding: 0 var(--space-2);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sc-tag.ver { font-family: var(--f-num); color: var(--t4); }
.sc-tag.plat { flex-shrink: 1; min-width: 0; }
.sc-tag.plat .tx { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sc-tag.plat .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--t5); flex-shrink: 0; }
.sc-tag.plat.on .dot { background: var(--good); }
.sc-tag.plat.off .dot { background: var(--warn); }
/* 底部:最近运行 / hover 出现的「配置运行」 */
.sc-foot {
flex-shrink: 0; margin-top: auto; padding-top: 10px;
border-top: 1px solid var(--line-soft);
display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
}
.sc-when {
display: inline-flex; align-items: center; gap: 5px; min-width: 0;
font: 400 11px/16px var(--f-cn); color: var(--t4);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sc-when svg { flex-shrink: 0; color: var(--t5); }
.sc-when.live { color: var(--brand-ink); }
.live-dot {
width: 5px; height: 5px; border-radius: 50%; background: var(--brand);
flex-shrink: 0; animation: scPulse 1.4s var(--ease) infinite;
}
@keyframes scPulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.72); } }
.sc-cta {
display: inline-flex; align-items: center; gap: 2px; flex-shrink: 0;
font: 500 12px/16px var(--f-cn); color: var(--brand);
opacity: 0; transition: opacity var(--dur), color var(--dur);
}
.sc-cta svg { display: block; }
.sc-cta.busy { font-family: var(--f-num); font-variant-numeric: tabular-nums; opacity: 1; }
.scene-card:hover .sc-cta, .scene-card.running .sc-cta { opacity: 1; }
.scene-card:hover .sc-cta { color: var(--brand-ink); }
</style>
@@ -1,32 +1,40 @@
<template>
<!-- 中栏整体按设计稿:白底面板 + 标题区 + 工具栏(Tab/搜索) + 三列卡片 + 底部计数/翻页 -->
<div class="scenes-page">
<!-- 页头:标题 + 搜索/计数同排 -->
<PageHead eyebrow="LIBRARY · 场景库" title="全部场景" sub="按账号授权自动同步 · 点击卡片进入场景">
<template #actions>
<el-button type="primary" size="default" :icon="Refresh" :loading="syncing"
:disabled="store.running" @click="syncNow">
同步场景
</el-button>
<div class="search tool-search">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="11" cy="11" r="6.6"/><path d="M16.2 16.2 21 21"/></svg>
<input v-model="q" placeholder="搜索场景" @input="onFilter" />
<header class="lib-head">
<div class="lib-title-row">
<div class="lib-title-group">
<h1 class="lib-title">场景库</h1>
<p class="lib-sub">提供开箱即用的自动化场景模板,快速接入您的业务流</p>
</div>
<span class="dim num">共 {{ filtered.length }} / {{ store.plugins.length }}</span>
</template>
</PageHead>
<div class="lib-actions">
<el-button type="primary" :icon="Refresh" :loading="syncing" :disabled="store.running" @click="syncNow">
同步场景
</el-button>
</div>
</div>
</header>
<!-- 分类筛选:横向 chips,一眼看到各分类规模 -->
<div class="cat-bar">
<button v-for="c in catTabs" :key="c.key" type="button" class="chip"
:class="{ on: cat === c.key }" @click="pickCat(c.key)">
<span class="chip-name">{{ c.label }}</span>
<span class="chip-n">{{ c.n }}</span>
</button>
<!-- 工具栏:左分类 Tab(带数量),右搜索 -->
<div class="lib-toolbar">
<div class="cat-bar">
<button v-for="c in catTabs" :key="c.key" type="button" class="chip"
:class="{ on: cat === c.key }" @click="pickCat(c.key)">
<span class="chip-name">{{ c.label }}</span>
<span class="chip-n">{{ c.n }}</span>
</button>
</div>
<div class="search">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round">
<circle cx="11" cy="11" r="6.6" /><path d="M16.2 16.2 21 21" />
</svg>
<input v-model="q" placeholder="在场景库中搜索..." @input="onFilter" />
</div>
</div>
<!-- 卡片网格:列数自适应;每页数量按可视区域实时计算,保证一页铺满而不是半屏 -->
<div ref="gridEl" class="sc-grid">
<SceneCard v-for="p in pagedList" :key="p.id" :plugin="p" @open="open" />
<!-- 卡片网格:三列;每页数量按可视区域实时计算,保证一页铺满而不是半屏 -->
<div ref="gridEl" class="sc-grid" :style="{ '--cols': cols }">
<SceneCard v-for="p in pagedList" :key="p.id" :plugin="p" :last-run="lastRunMap[p.id] || ''" @open="open" />
<div v-if="!store.plugins.length" class="sc-empty">
<b>当前账号暂无可用场景</b>
<span>点右上角「同步场景」按账号权限拉取;仍为空请联系管理员授权</span>
@@ -36,9 +44,15 @@
<span>换个关键词或分类试试</span>
</div>
</div>
<el-pagination v-if="filtered.length > perPage" class="sc-pager" size="small" background
layout="total, prev, pager, next" :total="filtered.length" :page-size="perPage"
:current-page="page" @current-change="(p) => page = p" />
<footer class="lib-foot">
<div class="lib-total">共 <b>{{ filtered.length }}</b> 个场景</div>
<div class="pager">
<button class="pg-btn" :disabled="page <= 1" @click="page = page - 1">上一页</button>
<button v-for="p in pageList" :key="p" class="pg-num" :class="{ on: p === page }" @click="page = p">{{ p }}</button>
<button class="pg-btn" :disabled="page >= totalPages" @click="page = page + 1">下一页</button>
</div>
</footer>
</div>
</template>
@@ -46,8 +60,9 @@
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { Refresh } from '@element-plus/icons-vue'
import { store } from '../store'
import { fetchRuns } from '../api'
import { fmtDayTime } from '../utils/format'
import { usePluginSync } from '../composables/usePluginSync'
import PageHead from './PageHead.vue'
import SceneCard from './SceneCard.vue'
// 同步入口与左栏图标共用同一份逻辑(并发保护、结果提示都在 composable 里)
@@ -60,13 +75,13 @@ const q = ref('')
const cat = ref('')
const page = ref(1)
// 每页数量按可视区域算:列数由宽度决定,行数由剩余高度决定,保证一页正好铺满。
// (固定 8 个在宽屏下只占两行,页脚一片空白)
// 每页数量按可视区域算:列数(3/2/1)由网格宽度决定,行数由剩余高度决定,
// 保证一页正好铺满而不是半屏(设计稿为 3 列 × N 行)
const gridEl = ref(null)
const perPage = ref(12)
const CARD_MIN_W = 300 // 与 .sc-grid 的 minmax 保持一致
const perPage = ref(6)
const cols = ref(3)
const GAP = 16 // 与 .sc-grid 的 gap 保持一致
const CARD_H = 108 // 卡片实际高度(含两行描述)
const CARD_H = 216 // 卡片固定行高(与 .sc-grid 的 grid-auto-rows 保持一致)
let ro = null
function recomputePerPage() {
@@ -74,20 +89,43 @@ function recomputePerPage() {
if (!el) return
const w = el.clientWidth
if (!w) return
const cols = Math.max(1, Math.floor((w + GAP) / (CARD_MIN_W + GAP)))
const nextCols = w >= 840 ? 3 : (w >= 560 ? 2 : 1)
if (nextCols !== cols.value) cols.value = nextCols
const scroller = el.closest('.page-scroll')
let availH = 620
let availH = 600
if (scroller) {
const top = el.getBoundingClientRect().top - scroller.getBoundingClientRect().top
availH = scroller.clientHeight - top - 32 // 32 = 页脚分页/留白
availH = scroller.clientHeight - top - 64 // 64 = 底部「计数 + 翻页」+ 页底留白
}
const rows = Math.max(1, Math.floor((availH + GAP) / (CARD_H + GAP)))
const next = Math.max(4, cols * rows)
const next = Math.max(nextCols, nextCols * rows)
if (next !== perPage.value) perPage.value = next
}
// ---- 卡片底部「最近运行」:取账号运行历史(新的在前),每个场景只留最近一条 ----
const lastRunMap = ref({})
async function loadRuns() {
try {
const r = await fetchRuns(100)
const m = {}
// 列表已按时间倒序:首次出现即该场景的最近一次运行
for (const it of (r.runs || [])) {
if (!it || !it.plugin_id || m[it.plugin_id]) continue
m[it.plugin_id] = fmtDayTime(it.finished || it.started, '')
}
lastRunMap.value = m
} catch (_) { /* 后端未就绪:静默,卡片显示「尚未运行」 */ }
}
// 本次会话内有运行结束 → 补刷一次(run_done 会往 store.recents 头部追加)
watch(() => store.recents.length, () => { loadRuns() })
// 切换账号:先清空(避免显示上一账号的运行时间)再按新账号拉取
watch(() => store.current, () => { lastRunMap.value = {}; loadRuns() })
onMounted(() => {
recomputePerPage()
loadRuns()
if (typeof ResizeObserver !== 'undefined' && gridEl.value) {
ro = new ResizeObserver(() => recomputePerPage())
ro.observe(gridEl.value)
@@ -111,8 +149,20 @@ const filtered = computed(() => {
(p.id || '').toLowerCase().includes(kw)
})
})
const pagedList = computed(() =>
filtered.value.slice((page.value - 1) * perPage.value, page.value * perPage.value))
const totalPages = computed(() => Math.max(1, Math.ceil(filtered.value.length / perPage.value)))
const pagedList = computed(() => {
const start = (page.value - 1) * perPage.value
return filtered.value.slice(start, start + perPage.value)
})
// 页码:总页数多时只显示当前页前后各 2 个,避免按钮溢出
const pageList = computed(() => {
const total = totalPages.value
if (total <= 5) return Array.from({ length: total }, (_, i) => i + 1)
let start = Math.max(1, page.value - 2)
const end = Math.min(total, start + 4)
start = Math.max(1, end - 4)
return Array.from({ length: end - start + 1 }, (_, i) => start + i)
})
// 分类 chips(含数量):按数量降序,未分类归「其他」;首项「全部」
const cats = computed(() => {
@@ -126,7 +176,7 @@ const cats = computed(() => {
.sort((a, b) => b.n - a.n || a.key.localeCompare(b.key, 'zh'))
})
const catTabs = computed(() => [
{ key: '', label: '全部', n: store.plugins.length },
{ key: '', label: '全部场景', n: store.plugins.length },
...cats.value.map((c) => ({ key: c.key, label: c.key, n: c.n })),
])
@@ -139,11 +189,11 @@ function pickCat(key) {
function onFilter() { page.value = 1 }
// 同步/撤销授权、或窗口缩放导致每页数量变化后,当前页可能超界,自动回退
function clampPage() {
const max = Math.max(1, Math.ceil(filtered.value.length / perPage.value))
if (page.value > max) page.value = max
if (page.value > totalPages.value) page.value = totalPages.value
}
watch(() => store.plugins.length, clampPage)
watch(perPage, clampPage)
watch(filtered, clampPage)
function open(id) {
store.selectedId = id
@@ -153,49 +203,102 @@ function open(id) {
</script>
<style scoped>
.scenes-page { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--page-pad); flex-shrink: 0; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
/* 直接铺在中栏上(.main.plain 已提供白底),不再套第二层面板 */
.scenes-page {
flex: 1; min-height: 0;
display: flex; flex-direction: column;
padding: 22px 24px 12px;
}
/* ---------- 标题区 ---------- */
.lib-head { flex-shrink: 0; padding-bottom: var(--space-2); }
.lib-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-3); }
.lib-title-group { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.lib-title { margin: 0; font: 700 24px/32px var(--f-cn); color: var(--t1); letter-spacing: -.3px; }
.lib-sub { margin: 0; font: 400 12px/17px var(--f-cn); color: var(--t3); }
.lib-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; padding-bottom: 2px; }
/* ---------- 工具栏:Tab + 搜索 ---------- */
.lib-toolbar {
flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
gap: var(--space-3); margin: 14px 0 16px;
}
.cat-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1-5); min-width: 0; }
.chip {
display: inline-flex; align-items: center; gap: var(--space-1-5);
height: 28px; padding: 0 var(--space-3);
border: 1px solid transparent; border-radius: var(--r-pill);
background: transparent; color: var(--t3); cursor: pointer;
font: 500 12px/1 var(--f-cn);
transition: background var(--dur), border-color var(--dur), color var(--dur);
}
.chip:hover { background: var(--field); color: var(--t1); }
.chip.on { background: var(--brand-soft); border-color: var(--brand-track); color: var(--brand-ink); }
.chip-name { white-space: nowrap; }
.chip-n { font: 500 10px/1 var(--f-num); color: var(--t4); }
.chip.on .chip-n { color: var(--brand); }
/* ---------- 头部工具条(在 PageHead 的 actions 内) ---------- */
.search {
height: 32px; display: flex; align-items: center; gap: var(--space-2);
padding: 0 var(--space-2-5); border-radius: var(--r-field);
background: var(--surface); border: 1px solid var(--line);
flex-shrink: 0; width: 232px; height: 32px;
display: flex; align-items: center; gap: var(--space-2);
padding: 0 var(--space-3); border-radius: var(--r-field);
background: var(--field); border: 1px solid var(--line);
transition: background var(--dur), border-color var(--dur);
}
.search:focus-within { background: var(--surface); border-color: var(--brand-track); }
.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); }
.tool-search { width: 200px; }
.dim { font-size: 11px; color: var(--t4); }
/* ---------- 分类 chips ---------- */
.cat-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1-5); }
.chip {
display: inline-flex; align-items: center; gap: var(--space-1-5);
height: 26px; padding: 0 var(--space-2-5);
border: 1px solid var(--line); border-radius: var(--r-pill);
background: var(--surface); color: var(--t2); cursor: pointer;
font: 500 11.5px/1 var(--f-cn);
transition: background var(--dur), border-color var(--dur), color var(--dur);
.search svg { flex: 0 0 14px; color: var(--t4); }
.search input {
flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
font: 400 12px/16px var(--f-cn); color: var(--t1);
}
.chip:hover { border-color: var(--border-hover); color: var(--t1); }
.chip.on { background: var(--brand-soft); border-color: var(--brand-track); color: var(--brand-ink); }
.chip-n { font: 500 10.5px/1 var(--f-num); color: var(--t4); }
.chip.on .chip-n { color: var(--brand); }
.search input::placeholder { color: var(--t4); }
/* ---------- 卡片网格(卡片本身为 SceneCard 共享) ---------- */
.sc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-4); }
/* ---------- 卡片网格:三列,行高固定;行数由可用高度算,一页装得下就不出现滚动 ---------- */
.sc-grid {
flex: 1; min-height: 0; align-content: start;
display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
grid-auto-rows: 216px; gap: var(--space-4);
}
/* ---------- 空态 ---------- */
.sc-empty {
grid-column: 1 / -1;
display: flex; flex-direction: column; align-items: center; gap: var(--space-1);
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1);
padding: var(--space-6) var(--space-5); color: var(--t4); font-size: 12px;
background: var(--surface); border: 1px dashed var(--line);
border-radius: var(--r-card);
background: var(--subtle); border: 1px dashed var(--line);
border-radius: var(--r-sub);
}
.sc-empty b { color: var(--t2); font-size: 13px; font-weight: 600; }
.sc-pager { justify-content: center; padding: var(--space-1) 0 var(--space-2); }
/* ---------- 底部:计数 + 翻页 ---------- */
.lib-foot {
flex-shrink: 0; margin-top: auto; padding-top: var(--space-4);
border-top: 1px solid var(--line-soft);
display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.lib-total { font: 400 12px/1 var(--f-cn); color: var(--t3); }
.lib-total b { font-family: var(--f-num); font-weight: 600; color: var(--t1); }
.pager { display: flex; align-items: center; gap: var(--space-1); }
.pg-btn {
height: 28px; padding: 0 var(--space-3);
border: 1px solid var(--line-btn); border-radius: var(--r-row);
background: var(--surface); color: var(--t2); cursor: pointer;
font: 500 12px/1 var(--f-cn);
transition: background var(--dur), border-color var(--dur), color var(--dur);
}
.pg-btn:hover:not(:disabled) { background: var(--field); color: var(--t1); }
.pg-btn:disabled { opacity: .5; cursor: not-allowed; }
.pg-num {
width: 28px; height: 28px; padding: 0;
display: grid; place-items: center;
border: 1px solid var(--line-btn); border-radius: var(--r-row);
background: var(--surface); color: var(--t2); cursor: pointer;
font: 500 12px/1 var(--f-num);
transition: background var(--dur), border-color var(--dur), color var(--dur);
}
.pg-num:hover { background: var(--field); color: var(--t1); }
.pg-num.on {
background: var(--brand); border-color: var(--brand); color: var(--on-primary);
box-shadow: var(--sh-brand-sm);
}
</style>
@@ -1,86 +1,127 @@
<template>
<div class="sched-page">
<PageHead eyebrow="SCHEDULE · 计划" title="定时任务" sub="客户端内置定时:场景与流程都能按 cron 到点自动执行,场景任务的配置会自动备份到中心机">
<template #actions>
<el-button type="primary" :icon="Plus" @click="openCreate">新建任务</el-button>
</template>
</PageHead>
<!-- 本周分布:按每周几聚合启用中的任务 -->
<section v-if="list.length" class="card week-card">
<div class="wc-head">
<div class="wc-titles">
<span class="sec-eyebrow">WEEK</span>
<b class="wc-title">本周分布</b>
</div>
<span class="wc-note">启用中 {{ enabledCount }} / {{ list.length }} 个任务</span>
<!-- 页头:统计概览 + 批量/新建入口 -->
<header class="pg-head">
<div class="pg-titles">
<span class="pg-crumb">计划</span>
<h1 class="pg-title">计划任务</h1>
<p class="pg-sub">
<b class="on">{{ statActive }}</b> 个启用 ·
<b>{{ statPaused }}</b> 个暂停 ·
下次执行 {{ statNext }} ·
平均用时 {{ statAvg }}
</p>
</div>
<div class="wc-bars">
<div v-for="(d, i) in weekDist" :key="i" class="wc-col">
<span class="wc-n">{{ d.n || '' }}</span>
<div class="wc-track"><i class="wc-bar" :style="{ height: barH(d.n) }"></i></div>
<span class="wc-label" :class="{ today: i === todayIdx }">{{ d.label }}</span>
<div class="pg-actions">
<button class="btn-ghost" :disabled="!statActive || pausingAll" @click="pauseAll">暂停全部</button>
<el-button type="primary" :icon="Plus" @click="openCreate">新建计划</el-button>
</div>
</header>
<!-- 本周运行分布:按本机运行记录聚合(周一起) -->
<section v-if="list.length" class="week">
<div class="week-head">
<h2>本周运行分布</h2>
<span class="week-note">共 {{ weekTotal }} 次 · 峰值 {{ peakText }}</span>
</div>
<div class="week-bars">
<div v-for="(d, i) in weekChart" :key="i" class="wb-col">
<div class="wb-slot">
<i class="wb-bar" :class="{ today: d.isToday, empty: !d.count }" :style="{ height: barH(d.count) }">
<span v-if="d.count" class="wb-tip">{{ d.count }} 次</span>
</i>
</div>
<span class="wb-label" :class="{ today: d.isToday }">{{ d.label }}</span>
</div>
</div>
</section>
<el-empty v-if="!list.length" description="暂无定时任务,点击右上角「新建任务」创建" />
<!-- 时间队列:按下次执行时间组织的任务行 -->
<div v-else class="sched-wrap">
<div class="sec-head">
<div class="wc-titles">
<span class="sec-eyebrow">QUEUE</span>
<b class="wc-title">时间队列</b>
</div>
<span class="head-note">共 {{ list.length }} 个任务</span>
<!-- 计划表:卡片容器(与总览「最近运行场景」同一套表格样式) -->
<section class="tbl-card">
<div class="tbl-head">
<h2>计划列表</h2>
<span class="tbl-stat">启用 {{ statActive }} · 暂停 {{ statPaused }}</span>
</div>
<div class="sched-list card">
<div v-for="row in pagedList" :key="row.id" class="sched-row" :class="{ off: !row.enabled }">
<div class="sr-when" :class="{ today: nextWhen(row).today }">
<b>{{ nextWhen(row).main }}</b>
<span>{{ nextWhen(row).sub }}</span>
</div>
<div class="sr-main">
<b>
<span class="kind-pill" :class="row.kind">{{ row.kind === 'flow' ? '流程' : '场景' }}</span>
{{ row.name }}<em v-if="!row.enabled" class="off-pill">停用</em>
</b>
<span v-if="row.kind === 'flow'">{{ row.node_count }} 个节点 · 按依赖串行执行</span>
<span v-else>{{ pluginName(row.plugin_id) }}</span>
</div>
<code class="cron-chip">{{ row.cron }}</code>
<div class="sr-last">
<!-- 队列态优先:本次触发的运行还排在队列里时,比"上次成功 · 3 天前"更有信息量 -->
<template v-if="queueState(row)">
<span class="st-pill mid">
<i class="dot"></i>{{ queueState(row).text }}
</span>
<span class="sr-last-time">{{ queueState(row).sub }}</span>
</template>
<template v-else-if="row.last_run_at">
<span class="st-pill" :class="row.last_status === 'ok' ? 'ok' : (row.last_status === 'error' ? 'err' : 'mid')">
<i class="dot"></i>
<template v-if="row.last_status === 'ok'">成功<template v-if="row.last_duration"> · {{ row.last_duration }}s</template></template>
<template v-else-if="row.last_status === 'error'">失败</template>
<template v-else>执行中</template>
</span>
<span class="sr-last-time">上次 {{ fmtShort(row.last_run_at) }}</span>
</template>
<span v-else class="st-pill none"><i class="dot"></i>从未执行</span>
</div>
<div class="sr-acts">
<el-switch :model-value="row.enabled" size="small" @change="(v) => onToggle(row, v)" />
<el-button v-if="row.kind === 'flow'" link type="primary" @click="onRunFlow(row)">运行</el-button>
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
<el-button link type="danger" @click="onDelete(row)">删除</el-button>
</div>
<div class="tbl-body">
<table v-if="list.length" class="tbl">
<!-- 用比例分配列宽:窗口变窄时各列等比收缩,「场景」列不会被挤到 0 与「频率」贴在一起 -->
<colgroup>
<col style="width: 8%" />
<col style="width: 7%" />
<col style="width: 15%" />
<col style="width: 23%" />
<col style="width: 12%" />
<col style="width: 12%" />
<col style="width: 9%" />
<col style="width: 14%" />
</colgroup>
<thead>
<tr>
<th>时间</th>
<th>类型</th>
<th>频率</th>
<th class="c-scene">场景</th>
<th>上次结果</th>
<th>下次执行</th>
<th class="c-state">状态</th>
<th class="c-acts">操作</th>
</tr>
</thead>
<tbody>
<tr v-for="row in pagedList" :key="row.id" :class="{ off: !row.enabled }">
<td class="c-time" :class="{ sm: row.cols.timeText, today: row.enabled && nextWhen(row).today }">{{ row.cols.time }}</td>
<td class="c-type">
<span class="kind-pill" :class="row.kind">{{ row.kind === 'flow' ? '流程' : '场景' }}</span>
</td>
<td class="c-freq">
<code v-if="row.cols.freqCron" class="cron-chip" :title="row.cron">{{ row.cols.freq }}</code>
<template v-else>{{ row.cols.freq }}</template>
</td>
<!-- 名称单行显示,补充说明(节点数/插件名)收进 i 里 -->
<td class="c-scene">
<span class="name-wrap">
<b class="nm">{{ row.name }}</b>
<el-tooltip :content="row.kind === 'flow' ? `${row.node_count} 个节点 · 按依赖串行执行` : pluginName(row.plugin_id)" placement="top">
<i class="info-dot">i</i>
</el-tooltip>
</span>
</td>
<!-- 队列态优先:本次触发的运行还排在队列里时,比"上次成功"更有信息量 -->
<td class="c-res">
<span v-if="queueState(row)" class="res-live">{{ queueState(row).text }}</span>
<span v-else-if="row.last_run_at"
:class="row.last_status === 'ok' ? 'res-ok' : (row.last_status === 'error' ? 'res-bad' : 'res-live')"
:title="'上次执行 ' + fmtShort(row.last_run_at)">
{{ row.last_status === 'ok' ? '成功' : (row.last_status === 'error' ? '失败' : '执行中') }}<i v-if="row.last_duration"> · {{ fmtDur(row.last_duration) }}</i>
</span>
<span v-else class="res-idle">从未执行</span>
</td>
<td class="c-next" :class="{ muted: !row.enabled, today: row.enabled && nextWhen(row).today }">
{{ row.enabled ? nextWhen(row).main : '暂停中' }}
</td>
<td class="c-state">
<button type="button" class="state-btn" :class="row.enabled ? 'on' : 'off'"
:title="row.enabled ? '点击暂停该计划' : '点击恢复执行'" @click="onToggle(row, !row.enabled)">
<i></i>{{ row.enabled ? '启用' : '暂停' }}
</button>
</td>
<td class="c-acts">
<el-button v-if="row.kind === 'flow'" link type="primary" @click="onRunFlow(row)">运行</el-button>
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
<el-button link type="danger" @click="onDelete(row)">删除</el-button>
</td>
</tr>
</tbody>
</table>
<div v-else class="tbl-empty">暂无定时任务,点击右上角「新建计划」创建</div>
</div>
</div>
<el-pagination v-if="list.length > pageSize" class="sched-pager" size="small" background
layout="total, prev, pager, next" :total="list.length" :page-size="pageSize"
:current-page="page" @current-change="(p) => page = p" />
</div>
<footer class="pg-foot">
<span>共 {{ list.length }} 个计划 · 调度器每 30 秒轮询一次</span>
<el-pagination v-if="list.length > pageSize" size="small" layout="prev, pager, next"
:total="list.length" :page-size="pageSize" :current-page="page"
@current-change="(p) => page = p" />
</footer>
</section>
<el-dialog v-model="dlg" :title="editing ? '编辑定时任务' : '新建定时任务'" width="min(780px, 94vw)" align-center
class="sched-dlg">
@@ -198,12 +239,11 @@ import { computed, ref, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import { store } from '../store'
import PageHead from './PageHead.vue'
import {
listSchedules, createSchedule, updateSchedule, deleteSchedule, toggleSchedule,
listPluginConfigs, listFlows, updateFlow, runFlow,
listPluginConfigs, listFlows, updateFlow, runFlow, fetchRuns,
} from '../api'
import { fmtShort } from '../utils/format'
import { fmtShort, durText } from '../utils/format'
const list = ref([])
// 计划页是"通用定时"入口:场景(插件)与流程(编排)都能在这里排期
@@ -245,30 +285,105 @@ watch(() => list.value.length, (n) => {
if (page.value > max) page.value = max
})
// ---- 本周分布:按每周几聚合启用中的任务(cron 第5段 dow;dom 固定日的任务不计入周分布) ----
const enabledCount = computed(() => list.value.filter((r) => r.enabled).length)
const todayIdx = computed(() => (new Date().getDay() + 6) % 7) // 周一=0
const weekDist = computed(() => {
const labels = ['一', '二', '三', '四', '五', '六', '日']
const counts = Array(7).fill(0)
for (const r of list.value) {
if (!r.enabled) continue
const parts = String(r.cron || '').trim().split(/\s+/)
if (parts.length !== 5) continue
const [dom, , dow] = [parts[2], parts[3], parts[4]]
if (dom !== '*') continue // 每月固定日:不落到本周分布
if (dow === '*') { for (let i = 0; i < 7; i++) counts[i] += 1; continue } // 每天/每隔N小时
for (const seg of dow.split(',')) {
const mm = seg.match(/^(\d+)(?:-(\d+))?$/)
if (mm) {
const a = +mm[1], b = mm[2] ? +mm[2] : a
for (let x = a; x <= b; x++) { const i = x === 0 ? 6 : x - 1; if (i >= 0 && i < 7) counts[i] += 1 }
}
}
// ---- 页头统计:启用 / 暂停 / 下次执行 / 平均用时 ----
const statActive = computed(() => list.value.filter((r) => r.enabled).length)
const statPaused = computed(() => list.value.length - statActive.value)
// ---- 本周运行分布:按本机运行记录聚合(周一为起点),不是"任务配置了几次" ----
const weekRuns = ref([])
const WD = ['一', '二', '三', '四', '五', '六', '日']
async function loadRuns() {
try {
const r = await fetchRuns(200)
// 取消/中断不算一次真实运行
weekRuns.value = (r.runs || []).filter((x) => x.started && x.status !== 'cancelled' && x.status !== 'interrupted')
} catch (_) { weekRuns.value = [] }
}
const weekChart = computed(() => {
const now = new Date()
const dow = (now.getDay() + 6) % 7 // 周一=0
const monday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - dow)
const days = []
for (let i = 0; i < 7; i++) {
const d = new Date(monday)
d.setDate(monday.getDate() + i)
days.push({
key: `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`,
label: i === dow ? `今天 ${d.getDate()}` : `周${WD[i]} ${d.getDate()}`,
count: 0,
isToday: i === dow,
})
}
return labels.map((label, i) => ({ label, n: counts[i] }))
const keyOf = (sec) => {
const d = new Date(sec * 1000)
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`
}
for (const r of weekRuns.value) {
const d = days.find((x) => x.key === keyOf(r.started))
if (d) d.count++
}
return days
})
function barH(n) { return n ? Math.max(14, Math.round((n / Math.max(1, Math.max(...weekDist.value.map((d) => d.n)))) * 46)) + 'px' : '3px' }
const weekTotal = computed(() => weekChart.value.reduce((s, d) => s + d.count, 0))
const peakText = computed(() => {
const max = Math.max(0, ...weekChart.value.map((d) => d.count))
if (!max) return '—'
const day = weekChart.value.find((d) => d.count === max)
return `${day.isToday ? '今天' : day.label.slice(0, 2)} ${max} 次`
})
function barH(n) {
const max = Math.max(1, ...weekChart.value.map((d) => d.count))
return n ? Math.max(10, Math.round((n / max) * 72)) + 'px' : '4px'
}
const statNext = computed(() => {
const ns = list.value.filter((r) => r.enabled && r.next_run_at).map((r) => String(r.next_run_at)).sort()
if (!ns.length) return '—'
const d = new Date(ns[0].replace(' ', 'T'))
if (isNaN(d.getTime())) return ns[0]
const now = new Date()
const t0 = new Date(now.getFullYear(), now.getMonth(), now.getDate())
const diff = Math.round((new Date(d.getFullYear(), d.getMonth(), d.getDate()) - t0) / 86400000)
const hm = pad2(d.getHours()) + ':' + pad2(d.getMinutes())
if (diff === 0) return `今天 ${hm}`
if (diff === 1) return `明天 ${hm}`
return `${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${hm}`
})
const statAvg = computed(() => {
const done = weekRuns.value.filter((r) => (r.duration_sec || 0) > 0)
if (!done.length) return '—'
const avg = done.reduce((s, r) => s + r.duration_sec, 0) / done.length
return durText(Math.round(avg))
})
// ---- 暂停全部:逐个关掉启用中的计划(流程的定时挂在流程记录上,走 updateFlow)----
const pausingAll = ref(false)
async function pauseAll() {
const targets = list.value.filter((r) => r.enabled)
if (!targets.length) return
try {
await ElMessageBox.confirm(
`确定暂停全部 ${targets.length} 个启用中的计划?之后可在列表中逐个恢复。`,
'暂停全部',
{ type: 'warning', confirmButtonText: '全部暂停', cancelButtonText: '取消' }
)
} catch (_) { return }
pausingAll.value = true
try {
for (const r of targets) {
if (r.kind === 'flow') await updateFlow(r.flow_id, { schedule: { enabled: false, cron: r.cron } })
else await toggleSchedule(r.id, false)
}
ElMessage.success(`已暂停 ${targets.length} 个计划`)
await load()
} catch (e) {
ElMessage.error('操作失败:' + (e.message || e))
} finally {
pausingAll.value = false
}
}
// ---- 闹钟式触发时间选择状态 ----
// freq: daily=每天 weekdays=工作日 weekly=每周 monthly=每月 hourly=每隔N小时 advanced=高级cron
@@ -338,6 +453,38 @@ function syncCron() {
if (freq.value !== 'advanced') form.value.cron = buildCron()
}
// ---- 表格列派生:cron → 时间/频率两列的人话展示 ----
const WEEK_CN = ['一', '二', '三', '四', '五', '六', '日']
function rowCols(row) {
const st = cronToState(row.cron)
const parts = String(row.cron || '').trim().split(/\s+/)
const isNum = (x) => /^\d+$/.test(x || '')
// timeText=true 表示时间列不是时分钟点(如"整点"),用中文字体展示
let time = '—', timeText = false, freq = '自定义', freqCron = false
switch (st.freq) {
case 'daily': time = st.timeStr; freq = '每天'; break
case 'weekdays': time = st.timeStr; freq = '工作日'; break
case 'weekly': time = st.timeStr; freq = '每周' + st.weekdays.map((d) => WEEK_CN[d - 1]).join('、'); break
case 'monthly': time = st.timeStr; freq = `每月 ${st.monthDay} 号`; break
case 'hourly': time = '整点'; timeText = true; freq = st.hourlyStep > 1 ? `每隔 ${st.hourlyStep} 小时` : '每小时'; break
default:
// 高级 cron:频率列直接给原始表达式;能取出固定时分时时间列照常显示
if (parts.length === 5 && parts[0] === '0' && parts.slice(1).join(' ') === '* * * *') {
time = '整点'; timeText = true; freq = '每小时' // 每小时整点(0 * * * *)反解不进 hourly
} else {
freq = row.cron; freqCron = true
if (parts.length === 5 && isNum(parts[0]) && isNum(parts[1])) time = pad2(+parts[1]) + ':' + pad2(+parts[0])
}
}
return { time, timeText, freq, freqCron }
}
// 上次耗时:秒 → mm:ss(与设计稿"成功 · 02:14"一致)
function fmtDur(sec) {
const s = parseInt(sec, 10) || 0
return pad2(Math.floor(s / 60)) + ':' + pad2(s % 60)
}
// 选择状态变化时自动重写 form.cron
watch([freq, timeStr, weekdays, monthDay, hourlyStep], syncCron)
watch(advancedCron, (v) => {
@@ -429,11 +576,13 @@ async function load() {
next_run_at: f.next_run_at || '',
node_count: (f.nodes || []).length,
}))
// 启用中的按下次触发时间靠前,停用的沉底
list.value = [...taskRows, ...flowRows].sort((a, b) => {
if (!!a.enabled !== !!b.enabled) return a.enabled ? -1 : 1
return String(a.next_run_at || '9999').localeCompare(String(b.next_run_at || '9999'))
})
// 启用中的按下次触发时间靠前,停用的沉底;并预派生时间/频率两列的展示
list.value = [...taskRows, ...flowRows]
.map((r) => ({ ...r, cols: rowCols(r) }))
.sort((a, b) => {
if (!!a.enabled !== !!b.enabled) return a.enabled ? -1 : 1
return String(a.next_run_at || '9999').localeCompare(String(b.next_run_at || '9999'))
})
} catch (e) {
ElMessage.error('加载定时任务失败:' + (e.message || e))
}
@@ -484,6 +633,8 @@ function openEdit(row) {
}
async function onSave() {
const nm = (form.value.name || '').trim()
if (!nm) { ElMessage.warning('请填写任务名称'); return }
if (target.value === 'flow') {
if (!flowId.value) { ElMessage.warning('请选择要定时执行的流程'); return }
} else if (!form.value.plugin_id) {
@@ -494,8 +645,10 @@ async function onSave() {
saving.value = true
try {
if (target.value === 'flow') {
// 流程的定时保存在流程自己身上(flows.json),与流程编辑器里的开关是同一份数据
// 流程的定时保存在流程自己身上(flows.json),与流程编辑器里的开关是同一份数据。
// ⚠️ 名称就是流程名:改名必须一起提交,否则只写了 schedule,名字改了也不生效
await updateFlow(flowId.value, {
name: nm,
schedule: { enabled: !!form.value.enabled, cron: form.value.cron },
})
ElMessage.success(editing.value ? '已保存' : '已创建')
@@ -571,92 +724,197 @@ async function onRunFlow(row) {
}
load()
loadRuns()
</script>
<style scoped>
.sched-page {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
gap: var(--space-4);
padding: var(--page-pad);
flex-shrink: 0; /* 自然高度,超出由中栏上下文区整体滚动 */
flex-direction: column; /* 页头/图表/底栏固定,中间表格区自己滚 */
}
/* ---------- 本周分布 ---------- */
.week-card {
padding-bottom: var(--space-3);
background: linear-gradient(160deg, var(--brand-soft-2) 0%, var(--surface) 62%);
border-color: var(--brand-track);
/* ---------- 页头 ---------- */
.pg-head {
flex-shrink: 0; display: flex; align-items: flex-end; justify-content: space-between;
gap: var(--space-4); padding: 20px 24px;
border-bottom: 1px solid var(--line);
}
.wc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4) 0; }
.wc-titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wc-title { font: 600 14px/20px var(--f-cn); color: var(--t1); }
.wc-note { font: 400 10.5px/15px var(--f-num); color: var(--t4); }
.head-note { font: 400 10.5px/15px var(--f-num); color: var(--t4); }
.sec-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-3); padding: 0 var(--space-1); }
.wc-bars { display: flex; gap: var(--space-1-5); padding: var(--space-3) var(--space-4) 0; }
.wc-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: var(--space-1); min-width: 0; }
.wc-n { font: 500 10px/13px var(--f-num); color: var(--t3); min-height: 13px; }
.wc-track { width: 100%; max-width: 44px; height: 56px; display: flex; align-items: flex-end; justify-content: center; background: var(--field); border-radius: var(--r-row); overflow: hidden; }
.wc-bar { width: 60%; border-radius: var(--space-1) var(--space-1) 0 0; background: var(--brand); transition: height .3s var(--ease); }
.wc-label { font: 400 10px/14px var(--f-cn); color: var(--t4); }
.wc-label.today { color: var(--brand-ink); font-weight: 600; }
.pg-titles { display: flex; flex-direction: column; min-width: 0; }
.pg-crumb { font: 400 12px/16px var(--f-cn); color: var(--t4); margin-bottom: 6px; }
.pg-title { margin: 0 0 4px; font: 700 24px/32px var(--f-cn); color: var(--t1); letter-spacing: -.3px; }
.pg-sub { margin: 0; font: 400 12px/17px var(--f-cn); color: var(--t3); }
.pg-sub b { font-family: var(--f-num); font-weight: 600; color: var(--t1); }
.pg-sub b.on { color: var(--brand); }
.pg-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.btn-ghost {
height: 32px; padding: 0 var(--space-3);
border: 1px solid var(--line-btn); border-radius: var(--r-row);
background: var(--surface); color: var(--t2); cursor: pointer;
font: 500 12.5px/1 var(--f-cn);
transition: background var(--dur), color var(--dur);
}
.btn-ghost:hover:not(:disabled) { background: var(--field); color: var(--t1); }
.btn-ghost:disabled { opacity: .5; cursor: not-allowed; }
/* ---------- 时间队列列表 ---------- */
.sched-wrap { display: flex; flex-direction: column; gap: var(--space-2-5); }
.sched-list { display: flex; flex-direction: column; overflow: hidden; }
.sched-row {
display: flex; align-items: center; gap: var(--space-3);
padding: var(--space-3) var(--space-4);
/* ---------- 本周运行分布 ---------- */
.week { flex-shrink: 0; padding: 16px 24px 14px; border-bottom: 1px solid var(--line-soft); }
.week-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: 12px; }
.week-head h2 { margin: 0; font: 600 13.5px/20px var(--f-cn); color: var(--t1); }
.week-note { font: 400 11px/16px var(--f-num); color: var(--t4); }
.week-bars { display: flex; align-items: flex-end; gap: 8px; height: 98px; padding: 0 4px; }
.wb-col {
flex: 1; height: 100%; min-width: 0;
display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px;
}
.wb-slot { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.wb-bar {
position: relative; width: 32px; max-width: 62%;
border-radius: 6px 6px 0 0; background: var(--field);
transition: height .3s var(--ease), background var(--dur), opacity var(--dur);
}
.wb-bar.today { background: var(--brand); }
.wb-bar:not(.empty):hover { opacity: .85; }
.wb-tip {
position: absolute; left: 50%; top: -26px; transform: translateX(-50%);
padding: 1px 6px; border-radius: 4px; white-space: nowrap;
background: var(--t1); color: var(--on-primary); font: 500 10px/16px var(--f-num);
opacity: 0; pointer-events: none; transition: opacity var(--dur);
}
.wb-bar:hover .wb-tip { opacity: 1; }
.wb-label { font: 400 11px/14px var(--f-cn); color: var(--t4); white-space: nowrap; }
.wb-label.today { color: var(--brand); font-weight: 700; }
/* ---------- 计划表:卡片容器 + 表格(同总览「最近运行场景」) ---------- */
.tbl-card {
flex: 1; min-height: 0; margin: 14px 24px 14px;
display: flex; flex-direction: column;
background: var(--surface); border: 1px solid var(--line);
border-radius: var(--r-sub); overflow: hidden;
}
.tbl-head {
flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
gap: var(--space-3); padding: 12px 16px;
border-bottom: 1px solid var(--line); background: var(--subtle);
}
.tbl-head h2 { margin: 0; font: 600 13.5px/20px var(--f-cn); color: var(--t1); }
.tbl-stat { font: 400 11.5px/16px var(--f-num); color: var(--t4); }
.tbl-body { flex: 1; min-height: 0; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; table-layout: fixed; }
.tbl th {
position: sticky; top: 0; z-index: 1;
padding: 10px 16px; text-align: center;
font: 500 11px/16px var(--f-cn); color: var(--t3);
background: var(--surface); border-bottom: 1px solid var(--line);
}
.tbl td {
padding: 10px 16px; text-align: center;
border-bottom: 1px solid var(--line-soft);
transition: background var(--dur);
font: 400 12px/18px var(--f-cn); color: var(--t2);
}
.sched-row:last-child { border-bottom: none; }
.sched-row:hover { background: var(--field); }
.sr-when { width: 112px; flex-shrink: 0; }
.sr-when b { display: block; font: 700 14px/18px var(--f-num); color: var(--t1); }
.sr-when.today b { color: var(--brand-ink); }
.sr-when span { font: 400 10.5px/15px var(--f-num); color: var(--t4); }
.sr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.sr-main b { display: flex; align-items: center; gap: var(--space-1-5); font: 600 12.5px/18px var(--f-cn); color: var(--t1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-main span { font-size: 11px; color: var(--t4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-row.off .sr-when, .sched-row.off .sr-main span, .sched-row.off .cron-chip { opacity: .55; }
.tbl tbody tr { transition: background var(--dur); }
.tbl tbody tr:hover { background: var(--field); }
.tbl tbody tr:last-child td { border-bottom: 0; }
/* 场景名称长短不一:这一列(含表头)左对齐并再往右让一点,其余列居中 */
.tbl th.c-scene, .tbl td.c-scene { text-align: left; padding-left: 22px; }
/* 时间列:等宽数字,整点类用中文字体 */
.c-time { font: 700 14px/20px var(--f-num); color: var(--t1); font-variant-numeric: tabular-nums; }
.c-time.sm { font: 600 12.5px/20px var(--f-cn); }
.c-time.today { color: var(--brand); }
.c-freq {
color: var(--t3); min-width: 0;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 类型列(居中胶囊) / 场景列(名称单行 + i 提示) */
.c-type { text-align: center; }
.c-scene .name-wrap { display: flex; align-items: center; gap: 5px; min-width: 0; }
/* 与总览「最近运行场景」的场景名称完全同款:600 / 12px / t1 */
.c-scene .nm {
min-width: 0; font: 600 12px/18px var(--f-cn); color: var(--t1);
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.info-dot {
flex-shrink: 0; width: 13px; height: 13px; border-radius: 50%;
display: inline-grid; place-items: center; cursor: help;
border: 1px solid var(--line-btn); color: var(--t4);
font: 600 9px/1 var(--f-num); font-style: normal;
transition: color var(--dur), border-color var(--dur);
}
.info-dot:hover { color: var(--brand); border-color: var(--brand-track); }
/* 上次结果 / 下次执行 */
.c-res { white-space: nowrap; }
.res-ok { color: var(--good-ink); font-weight: 500; }
.res-bad { color: var(--danger-ink); font-weight: 500; }
.res-live { color: var(--brand-ink); font-weight: 500; }
.res-idle { color: var(--t4); }
.c-res i { font-style: normal; font-weight: 400; opacity: .78; }
.c-next { color: var(--t2); white-space: nowrap; }
.c-next.today { color: var(--brand-ink); font-weight: 600; }
.c-next.muted { color: var(--t4); }
/* 执行对象标签:场景 / 流程 */
.kind-pill {
flex-shrink: 0; font: 500 9.5px/15px var(--f-cn);
flex-shrink: 0; font: 500 9.5px/16px var(--f-cn);
color: var(--t3); background: var(--field);
border-radius: var(--r-pill); padding: 0 var(--space-1-5);
}
.kind-pill.flow { color: var(--brand-ink); background: var(--brand-soft); }
.off-pill {
flex-shrink: 0; font-style: normal; font: 500 10px/17px var(--f-cn);
color: var(--t3); background: var(--field);
border: 1px solid var(--line); border-radius: var(--r-pill);
padding: 0 var(--space-2);
}
/* 长 cron 表达式必须自己裁切,否则会顶出频率列、压到右边「场景」列上 */
.cron-chip {
flex-shrink: 0;
display: inline-block; max-width: 100%; box-sizing: border-box;
overflow: hidden; text-overflow: ellipsis; vertical-align: middle; white-space: nowrap;
font-family: var(--f-mono); font-size: 11px; color: var(--brand-ink);
background: var(--brand-soft); border: 1px solid var(--brand-track);
border-radius: var(--r-row); padding: 2px var(--space-2);
border-radius: var(--r-row); padding: 1px var(--space-1-5);
}
.sr-last { width: 150px; flex-shrink: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.st-pill {
display: inline-flex; align-items: center; gap: var(--space-1); width: fit-content;
padding: 1px var(--space-2); border-radius: var(--r-pill);
font: 600 10.5px/17px var(--f-cn);
background: var(--field); color: var(--t3);
border: 1px solid var(--line);
/* 暂停中的行压灰 */
.tbl tbody tr.off .c-time, .tbl tbody tr.off .c-freq, .tbl tbody tr.off .c-scene .nm { color: var(--t4); }
.tbl tbody tr.off .kind-pill { color: var(--t4); background: var(--field); }
.tbl tbody tr.off .cron-chip { opacity: .7; }
/* 行内操作:低饱和次级文字按钮,悬停点题 */
.c-acts :deep(.el-button) {
font-size: 11.5px; font-weight: 500; padding: 2px 4px;
margin-left: 0; color: var(--t3);
}
.c-acts :deep(.el-button + .el-button) { margin-left: 0; }
.c-acts :deep(.el-button--primary.is-link):hover { color: var(--brand-ink); }
.c-acts :deep(.el-button--danger.is-link):hover { color: var(--danger-ink); }
/* 状态胶囊:点击即暂停/恢复 */
.state-btn {
height: 22px; padding: 0 10px;
border: 1px solid transparent; border-radius: 6px; box-sizing: border-box;
display: inline-flex; align-items: center; justify-content: center; gap: 5px;
font: 500 11px/1 var(--f-cn); white-space: nowrap; cursor: pointer;
transition: filter var(--dur);
}
.state-btn:hover { filter: brightness(.97); }
.state-btn i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: 0 0 5px; }
.state-btn.on { background: var(--good-soft); color: var(--good-ink); border-color: var(--good-line); }
.state-btn.on i { background: var(--good); }
.state-btn.off { background: var(--field); color: var(--t3); border-color: var(--line); }
.state-btn.off i { background: var(--t5); }
.tbl-empty { padding: 48px 20px; text-align: center; font: 400 12px/20px var(--f-cn); color: var(--t4); }
/* 表尾(在卡片内,与总览表格一致) */
.pg-foot {
flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
gap: var(--space-3); padding: 10px 16px;
border-top: 1px solid var(--line);
font: 400 11.5px/16px var(--f-cn); color: var(--t4);
}
.pg-foot :deep(.el-pagination) {
--el-pagination-button-width: 24px;
--el-pagination-button-height: 24px;
--el-pagination-font-size: 11.5px;
}
.st-pill .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.st-pill.ok { color: var(--good-ink); background: var(--good-soft); border-color: transparent; }
.st-pill.err { color: var(--danger-ink); background: var(--danger-soft); border-color: transparent; }
.st-pill.mid { color: var(--brand-ink); background: var(--brand-soft); border-color: transparent; }
.st-pill.none { color: var(--t4); }
.sr-last-time { font: 400 10.5px/15px var(--f-num); color: var(--t4); }
.sr-acts { flex-shrink: 0; display: flex; align-items: center; gap: var(--space-2); }
.sr-acts .el-button + .el-button { margin-left: 0; }
.sched-pager { justify-content: center; }
.cron-row {
display: flex;
+27 -25
View File
@@ -50,6 +50,8 @@
--con-warn: #E8B15C;
--con-ok: #7FD1AD;
--con-live: #34D399;
--con-info: #8C9BFF; /* 暗色控制台:INFO 蓝 */
--con-err: #F0777C; /* 暗色控制台:ERROR 红 */
/* ---- 圆角 ---- */
--r-row: 8px;
@@ -361,50 +363,50 @@ select.input { padding-right: 30px; appearance: none; cursor: pointer;
.fade-leave-to { opacity: 0; }
/* 页头(对齐设计稿 .page-head 组):所有一级视图共用 PageHead 组件 */
/* 统一页头:白底一体化(不画卡片),页头下方一条分隔线,右侧操作对齐基线 */
.page-head {
display: flex;
align-items: flex-end;
gap: var(--space-3);
justify-content: space-between;
gap: var(--space-4);
flex: 0 0 auto;
padding: var(--space-4) var(--space-5);
background: linear-gradient(118deg, var(--brand-soft-2) 0%, var(--surface) 52%, var(--subtle) 100%);
border: 1px solid var(--brand-track);
border-radius: var(--r-card);
box-shadow: var(--sh-card);
padding: 20px 24px;
background: transparent;
border: 0;
border-bottom: 1px solid var(--line);
border-radius: 0;
box-shadow: none;
}
.page-title-group {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: var(--space-1);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: var(--space-1-5);
font: 600 9.5px/14px var(--f-num);
color: var(--brand);
letter-spacing: .14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--brand);
font: 400 12px/16px var(--f-cn);
color: var(--t4);
letter-spacing: 0;
text-transform: none;
margin-bottom: 6px;
}
.eyebrow::before { display: none; }
.page-title {
margin: 0;
font: 600 24px/32px var(--f-cn);
margin: 0 0 4px;
font: 700 24px/32px var(--f-cn);
color: var(--t1);
letter-spacing: -.2px;
letter-spacing: -.3px;
}
.page-sub {
margin: 0;
font: 400 11.5px/17px var(--f-cn);
font: 400 12px/17px var(--f-cn);
color: var(--t3);
/* 描述可能很长(插件 manifest 一整段):页头只留两行,全文走悬停/「详情」弹窗 */
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-word;
}
/* 分区英文小标(带圆点):各一级页面的分区标题复用 */
.sec-eyebrow {
@@ -18,6 +18,21 @@ export function fmtTime(ts, fallback = '—') {
return `${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`
}
// 时间戳(秒)→ 口语化相对日期:"今天 14:30" / "昨天 09:05" / "10-20 10:00"
// 场景库卡片底部、总览「最近运行场景」表格共用,口径一致
export function fmtDayTime(ts, fallback = '—') {
if (!ts) return fallback
const d = new Date(ts * 1000)
if (isNaN(d.getTime())) return fallback
const hm = `${pad2(d.getHours())}:${pad2(d.getMinutes())}`
const now = new Date()
const dayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime()
const t = d.getTime()
if (t >= dayStart) return `今天 ${hm}`
if (t >= dayStart - 86400000) return `昨天 ${hm}`
return `${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${hm}`
}
// 时间字符串(如后端 "2026-10-26 14:30:00")→ "10-26 14:30"
export function fmtShort(s) {
if (!s) return ''
@@ -34,6 +49,20 @@ export function durText(s) {
return m + '分' + (n % 60 ? pad2(n % 60) + 's' : '')
}
// 场景描述清洗:去掉与页头标题重复的「XQ0020 插件名:」前缀(各插件 manifest 里习惯这么写)
export function cleanDesc(desc) {
const s = String(desc || '').trim()
if (!s) return ''
return s.replace(/^XQ\d{3,4}[^::]{0,40}[::]\s*/i, '').trim()
}
// 描述拆句:manifest 的 description 常是一长串「;」句,详情弹窗按句分段更好读
export function splitDesc(desc) {
const s = cleanDesc(desc)
if (!s) return []
return s.split(/[;;]/).map((x) => x.trim()).filter(Boolean)
}
// 版本比较:数字段按 int(1.10.0 > 1.9.0),非数字段按小写字符串;对齐 electron/crypto.js 的 versionLt
export function versionLt(a, b) {
const key = (s) => String(s || '').split('.')
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "37du-electron-shell",
"productName": "37du 自动化工作台",
"version": "1.8.1",
"version": "1.9.3",
"description": "37du 执行机 Node/Electron 客户端(替代 Python webhost 底座,插件保持 Python 子进程执行)",
"main": "electron/main.js",
"private": true,