Files
37duAutomation/docs/插件/插件UI开发规范.md
puddy 9873eb1963 restore: 恢复 11-06~11-09 本地未提交改动
- libs: 新增 hr_sdk / hotel_report / dingtalk,更新 desktopauto
- controlplane-next: SDK 管理模块(controller/entity/migrations)与前端视图
- electron-shell: 插件同步、注册表、runner 调整
- plugins: XQ0035/XQ0041/XQ0042/XQ0045_XQ0046/XQ0048/XQ0076/XQ0078 等版本更新
- tests/tools: 新增 SDK 兼容性检查与打包工具(sdk_pack.py、sdk_compat_check.py)
2026-11-09 17:27:10 +08:00

858 lines
38 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 插件 UI 开发规范(v3.1 · 对齐壳子「白底面板 + 描边卡」新版样式)
> **v3 说明(2026-10)**:壳子中栏已统一为「白底面板 + 描边卡 + 浅灰卡头」的版面(总览 / 场景库 / 计划 / 流程 / 平台账号 / 运行台全部一致),
> 并且插件 iframe **取消了自己的外框**(无描边、无圆角)。插件 UI 因此必须跟着改:
> ① 左右内边距归零(24px 由壳子给);② 分区改为「描边卡 + 浅灰卡头」;③ 一律用壳子 token,禁止白卡叠白卡。
>
> 本文档为**当前唯一有效版本**;可直接复制的完整样式见 **§7 附录 style.css v3**。
> 参考实现已迁移到 v3:`plugins/XQ0001-0100/XQ0041 新美大平台核对/ui-src`
> (`.toolbar` 方案工具条 → `.sec` 分区卡 → `.actions` 操作区 → `.runline` 运行态,`ui/` 产物已重新构建)。
> 其余 v1 老插件按 §10 迁移。
## 1. 硬规则:要做 UI,否则插件根本跑不起来
当前壳子(`desktop/electron-shell/frontend/src/components/PluginPage.vue`):
```js
// 执行与参数配置收口在插件界面内(插件自包含前端+执行按钮),壳子不再提供参数表单与一键执行
const tabs = computed(() => {
const t = plugin.value?.ui ? [{ k: 'ui', label: '插件界面' }] : []
return [...t, { k: 'log', label: '运行日志' }, { k: 'history', label: '历史运行' }]
})
```
- `plugin.json.ui = true` → 多一个「插件界面」tab,界面在 iframe 里,**参数表单 + 执行按钮都在插件 UI 内**。
- `plugin.json.ui = false` → 只有「运行日志 / 历史运行」,**没有任何入口提交参数或触发执行**。
结论:
| 场景 | 形态 |
|---|---|
| 需要人工点「执行」(绝大多数) | **必须 `ui: true`** |
| 纯定时任务、参数永久固定、永不人工触发 | 可以 `ui: false`,但要知道代价:界面上无法手动跑一次 |
`plugin.json.fields` 仍然**必须完整声明**(JSON Schema):它是定时任务注入参数、后端校验、`/api/plugins/<id>/last-fields` 的依据,UI 只是它的可视化编辑器。
## 2. 技术栈(锁定)
| 依赖 | 版本 |
|---|---|
| vue | ^3.5.13 |
| element-plus | ^2.14.5 |
| @element-plus/icons-vue | ^2.3.2 |
| vite | ^6.0.3 |
| @vitejs/plugin-vue | ^5.2.1 |
`package.json` 保留 `"allowScripts": {"esbuild@0.25.12": true}`。构建产物自包含,运行期不加载任何 CDN。
## 3. 目录结构
```
plugins/<号段桶>/<插件目录>/
├── plugin.json # ui: true
├── ui-src/ # 源码(打包时排除)
│ ├── index.html # <title> = 插件中文名
│ ├── package.json # name = <id>-ui
│ ├── vite.config.js # base=/pui/<id>/、outDir=../ui、独立 dev 端口
│ └── src/
│ ├── main.js # createApp + ElementPlus + element-plus/dist/index.css → 再引入 style.css
│ ├── style.css # ★ 直接复制 §7 附录(token + --el-* 映射 + 版式类)
│ ├── api.js # 一行:export const PLUGIN_ID = '<id>'
│ ├── usePluginUI.js # ★ kit v2(vendored 副本,逻辑勿改)
│ └── App.vue # 插件差异:分区字段、DEFAULTS、validate、buildPayload
└── ui/ # 构建产物(勿手改,随包发布)
```
`main.js` 引入顺序不能反:
```js
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './style.css' // 必须在 element-plus 之后,才能覆盖 --el-* 变量
```
## 4. 视觉基线(与壳子一致)
### 4.1 三条硬约束
1. **不要画外框**:壳子的 `.pui-frame` 已取消描边/圆角(`border: 0`),中栏本身就是白底面板。
插件里再画一圈卡片边框 = 框套框,一律禁止。
2. **左右内边距归零**:壳子 `.page-body` 已经给了 `padding: 0 24px 18px`、iframe 容器再给了 `padding: 14px 0 0`。
插件根容器 `.page` **只能排垂直节奏**(`padding: 2px 0 20px`),不要再加左右 padding(否则 24 + 16 = 40 双缩进)。
3. **只用 token**:颜色/圆角/阴影/字体全部 `var(--xxx)`,不写字面色值;Element Plus 默认蓝一律禁止。
### 4.2 核心 token(插件 `style.css` 顶部照抄,完整版见 §7)
| 类别 | token |
|---|---|
| 画布 / 卡面 | `--canvas:#F2F4F8`、`--surface:#FFFFFF`、`--field:#F5F6FA`、`--subtle:#F7F8FC` |
| 描边 | `--line:#E8EAF1`、`--line-soft:#F0F2F7`、`--line-btn:#E3E6EF` |
| 文字五阶 | `--t1:#12141B`、`--t2:#3C4250`、`--t3:#6E7686`、`--t4:#A3AAB8`、`--t5:#C6CBD6` |
| 主色(靛蓝) | `--brand:#4F5AE8`、`--brand-ink:#3D47D4`、`--brand-soft:#EEF0FE`、`--brand-track:#DDE1F8`、`--brand-hover:#4550E0` |
| 语义色 | `--good:#0E9F76`/`--good-ink`/`--good-soft`/`--good-line`;`--warn:#D98218`/`--warn-ink`/`--warn-soft`/`--warn-line`;`--danger:#E5484D`/`--danger-ink`/`--danger-soft`/`--danger-line` |
| 圆角 | `--r-row:8px`、`--r-field:9px`、`--r-btn:10px`、`--r-sub:12px`、`--r-card:14px`、`--r-pill:999px` |
| 阴影 | `--sh-card`、`--sh-float`、`--sh-brand`、`--sh-brand-sm` |
| 字体 | `--f-cn`(PingFang/HarmonyOS/微软雅黑…)、`--f-num`(Inter/SF…)、`--f-mono` |
| 间距 | `--space-1:4px` … `--space-6:28px`(4/6/8/10/12/16/20/28) |
### 4.3 字号体系(与壳子同口径)
| 用途 | 规格 |
|---|---|
| 表单正文 / 表格单元格 | 12.5px / 12px,行高 18px |
| 说明文字(`.tip`、副标题) | 11.5px,`--t3` |
| 分区标题 / 卡片头标题 | 13px ~ 13.5px / 600 |
| 徽章、状态胶囊 | 11px / 500 |
| 数字(计数、百分比、时间) | `--f-num` + `font-variant-numeric: tabular-nums` |
| 页级大标题(24px) | **插件内不要用**——壳子 `PageHead` 已经渲染 |
## 5. 结构规范:只写「壳子没有的那部分」
壳子已经在插件页渲染了以下内容,**插件 UI 内不得重复**:
| 壳子已渲染 | 位置 |
|---|---|
| 插件名 + 版本 + 描述(小标/大标题/副标题) | `PageHead`(20/24 内边距 + 底部分隔线) |
| 平台登录态徽标、排队数、运行中 chip、版本回滚 | `PageHead` actions |
| 执行结果横幅(成功/失败/取消) | `PluginPage` `.banner` |
| 实时进度指示 | `RunIndicator` |
| 运行日志 / 历史运行 | 运行台 tab |
| iframe 容器(**无描边、无圆角、白底铺满**) | `.pui-frame` |
| 左右 24px、顶部 14px 的版面内边距 | `.page-body` + `.ui-pane` |
插件页面只保留五段(顺序固定):
```text
① 工具条 .toolbar **整组靠右**(首位一个 <span class="spacer" />,其余元素依次紧排),从左到右:
「已保存 HH:MM:SS」胶囊 → 方案下拉(当前配置 / 已存方案)→ 存为方案 → 删除;左侧留空
(方案供壳子「定时任务」按 config_id 引用,必须保留;不要把下拉和按钮拆到左右两端)
② 内联提示 .notice 仅两类:needLogin(未登录,不可关)/ 本次动作短提示(校验失败、已取消入队、执行结论一句话)
③ 参数分区 .sec 01/02/03…,每个分区 = 一张描边卡:
.sec-head(浅灰底:.sec-badge + .sec-name + .sec-line)+ .sec-body(.grid + .tip)
分区内部按内容挑组件,别一律用栅格表单:
· 互斥步骤(3~4 个选项)→ .step-cards 卡片单选,选项语义一眼可见
· 开关 / 联动下拉等少量设置 → .rows 行式设置项(标题+说明在左,控件在右)
④ 折叠说明 .help 大段流程说明收进 <details class="help">,默认收起;正文只留必要提示
⑤ 操作区 .actions 一键执行(running 时「执行中 N%」)+ 强制停止 + 恢复上次参数 + 保存配置 + 恢复默认
```
### 5.1 组件规格(照此实现,不要自创)
| 元素 | 规格 |
|---|---|
| 分区卡 `.sec` | `--surface` 底 + `1px var(--line)` + `--r-sub` + `overflow:hidden`,**不加阴影** |
| 卡头 `.sec-head` | `--subtle` 底 + 下边框 `1px var(--line)` + `padding: 10px 14px` |
| 卡头徽标 `.sec-badge` | 20×20、6px 圆角、`--brand-soft` 底 + `--brand-ink` 字、`--f-num` 10.5px/600 |
| 卡体 `.sec-body` | `padding: 14px 14px 6px` |
| 栅格 `.grid` | `repeat(auto-fit, minmax(240px, 1fr))`,列间距 16px;开关区 `minmax(200px,1fr)` |
| 步骤卡 `.step-cards` | `repeat(auto-fit, minmax(200px, 1fr))`;每张 `.step-card` = 标题 + 一行说明,选中态 `--brand` 边 + `--brand-soft` 底,右上角对勾 |
| 行式设置项 `.rows` | `--subtle` 底 + `--line` 边的竖排容器;每行 `.row` = 左「标题 + 说明」+ 右控件;联动项用 `.is-hidden` 收起 |
| 折叠说明 `.help` | `<details>` 卡片:`<summary>` 浅灰底标题栏(`list-style:none`,箭头 `▾` 旋转),展开后 `--line` 下边线 |
| 提示 `.notice` | `--subtle` 底 + `--line` 边 + `--r-sub` + `padding: 9px 12px`;warn/error/ok 用对应 `-soft/-line/-ink` |
| 操作区 `.actions` | 上边框 `1px var(--line-soft)` + `padding-top: 14px`;主按钮在左或右固定一处,不要两边都有 |
| 主按钮 `.btn-run` | `--brand` 实底 + 白字 + `--r-btn` + 34px 高 + `--sh-brand`,hover `--brand-hover`,active 下沉 1px |
| 次按钮 | 统一用 `el-button`(默认白底 + `--line-btn` 边);文字操作用 `text` 型 |
| 状态胶囊 `.badge` | 22px 高、6px 圆角、带 5px 圆点;`ok/warn/danger/idle` 四态,配色同壳子 |
| 表格(插件内如需要) | 表头 sticky 白底 11px 居中 `--t3`;单元格 12px 居中,`line-soft` 分隔;名称列左对齐 600/`--t1` |
| 空态 | `padding: 40px 20px`,居中 12px `--t4`,不要画虚线大框 |
### 5.2 参考骨架(App.vue)
```vue
<template>
<div class="page">
<div class="toolbar">
<span class="spacer" />
<span class="saved" :class="{ 'is-idle': !lastSavedAt }">
<i />{{ lastSavedAt ? '已保存 ' + lastSavedAt : '尚未保存' }}
</span>
<el-select v-model="schemeSel" class="scheme-sel" size="small" :disabled="running" @change="onSchemeChange">
<el-option v-for="o in schemeOptions" :key="o.value" :label="o.label" :value="o.value" />
</el-select>
<el-button size="small" :disabled="running" @click="saveSchemeAs">存为方案</el-button>
<el-button size="small" text type="danger" :disabled="running || !schemeSel" @click="removeScheme">删除</el-button>
</div>
<div v-if="needLogin" class="notice is-warn"><span class="n-ico">!</span><span>未登录:请先在壳子登录统一账户</span></div>
<div v-else-if="notice" class="notice" :class="'is-' + notice.type"><span class="n-ico">·</span><span>{{ notice.text }}</span></div>
<!-- 01 互斥步骤:卡片单选 -->
<section class="sec">
<div class="sec-head">
<span class="sec-badge">01</span>
<span class="sec-name">执行步骤</span>
<span class="sec-line" />
</div>
<div class="sec-body">
<div class="step-cards" :class="{ 'is-disabled': running }">
<label v-for="s in STEPS" :key="s.value" class="step-card" :class="{ on: form.step === s.value }">
<input class="sr-only" type="radio" :value="s.value" v-model="form.step" :disabled="running" />
<span class="sc-title">{{ s.label }}</span>
<span class="sc-desc">{{ s.desc }}</span>
</label>
</div>
</div>
</section>
<!-- 02 少量设置:行式设置项(标题+说明在左,控件在右) -->
<section class="sec">
<div class="sec-head">
<span class="sec-badge">02</span>
<span class="sec-name">执行设置</span>
<span class="sec-line" />
</div>
<div class="sec-body">
<div class="rows">
<div class="row">
<div class="r-main">
<div class="r-title">试算模式</div>
<div class="r-desc">只检查不写入,用于人工验证</div>
</div>
<div class="r-ctrl"><el-switch v-model="form.dry_run" :disabled="running" /></div>
</div>
<div class="row" :class="{ 'is-hidden': !form.notify }">
<div class="r-main">
<div class="r-title">通知对象</div>
<div class="r-desc">接收执行结果的群</div>
</div>
<div class="r-ctrl"><el-select v-model="form.notify_target" :disabled="running || !form.notify" style="width: 132px" /></div>
</div>
</div>
</div>
</section>
<!-- 流程说明:大段说明收进折叠区 -->
<details class="help">
<summary><span>流程说明</span><span class="h-arrow">▾</span></summary>
<div class="help-body">
<div class="hb-line"><b>① 全流程</b>:做什么、跳过什么。</div>
</div>
</details>
<div class="actions">
<el-button type="primary" class="btn-run" :loading="running" @click="run">
{{ running ? '执行中 ' + progress + '%' : '一键执行' }}
</el-button>
<el-button v-if="running" type="danger" plain :loading="stopping" @click="forceStop">强制停止</el-button>
<span class="spacer" />
<el-button :disabled="running" @click="restoreLastFields">恢复上次参数</el-button>
<el-button :disabled="running" @click="saveNow(true)">保存配置</el-button>
<el-button text :disabled="running" @click="resetDefaults">恢复默认</el-button>
</div>
</div>
</template>
```
### 5.3 字段与表单约定
- 字段名必须与 `plugin.json.fields.properties` 完全一致(改名 = 破坏性变更);`DEFAULTS` 与该 `default` 一致。
- 互斥字段(enum 且互斥,如「执行步骤」)用 `.step-cards` 卡片单选,`radio` 的 `value` 必须与 enum 值逐字一致,
展示文案(`.sc-title`)可以简写,但提交值不能变;后端同样校验。
- 日期用 `el-date-picker` + `value-format="YYYY-MM-DD"`(提交是字符串,不要 Date 对象)。
- 开关用 `el-switch`,放进 `.grid.grid-switch`,分区尾部配 `.tip` 解释。
- 执行中所有输入 `:disabled="running"`。
- 密码字段 `el-input show-password`,提交前 trim(防误存空格导致平台锁号)。
- 输入框/日期/下拉一律 `width: 100%`(`.grid` 里已统一撑满)。
### 5.4 运行备注(壳子统一提供,插件内不要重复实现)
- 运行台插件页由**壳子**在 iframe 之上渲染「运行备注」输入栏:账号 × 插件唯一,本机保存(`%LOCALAPPDATA%\37duAutomation\plugin_notes.json`)
并回传中心机 `plugin_notes` 表;切换插件分别记忆、可清空,输入防抖保存并显示「已保存 时间」。
- 执行时壳子通过 iframe `window.fetch` 拦截,给 `POST /api/runs` 的请求体注入 `note`;定时任务 / 流程编排触发时,
壳子按「账号 + 插件」取长期备注自动带上,插件无需感知备注的存在。
- 备注随运行落 `run_history`,整条回传中心机 `run_logs.note`(快照,改备注不影响历史追溯),管理台「运行日志」可看可搜。
- 因此:**`plugin.json.fields` 不要再加 remark / note 之类备注字段**,插件 UI 内也不要自绘备注框(会与壳子重复且两处不一致)。
备注能力对全部插件(含新插件)自动生效,插件侧零改动。
### 5.5 路径字段必须配「选择文件夹」按钮(硬要求)
任何目录 / 文件路径字段(`save_dir`、`base_dir`、输出目录、花名册路径…)**不能只给一个手输框**,
必须配一个调壳子原生目录对话框的按钮。参照实现:`XQ0002`、`XQ0048`、`XQ0065`。
```vue
<el-form-item label="保存目录">
<div class="dir-ctrl">
<el-input v-model="form.save_dir" class="dir-input" :disabled="running" clearable
placeholder="留空 = D:\资料\财务\抖音平台核对" />
<el-button class="dir-btn" :disabled="running || picking" :loading="picking"
@click="pickDir">选择</el-button>
</div>
</el-form-item>
```
```js
// 调用壳子本机接口打开原生「选择文件夹」对话框(壳子 /api/dialog/directory,仅返回路径)
const picking = ref(false)
async function pickDir() {
picking.value = true
try {
const r = await fetch('/api/dialog/directory', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title: '选择保存目录', current: form.save_dir || '' }),
})
const d = await r.json().catch(() => ({}))
if (!r.ok) throw new Error(d.detail || d.error || ('HTTP ' + r.status))
if (d.path) form.save_dir = d.path
} catch (e) {
ElMessage.warning('打开文件夹选择失败:' + e.message)
} finally {
picking.value = false
}
}
```
```css
/* App.vue 的 <style scoped>,只用 token,不写字面色值 */
.dir-ctrl { display: flex; align-items: center; gap: var(--space-2); width: 100%; }
.dir-ctrl .dir-input { flex: 1 1 auto; min-width: 0; }
.dir-ctrl .dir-btn { flex: 0 0 auto; }
```
约束:
- 接口契约:`POST /api/dialog/directory`,body `{title, current}` → `{ok, canceled, path}`;壳子(Electron)用原生
`showOpenDialog({properties:['openDirectory','createDirectory']})`,**只回路径、不写盘**。`npm run dev` 经 8799 代理同样可用;
纯浏览器打开时无壳子接口,按钮会提示失败,属正常。
- **单文件参数**(模板 Excel、数据源文件等)用 `POST /api/dialog/file`,body `{title, current, filters?}` →
`{ok, canceled, path}`(`filters` 只传扩展名、不带点,默认 `xlsx/xlsm`)。该接口**壳子侧已实现但尚未发版**
(1.10.x 没有),插件里必须先 `fetch` 再判 `r.status === 404` 退化成选文件夹,不能假设它一定存在。
首个接入:湖畔储值卡每日导出统计(xq0052)「台账文件」。
- 按钮文案统一「选择」,`running || picking` 时禁用并 `loading`;用户取消(`canceled=true` / `path` 为空)**不报错、不清空已填值**。
- 纵向排布:路径字段可以和相邻开关排同一行省空间
(`.grid` 加修饰类,例:`grid-template-columns: 104px 104px minmax(220px, 1fr)` = 两个窄开关 + 路径撑满)。
## 6. kit v2 契约(`usePluginUI.js`)
```js
const {
form, needLogin, notice, lastSavedAt, running, progress, stopping,
saveNow, resetDefaults, restoreLastFields,
schemeSel, schemeOptions, onSchemeChange, saveSchemeAs, removeScheme,
run, forceStop,
} = usePluginUI({
defaults: DEFAULTS, // 必传
validate() { ... }, // 返回 false 阻断执行
buildPayload(form) { ... } // 定制提交参数
})
```
内置行为(App.vue 不要重复实现):
- **自动保存**:表单变更防抖 800ms 保存到本机;执行中不保存;`lastSavedAt` 驱动「已保存」胶囊。
- **合并规则**:载入已存配置时,标量空值不覆盖默认值;数组照原样应用。
- **方案**:同名覆盖、单插件上限 10 套、密码明文保存;应用方案 = 合并进表单。
- **执行**:`run()` = 未登录重试 → validate → saveNow → `POST /api/runs` → 连 WS → 5s 轮询兜底。
- **入队确认**:壳子在 iframe 的 `window.fetch` 上包了一层,提交前查队列;用户取消会返回 **409**,
kit 不再当失败,而是给出「已取消加入执行队列」提示。
- **恢复上次参数**:`restoreLastFields()` → `GET /api/plugins/<id>/last-fields`(password 不落盘)。
- **notice 取代 banner**:执行结果横幅由壳子展示,插件内 `notice` 只用于本插件短提示。
### 6.1 后端 API
| 端点 | 方法 | 用途 |
|---|---|---|
| `/api/plugin-config/<id>` | GET / POST | 本机当前配置(明文 JSON) |
| `/api/plugin-configs?plugin_id=` | GET | 方案列表 |
| `/api/plugin-configs` | POST | 存方案 `{plugin_id,name,fields}` |
| `/api/plugin-configs/<pluginId>/<cfgId>` | DELETE | 删方案 |
| `/api/plugins/<id>/last-fields` | GET | 上次执行参数(password 不落盘) |
| `/api/runs` | POST | 启动 `{plugin_id, fields}` → `{run_id}`(可能 409) |
| `/api/runs/<runId>` | GET | 轮询兜底 |
| `/api/runs/<runId>/stop` | POST | 强制停止(整树强杀) |
| `/ws` | WS | `progress` / `run_done` |
| `/pui/<id>/` | GET | 插件 UI 托管(壳子 iframe 内嵌) |
**密码口径**:一律明文落盘(本机 `%LOCALAPPDATA%\37duAutomation\plugin_configs\<id>.json`、方案存 SQLite),
后端不加解密;界面文案不要出现「加密」字样。
## 7. 附录:style.css v3(直接整份复制)
> 与壳子 2026-10 版样式一致。新插件把下面整份内容拷到 `ui-src/src/style.css`,
> 再在 `App.vue` 里按 §5.2 结构写业务字段即可,无需再写任何自定义颜色/间距。
```css
/* ============================================================
插件 UI 基础样式(规范 v3 · 对齐壳子「白底面板 + 描边卡」)
- token 与壳子 frontend/src/style.css 同源(权威源 design-app/styles.css)
- Element Plus 变量映射到壳子 token
- 版式类:page / toolbar / notice / sec / grid / tip / actions / badge / table
规则:插件内只用 var(--xxx),不写字面色值;左右内边距由壳子提供,不要重复加
============================================================ */
:root {
/* 底色与卡面 */
--canvas: #F2F4F8;
--surface: #FFFFFF;
--field: #F5F6FA;
--subtle: #F7F8FC;
/* 描边 */
--line: #E8EAF1;
--line-soft: #F0F2F7;
--line-btn: #E3E6EF;
/* 文字五阶 */
--t1: #12141B;
--t2: #3C4250;
--t3: #6E7686;
--t4: #A3AAB8;
--t5: #C6CBD6;
/* 主色(靛蓝) */
--brand: #4F5AE8;
--brand-ink: #3D47D4;
--brand-soft: #EEF0FE;
--brand-track: #DDE1F8;
--brand-hover: #4550E0;
/* 语义色 */
--good: #0E9F76; --good-ink: #0B8A66; --good-soft: #EBF7F2; --good-line: #D3EDE3;
--warn: #D98218; --warn-ink: #B4700F; --warn-soft: #FDF3E4; --warn-line: rgba(217, 130, 24, .28);
--danger: #E5484D; --danger-ink: #CC3B40; --danger-soft: #FDEDED; --danger-line: #F6D7D8;
/* 圆角 */
--r-row: 8px;
--r-field: 9px;
--r-btn: 10px;
--r-sub: 12px;
--r-card: 14px;
--r-pill: 999px;
/* 阴影(插件内基本不用,保持与壳子同值) */
--sh-card: 0 2px 8px rgba(18, 20, 31, .05);
--sh-float: 0 8px 24px rgba(18, 20, 31, .10);
--sh-brand: 0 4px 12px rgba(79, 89, 232, .28);
--sh-brand-sm: 0 2px 8px rgba(79, 89, 232, .24);
/* 字体 */
--f-cn: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
--f-num: "Inter", "SF Pro Display", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
--f-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
/* 间距 */
--space-1: 4px;
--space-1-5: 6px;
--space-2: 8px;
--space-2-5: 10px;
--space-3: 12px;
--space-4: 16px;
--space-5: 20px;
--space-6: 28px;
--dur: .15s;
--ease: cubic-bezier(.22, 1, .36, 1);
}
/* ---------- Element Plus → 壳子 token ---------- */
:root {
--el-color-primary: var(--brand);
--el-color-primary-light-3: #7A83EE;
--el-color-primary-light-5: #A6ACF4;
--el-color-primary-light-7: #C9CDF9;
--el-color-primary-light-8: #DDE0FB;
--el-color-primary-light-9: var(--brand-soft);
--el-color-primary-dark-2: var(--brand-ink);
--el-color-success: var(--good);
--el-color-success-light-9: var(--good-soft);
--el-color-warning: var(--warn);
--el-color-warning-light-9: var(--warn-soft);
--el-color-danger: var(--danger);
--el-color-danger-light-9: var(--danger-soft);
--el-color-error: var(--danger);
--el-text-color-primary: var(--t1);
--el-text-color-regular: var(--t2);
--el-text-color-secondary: var(--t3);
--el-text-color-placeholder: var(--t4);
--el-border-color: var(--line);
--el-border-color-light: var(--line);
--el-border-color-lighter: var(--line-soft);
--el-border-color-extra-light: var(--line-soft);
--el-fill-color-blank: var(--surface);
--el-fill-color-light: var(--field);
--el-bg-color: var(--surface);
--el-border-radius-base: var(--r-field);
--el-border-radius-small: var(--r-field);
--el-font-family: var(--f-cn);
--el-font-size-base: 12.5px;
--el-box-shadow-light: var(--sh-card);
}
/* ---------- 基础重置 ---------- */
* { box-sizing: border-box; }
html, body {
margin: 0;
padding: 0;
background: var(--surface);
color: var(--t1);
font-family: var(--f-cn);
font-size: 12.5px;
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
#app { padding: 0; }
/* ---------- 页面:只排垂直节奏(左右 24px 由壳子给) ---------- */
.page {
width: 100%;
display: flex;
flex-direction: column;
gap: var(--space-4);
padding: 2px 0 20px;
}
/* ---------- 工具条:方案下拉 + 存为方案 + 删除 + 已保存胶囊 ---------- */
.toolbar {
display: flex;
align-items: center;
gap: var(--space-2);
flex-wrap: wrap;
min-height: 32px;
}
.toolbar .spacer { flex: 1; }
.scheme-sel { width: 200px; }
.saved {
display: inline-flex;
align-items: center;
gap: 6px;
height: 22px;
padding: 0 9px;
border-radius: var(--r-pill);
background: var(--good-soft);
border: 1px solid var(--good-line);
color: var(--good-ink);
font: 500 11px/1 var(--f-cn);
white-space: nowrap;
}
.saved i { width: 5px; height: 5px; border-radius: 50%; background: var(--good); }
.saved.is-idle { background: var(--field); border-color: var(--line); color: var(--t4); }
.saved.is-idle i { background: var(--t5); }
/* ---------- 提示条(替代顶部大横幅) ---------- */
.notice {
display: flex;
align-items: flex-start;
gap: var(--space-2);
padding: 9px 12px;
border-radius: var(--r-sub);
border: 1px solid var(--line);
background: var(--subtle);
font: 400 12px/18px var(--f-cn);
color: var(--t2);
}
.notice .n-ico { flex: 0 0 auto; font-weight: 700; }
.notice.is-warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn-ink); }
.notice.is-error { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger-ink); }
.notice.is-ok { background: var(--good-soft); border-color: var(--good-line); color: var(--good-ink); }
/* ---------- 分区卡:与壳子列表卡/表格卡同一套 ---------- */
.sec {
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-sub);
overflow: hidden;
}
.sec-head {
display: flex;
align-items: center;
gap: var(--space-2);
padding: 10px 14px;
background: var(--subtle);
border-bottom: 1px solid var(--line);
}
.sec-badge {
width: 20px;
height: 20px;
border-radius: 6px;
display: inline-grid;
place-items: center;
font: 600 10.5px/1 var(--f-num);
color: var(--brand-ink);
background: var(--brand-soft);
flex-shrink: 0;
}
.sec-name { font: 600 13px/18px var(--f-cn); color: var(--t1); white-space: nowrap; }
.sec-line { flex: 1; height: 1px; background: var(--line-soft); }
.sec-body { padding: 14px 14px 6px; }
/* ---------- 栅格与表单 ---------- */
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 0 16px;
}
.grid-switch { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
/* 日期行紧跟在开关行后,补一点呼吸 */
.grid-date { margin-top: 4px; }
.grid .el-form-item { margin-bottom: 12px; }
.grid .el-form-item__label {
padding-bottom: 6px !important;
font-weight: 500;
color: var(--t2);
}
.grid .el-input,
.grid .el-select,
.grid .el-date-editor,
.grid .el-input-number { width: 100% !important; }
/* ---------- 说明文字 ---------- */
.tip {
margin-top: var(--space-2);
font: 400 11.5px/1.65 var(--f-cn);
color: var(--t3);
}
.tip b { color: var(--t2); font-weight: 600; }
/* ---------- 执行摘要(操作区上方一行低调说明) ---------- */
.plan { display: flex; align-items: baseline; gap: var(--space-2); font-size: 11.5px; line-height: 1.6; color: var(--t3); }
.plan .p-tag { flex: 0 0 auto; font-weight: 600; color: var(--brand-ink); }
.plan .p-text { min-width: 0; }
.plan.is-empty .p-text { color: var(--warn); }
/* ---------- 操作区 ---------- */
.actions {
display: flex;
align-items: center;
gap: var(--space-2);
flex-wrap: wrap;
padding-top: 14px;
border-top: 1px solid var(--line-soft);
}
.actions .spacer { flex: 1; }
.btn-run {
min-width: 150px;
height: 34px;
border: none;
border-radius: var(--r-btn);
background: var(--brand);
color: #fff;
font: 600 12.5px/18px var(--f-cn);
letter-spacing: 1px;
box-shadow: var(--sh-brand);
transition: background var(--dur), box-shadow var(--dur), transform .06s;
}
.btn-run:hover { background: var(--brand-hover); }
.btn-run:active { transform: translateY(1px); box-shadow: var(--sh-brand-sm); }
.btn-run.is-loading { pointer-events: none; }
/* ---------- 状态胶囊(与壳子表格状态列同款) ---------- */
.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;
}
.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.warn { color: var(--warn-ink); background: var(--warn-soft); border-color: var(--warn-line); }
.badge.warn i { background: var(--warn); }
.badge.bad { color: var(--danger-ink); background: var(--danger-soft); border-color: var(--danger-line); }
.badge.bad i { background: var(--danger); }
.badge.idle { color: var(--t3); background: var(--field); border-color: var(--line); }
.badge.idle i { background: var(--t5); }
/* ---------- 表格(插件内需要列表时用;与壳子表格同口径) ---------- */
.table-card {
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-sub);
overflow: hidden;
}
.table-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--space-3);
padding: 12px 16px;
background: var(--subtle);
border-bottom: 1px solid var(--line);
font: 600 13.5px/20px var(--f-cn);
color: var(--t1);
}
.table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.table th {
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);
}
.table td {
padding: 10px 16px;
text-align: center;
border-bottom: 1px solid var(--line-soft);
font: 400 12px/18px var(--f-cn);
color: var(--t2);
}
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--dur); }
.table tbody tr:hover { background: var(--field); }
.table td.is-name { text-align: left; font-weight: 600; color: var(--t1); }
.table th.is-name { text-align: left; }
/* ---------- 运行态一行文字(进度由壳子 RunIndicator 展示) ---------- */
.runline { display: flex; align-items: center; gap: var(--space-2); font-size: 12px; color: var(--t3); }
.runline .pct { font: 600 12px/1 var(--f-num); color: var(--brand-ink); font-variant-numeric: tabular-nums; }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); animation: pulse 1.4s ease-out infinite; }
@keyframes pulse {
0% { box-shadow: 0 0 0 0 var(--brand-soft); }
70% { box-shadow: 0 0 0 7px transparent; }
100% { box-shadow: 0 0 0 0 transparent; }
}
/* ============================================================
v3.1 扩展:步骤卡 / 行式设置项 / 折叠说明
- 适用于「互斥步骤」「开关+联动下拉」「大段流程说明」
- 仍然只用 token,不写字面色值
============================================================ */
/* ---------- 步骤卡(互斥单选,≤4 项) ---------- */
.step-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: var(--space-2-5);
}
.step-card {
position: relative;
display: flex;
flex-direction: column;
gap: 3px;
padding: 11px 32px 11px 13px;
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-sub);
cursor: pointer;
transition: border-color var(--dur), background var(--dur), box-shadow var(--dur);
}
.step-card:hover { border-color: var(--brand-track); background: var(--subtle); }
.step-card.on {
border-color: var(--brand);
background: var(--brand-soft);
box-shadow: inset 0 0 0 1px var(--brand-soft);
}
.step-card .sc-title { font: 600 13px/18px var(--f-cn); color: var(--t1); }
.step-card.on .sc-title { color: var(--brand-ink); }
.step-card .sc-desc { font: 400 11.5px/1.6 var(--f-cn); color: var(--t3); }
.step-card .sc-check {
position: absolute; top: 10px; right: 10px;
width: 16px; height: 16px; color: var(--brand);
}
.step-cards.is-disabled .step-card { opacity: .55; pointer-events: none; }
.sr-only {
position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
/* ---------- 行式设置项(标题+说明在左,控件在右) ---------- */
.rows {
display: flex; flex-direction: column; gap: var(--space-2);
padding: var(--space-2);
background: var(--subtle);
border: 1px solid var(--line);
border-radius: var(--r-sub);
}
.row {
display: flex; align-items: center; justify-content: space-between;
gap: var(--space-4);
padding: 9px 12px;
background: var(--surface);
border: 1px solid var(--line-soft);
border-radius: var(--r-field);
}
.row .r-main { min-width: 0; }
.row .r-title { font: 500 12.5px/18px var(--f-cn); color: var(--t1); }
.row .r-desc { margin-top: 1px; font: 400 11.5px/1.6 var(--f-cn); color: var(--t3); }
.row .r-ctrl { flex: 0 0 auto; }
.row.is-hidden { display: none; }
/* ---------- 折叠说明(流程说明气泡卡片) ---------- */
.help {
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-sub);
overflow: hidden;
}
.help > summary {
display: flex; align-items: center; justify-content: space-between;
gap: var(--space-2); padding: 10px 14px;
background: var(--subtle);
font: 600 12.5px/18px var(--f-cn); color: var(--t2);
cursor: pointer; list-style: none;
}
.help > summary::-webkit-details-marker { display: none; }
.help[open] > summary { border-bottom: 1px solid var(--line); }
.help .h-arrow { color: var(--t4); transition: transform var(--dur); font-size: 11px; }
.help[open] .h-arrow { transform: rotate(180deg); }
.help-body {
padding: 12px 14px;
font: 400 12px/1.8 var(--f-cn); color: var(--t3);
}
.help-body b { color: var(--t2); font-weight: 600; }
.help-body .hb-line + .hb-line { margin-top: 6px; }
```
## 8. 构建、联调、打包
```bash
cd "plugins/<桶>/<插件目录>/ui-src"
npm install # 首次
npm run build # 产物 → ../ui/
```
- dev 联调:`npm run dev` → `http://localhost:<端口>/`,`/api` 与 `/ws` 代理到本机壳子 `127.0.0.1:8799`。
端口按插件错开(xq0002=5180、xq0047=5181、xq0041=5182…)。dev 下没有壳子的 24px 内边距,页面会贴边,属正常。
- **顺序铁律**:改 ui-src → `npm run build` → `_pack.py`。`_pack.py` 校验 `ui/index.html` 存在。
- 打包产物:`dist-plugin/<id>_v<版本>.zip`(`ui-src` 不进包,`ui/` 进包)。
## 9. 自检清单
- [ ] `plugin.json.ui = true`(需要人工执行的插件)
- [ ] `plugin.json.fields` 完整,App.vue 字段名与 DEFAULTS 与之逐项一致
- [ ] `vite.config.js`:`base=/pui/<id>/`、`outDir=../ui`、独立 dev 端口
- [ ] `style.css` 是 §7 的 v3 版本(token + `--el-*` 映射 + 版式类),`main.js` 里在 element-plus 之后引入
- [ ] 页面只有 工具条 / 提示 / 分区卡 / 操作区,**没有**重复插件名、结果横幅、进度条、外层卡片边框
- [ ] `.page` 没有左右 padding(避免与壳子 24px 叠加)
- [ ] 分区用 `.sec` + `.sec-head`(浅灰卡头)+ `.sec-body`,卡片无阴影
- [ ] **路径类字段配了「选择文件夹」按钮**(`.dir-ctrl` + `POST /api/dialog/directory`,见 §5.5)
- [ ] 方案工具条存在(下拉 + 存为方案 + 删除)
- [ ] `restoreLastFields` 按钮已接
- [ ] 执行中禁用所有输入,`running` 时主按钮显示「执行中 N%」
- [ ] 全文无字面色值(除 §7 的 token 定义处)
- [ ] `npm run build` 通过、`ui/index.html` 已更新(hash 变化)
- [ ] `_pack.py` 打包成功,zip 内含 `ui/`
## 10. 迁移说明
| 版本 | 形态 | 现状 |
|---|---|---|
| v1 | 五段式(顶部横幅 + 卡片头 + 进度条) | `xq0002`、`xq0011`、`xq0031_xq0032`、`xq0045_xq0046`;功能正常,视觉与新壳子差距最大,待迁移 |
| v2 | 无边框平铺 + `.panel` 卡片头(el-card) | 已被 v3 取代 |
| v3 | 本文档:描边卡 + 浅灰卡头 + 零左右内边距 | **新插件一律用 v3**;参考实现 `XQ0041 新美大平台核对` 已迁移(`ui/` 已重新构建) |
v2 → v3 迁移(只动样式与容器结构,不动业务逻辑,XQ0041 即按此改完):
1. 用 §7 的 `style.css` 整份覆盖;
2. `App.vue`:`.page` 内不再需要 `el-card.panel` 包裹;分组改成 `.sec` + `.sec-head` + `.sec-body`;
3. 删除 `.panel`、`.panel-head`、`.title-ico`、`.title-txt` 等 v2 卡片头节点,方案工具(下拉/存为方案/删除/已保存)
上移成独立的 `.toolbar`(插件名/版本已由壳子 `PageHead` 展示);
4. 每个分区内的 `el-form` 单独包在 `.sec-body` 里(`label-position="top"`);
5. `.status` 进度条改成 `.runline` 一行文字(进度/日志由壳子展示);
6. `.actions` 的上边框由虚线改实线(已在 v3 样式内);
7. `npm run build` → `_pack.py` → 按发版规范发布。
> kit 是 vendored 副本:**同一插件内自洽即可**,不要求跨插件 MD5 一致。