feat(electron-shell): 启动链路修复与执行/配置收口插件侧

- 启动链路 P1-P7 修复:预算对齐、完成事件推送、端口占用提示、前端阶段文案接管
- 静态缓存按 IS_FROZEN 区分开发/打包态,bootPhaseOwned 竞态修复
- 一键执行与参数配置统一收口到插件界面,定时任务引用 config_id
- 环境包迁移到 %LOCALAPPDATA%\37duAutomation\python-env,重装零解压
- shell-updater:缓存包 sha256 校验、静默升级后自动拉起新版、自动清理旧安装包
- after-pack 钩子生成 shell.version 修复打包态版本识别
- 插件 xq0031/xq0045 迁移至 plugins/XQ0001-0100/ 号段分桶中文目录
This commit is contained in:
2026-09-28 14:20:35 +08:00
parent f3311339e5
commit dbb05e6ab3
55 changed files with 1426 additions and 4280 deletions
@@ -19,8 +19,11 @@
</div>
<p class="p-hint">账号密码仅本机加密保存;登录后场景按<b>你的身份</b>执行。</p>
<!-- 账号配置弹窗 -->
<el-dialog v-model="dlg" :title="`配置 ${editLabel} 账号`" width="380px" align-center class="pacc-dlg">
<!-- 账号配置弹窗(必须 append-to-body:本组件位于 HomePage 的 .block 内,其
container-type: inline-size 隐含 contain: layout,会把 position:fixed 的遮罩
劫持为卡片包含块,导致弹窗"钉"在平台账号区域而不是全屏居中) -->
<el-dialog v-model="dlg" :title="`配置 ${editLabel} 账号`" width="380px" align-center
append-to-body class="pacc-dlg">
<el-form label-width="72px" @submit.prevent>
<el-form-item label="登录账号">
<el-input v-model="form.user" placeholder="平台登录账号" maxlength="64" />
@@ -1,6 +1,6 @@
<template>
<div v-if="plugin" class="plugin-page">
<!-- Hero:场景身份 + 大执行按钮 -->
<!-- Hero:场景身份 + 运行状态(执行入口收口在插件界面内,壳子不再提供一键执行) -->
<section class="hero card">
<div class="hero-main">
<span class="avatar" :style="{ background: avatarBg }">{{ plugin.name.slice(0, 1) }}</span>
@@ -13,35 +13,24 @@
<span v-if="plugin.platform" class="badge" :class="platformOnline ? 'on' : 'off'">
<i class="bdot"></i>{{ platformLabel }} {{ platformOnline ? '已登录' : '未登录' }}
</span>
<span v-if="plugin.uses_month" class="badge">
<el-select v-model="month" size="small" class="month-sel" :disabled="store.running">
<el-option v-for="m in months" :key="m" :value="m" :label="m" />
</el-select>
</span>
</div>
</div>
</div>
<div class="hero-actions">
<button class="run-btn" :class="{ running: store.running }" :disabled="store.running" @click="run">
<template v-if="store.running">
<span class="ring">
<svg viewBox="0 0 36 36" width="26" height="26">
<circle class="ring-bg" cx="18" cy="18" r="15.5" fill="none" stroke-width="3.5" />
<circle class="ring-fg" cx="18" cy="18" r="15.5" fill="none" stroke-width="3.5"
stroke-linecap="round" :stroke-dasharray="ringDash" transform="rotate(-90 18 18)" />
</svg>
</span>
<span>执行中 {{ store.progress }}%</span>
</template>
<template v-else>
<span class="play-ic">▶</span>
<span>一键执行</span>
</template>
</button>
<div v-if="store.running" class="run-chip">
<span class="ring">
<svg viewBox="0 0 36 36" width="22" height="22">
<circle class="ring-bg" cx="18" cy="18" r="15.5" fill="none" stroke-width="3.5" />
<circle class="ring-fg" cx="18" cy="18" r="15.5" fill="none" stroke-width="3.5"
stroke-linecap="round" :stroke-dasharray="ringDash" transform="rotate(-90 18 18)" />
</svg>
</span>
<span>执行中 {{ store.progress }}%</span>
</div>
<el-button v-if="rollbackVer" size="small" text type="warning" class="rollback-btn"
:disabled="store.running" @click="doRollback">回滚 v{{ rollbackVer }}</el-button>
<span class="hero-tip">配置与运行日志都在下方运行台</span>
<span class="hero-tip">在插件界面内配置并执行,运行日志与历史见下方</span>
</div>
</section>
@@ -55,8 +44,8 @@
<button class="b-close" @click="closeBanner" title="关闭">✕</button>
</section>
<!-- 运行台:参数 / 插件界面 / 运行日志
日志归属"本次运行"(不再是全局面板);带专属界面的插件用界面本身配置,故不并列参数表单 -->
<!-- 运行台:插件界面 / 运行日志 / 历史运行
执行与参数配置收口在插件界面内(插件自包含前端+执行);日志归属"本次运行" -->
<div class="run-tabs card">
<div class="rt-head">
<div class="rt-tabs">
@@ -66,56 +55,9 @@
<i v-if="t.k === 'log' && store.running" class="rt-live"></i>
</button>
</div>
<el-button v-if="tab === 'params' && fieldCount" size="small" text :disabled="store.running" :icon="RefreshLeft"
@click="resetForm">恢复默认</el-button>
</div>
<div class="rt-body">
<!-- 参数配置 -->
<section v-show="tab === 'params'" class="params">
<div class="cfg-bar">
<el-select v-model="curCfg" size="small" class="cfg-sel" placeholder="默认配置" @change="onCfgChange">
<el-option label="默认配置" value="" />
<el-option v-for="c in configs" :key="c.id" :value="c.id" :label="c.name" />
</el-select>
<el-button size="small" text :icon="FolderAdd" :disabled="store.running" @click="saveAsCfg">存为配置</el-button>
<el-button v-if="curCfg" size="small" text type="danger" :icon="Delete" :disabled="store.running" @click="delCfg">删除</el-button>
<span v-if="curCfgLabel" class="cfg-note">已套用「{{ curCfgLabel }}」,定时任务可引用</span>
</div>
<el-form label-width="auto" class="form-card">
<div class="fields">
<el-form-item v-for="f in plugin.fields" :key="f.key" :label="f.label">
<template v-if="f.type === 'int'">
<el-input-number v-model="form[f.key]" :controls="false" placeholder="0" :disabled="store.running" />
</template>
<el-input v-else-if="f.type === 'password'" v-model="form[f.key]" type="password" show-password
:placeholder="String(f.default ?? '')" :disabled="store.running">
<template v-if="f.help || f.description" #suffix>
<el-tooltip :content="f.help || f.description" placement="bottom"><el-icon class="help-ic">
<QuestionFilled />
</el-icon></el-tooltip>
</template>
</el-input>
<el-input v-else-if="f.type === 'text'" v-model="form[f.key]" :placeholder="String(f.default ?? '')"
:disabled="store.running">
<template v-if="f.help || f.description" #suffix>
<el-tooltip :content="f.help || f.description" placement="bottom"><el-icon class="help-ic">
<QuestionFilled />
</el-icon></el-tooltip>
</template>
</el-input>
<el-select v-else-if="f.type === 'multiselect'" v-model="form[f.key]" multiple filterable allow-create
default-first-option placeholder="选择或输入后回车" :disabled="store.running">
<el-option v-for="opt in (f.options || [])" :key="opt" :value="opt" :label="opt" />
</el-select>
<el-select v-else v-model="form[f.key]" :disabled="store.running">
<el-option v-for="opt in f.options" :key="opt" :value="opt" :label="opt" />
</el-select>
</el-form-item>
</div>
</el-form>
</section>
<!-- 插件专属界面(同源 iframe,自动携带会话 cookie)
sandbox 白名单加固:允许脚本/同源/表单,禁用 top 跳转与弹窗
仅一层容器承载尺寸,不再叠提示条/卡片 -->
@@ -176,10 +118,10 @@
<script setup>
import { computed, ref, watch } from 'vue'
import { QuestionFilled, Refresh, RefreshLeft, ArrowLeft, ArrowRight, FolderAdd, Delete } from '@element-plus/icons-vue'
import { Refresh, ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { store, log } from '../store'
import { startRun, getRun, fetchRuns, fetchMeta, listRollbacks, rollbackPlugin, listPluginConfigs, savePluginConfig, deletePluginConfig } from '../api'
import { store } from '../store'
import { getRun, fetchRuns, fetchMeta, listRollbacks, rollbackPlugin } from '../api'
import LogPanel from './LogPanel.vue'
const GRADS = [
@@ -187,136 +129,26 @@ const GRADS = [
'var(--grad-lilac)', 'var(--grad-honey)', 'var(--grad-blush)',
]
const months = computed(() => {
const now = new Date()
const list = []
for (let off = 1; off <= 6; off++) {
const d = new Date(now.getFullYear(), now.getMonth() - off, 1)
list.push(`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`)
}
return list
})
const month = ref(months.value[0])
const idx = computed(() => Math.max(0, store.plugins.findIndex((p) => p.id === store.selectedId)))
const avatarBg = computed(() => GRADS[idx.value % GRADS.length])
const plugin = computed(() => store.plugins.find((p) => p.id === store.selectedId) || null)
const form = ref({})
function buildFormDefaults(p) {
const f = {}
if (p) p.fields.forEach((x) => (f[x.key] = x.default ?? (x.type === 'int' ? 0 : '')))
return f
}
watch(
() => plugin.value?.id,
(id) => {
form.value = buildFormDefaults(store.plugins.find((x) => x.id === id))
loadConfigs()
},
{ immediate: true }
)
function resetForm() {
form.value = buildFormDefaults(plugin.value)
curCfg.value = ''
}
// ===== 配置方案(多配置):把当前参数存成命名方案,运行台可一键套用、定时任务可引用 =====
const configs = ref([])
const curCfg = ref('')
const curCfgLabel = computed(() => {
if (!curCfg.value) return ''
const c = configs.value.find((x) => x.id === curCfg.value)
return c ? c.name : ''
})
async function loadConfigs() {
if (!plugin.value?.id) {
configs.value = []
curCfg.value = ''
return
}
try {
const r = await listPluginConfigs(plugin.value.id)
configs.value = r.configs || []
if (curCfg.value && !configs.value.some((c) => c.id === curCfg.value)) curCfg.value = ''
} catch (e) {
ElMessage.error('配置方案加载失败:' + (e.message || e))
}
}
function onCfgChange(id) {
const c = configs.value.find((x) => x.id === id)
if (!c) return
Object.assign(form.value, c.fields)
ElMessage.success(`已套用配置「${c.name}」`)
}
async function saveAsCfg() {
let name
try {
const r = await ElMessageBox.prompt('给这套参数起个名字(同名会覆盖旧配置)', '保存为配置', {
confirmButtonText: '保存',
cancelButtonText: '取消',
inputPattern: /\S+/,
inputErrorMessage: '名称不能为空',
inputValue: curCfgLabel.value || '',
})
name = r.value
} catch (e) {
if (e === 'cancel') return
throw e
}
try {
const r = await savePluginConfig(plugin.value.id, name, { ...form.value })
await loadConfigs()
curCfg.value = r.config.id
ElMessage.success(`配置「${r.config.name}」已保存`)
} catch (e) {
ElMessage.error(e.message || String(e))
}
}
async function delCfg() {
try {
await ElMessageBox.confirm(`确定删除配置「${curCfgLabel.value}」?`, '删除配置', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消',
})
} catch (_) { return }
try {
await deletePluginConfig(plugin.value.id, curCfg.value)
curCfg.value = ''
await loadConfigs()
ElMessage.success('已删除')
} catch (e) {
ElMessage.error('删除失败:' + (e.message || e))
}
}
// 专属界面插件:插件 UI 直接内嵌在页面主体(同源自动携带会话 cookie,不再弹窗/外跳)。
const uiSrc = computed(() => (plugin.value?.ui ? `/pui/${plugin.value.id}/` : ''))
// ===== 运行台标签页 =====
// 带专属界面的插件由界面自己配置参数,故不并列参数表单(与改造前语义一致)
// ===== 运行台标签页:插件界面(如有)/ 运行日志 / 历史运行 =====
// 执行与参数配置收口在插件界面内(插件自包含前端+执行按钮),壳子不再提供参数表单与一键执行
const tabs = computed(() => {
const base = plugin.value?.ui
? [{ k: 'ui', label: '插件界面' }]
: [{ k: 'params', label: '参数配置' }]
return [...base, { k: 'log', label: '运行日志' }, { k: 'history', label: '历史运行' }]
const t = plugin.value?.ui ? [{ k: 'ui', label: '插件界面' }] : []
return [...t, { k: 'log', label: '运行日志' }, { k: 'history', label: '历史运行' }]
})
const tab = ref('params')
const fieldCount = computed(() => (plugin.value?.fields || []).length)
const tab = ref('log')
watch(
() => plugin.value?.id,
(id) => {
tab.value = plugin.value?.ui ? 'ui' : 'params'
() => {
tab.value = plugin.value?.ui ? 'ui' : 'log'
resetHistory()
consumePendingReplay()
},
@@ -446,29 +278,7 @@ async function doRollback() {
}
}
async function run() {
if (!plugin.value || store.running) return
if (plugin.value.platform && !platformOnline.value) {
log('WARN', `插件「${plugin.value.name}」需要先登录平台「${platformLabel.value}」才能正确执行`)
}
store.running = true
store.progress = 0
store.currentRun = ''
store.lastResult = null
store.lastSummary = ''
const payload = { ...form.value }
if (plugin.value.uses_month) payload.ref_month = month.value // 仅月度插件注入月份
try {
const r = await startRun(plugin.value.id, payload)
store.lastRunId = r.run_id
} catch (e) {
store.running = false
store.lastResult = { ok: false, error: e.message || String(e) }
log('ERROR', `启动执行失败:${e.message || e}`)
}
}
// 完成时拉取后端摘要填充横幅
// 完成时拉取后端摘要填充横幅(触发源无关:插件界面/定时任务触发的运行同样回填)
watch(
() => store.lastResult,
async (res) => {
@@ -537,27 +347,18 @@ function closeBanner() {
.badge.off { color: var(--badge-off-text); }
.bdot { width: 6px; height: 6px; border-radius: 50%; background: var(--badge-dot); }
.badge.on .bdot { background: var(--ok); }
.month-sel { width: 108px; --el-component-size: 24px; }
.hero-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; flex-shrink: 0; }
.run-btn {
display: inline-flex; align-items: center; gap: 9px;
padding: 0 26px; height: 50px;
border: none; border-radius: 16px;
background: var(--primary-grad-2);
color: var(--on-primary); font-size: 15px; font-weight: 600; letter-spacing: .06em;
cursor: pointer; font-family: inherit;
box-shadow: 0 12px 26px -12px rgba(var(--primary-rgb), .85);
transition: all .16s ease;
/* 运行状态 chip:仅展示进度,不可点击(执行入口在插件界面内) */
.run-chip {
display: inline-flex; align-items: center; gap: 8px;
padding: 6px 15px; border-radius: 999px;
background: var(--primary-grad-3); color: var(--on-primary);
font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums;
box-shadow: 0 8px 18px -10px rgba(var(--primary-rgb), .8);
}
.run-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 16px 30px -12px rgba(var(--primary-rgb), .95); }
.run-btn:active:not(:disabled) { transform: translateY(0) scale(.98); }
.run-btn.running { background: var(--primary-grad-3); cursor: default; min-width: 168px; font-variant-numeric: tabular-nums; }
/* 进度环用 CSS 上色(SVG 表现属性不支持 var(),故不写在 stroke="" 上) */
.ring-bg { stroke: rgba(var(--on-primary-rgb), .35); }
.ring-fg { stroke: var(--on-primary); }
.run-btn:disabled { opacity: 1; }
.play-ic { font-size: 13px; transform: translateY(-1px); }
.ring { display: inline-flex; }
.ring-fg { transition: stroke-dasharray .25s ease; }
.hero-tip { font-size: 10.5px; color: var(--text-faint); letter-spacing: .02em; }
@@ -623,15 +424,6 @@ function closeBanner() {
border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
/* ---------- 参数 ---------- */
.params { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 18px 22px 6px; }
.cfg-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.cfg-sel { width: 200px; }
.cfg-note { font-size: 11.5px; color: var(--text-faint); }
.fields { display: flex; gap: 24px; flex-wrap: wrap; }
.form-card .el-form-item { margin-bottom: 18px; }
.help-ic { color: var(--text-faint); cursor: help; }
/* ---------- 历史运行 ---------- */
.history { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.hist-view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
@@ -5,7 +5,7 @@
<span class="avatar"><el-icon><Clock /></el-icon></span>
<div class="ident-meta">
<h2>定时任务</h2>
<p>壳子内置定时:按 cron 到点自动执行插件,配置自动备份到中心机防丢失</p>
<p>客户端内置定时:按 cron 到点自动执行插件,配置自动备份到中心机防丢失</p>
</div>
</div>
<el-button type="primary" :icon="Plus" @click="openCreate">新建任务</el-button>
@@ -60,9 +60,9 @@
:label="`${p.name}(${p.id})`" />
</el-select>
</el-form-item>
<el-form-item v-if="form.plugin_id" label="使用配置">
<el-select v-model="cfgSel" class="w-full" placeholder="默认配置">
<el-option label="默认配置" value="" />
<el-form-item v-if="form.plugin_id" label="执行配置">
<el-select v-model="cfgSel" class="w-full" placeholder="插件当前配置">
<el-option label="插件当前配置" value="" />
<el-option v-for="c in configs" :key="c.id" :value="c.id" :label="c.name" />
</el-select>
</el-form-item>
@@ -130,9 +130,9 @@
</div>
</div>
</el-form-item>
<!-- 定时执行引用运行台保存的配置方案:不在此复刻参数字段表单(各场景字段千差万别) -->
<!-- 参数引用插件界面维护的多配置方案:到点自动取所选方案的最新参数(方案更新自动跟随) -->
<el-form-item label="执行配置">
<span class="params-tip">到点自动执行该场景,使用上方<b>所选配置</b>(默认 = 插件默认参数);自定义参数请在运行台「存为配置」后引用</span>
<span class="params-tip">到点自动执行该场景,使用上方<b>所选方案</b>的最新参数;方案在插件界面内保存维护(同名覆盖);不选 = 使用插件当前保存的配置</span>
</el-form-item>
<el-form-item label="启用">
<el-switch v-model="form.enabled" />
@@ -252,7 +252,7 @@ const presets = [
{ label: '每月 1 日 09:00', cron: '0 9 1 * *' },
]
const form = ref({ name: '', plugin_id: '', cron: '', enabled: true, fields: {} })
const form = ref({ name: '', plugin_id: '', cron: '', enabled: true })
function pluginName(id) {
return store.plugins.find((p) => p.id === id)?.name || id
@@ -287,19 +287,12 @@ function fmtShort(s) {
return pad2(d.getMonth() + 1) + '-' + pad2(d.getDate()) + ' ' + pad2(d.getHours()) + ':' + pad2(d.getMinutes())
}
function buildFields(p) {
const f = {}
if (p) p.fields.forEach((x) => (f[x.key] = x.default ?? (x.type === 'int' ? 0 : '')))
return f
}
function onPluginChange(id) {
form.value.fields = buildFields(store.plugins.find((x) => x.id === id))
cfgSel.value = ''
loadConfigs(id)
}
// ===== 配置方案引用:运行台「存为配置」的方案可在此选用 =====
// ===== 配置方案引用:方案由插件界面内保存维护(同名覆盖),定时任务到点取方案最新参数 =====
const configs = ref([])
const cfgSel = ref('')
@@ -310,22 +303,10 @@ async function loadConfigs(pluginId) {
const r = await listPluginConfigs(pluginId)
configs.value = r.configs || []
} catch (e) {
// 方案加载失败不阻塞任务编辑,静默降级为「默认配置」
// 方案加载失败不阻塞任务编辑,静默降级为「插件当前配置」
}
}
// 把选中的配置方案字段应用到任务(未选 = 插件默认参数)
function applySelectedConfig() {
if (cfgSel.value) {
const c = configs.value.find((x) => x.id === cfgSel.value)
if (c) {
form.value.fields = { ...c.fields }
return
}
}
form.value.fields = buildFields(store.plugins.find((x) => x.id === form.value.plugin_id))
}
function onPreset(cron) {
advancedCron.value = cron
preset.value = ''
@@ -342,7 +323,7 @@ async function load() {
function openCreate() {
editing.value = null
form.value = { name: '', plugin_id: '', cron: '', enabled: true, fields: {} }
form.value = { name: '', plugin_id: '', cron: '', enabled: true }
cfgSel.value = ''
configs.value = []
// 默认:每天 08:00
@@ -358,15 +339,13 @@ function openCreate() {
function openEdit(row) {
editing.value = row
// 执行参数引用配置方案:编辑时先按「默认配置」展示,可自行改选
form.value = {
name: row.name || '',
plugin_id: row.plugin_id || '',
cron: row.cron || '',
enabled: !!row.enabled,
fields: buildFields(store.plugins.find((x) => x.id === row.plugin_id)),
}
cfgSel.value = ''
cfgSel.value = row.config_id || ''
loadConfigs(row.plugin_id)
// 把已有 cron 解析回可视化选择状态
const st = cronToState(row.cron || '')
@@ -383,14 +362,15 @@ function openEdit(row) {
async function onSave() {
if (!form.value.plugin_id) { ElMessage.warning('请选择执行插件'); return }
if (!form.value.cron.trim()) { ElMessage.warning('请填写 cron 表达式'); return }
applySelectedConfig()
saving.value = true
try {
// 引用插件界面维护的多配置方案(config_id),到点取方案最新参数;不选 = 插件当前配置
const payload = { ...form.value, config_id: cfgSel.value }
if (editing.value) {
await updateSchedule(editing.value.id, { ...form.value })
await updateSchedule(editing.value.id, payload)
ElMessage.success('已保存')
} else {
await createSchedule({ ...form.value })
await createSchedule(payload)
ElMessage.success('已创建,配置已备份到中心机')
}
dlg.value = false