feat(xq0082): 新增通联数据核对插件(v1.0.0)
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
# XQ0082 通联数据核对 — 交接文档
|
||||
|
||||
> 状态:**从 XQ0085 拆出的独立插件**(2026-11-27),代码 = 原 `XQ0085/logic/tonglian.py` 原样迁移,
|
||||
> 只换了配置层(目录 + 日志/进度钩子),单测由 XQ0085 的 44 项覆盖底层公共逻辑,本插件为流程脚本。
|
||||
> 版本 `1.0.0`,已带 UI(`ui/`),未发布。
|
||||
|
||||
---
|
||||
|
||||
## 1. 为什么拆
|
||||
|
||||
原来 XQ0085 一条插件挂三条互不相干的分支(美团 / 抖音 / 通联),界面上一屏塞三类参数,
|
||||
定时任务也容易配错。通联这条:
|
||||
|
||||
- 不碰共享盘、不做马敏总表对比,只在本机一个目录里跑;
|
||||
- 输入是扫码统计工作簿 + 平台/工作台导出件,和美团/抖音完全不同;
|
||||
- 需要 WPS/Excel COM 的次数更多、失败点也更集中。
|
||||
|
||||
所以单独成插件,XQ0085 只保留美团和抖音。
|
||||
|
||||
## 2. 输入(全部放在界面指定的「通联工作目录」,默认 `D:\资料\财务\团购数据核对\通联`)
|
||||
|
||||
| 文件 | 说明 |
|
||||
|---|---|
|
||||
| `扫码统计M.D.xlsx` | 历史工作簿(取目录里最新的一份作为今日的复制来源) |
|
||||
| `支付数据-YYYYMMDD.xlsx` | 平台每日导出 |
|
||||
| `支付数据保留.xlsx` / `导出计数_门店` | 支付数据「标准门店名称」映射 |
|
||||
| `后台号.xlsx` / `门店对应` | 日交易查询按商户名称补门店名称的映射 |
|
||||
| `日账单_*`(目录) | 工作台导出的日账单,目录内放对账明细 `*.xlsx` |
|
||||
| `第三方支付(门店)-*.xlsx` | 工作台导出 |
|
||||
| `日交易查询结果_*_其他账号.xlsx` | 按「后台号/门店对应」补门店名 |
|
||||
| `日交易查询结果_*_综合门店.xlsx` | 原样使用 |
|
||||
| `日交易查询结果_*_品牌管理公司.xlsx` | 门店名称由商户名称复制 |
|
||||
|
||||
预检缺任何一项直接中止,不改文件。
|
||||
|
||||
## 3. 执行流程(`logic/tonglian.py`)
|
||||
|
||||
块 1 今日工作簿基础
|
||||
① 复制最新「扫码统计M.D.xlsx」为今日工作簿
|
||||
② 本日 A5:N 末行贴值到「统计表上日」(先于 ⑫)
|
||||
③ B2 = 今日 10:00、F2 = 明日 00:00
|
||||
|
||||
块 2 支付数据
|
||||
⑤ 导出表 D 列右侧插「标准门店名称」列,按映射 VLOOKUP
|
||||
④ 按标题列对齐累计贴入今日工作簿「支付数据」,保存导出文件
|
||||
|
||||
块 3 校验 ②③④
|
||||
|
||||
块 4 三张日交易查询
|
||||
⑦ 按账号分流补门店名(其他账号查映射 / 综合门店不处理 / 品牌管理公司复制商户名)
|
||||
⑧ 三表按 A~R 累计贴入「导入表」并重写 T..Y 公式
|
||||
|
||||
块 5 导入表后处理
|
||||
⑨ S 列按订单号匹配导出「支付数据」取标准门店名
|
||||
⑪ J 为「--」/空白的行清空 L
|
||||
|
||||
块 6 统计表核对与 Sheet3
|
||||
⑫ 日账单汇总填 M5/O5,校验 P5 在 ±1000 内
|
||||
⑬ 第三方支付(门店)A~L 覆盖 Sheet3,统计表本日 A5:F 末格 → AK2
|
||||
⑭ Sheet3 清 T/V/W/Z,U 列日期后移一天并整列填充,Q 列重算,recalc 后核对 Y 列全 0
|
||||
|
||||
要点:导出与目标列位不同,一律按标题名对齐;④ 有幂等保护(末行订单 id 相同视为已追加);
|
||||
步骤内失败抛 `FlowError` 中止,不留半成品;校验不过只告警、`ok=False`。
|
||||
|
||||
## 4. 参数
|
||||
|
||||
| 参数 | 默认 | 说明 |
|
||||
|---|---|---|
|
||||
| `save_dir` | 空 | 留空 = `D:\资料\财务\团购数据核对\通联` |
|
||||
| `tonglian_overwrite` | true | 关闭时今日工作簿已存在则报错中止 |
|
||||
| `dry_run` | false | 只跑预检,不改任何文件(界面「预检」按钮用的就是它) |
|
||||
| `debug_mode` | false | 调试日志 |
|
||||
|
||||
## 5. 界面
|
||||
|
||||
`ui-src/`(Vue 3 + Element Plus + Vite,公共 kit 与 XQ0041/XQ0085 同一套)→ `ui/` 构建产物。
|
||||
两个区块:通联工作目录(含「选择」按钮)、运行选项;按钮:一键执行 / 预检 / 强制停止 / 恢复上次参数 / 保存配置 / 恢复默认。
|
||||
|
||||
构建:`ui-src` 下 `npm install && npm run build`(产物输出到 `../ui`,base=`/pui/xq0082/`)。
|
||||
打包:`_pack.py` 排除 `ui-src`、`node_modules`、`__pycache__`,缺 `ui/index.html` 时报错。
|
||||
|
||||
## 6. 注意
|
||||
|
||||
- 全程用 WPS/Excel COM;执行期间关闭同名工作簿,避免 `~$` 锁文件。
|
||||
- 目录里只留当天要用的导出件,历史文件会干扰「取最新一份」与文件名解析。
|
||||
- 拆出后 XQ0085 不再有 `check_tonglian`,定时任务如果原来配的是 `action=check_tonglian`,要改建成 XQ0082 的任务。
|
||||
@@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""XQ0082 通联数据核对 —— 从 XQ0085 拆出的独立插件。
|
||||
|
||||
原 XQ0085 三条分支里的「通联扫码统计表每日流程」单独成插件:
|
||||
扫码统计工作簿复制 → 上日快照/日期 → 支付数据插列映射与累计贴入 → 三张日交易查询合并导入表
|
||||
→ 标准门店名/收支方向清理 → 日账单、第三方支付、Sheet3 核对。
|
||||
全部在界面指定的「通联」目录内完成,不碰共享盘、不做对比表。
|
||||
"""
|
||||
from webhost.backend.plugins.base import PLUGINS, ScenePlugin
|
||||
|
||||
from . import config
|
||||
from .logic import tonglian
|
||||
|
||||
|
||||
class Xq0082Plugin(ScenePlugin):
|
||||
id = 'xq0082'
|
||||
name = '通联数据核对'
|
||||
version = '1.0.0'
|
||||
description = ('通联扫码统计表每日流程:复制历史工作簿为今日 → 本日贴值到上日、B2/F2 日期 → '
|
||||
'支付数据插「标准门店名称」列并累计贴入 → 三张日交易查询按账号分流补门店名后合并到导入表 '
|
||||
'→ 导入表 S 列标准门店名、J 为「--」清 L → 日账单汇总、第三方支付、Sheet3 刷新。'
|
||||
'全程使用本机 WPS/Excel COM,任一硬性校验不通过即中止,不留半成品。')
|
||||
platform = ''
|
||||
uses_month = False
|
||||
capabilities = ['xq0082']
|
||||
permissions = {'platforms': []}
|
||||
|
||||
fields = {
|
||||
'save_dir': {'type': 'string', 'title': '通联工作目录', 'default': '',
|
||||
'description': '留空 = D:\\资料\\财务\\团购数据核对\\通联;'
|
||||
'扫码统计工作簿、支付数据/日账单/第三方支付/三张日交易查询都放这里'},
|
||||
'tonglian_overwrite': {'type': 'boolean', 'title': '覆盖今日工作簿', 'default': True,
|
||||
'description': '关闭时若今日「扫码统计M.D.xlsx」已存在则报错中止,不覆盖'},
|
||||
'dry_run': {'type': 'boolean', 'title': '只预检不写入', 'default': False,
|
||||
'description': '只跑预检(文件、sheet、表头、映射是否齐全),不改任何文件'},
|
||||
'debug_mode': {'type': 'boolean', 'title': '调试日志', 'default': False},
|
||||
}
|
||||
|
||||
def run(self, fields, ctx):
|
||||
fields = fields or {}
|
||||
config.set_log(ctx.log)
|
||||
config.set_progress(ctx.progress)
|
||||
config.set_debug(fields.get('debug_mode'))
|
||||
|
||||
out_dir = config.set_out_dir(fields.get('save_dir'))
|
||||
dry = bool(fields.get('dry_run'))
|
||||
config.log(f'== {self.name} ==')
|
||||
config.log(f'通联目录:{out_dir}' + ('(只预检不写入)' if dry else ''))
|
||||
config.ensure_dirs()
|
||||
ctx.progress(3)
|
||||
|
||||
result = tonglian.run(overwrite=bool(fields.get('tonglian_overwrite', True)),
|
||||
dry_run=dry, progress=ctx.progress)
|
||||
config.log(result.get('message') or '')
|
||||
ctx.progress(100)
|
||||
return {'ok': bool(result.get('ok')), 'message': result.get('message') or '',
|
||||
'detail': result}
|
||||
|
||||
|
||||
PLUGINS.append(Xq0082Plugin)
|
||||
@@ -0,0 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""xq0085 团购数据核对 打包脚本:生成 dist-plugin/xq0085_v<版本>.zip。
|
||||
|
||||
排除:ui-src(前端源码,发布包只要构建产物 ui/)、node_modules、__pycache__、
|
||||
debug、.sessions、本脚本、*.pyc/*.pyo。
|
||||
声明了 ``"ui": true`` 时必须先构建出 ``ui/index.html``,否则直接报错。
|
||||
|
||||
用法:.venv\\Scripts\\python.exe plugins\\XQ0001-0100\\XQ0085 团购数据核对\\_pack.py
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
ROOT = os.path.abspath(os.path.join(HERE, '..', '..', '..'))
|
||||
OUT = os.path.join(ROOT, 'dist-plugin')
|
||||
EXCLUDE_DIRS = {'ui-src', 'node_modules', '__pycache__', 'debug', '.sessions'}
|
||||
EXCLUDE_FILES = {'_pack.py'}
|
||||
|
||||
|
||||
def main():
|
||||
with open(os.path.join(HERE, 'plugin.json'), encoding='utf-8') as fp:
|
||||
manifest = json.load(fp)
|
||||
|
||||
if manifest.get('ui') and not os.path.isfile(os.path.join(HERE, 'ui', 'index.html')):
|
||||
sys.exit('插件声明了 ui: true,但缺少 ui/index.html;请先在 ui-src 下执行 npm run build')
|
||||
|
||||
name = 'xq%s_v%s.zip' % (manifest['id'].replace('xq', ''), manifest['version'])
|
||||
os.makedirs(OUT, exist_ok=True)
|
||||
target = os.path.join(OUT, name)
|
||||
|
||||
with zipfile.ZipFile(target, 'w', zipfile.ZIP_DEFLATED) as zf:
|
||||
for dirpath, dirnames, files in os.walk(HERE):
|
||||
dirnames[:] = [d for d in dirnames if d not in EXCLUDE_DIRS]
|
||||
for f in files:
|
||||
if f in EXCLUDE_FILES or f.endswith(('.pyc', '.pyo')):
|
||||
continue
|
||||
full = os.path.join(dirpath, f)
|
||||
zf.write(full, os.path.relpath(full, HERE))
|
||||
|
||||
size = os.path.getsize(target) / 1024
|
||||
print(f'{target}({size:.0f} KB)')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,72 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""xq0082 通联数据核对 —— 配置常量与全局钩子。
|
||||
|
||||
从 XQ0085 拆出的独立插件:只做通联扫码统计表的每日流程,不涉及共享盘,也不做对比表。
|
||||
只依赖标准库 / 第三方库 / 底座注入的 RunContext。
|
||||
"""
|
||||
import os
|
||||
import time
|
||||
|
||||
# ==================== 全局钩子(run() 启动时注入) ====================
|
||||
_log = None
|
||||
_progress = None
|
||||
_debug = False
|
||||
|
||||
|
||||
def set_log(fn):
|
||||
global _log
|
||||
_log = fn
|
||||
|
||||
|
||||
def set_progress(fn):
|
||||
global _progress
|
||||
_progress = fn
|
||||
|
||||
|
||||
def set_debug(on):
|
||||
global _debug
|
||||
_debug = bool(on)
|
||||
|
||||
|
||||
def debug_enabled():
|
||||
return _debug
|
||||
|
||||
|
||||
def log(msg, level='INFO'):
|
||||
text = f'[{time.strftime("%H:%M:%S")}] {msg}'
|
||||
if level == 'DEBUG' and not _debug:
|
||||
return
|
||||
if _log:
|
||||
_log(str(msg), level)
|
||||
else:
|
||||
print(f'[{level}] {text}')
|
||||
|
||||
|
||||
def progress(pct):
|
||||
if _progress:
|
||||
try:
|
||||
_progress(int(pct))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
# ==================== 工作目录 ====================
|
||||
# 界面「本地工作目录」= 放扫码统计工作簿与各类导出件的目录,留空用默认。
|
||||
DEFAULT_DIR = r'D:\资料\财务\团购数据核对\通联'
|
||||
OUT_DIR = DEFAULT_DIR
|
||||
|
||||
|
||||
def set_out_dir(path=None):
|
||||
"""界面填的目录优先,留空回默认;返回最终目录。"""
|
||||
global OUT_DIR
|
||||
OUT_DIR = str(path or '').strip().strip('"').strip() or DEFAULT_DIR
|
||||
return OUT_DIR
|
||||
|
||||
|
||||
def ensure_dirs():
|
||||
os.makedirs(OUT_DIR, exist_ok=True)
|
||||
return OUT_DIR
|
||||
|
||||
|
||||
# ==================== 运行参数 ====================
|
||||
RETRY_MAX = 3
|
||||
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""xq0082 通联核对逻辑子包。"""
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": "xq0082",
|
||||
"name": "通联数据核对",
|
||||
"version": "1.0.0",
|
||||
"description": "通联扫码统计表每日流程(从 XQ0085 拆出):复制历史工作簿为今日 → 本日贴值到上日、B2/F2 日期 → 支付数据插「标准门店名称」列并累计贴入 → 三张日交易查询按账号分流补门店名后合并到导入表 → 导入表 S 列标准门店名、J 为「--」清 L → 日账单汇总、第三方支付、Sheet3 刷新。全程使用本机 WPS/Excel COM,任一硬性校验不通过即中止,不留半成品。",
|
||||
"category": "财务",
|
||||
"icon": "",
|
||||
"platform": "",
|
||||
"uses_month": false,
|
||||
"ui": true,
|
||||
"capabilities": [
|
||||
"xq0082"
|
||||
],
|
||||
"permissions": {
|
||||
"platforms": []
|
||||
},
|
||||
"fields": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"save_dir": {
|
||||
"type": "string",
|
||||
"title": "通联工作目录",
|
||||
"default": "",
|
||||
"description": "留空 = D:\\资料\\财务\\团购数据核对\\通联;扫码统计工作簿、支付数据、日账单、第三方支付、三张日交易查询、支付数据保留.xlsx、后台号.xlsx 都放这里"
|
||||
},
|
||||
"tonglian_overwrite": {
|
||||
"type": "boolean",
|
||||
"title": "覆盖今日工作簿",
|
||||
"default": true,
|
||||
"description": "关闭时若今日「扫码统计M.D.xlsx」已存在则报错中止,不覆盖"
|
||||
},
|
||||
"dry_run": {
|
||||
"type": "boolean",
|
||||
"title": "只预检不写入",
|
||||
"default": false,
|
||||
"description": "只跑预检(文件、sheet、表头、门店映射是否齐全),不改任何文件"
|
||||
},
|
||||
"debug_mode": {
|
||||
"type": "boolean",
|
||||
"title": "调试日志",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
openpyxl>=3.1
|
||||
pywin32>=306
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>通联数据核对</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+1579
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "xq0082-ui",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
"element-plus": "^2.14.5",
|
||||
"vue": "^3.5.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"vite": "^6.0.3"
|
||||
},
|
||||
"allowScripts": {
|
||||
"esbuild@0.25.12": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<!-- 方案工具条:方案供「定时任务」按 config_id 引用 -->
|
||||
<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"
|
||||
placeholder="当前配置(自动保存)" @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="notice" class="notice" :class="'is-' + notice.type">
|
||||
<span class="n-ico">{{ notice.type === 'ok' ? '✓' : (notice.type === 'error' ? '✕' : '!') }}</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">
|
||||
<el-form label-position="top">
|
||||
<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" :loading="picking"
|
||||
@click="pickDir">选择</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<div class="tip">
|
||||
预检要求目录内齐全:历史 <b>扫码统计M.D.xlsx</b>、<b>支付数据-YYYYMMDD.xlsx</b>、
|
||||
<b>支付数据保留.xlsx</b>、<b>后台号.xlsx</b>、<b>日账单_*</b> 目录、
|
||||
<b>第三方支付(门店)-*.xlsx</b>、三张 <b>日交易查询结果_*.xlsx</b>(其他账号 / 综合门店 / 品牌管理公司)。
|
||||
任一缺失直接中止,不改任何文件。
|
||||
</div>
|
||||
</el-form>
|
||||
</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">
|
||||
<el-form label-position="top">
|
||||
<div class="switch-row">
|
||||
<el-form-item label="覆盖今日工作簿">
|
||||
<el-switch v-model="form.tonglian_overwrite" :disabled="running" />
|
||||
</el-form-item>
|
||||
<el-form-item label="只预检不写入">
|
||||
<el-switch v-model="form.dry_run" :disabled="running" />
|
||||
</el-form-item>
|
||||
<el-form-item label="调试日志">
|
||||
<el-switch v-model="form.debug_mode" :disabled="running" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div class="tip">
|
||||
关闭「覆盖」时,今日「扫码统计M.D.xlsx」已存在会直接报错中止。
|
||||
全程用本机 WPS/Excel COM;执行期间请关闭同名工作簿,避免锁文件。
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="actions">
|
||||
<el-button type="primary" class="btn-run" :loading="running" @click="start">
|
||||
{{ running ? '执行中 ' + progress + '%' : '一键执行' }}
|
||||
</el-button>
|
||||
<el-button :disabled="running" @click="preflight">预检</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 v-if="running" class="runline">
|
||||
<span class="pulse" />
|
||||
<span>正在执行,日志与进度实时显示在工作台下方「运行日志」区</span>
|
||||
<span class="pct">{{ progress }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { usePluginUI } from './usePluginUI'
|
||||
|
||||
const DEFAULTS = () => ({
|
||||
save_dir: '',
|
||||
tonglian_overwrite: true,
|
||||
dry_run: false,
|
||||
debug_mode: false,
|
||||
})
|
||||
|
||||
const preview = ref(false)
|
||||
|
||||
const {
|
||||
form, notice, lastSavedAt, running, progress, stopping,
|
||||
saveNow, resetDefaults, restoreLastFields,
|
||||
schemeSel, schemeOptions, onSchemeChange, saveSchemeAs, removeScheme,
|
||||
run, forceStop,
|
||||
} = usePluginUI({
|
||||
defaults: DEFAULTS,
|
||||
buildPayload(f) {
|
||||
const t = (v) => (v || '').trim()
|
||||
return {
|
||||
save_dir: t(f.save_dir),
|
||||
tonglian_overwrite: !!f.tonglian_overwrite,
|
||||
dry_run: !!(f.dry_run || preview.value),
|
||||
debug_mode: !!f.debug_mode,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
function start() {
|
||||
run()
|
||||
}
|
||||
|
||||
// 预检:以 dry_run 只跑预检(文件 / sheet / 表头 / 映射),不改任何文件
|
||||
async function preflight() {
|
||||
if (running.value) return
|
||||
preview.value = true
|
||||
try {
|
||||
await run()
|
||||
} finally {
|
||||
preview.value = false
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.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; }
|
||||
.switch-row { display: flex; flex-wrap: wrap; gap: 0 var(--space-5); }
|
||||
.switch-row :deep(.el-form-item) { margin-bottom: 12px; min-width: 150px; }
|
||||
</style>
|
||||
@@ -0,0 +1 @@
|
||||
export const PLUGIN_ID = 'xq0082'
|
||||
@@ -0,0 +1,8 @@
|
||||
import { createApp } from 'vue'
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
// 注意顺序:style.css 必须在 element-plus 之后引入,才能覆盖 --el-* 变量映射到壳子 token
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).use(ElementPlus).mount('#app')
|
||||
@@ -0,0 +1,431 @@
|
||||
/* ============================================================
|
||||
插件 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; }
|
||||
@@ -0,0 +1,356 @@
|
||||
// 插件 UI 公共 kit v2(vendored 进各插件 ui-src,构建期内联,运行零外部依赖)。
|
||||
//
|
||||
// 与 v1 的差异(适配当前壳子):
|
||||
// 1. 新增 restoreLastFields():调 /api/plugins/<id>/last-fields 恢复上次执行参数(password 不落盘);
|
||||
// 2. 顶部大横幅 → 内联 notice:执行结果横幅、插件名/版本、运行 Indicator 已由壳子
|
||||
// (PageHead + 结果横幅 + RunIndicator)统一渲染,插件内不再重复;
|
||||
// 3. startRun 的 409 单独识别:壳子在 iframe fetch 上包了「入队确认」,用户取消会返回 409,
|
||||
// 不能再当成普通失败提示。
|
||||
//
|
||||
// 保留能力:本机当前配置(加载/防抖自动保存/恢复默认)、多配置方案(供定时任务按 config_id 引用)、
|
||||
// 执行状态机(执行/强停/WS 进度 + 轮询兜底/未登录重试)。
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { PLUGIN_ID } from './api'
|
||||
|
||||
async function j(url, opts) {
|
||||
const res = await fetch(url, opts)
|
||||
if (res.status === 401) {
|
||||
throw Object.assign(new Error('未登录:请先在壳子登录统一账户再打开本界面'), { code: 401 })
|
||||
}
|
||||
if (!res.ok) {
|
||||
let msg = `HTTP ${res.status}`
|
||||
try {
|
||||
msg = (await res.json()).detail || msg
|
||||
} catch (_) { /* 保留默认 */ }
|
||||
throw Object.assign(new Error(msg), { code: res.status, status: res.status })
|
||||
}
|
||||
return res.json()
|
||||
}
|
||||
|
||||
// ---- 后端 API(同源,统一账户会话 cookie 自动携带)----
|
||||
const loadConfig = () => j(`/api/plugin-config/${PLUGIN_ID}`)
|
||||
const saveConfig = (data) => j(`/api/plugin-config/${PLUGIN_ID}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
const loadLastFields = () => j(`/api/plugins/${PLUGIN_ID}/last-fields`)
|
||||
const listSchemes = () => j(`/api/plugin-configs?plugin_id=${encodeURIComponent(PLUGIN_ID)}`)
|
||||
const saveScheme = (name, fields) => j('/api/plugin-configs', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ plugin_id: PLUGIN_ID, name, fields }),
|
||||
})
|
||||
const deleteScheme = (cfgId) =>
|
||||
j(`/api/plugin-configs/${encodeURIComponent(PLUGIN_ID)}/${encodeURIComponent(cfgId)}`, { method: 'DELETE' })
|
||||
const startRun = (fields) => j('/api/runs', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ plugin_id: PLUGIN_ID, fields }),
|
||||
})
|
||||
const getRun = (runId) => j(`/api/runs/${runId}`)
|
||||
const stopRun = (runId) => j(`/api/runs/${runId}/stop`, { method: 'POST' })
|
||||
|
||||
function connectWS(onEvent) {
|
||||
const ws = new WebSocket((location.protocol === 'https:' ? 'wss://' : 'ws://')
|
||||
+ location.host + '/ws')
|
||||
ws.onmessage = (e) => { try { onEvent(JSON.parse(e.data)) } catch (_) { /* 忽略脏帧 */ } }
|
||||
return ws
|
||||
}
|
||||
|
||||
// ---- 工具 ----
|
||||
const clone = (o) => JSON.parse(JSON.stringify(o))
|
||||
|
||||
// 本机配置的「上次保存时间」:后端只存字段、不返回时间戳,
|
||||
// 这里用 localStorage 记住,刷新后仍能显示(取不到时静默)。
|
||||
const SAVED_AT_KEY = `plugin:${PLUGIN_ID}:lastSavedAt`
|
||||
function readSavedAt() {
|
||||
try { return localStorage.getItem(SAVED_AT_KEY) || '' } catch (_) { return '' }
|
||||
}
|
||||
function writeSavedAt(v) {
|
||||
try { localStorage.setItem(SAVED_AT_KEY, v) } catch (_) { /* 存储不可用时只保留内存态 */ }
|
||||
}
|
||||
|
||||
// 保存字段合并规则:标量空值(''/null/undefined)不覆盖;数组照原样应用
|
||||
// (空数组可能是有意配置,如「留空=不筛选」)
|
||||
function mergeSaved(form, saved) {
|
||||
Object.keys(form).forEach((k) => {
|
||||
const v = saved ? saved[k] : undefined
|
||||
if (v === undefined || v === null || v === '') return
|
||||
form[k] = Array.isArray(v) ? [...v] : v
|
||||
})
|
||||
}
|
||||
|
||||
export function usePluginUI(opts = {}) {
|
||||
const { defaults, validate, buildPayload } = opts
|
||||
|
||||
const form = reactive(defaults ? defaults() : {})
|
||||
const loaded = ref(false)
|
||||
const needLogin = ref(false)
|
||||
const notice = ref(null) // { type: 'warn'|'error'|'ok', text }
|
||||
const lastSavedAt = ref(readSavedAt())
|
||||
const running = ref(false)
|
||||
const progress = ref(0)
|
||||
const stopping = ref(false)
|
||||
|
||||
let ws = null
|
||||
let runId = ''
|
||||
let pollTimer = null
|
||||
let saveTimer = null
|
||||
|
||||
// 传空 type 视为清除横幅(不能留 {type:null},否则会渲染成只有"!"的空横幅)
|
||||
const notify = (type, text) => { notice.value = type ? { type, text } : null }
|
||||
|
||||
// ---------- 当前配置:加载 / 防抖自动保存 ----------
|
||||
// 登录由壳子统一处理(打开界面时会话必然就绪),这里读取失败一律静默回退默认值,
|
||||
// 不弹任何提示;真到执行时才发现会话问题,再明确告知。
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const saved = await loadConfig()
|
||||
mergeSaved(form, saved)
|
||||
} catch (e) {
|
||||
if (e.code === 401) needLogin.value = true
|
||||
}
|
||||
loaded.value = true
|
||||
refreshSchemes()
|
||||
})
|
||||
|
||||
watch(form, () => {
|
||||
if (!loaded.value || running.value) return
|
||||
clearTimeout(saveTimer)
|
||||
saveTimer = setTimeout(() => saveNow(false), 800)
|
||||
}, { deep: true })
|
||||
|
||||
async function saveNow(explicit) {
|
||||
try {
|
||||
await saveConfig(clone(form))
|
||||
lastSavedAt.value = new Date().toLocaleTimeString('zh-CN', { hour12: false })
|
||||
writeSavedAt(lastSavedAt.value)
|
||||
if (explicit) ElMessage.success('配置已保存到本机')
|
||||
} catch (e) {
|
||||
if (e.code === 401) needLogin.value = true
|
||||
else ElMessage.error('配置保存失败:' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
function resetDefaults() {
|
||||
Object.assign(form, defaults ? defaults(form) : {})
|
||||
notify(null)
|
||||
ElMessage.info('已恢复默认配置')
|
||||
}
|
||||
|
||||
// 恢复上次执行参数(壳子记录,password 类字段不落盘)
|
||||
async function restoreLastFields() {
|
||||
try {
|
||||
const r = await loadLastFields()
|
||||
const fields = r.fields || {}
|
||||
if (!Object.keys(fields).length) {
|
||||
ElMessage.info('暂无上次执行参数')
|
||||
return
|
||||
}
|
||||
mergeSaved(form, fields)
|
||||
ElMessage.success('已恢复上次执行参数' + (r.at ? `(${r.at})` : ''))
|
||||
} catch (e) {
|
||||
if (e.code === 401) needLogin.value = true
|
||||
else ElMessage.error('恢复上次参数失败:' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 多配置方案 ----------
|
||||
const schemes = ref([])
|
||||
const schemeSel = ref('')
|
||||
const schemeOptions = computed(() => [
|
||||
{ value: '', label: '当前配置(自动保存)' },
|
||||
...schemes.value.map((s) => ({ value: s.id, label: s.name })),
|
||||
])
|
||||
|
||||
async function refreshSchemes() {
|
||||
try {
|
||||
const r = await listSchemes()
|
||||
schemes.value = r.configs || []
|
||||
} catch (_) { /* 方案是辅助能力,失败静默 */ }
|
||||
}
|
||||
|
||||
function onSchemeChange(id) {
|
||||
if (!id) return
|
||||
const s = schemes.value.find((x) => x.id === id)
|
||||
if (!s) return
|
||||
mergeSaved(form, s.fields)
|
||||
ElMessage.success(`已应用方案「${s.name}」`)
|
||||
}
|
||||
|
||||
async function saveSchemeAs() {
|
||||
const cur = schemes.value.find((x) => x.id === schemeSel.value)
|
||||
let name = ''
|
||||
try {
|
||||
({ value: name } = await ElMessageBox.prompt(
|
||||
'方案保存到本机(同名覆盖,密码明文保存,每套方案可绑定不同账号),供「定时任务」引用:到点自动取该方案的最新参数执行。',
|
||||
'存为配置方案',
|
||||
{
|
||||
inputValue: cur ? cur.name : '',
|
||||
confirmButtonText: '保存方案',
|
||||
cancelButtonText: '取消',
|
||||
inputPattern: /\S/,
|
||||
inputErrorMessage: '请输入方案名称',
|
||||
},
|
||||
))
|
||||
} catch (_) {
|
||||
return
|
||||
}
|
||||
name = String(name).trim()
|
||||
if (!name) return
|
||||
const dup = schemes.value.find((x) => x.name === name)
|
||||
if (dup) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`已存在同名方案「${dup.name}」,保存将覆盖它的参数(多套不同配置请用不同名称)。`,
|
||||
'覆盖已有方案',
|
||||
{ type: 'warning', confirmButtonText: '覆盖保存', cancelButtonText: '取消' },
|
||||
)
|
||||
} catch (_) {
|
||||
return
|
||||
}
|
||||
}
|
||||
try {
|
||||
const r = await saveScheme(name, clone(form))
|
||||
await refreshSchemes()
|
||||
schemeSel.value = r.config ? r.config.id : ''
|
||||
ElMessage.success(`方案「${name}」已保存`)
|
||||
} catch (e) {
|
||||
if (e.code === 401) needLogin.value = true
|
||||
else ElMessage.error('方案保存失败:' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
async function removeScheme() {
|
||||
const s = schemes.value.find((x) => x.id === schemeSel.value)
|
||||
if (!s) return
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`删除配置方案「${s.name}」?引用它的定时任务到点会跳过触发并提示重选。`,
|
||||
'删除方案',
|
||||
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' },
|
||||
)
|
||||
} catch (_) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await deleteScheme(s.id)
|
||||
schemeSel.value = ''
|
||||
await refreshSchemes()
|
||||
ElMessage.success('方案已删除')
|
||||
} catch (e) {
|
||||
ElMessage.error('方案删除失败:' + e.message)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 执行 ----------
|
||||
// action: download(只下载)/ reconcile(只核对);不传则用 payload 里的 action
|
||||
async function run(action) {
|
||||
if (running.value) return
|
||||
if (needLogin.value) {
|
||||
try {
|
||||
await loadConfig()
|
||||
needLogin.value = false
|
||||
} catch (_) {
|
||||
notify('error', '登录态未就绪,请稍后重试')
|
||||
return
|
||||
}
|
||||
}
|
||||
if (validate && !validate(action)) return
|
||||
await saveNow(false)
|
||||
notify(null)
|
||||
running.value = true
|
||||
progress.value = 0
|
||||
try {
|
||||
const payload = buildPayload ? buildPayload(form) : clone(form)
|
||||
if (action) payload.action = action
|
||||
const r = await startRun(payload)
|
||||
runId = r.run_id
|
||||
connect()
|
||||
startPolling()
|
||||
} catch (e) {
|
||||
running.value = false
|
||||
stopPolling()
|
||||
if (e.code === 401) {
|
||||
needLogin.value = true
|
||||
notify('error', '登录态未就绪,本次没有启动,请稍后重试')
|
||||
} else if (e.code === 409) {
|
||||
// 壳子「入队确认」里用户点了取消
|
||||
notify('warn', '已取消加入执行队列,本次没有启动')
|
||||
} else {
|
||||
notify('error', '启动执行失败:' + e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function forceStop() {
|
||||
if (!runId || stopping.value) return
|
||||
stopping.value = true
|
||||
try {
|
||||
await stopRun(runId)
|
||||
ElMessage.warning('已发出强制停止指令,正在终止执行进程…')
|
||||
} catch (e) {
|
||||
ElMessage.error('停止失败:' + e.message)
|
||||
} finally {
|
||||
stopping.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function connect() {
|
||||
if (ws && ws.readyState <= 1) return
|
||||
ws = connectWS((ev) => {
|
||||
if (ev.run_id && ev.run_id !== runId) return
|
||||
if (ev.t === 'progress') progress.value = Math.max(progress.value, ev.pct || 0)
|
||||
// 用户强制停止 / 排队取消 / 排队超时 → 「已取消」,不显示成「执行失败」
|
||||
else if (ev.t === 'run_done') ev.ok ? finished() : (ev.status === 'cancelled' ? cancelled(ev.error) : failed(ev.error || '执行失败'))
|
||||
})
|
||||
ws.onclose = () => { ws = null }
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
stopPolling()
|
||||
pollTimer = setInterval(async () => {
|
||||
if (!runId) return
|
||||
try {
|
||||
const r = await getRun(runId)
|
||||
if (r.status === 'done') finished(r.result?.summary)
|
||||
else if (r.status === 'cancelled') cancelled(r.error)
|
||||
else if (r.status === 'error') failed(r.error || '执行失败')
|
||||
} catch (_) { /* 下轮再试 */ }
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
if (pollTimer) { clearInterval(pollTimer); pollTimer = null }
|
||||
}
|
||||
|
||||
function finished(summary) {
|
||||
stopPolling()
|
||||
running.value = false
|
||||
progress.value = 100
|
||||
// 结果横幅由壳子统一展示,插件内仅在需要时给一句简短结论
|
||||
if (summary) notify('ok', summary)
|
||||
}
|
||||
|
||||
// 用户主动停止 / 排队取消 / 排队超时:不算失败,给中性的「已取消」提示
|
||||
function cancelled(err) {
|
||||
stopPolling()
|
||||
running.value = false
|
||||
notify('warn', '任务已取消:' + (err || '用户已停止'))
|
||||
}
|
||||
|
||||
function failed(err) {
|
||||
stopPolling()
|
||||
running.value = false
|
||||
notify('error', '执行失败:' + err)
|
||||
}
|
||||
|
||||
return {
|
||||
form, loaded, needLogin, notice, lastSavedAt, running, progress, stopping,
|
||||
saveNow, resetDefaults, restoreLastFields,
|
||||
schemes, schemeSel, schemeOptions, onSchemeChange, saveSchemeAs, removeScheme,
|
||||
run, forceStop,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// 插件 UI 由壳子托管在 /pui/xq0082/ 下,构建产物输出到插件包 ui/ 目录。
|
||||
// dev 端口 5186(避开已占用的 5180~5182/5185),代理到本机壳子 8799。
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
base: '/pui/xq0082/',
|
||||
build: {
|
||||
outDir: '../ui',
|
||||
emptyOutDir: true,
|
||||
},
|
||||
server: {
|
||||
port: 5186,
|
||||
proxy: {
|
||||
'/api': { target: 'http://127.0.0.1:8799', changeOrigin: true },
|
||||
'/ws': { target: 'ws://127.0.0.1:8799', ws: true },
|
||||
},
|
||||
},
|
||||
})
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>通联数据核对</title>
|
||||
<script type="module" crossorigin src="/pui/xq0082/assets/index-BY1GIHkB.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/pui/xq0082/assets/index-D92smxw2.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user