feat(electron-shell): 新增插件目录选择接口并将版本升至 1.10.0

This commit is contained in:
2026-10-30 10:00:18 +08:00
parent 526116af83
commit 210de5b68b
337 changed files with 3254 additions and 49349 deletions
@@ -5,7 +5,7 @@
1) 登录态预检(API 校验 %LOCALAPPDATA%\\37duAutomation\\.sessions\\crm_cookie_header.txt);
有效则全程免扫码,失效则打开可见浏览器等钉钉扫码一次(同次运行最多弹一次);
2) 打开「报表统计/储值卡余额」整页截图 → 储值卡余额-YYYYMMDD.png;
3) requests 复用同一登录态,按日期规则导出 18 张报表 xlsx
3) requests 复用同一登录态,按日期规则导出 22 张报表 xlsx
(礼品卡订单因接口限制跨度 ≤31 天,近 3 个自然月按月拆分)。
"""
import os
@@ -19,8 +19,8 @@ from .data import crm_export
class CrmDataExportPlugin(ScenePlugin):
id = "xq0048"
name = "CRM数据导出"
version = "1.1.6"
description = ("37du CRM(crm.37du.co)数据导出:储值卡余额整页截图 + 18 张报表自动导出(导出内容可勾选),"
version = "1.1.10"
description = ("37du CRM(crm.37du.co)数据导出:储值卡余额整页截图 + 22 张报表自动导出(导出内容可勾选),"
"登录态钉钉扫码一次后缓存复用(约 30 分钟内免扫码),"
"按各报表日期规则自动计算区间,礼品卡订单按月拆分")
platform = "" # CRM 为钉钉扫码登录,插件内自带登录流程,不使用底座共享登录态
@@ -114,15 +114,21 @@ UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
# ==================== 报表清单(名称, 导出接口, 日期规则, 附加参数, 日期参数字段) ====================
# 规则:prev=前一天单日;prev_today=昨日~今日;month_to_today=本月1日~今日;
# prev_prev=昨日~昨日;month1_to_prev=本月1日~前一天;last_month=上月完整;
# last3_months=近 3 个自然月按月拆分(止日不超过前一天)
# last3_months=近 3 个自然月按月拆分(止日不超过前一天);
# today=当日快照(无日期筛选参数,仅用于文件命名)
# 日期参数字段:报表统计类为 reportDate;淘宝订单为 createTimePeriod(页面「购买时间」);
# 微盟核销为 validateDatePeriod;开卡订单/会员退卡为 period;
# 礼品卡订单为 receiveTimePeriod(接口限制跨度 ≤31 天,故按月拆分)
# 礼品卡订单为 receiveTimePeriod(接口限制跨度 ≤31 天,故按月拆分);
# 储值余额为 None(页面只有手机号筛选,查询即全量导出)
REPORTS = [
('储值余额', 'report/debitCard/memberBalanceExport', 'today', None, None),
('储值记录', 'report/debitCard/depositExport', 'month_to_today', {'depositType': 2}, 'reportDate'), # 储值类型=小程序储值
('储值台账', 'report/debitCard/balanceAccountBookExport', 'month_to_today', {'depositType': 2}, 'reportDate'), # 储值类型=小程序储值
('团购支付数据', 'report/groupPay/export', 'prev', None, 'reportDate'),
('现金支付', 'report/cashPay/export', 'prev', None, 'reportDate'),
('第三方支付(门店)', 'report/thirdPayShop/export', 'prev', None, 'reportDate'),
('支付数据', 'report/unionPay/export', 'prev', None, 'reportDate'),
('订单附加属性统计', 'report/orderSubjectAddition/export', 'prev', None, 'payFinishTimePeriod'),
('团购数据', 'report/groupData/export', 'prev_today', None, 'reportDate'),
('淘宝订单数据', 'report/taobaoTicket/export', 'prev_today', None, 'createTimePeriod'),
('技师综合业绩', 'report/comprehensivePerformance/export', 'month_to_today', None, 'reportDate'),
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""xq0048 CRM 数据导出 - 储值卡余额截图 + 18 张报表导出。
"""xq0048 CRM 数据导出 - 储值卡余额截图 + 22 张报表导出。
从影刀版 workflows/XQ0001-0100/XQ0048 CRM数据导出/crm_export_all.py 迁移,
登录逻辑改为插件内 data/crm_login.py(自包含,不跨目录 import)。
@@ -216,9 +216,11 @@ def _screenshot(save_dir, date_str):
# ==================== 报表导出 ====================
def _date_window(rule):
"""按规则返回 (起, 止) 日期。"""
"""按规则返回 (起, 止) 日期。today 仅用于无日期筛选报表的文件命名。"""
today = date.today()
prev = today - timedelta(days=1)
if rule == 'today':
return today, today
if rule == 'prev' or rule == 'prev_prev':
return prev, prev
if rule == 'prev_today':
@@ -288,11 +290,15 @@ def _export_window(title, path, beg, end, extra, save_dir, date_key, idx, total)
filename = _filename(title, beg, end)
save_path = os.path.join(save_dir, filename)
url = config.BASE + path
date_val = f'{beg:%Y-%m-%d} {end:%Y-%m-%d}'
if date_key == 'reportDate' and beg == end:
date_val = f'{beg:%Y-%m-%d}'
params = {'pageNum': 1, 'pageSize': config.PAGE_SIZE, date_key: date_val}
date_desc = f'{date_key}={date_val}'
params = {'pageNum': 1, 'pageSize': config.PAGE_SIZE}
if date_key:
date_val = f'{beg:%Y-%m-%d} {end:%Y-%m-%d}'
if date_key == 'reportDate' and beg == end:
date_val = f'{beg:%Y-%m-%d}'
params[date_key] = date_val
date_desc = f'{date_key}={date_val}'
else:
date_desc = '无日期筛选(全量)'
if extra:
params.update(extra)
@@ -2,8 +2,8 @@
"schema_version": 1,
"id": "xq0048",
"name": "CRM数据导出",
"version": "1.1.6",
"description": "37du CRM(crm.37du.co)数据导出:储值卡余额整页截图 + 18 张报表自动导出(导出内容可勾选)。登录态钉钉扫码一次后缓存复用(约 30 分钟内免扫码),按各报表日期规则自动计算区间,礼品卡订单因接口限制跨度 ≤31 天按月拆分。",
"version": "1.1.10",
"description": "37du CRM(crm.37du.co)数据导出:储值卡余额整页截图 + 22 张报表自动导出(导出内容可勾选)。登录态钉钉扫码一次后缓存复用(约 30 分钟内免扫码),按各报表日期规则自动计算区间,礼品卡订单因接口限制跨度 ≤31 天按月拆分。",
"category": "财务",
"icon": "",
"platform": "",
@@ -1,140 +1,133 @@
<template>
<div class="page">
<!-- 未登录 / 结果横幅 -->
<transition name="fade-slide">
<el-alert v-if="needLogin" type="warning" :closable="false" show-icon title="未登录:请先在壳子(工作台)登录统一账户,再刷新本界面" />
<el-alert v-else-if="banner" :type="banner.type" :closable="true" show-icon @close="banner = null">
<template #title>{{ banner.text }}</template>
</el-alert>
</transition>
<!-- 方案工具条:方案供「定时任务」按 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>
<!-- 执行配置(头部含多配置方案:方案供「定时任务」引用,到点自动取方案最新参数) -->
<el-card shadow="never" class="panel">
<template #header>
<div class="panel-head">
<div class="panel-title">
<span class="title-ico">
<svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
<polyline points="7 10 12 15 17 10" />
<line x1="12" y1="15" x2="12" y2="3" />
</svg>
</span>
<div class="title-txts">
<div class="title-txt">执行配置</div>
<div class="title-sub">勾选导出内容,参数自动保存到本机,方案供定时任务到点引用</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">{{ 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">
<div class="grp-tools">
<span class="gt-count">已选 <b>{{ form.reports.length }}</b> / {{ ALL_KEYS.length }} 项</span>
<span class="spacer" />
<el-button size="small" :disabled="running" @click="selectAll">全选</el-button>
<el-button size="small" text :disabled="running || !form.reports.length"
@click="clearAll">清空</el-button>
</div>
<div class="groups">
<div v-for="g in GROUPED" :key="g.name" class="grp">
<div class="grp-head">
<el-checkbox :model-value="g.all" :indeterminate="g.some" :disabled="running"
@change="toggleGroup(g)">{{ g.name }}</el-checkbox>
<span class="grp-count" :class="{ full: g.all }">{{ g.picked }}/{{ g.items.length }}</span>
</div>
<div class="grp-body">
<el-checkbox v-for="it in g.items" :key="it.key" :model-value="form.reports.includes(it.key)"
:disabled="running" class="rep-item" @change="toggleItem(it.key)">
<span class="rep-name">{{ it.name }}</span>
<el-tooltip :content="it.tag" placement="top" :show-after="150">
<el-icon class="rep-info"><InfoFilled /></el-icon>
</el-tooltip>
</el-checkbox>
</div>
</div>
<div class="head-tools">
<span v-if="lastSavedAt" class="saved">
<i class="dot" />已保存 {{ 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>
</template>
<div class="tip">
勾选项由后端按各自规则自动计算日期区间并导出;<b>截图</b>=储值卡余额整页,<b>储值余额</b>=当天快照(无日期筛选)。
</div>
</div>
</section>
<el-form label-position="top">
<!-- 执行说明 -->
<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="flow-desc">
<div class="flow-item"><span class="flow-no">1</span>登录态预检:约 30 分钟内免扫码;失效时自动打开浏览器,钉钉扫码一次后全程复用</div>
<div class="flow-item"><span class="flow-no">2</span>「报表统计/储值卡余额」整页截图 → 储值卡余额-YYYYMMDD.png</div>
<div class="flow-item"><span class="flow-no">3</span>按勾选的报表自动计算日期区间,逐张导出 xlsx(礼品卡订单因接口限制跨度 ≤31 天,按月拆分)</div>
</div>
</section>
<!-- 导出内容(按业务分组) -->
<section class="sec">
<div class="sec-head">
<span class="sec-badge">02</span>
<span class="sec-name">导出内容</span>
<span class="sec-line" />
<span class="sec-count">已选 <b>{{ form.reports.length }}</b> / {{ ALL_KEYS.length }} 项</span>
<el-button size="small" text type="primary" :disabled="running" @click="selectAll">全选</el-button>
<el-button size="small" text :disabled="running || !form.reports.length" @click="clearAll">清空</el-button>
</div>
<div class="groups">
<div v-for="g in GROUPED" :key="g.name" class="grp">
<div class="grp-head">
<el-checkbox :model-value="g.all" :indeterminate="g.some" :disabled="running"
@change="toggleGroup(g)">{{ g.name }}</el-checkbox>
<span class="grp-count" :class="{ full: g.all }">{{ g.picked }}/{{ g.items.length }}</span>
</div>
<div class="grp-body">
<el-checkbox v-for="it in g.items" :key="it.key" :model-value="form.reports.includes(it.key)"
:disabled="running" class="rep-item" @change="toggleItem(it.key)">
<span class="rep-name">{{ it.name }}</span>
<el-tooltip :content="it.tag" placement="top" :show-after="150">
<el-icon class="rep-info"><InfoFilled /></el-icon>
</el-tooltip>
</el-checkbox>
</div>
</div>
</div>
<div class="tip">日期区间由各报表规则自动计算:截图=当天;前一天;昨日~今日;昨日;本月1日~今日;本月1日~昨日;上月完整;近3个自然月(礼品卡订单按月拆分)</div>
</section>
<!-- 执行设置 -->
<section class="sec">
<div class="sec-head">
<span class="sec-badge">03</span>
<span class="sec-name">执行设置</span>
<span class="sec-line" />
</div>
<!-- 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="grid">
<el-form-item label="保存目录">
<el-input v-model="form.save_dir" :disabled="running" clearable
placeholder="留空 = D:\资料\财务\CRM数据导出" />
<div class="dir-ctrl">
<el-input v-model="form.save_dir" class="dir-input" :disabled="running" clearable
placeholder="D:\资料\财务\CRM数据导出" />
<el-button class="dir-btn" :disabled="running || picking" :loading="picking"
@click="pickDir">选择</el-button>
</div>
</el-form-item>
<el-form-item label="调试日志">
<el-switch v-model="form.debug_mode" :disabled="running" />
</el-form-item>
</div>
<div class="tip">截图与全部 xlsx 统一输出到保存目录;「调试日志」开启后输出完整调试信息(默认关闭)</div>
</section>
<!-- 操作 -->
<div class="actions">
<el-button type="primary" size="large" class="btn-run" :loading="running" @click="run">
{{ running ? '执行中 ' + progress + '%' : '一键执行' }}
</el-button>
<el-button v-if="running" type="danger" size="large" plain :loading="stopping"
@click="forceStop">强制停止</el-button>
<span class="spacer" />
<el-button size="large" :disabled="running" @click="saveNow(true)">保存配置</el-button>
<el-button size="large" text :disabled="running" @click="resetDefaults">恢复默认</el-button>
</div>
</el-form>
</el-card>
<!-- 运行状态 -->
<transition name="fade-slide">
<div v-if="running" class="status">
<el-progress :percentage="progress" :stroke-width="10" :show-text="false" class="status-bar" />
<div class="status-row">
<span class="pulse" />
<span class="status-txt">正在执行,日志与进度实时显示在工作台下方【运行日志】区</span>
<span class="status-pct">{{ progress }}%</span>
</div>
<div class="tip">
截图与全部 xlsx 统一输出到该目录(留空 = 默认目录);<b>调试日志</b>开启后输出完整调试信息,默认关闭。
</div>
</el-form>
</div>
</transition>
</section>
<!-- 流程说明:大段说明收进折叠区 -->
<details class="help">
<summary><span>流程说明</span><span class="h-arrow">▾</span></summary>
<div class="help-body">
<div class="hb-line"><b>① 登录态预检</b>:约 30 分钟内免扫码;失效时自动打开浏览器,钉钉扫码一次后全程复用。</div>
<div class="hb-line"><b>② 截图</b>:进入「报表统计 / 储值卡余额」整页截图 → <b>储值卡余额-YYYYMMDD.png</b>。</div>
<div class="hb-line"><b>③ 报表导出</b>:按勾选项逐张导出 xlsx;礼品卡订单因接口限制跨度 ≤31 天,按月拆分。</div>
<div class="hb-line"><b>日期规则</b>:当天快照(储值余额)/ 前一天 / 昨日~今日 / 昨日 / 本月1日~今日 / 本月1日~昨日 / 上月完整 / 近3个自然月。</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 v-if="running" class="runline">
<span class="pulse" />
<span>正在执行,日志与进度实时显示在工作台下方「运行日志」区</span>
<span class="pct">{{ progress }}%</span>
</div>
</div>
</template>
<script setup>
import { computed } from 'vue'
import { computed, ref } from 'vue'
import { usePluginUI } from './usePluginUI'
import { ElMessage } from 'element-plus'
import { InfoFilled } from '@element-plus/icons-vue'
@@ -146,10 +139,14 @@ const ITEMS = [
{ key: 'report/cashPay/export#prev', name: '现金支付', tag: '前一天', group: '支付数据' },
{ key: 'report/thirdPayShop/export#prev', name: '第三方支付(门店)', tag: '前一天', group: '支付数据' },
{ key: 'report/unionPay/export#prev', name: '支付数据', tag: '前一天', group: '支付数据' },
{ key: 'report/orderSubjectAddition/export#prev', name: '订单附加属性统计', tag: '前一天', group: '支付数据' },
{ key: 'report/groupData/export#prev_today', name: '团购数据', tag: '昨日~今日', group: '支付数据' },
{ key: 'report/taobaoTicket/export#prev_today', name: '淘宝订单数据', tag: '昨日~今日', group: '支付数据' },
{ key: 'report/comprehensivePerformance/export#month_to_today', name: '技师综合业绩', tag: '本月1日~今日', group: '业绩与核销' },
{ key: 'report/weimeng/exportValidate#prev_prev', name: '微盟核销统计', tag: '昨日', group: '业绩与核销' },
{ key: 'report/debitCard/memberBalanceExport#today', name: '储值余额', tag: '当天快照·无日期筛选', group: '储值卡与霸王餐' },
{ key: 'report/debitCard/depositExport#month_to_today', name: '储值记录', tag: '本月1日~今日·小程序储值', group: '储值卡与霸王餐' },
{ key: 'report/debitCard/balanceAccountBookExport#month_to_today', name: '储值台账', tag: '本月1日~今日·小程序储值', group: '储值卡与霸王餐' },
{ key: 'report/debitCardConsume/export#month1_to_prev', name: '储值卡消费', tag: '本月1日~昨日', group: '储值卡与霸王餐' },
{ key: 'report/depositData/export#month1_to_prev', name: '储值卡线上充值', tag: '本月1日~昨日·渠道=管理端', group: '储值卡与霸王餐' },
{ key: 'report/overlordOrderDeposit/export#month1_to_prev', name: '霸王餐充值明细', tag: '本月1日~昨日', group: '储值卡与霸王餐' },
@@ -164,15 +161,16 @@ const ITEMS = [
const ALL_KEYS = ITEMS.map((i) => i.key)
const GROUPS = [...new Set(ITEMS.map((i) => i.group))]
// DEFAULTS 与 plugin.json.fields 的 default 逐项一致
const DEFAULTS = () => ({
reports: [...ALL_KEYS],
save_dir: '',
save_dir: 'D:\\资料\\财务\\CRM数据导出',
debug_mode: false,
})
const {
form, needLogin, banner, lastSavedAt, running, progress, stopping,
saveNow, resetDefaults,
form, needLogin, notice, lastSavedAt, running, progress, stopping,
saveNow, resetDefaults, restoreLastFields,
schemeSel, schemeOptions, onSchemeChange, saveSchemeAs, removeScheme,
run, forceStop,
} = usePluginUI({
@@ -223,413 +221,108 @@ function selectAll() {
function clearAll() {
form.reports = []
}
// 调用壳子本机接口打开原生「选择文件夹」对话框(壳子 /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
}
}
</script>
<style scoped>
/* ---------- 页面骨架 ---------- */
.page {
width: 100%;
padding: 6px 4px 28px;
display: flex;
flex-direction: column;
gap: 14px;
}
/* 插件差异样式:只用壳子 token,不写字面色值;左右内边距由壳子提供 */
.fade-slide-enter-active,
.fade-slide-leave-active {
transition: opacity 0.25s ease, transform 0.25s ease;
}
.fade-slide-enter-from,
.fade-slide-leave-to {
opacity: 0;
transform: translateY(-6px);
}
/* ---------- 主容器(无边框平铺:外层由壳子 iframe 的边框统一包裹) ---------- */
.panel {
background: transparent;
border-radius: 0;
border: none;
box-shadow: none;
overflow: hidden;
}
.panel :deep(.el-card__header) {
padding: 6px 2px 16px;
border-bottom: 1px solid var(--el-border-color-lighter);
background: transparent;
}
.panel :deep(.el-card__body) {
padding: 16px 2px 2px;
}
/* ---------- 卡片头部 ---------- */
.panel-head {
/* ---------- 导出内容:顶部计数 + 按钮 ---------- */
.grp-tools {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
gap: var(--space-2);
margin-bottom: var(--space-2-5);
}
.grp-tools .spacer { flex: 1; }
.gt-count { font: 400 11.5px/1 var(--f-cn); color: var(--t3); }
.gt-count b { font: 600 12px/1 var(--f-num); color: var(--brand-ink); font-variant-numeric: tabular-nums; }
.panel-title {
display: flex;
align-items: center;
gap: 12px;
}
.title-ico {
width: 36px;
height: 36px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
color: var(--el-color-primary);
background: linear-gradient(135deg, var(--el-color-primary-light-8), var(--el-color-primary-light-6));
box-shadow: inset 0 0 0 1px var(--el-color-primary-light-5);
flex-shrink: 0;
}
.title-txts {
display: flex;
flex-direction: column;
gap: 2px;
}
.title-txt {
font-weight: 700;
font-size: 15px;
line-height: 1.2;
color: var(--el-text-color-primary);
}
.title-sub {
font-size: 12px;
color: var(--el-text-color-secondary);
line-height: 1.3;
}
.head-tools {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.scheme-sel {
width: 200px;
}
.saved {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: #2ea44f;
background: rgba(46, 164, 79, 0.1);
border: 1px solid rgba(46, 164, 79, 0.25);
padding: 2px 10px;
border-radius: 999px;
white-space: nowrap;
}
.saved .dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #2ea44f;
}
/* ---------- 表单分区 ---------- */
.sec {
margin-bottom: 20px;
}
.sec:last-of-type {
margin-bottom: 4px;
}
.sec-head {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 14px;
}
.sec-badge {
width: 24px;
height: 24px;
border-radius: 7px;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 12px;
font-weight: 700;
color: var(--el-color-primary);
background: var(--el-color-primary-light-9);
border: 1px solid var(--el-color-primary-light-7);
flex-shrink: 0;
}
.sec-name {
font-size: 14px;
font-weight: 600;
color: var(--el-text-color-primary);
white-space: nowrap;
}
.sec-line {
flex: 1;
height: 1px;
background: linear-gradient(90deg, var(--el-border-color-lighter), transparent);
}
.sec-count {
font-size: 12px;
color: var(--el-text-color-secondary);
white-space: nowrap;
}
.sec-count b {
color: var(--el-color-primary);
font-weight: 700;
}
/* 执行说明 */
.flow-desc {
display: flex;
flex-direction: column;
gap: 8px;
}
.flow-item {
display: flex;
align-items: flex-start;
gap: 10px;
font-size: 13px;
color: var(--el-text-color-regular);
line-height: 1.6;
}
.flow-no {
width: 20px;
height: 20px;
border-radius: 6px;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 12px;
font-weight: 700;
color: var(--el-color-primary);
background: var(--el-color-primary-light-9);
border: 1px solid var(--el-color-primary-light-7);
flex-shrink: 0;
margin-top: 2px;
}
/* ---------- 导出内容分组 ---------- */
/* ---------- 分组块:浅灰底 + 描边,避免白卡叠白卡 ---------- */
.groups {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
gap: 10px;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
gap: var(--space-2-5);
}
.grp {
border: 1px solid var(--el-border-color-lighter);
border-radius: 10px;
padding: 10px 14px 12px;
background: var(--el-fill-color-blank);
transition: border-color 0.2s;
background: var(--subtle);
border: 1px solid var(--line);
border-radius: var(--r-field);
padding: 8px 12px 10px;
}
.grp:hover {
border-color: var(--el-color-primary-light-5);
}
.grp-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
gap: var(--space-2);
padding-bottom: 6px;
margin-bottom: 4px;
border-bottom: 1px dashed var(--el-border-color-lighter);
border-bottom: 1px solid var(--line-soft);
}
.grp-head :deep(.el-checkbox__label) {
font-weight: 600;
font-size: 13px;
font: 600 12.5px/18px var(--f-cn);
color: var(--t1);
}
.grp-count {
font-size: 12px;
color: var(--el-text-color-secondary);
font: 500 11px/1 var(--f-num);
color: var(--t3);
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--r-pill);
padding: 4px 8px;
font-variant-numeric: tabular-nums;
background: var(--el-fill-color);
border-radius: 999px;
padding: 1px 8px;
}
.grp-count.full {
color: var(--el-color-success);
background: rgba(46, 164, 79, 0.1);
color: var(--good-ink);
background: var(--good-soft);
border-color: var(--good-line);
}
.grp-body {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 2px 8px;
margin-top: 4px;
margin-top: 6px;
}
.grp-body :deep(.el-checkbox) {
margin-right: 0;
height: 26px;
height: 24px;
}
.grp-body :deep(.el-checkbox__label) {
display: inline-flex;
align-items: center;
gap: 5px;
font-size: 12.5px;
color: var(--el-text-color-primary);
padding-left: 4px;
font: 400 12px/18px var(--f-cn);
color: var(--t2);
}
.rep-info {
font-size: 13px;
color: var(--el-text-color-placeholder);
cursor: help;
flex-shrink: 0;
transition: color 0.2s;
}
.rep-info:hover {
color: var(--el-color-primary);
}
.grid {
display: grid;
grid-template-columns: minmax(280px, 1fr) auto;
gap: 0 18px;
align-items: start;
}
.grid :deep(.el-form-item) {
margin-bottom: 0;
}
.grid :deep(.el-form-item__label) {
padding-bottom: 6px;
font-weight: 500;
}
.tip {
width: 100%;
font-size: 12px;
color: var(--el-text-color-secondary);
line-height: 1.6;
margin-top: 6px;
color: var(--t4);
cursor: help;
transition: color var(--dur);
}
.rep-info:hover { color: var(--brand); }
/* ---------- 操作区 ---------- */
.actions {
display: flex;
align-items: center;
gap: 10px;
border-top: 1px dashed var(--el-border-color);
padding-top: 18px;
margin-top: 18px;
}
.spacer {
flex: 1;
}
.btn-run {
min-width: 150px;
border: none;
border-radius: 10px;
letter-spacing: 2px;
background: linear-gradient(135deg, var(--el-color-primary), var(--el-color-primary-dark-2));
box-shadow: 0 6px 16px var(--el-color-primary-light-6);
transition: filter 0.2s, box-shadow 0.2s, transform 0.15s;
}
.btn-run:hover {
filter: brightness(1.06);
box-shadow: 0 8px 20px var(--el-color-primary-light-5);
transform: translateY(-1px);
}
.btn-run:active {
transform: translateY(0);
}
.btn-run.is-loading {
pointer-events: none;
}
/* ---------- 运行状态 ---------- */
.status {
padding: 14px 16px;
border-radius: 12px;
background: linear-gradient(135deg, var(--el-color-primary-light-9), var(--el-color-primary-light-8));
border: 1px solid var(--el-color-primary-light-6);
box-shadow: 0 2px 10px var(--el-color-primary-light-7);
}
.status-bar :deep(.el-progress-bar__outer) {
background: rgba(64, 158, 255, 0.15);
}
.status-bar :deep(.el-progress-bar__inner) {
background: linear-gradient(90deg, var(--el-color-primary), var(--el-color-primary-dark-2));
}
.status-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 8px;
}
.pulse {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--el-color-primary);
animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
0% {
box-shadow: 0 0 0 0 var(--el-color-primary-light-6);
}
70% {
box-shadow: 0 0 0 8px transparent;
}
100% {
box-shadow: 0 0 0 0 transparent;
}
}
.status-txt {
flex: 1;
font-size: 12.5px;
color: var(--el-text-color-regular);
line-height: 1.5;
}
.status-pct {
font-size: 14px;
font-weight: 700;
color: var(--el-color-primary);
font-variant-numeric: tabular-nums;
}
/* ---------- 执行设置:目录输入框 + 选择按钮(同一行两列) ---------- */
.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; }
</style>
@@ -1,7 +1,9 @@
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import App from './App.vue'
createApp(App).use(ElementPlus, { locale: zhCn }).mount('#app')
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 zhCn from 'element-plus/es/locale/lang/zh-cn'
import App from './App.vue'
createApp(App).use(ElementPlus, { locale: zhCn }).mount('#app')
@@ -0,0 +1,341 @@
/* ============================================================
插件 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; }
}
@@ -1,9 +1,14 @@
// 插件 UI 公共 kit(vendored 进各插件 ui-src,构建期内联进产物,运行零外部依赖)。
// 收敛三块通用逻辑,App.vue 只保留各插件差异部分(表单字段/校验/布局):
// 1. 本机当前配置:加载、防抖自动保存、恢复默认(/api/plugin-config/<id>)
// 2. 多配置方案:列表/应用/存为方案/删除(/api/plugin-configs,同名覆盖、密码明文保存;
// 供壳子「定时任务」按 config_id 引用,到点自动取方案最新参数)
// 3. 执行状态机:一键执行、强制停止、WS 实时进度 + 轮询兜底、未登录重试
// 插件 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'
@@ -15,58 +20,37 @@ async function j(url, opts) {
}
if (!res.ok) {
let msg = `HTTP ${res.status}`
try { msg = (await res.json()).detail || msg } catch (_) { /* 保留默认 */ }
throw new Error(msg)
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 自动携带)----
function loadConfig() {
return j(`/api/plugin-config/${PLUGIN_ID}`)
}
function saveConfig(data) {
return j(`/api/plugin-config/${PLUGIN_ID}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
})
}
function listSchemes() {
return j(`/api/plugin-configs?plugin_id=${encodeURIComponent(PLUGIN_ID)}`)
}
function saveScheme(name, fields) {
return j('/api/plugin-configs', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ plugin_id: PLUGIN_ID, name, fields }),
})
}
function deleteScheme(cfgId) {
return j(`/api/plugin-configs/${encodeURIComponent(PLUGIN_ID)}/${encodeURIComponent(cfgId)}`, {
method: 'DELETE',
})
}
function startRun(fields) {
return j('/api/runs', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ plugin_id: PLUGIN_ID, fields }),
})
}
function getRun(runId) {
return j(`/api/runs/${runId}`)
}
function stopRun(runId) {
return j(`/api/runs/${runId}/stop`, { method: 'POST' })
}
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://')
@@ -78,8 +62,18 @@ function connectWS(onEvent) {
// ---- 工具 ----
const clone = (o) => JSON.parse(JSON.stringify(o))
// 保存字段合并规则:标量空值(''/null/undefined)不覆盖;数组照原样应用——
// 空数组可能是有意配置(如 xq0031 仓库留空 = 全部不筛选),必须还原
// 本机配置的「上次保存时间」:后端只存字段、不返回时间戳,
// 这里用 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
@@ -88,22 +82,14 @@ function mergeSaved(form, saved) {
})
}
/**
* 插件 UI 公共状态机
* @param {Object} opts
* @param {Function} opts.defaults 默认表单工厂;恢复默认时传入当前表单作参考
* (如 xq0031 按当前 erp_system 带出对应默认组织/仓库)
* @param {Function} [opts.validate] 执行前校验,失败自行 ElMessage 提示并返回 false
* @param {Function} [opts.buildPayload] 定制提交参数(缺省 = 表单全量深拷贝)
*/
export function usePluginUI(opts = {}) {
const { defaults, validate, buildPayload } = opts
const form = reactive(defaults ? defaults() : {})
const loaded = ref(false)
const needLogin = ref(false)
const banner = ref(null)
const lastSavedAt = ref('')
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)
@@ -113,20 +99,23 @@ export function usePluginUI(opts = {}) {
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
else ElMessage.warning('读取本机配置失败,已用默认值:' + e.message)
}
loaded.value = true
refreshSchemes() // 方案列表一并加载:重开界面/切插件回来(iframe 重挂载)后,下拉仍列出全部已存方案
refreshSchemes()
})
// 配置变更自动保存(防抖 800ms),执行中不保存
watch(form, () => {
if (!loaded.value || running.value) return
clearTimeout(saveTimer)
@@ -137,6 +126,7 @@ export function usePluginUI(opts = {}) {
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
@@ -146,12 +136,30 @@ export function usePluginUI(opts = {}) {
function resetDefaults() {
Object.assign(form, defaults ? defaults(form) : {})
notify(null)
ElMessage.info('已恢复默认配置')
}
// ---------- 多配置方案(定时任务引用的参数快照,在插件界面维护) ----------
const schemes = ref([]) // [{id, name, fields, at}]
const schemeSel = ref('') // '' = 当前配置(即表单本身)
// 恢复上次执行参数(壳子记录,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 })),
@@ -161,15 +169,11 @@ export function usePluginUI(opts = {}) {
try {
const r = await listSchemes()
schemes.value = r.configs || []
} catch (_) {
/* 方案是辅助能力,加载失败静默(下拉仅剩当前配置) */
}
} catch (_) { /* 方案是辅助能力,失败静默 */ }
}
// 应用方案:载入方案字段(密码随方案明文保存)→ 防抖自动保存固化为当前配置;
// 执行永远提交表单当前值,方案本身只作为定时任务的参数快照源
function onSchemeChange(id) {
if (!id) return // 切回「当前配置」:表单即当前配置,无需动作
if (!id) return
const s = schemes.value.find((x) => x.id === id)
if (!s) return
mergeSaved(form, s.fields)
@@ -189,10 +193,10 @@ export function usePluginUI(opts = {}) {
cancelButtonText: '取消',
inputPattern: /\S/,
inputErrorMessage: '请输入方案名称',
}
},
))
} catch (_) {
return // 用户取消
return
}
name = String(name).trim()
if (!name) return
@@ -202,10 +206,10 @@ export function usePluginUI(opts = {}) {
await ElMessageBox.confirm(
`已存在同名方案「${dup.name}」,保存将覆盖它的参数(多套不同配置请用不同名称)。`,
'覆盖已有方案',
{ type: 'warning', confirmButtonText: '覆盖保存', cancelButtonText: '取消' }
{ type: 'warning', confirmButtonText: '覆盖保存', cancelButtonText: '取消' },
)
} catch (_) {
return // 用户取消覆盖
return
}
}
try {
@@ -226,7 +230,7 @@ export function usePluginUI(opts = {}) {
await ElMessageBox.confirm(
`删除配置方案「${s.name}」?引用它的定时任务到点会跳过触发并提示重选。`,
'删除方案',
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' }
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' },
)
} catch (_) {
return
@@ -242,38 +246,45 @@ export function usePluginUI(opts = {}) {
}
// ---------- 执行 ----------
async function run() {
// action: download(只下载)/ reconcile(只核对);不传则用 payload 里的 action
async function run(action) {
if (running.value) return
// 未登录不再静默返回:先重试一次配置读取(会话可能在打开后已恢复),仍失败则明确提示
if (needLogin.value) {
try {
await loadConfig()
needLogin.value = false
ElMessage.success('登录态已恢复,请再次点击执行')
} catch (_) {
notify('error', '登录态未就绪,请稍后重试')
return
} catch (_) { /* 仍未登录 */ }
ElMessage.warning('未登录:请先在壳子登录统一账户,再打开本界面')
return
}
}
if (validate && !validate()) return
if (validate && !validate(action)) return
await saveNow(false)
notify(null)
running.value = true
progress.value = 0
banner.value = null
try {
const r = await startRun(buildPayload ? buildPayload(form) : clone(form))
const payload = buildPayload ? buildPayload(form) : clone(form)
if (action) payload.action = action
const r = await startRun(payload)
runId = r.run_id
connect() // runId 就绪后再连 WS,避免早到的运行事件被过滤掉
connect()
startPolling()
} catch (e) {
running.value = false
stopPolling()
if (e.code === 401) needLogin.value = true
banner.value = { type: 'error', text: '启动执行失败:' + e.message }
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
@@ -287,11 +298,10 @@ export function usePluginUI(opts = {}) {
}
}
// 实时进度 + 完成(WS 只取进度/结束事件,日志由壳子下方日志区展示;断开后轮询兜底)
function connect() {
if (ws && ws.readyState <= 1) return
ws = connectWS((ev) => {
if (ev.run_id && ev.run_id !== runId) return // 只看本次运行
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() : failed(ev.error || '执行失败')
})
@@ -304,7 +314,7 @@ export function usePluginUI(opts = {}) {
if (!runId) return
try {
const r = await getRun(runId)
if (r.status === 'done') finished(r.result?.summary || '执行完成')
if (r.status === 'done') finished(r.result?.summary)
else if (r.status === 'error') failed(r.error || '执行失败')
} catch (_) { /* 下轮再试 */ }
}, 5000)
@@ -318,23 +328,20 @@ export function usePluginUI(opts = {}) {
stopPolling()
running.value = false
progress.value = 100
banner.value = { type: 'success', text: summary || '执行完成' }
// 结果横幅由壳子统一展示,插件内仅在需要时给一句简短结论
if (summary) notify('ok', summary)
}
function failed(err) {
stopPolling()
running.value = false
banner.value = { type: 'error', text: '执行失败:' + err }
notify('error', '执行失败:' + err)
}
return {
// 状态
form, loaded, needLogin, banner, lastSavedAt, running, progress, stopping,
// 当前配置
saveNow, resetDefaults,
// 多配置方案
form, loaded, needLogin, notice, lastSavedAt, running, progress, stopping,
saveNow, resetDefaults, restoreLastFields,
schemes, schemeSel, schemeOptions, onSchemeChange, saveSchemeAs, removeScheme,
// 执行
run, forceStop,
}
}
@@ -4,8 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CRM数据导出</title>
<script type="module" crossorigin src="/pui/xq0048/assets/index-DLXNU8di.js"></script>
<link rel="stylesheet" crossorigin href="/pui/xq0048/assets/index-CLtlaiAs.css">
<script type="module" crossorigin src="/pui/xq0048/assets/index-DDWdGAco.js"></script>
<link rel="stylesheet" crossorigin href="/pui/xq0048/assets/index-B4OFoa9k.css">
</head>
<body>
<div id="app"></div>