feat(electron-shell): 1.8.0 执行队列、流程编排、流程定时与版本回滚
- 执行队列:多任务串行排队,可单独取消,超时自动放弃,异常退出后标记已中断 - 流程编排:画布多场景依赖图,内置确保登录/等待/通知/人工确认节点 - 流程定时:场景与流程统一配置定时(每天/工作日/每周/每月/每隔N小时) - 流程版本历史:自动留档 20 版,画布一键回滚且回滚可撤销 - 流程配置云备份:随定时任务备份到中心机,换机自动恢复 - 总览页/场景库布局调整,通知浮窗右下角堆叠显示
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
<span v-if="plugin.platform" class="badge" :class="platformOnline ? 'on' : 'off'">
|
||||
<i class="bdot"></i>{{ platformLabel }} {{ platformOnline ? '已登录' : '未登录' }}
|
||||
</span>
|
||||
<span v-if="queuedCount" class="qchip" :title="`该场景有 ${queuedCount} 个任务正在排队,可在右侧「执行队列」查看或取消`">
|
||||
排队 {{ queuedCount }}
|
||||
</span>
|
||||
<RunIndicator v-if="store.running" variant="chip" :progress="store.progress" />
|
||||
<button v-if="rollbackVer" class="btn rollback-btn" :disabled="store.running" @click="doRollback">
|
||||
回滚 v{{ rollbackVer }}
|
||||
@@ -18,10 +21,11 @@
|
||||
</PageHead>
|
||||
|
||||
<!-- 结果横幅 -->
|
||||
<section v-if="store.lastResult" class="banner" :class="store.lastResult.ok ? 'ok' : 'err'">
|
||||
<span class="b-ic">{{ store.lastResult.ok ? '✓' : '✕' }}</span>
|
||||
<section v-if="store.lastResult" class="banner"
|
||||
:class="store.lastResult.ok ? 'ok' : (store.lastResult.cancelled ? 'mid' : 'err')">
|
||||
<span class="b-ic">{{ store.lastResult.ok ? '✓' : (store.lastResult.cancelled ? '⊘' : '✕') }}</span>
|
||||
<div class="b-body">
|
||||
<b>{{ store.lastResult.ok ? (store.lastSummary || '执行完成') : '执行失败' }}</b>
|
||||
<b>{{ store.lastResult.ok ? (store.lastSummary || '执行完成') : (store.lastResult.cancelled ? '任务已取消' : '执行失败') }}</b>
|
||||
<span v-if="!store.lastResult.ok">{{ store.lastResult.error }}</span>
|
||||
</div>
|
||||
<button class="b-close" @click="closeBanner" title="关闭">✕</button>
|
||||
@@ -45,8 +49,8 @@
|
||||
sandbox 白名单加固:允许脚本/同源/表单,禁用 top 跳转与弹窗
|
||||
仅一层容器承载尺寸,不再叠提示条/卡片 -->
|
||||
<div v-if="plugin.ui" v-show="tab === 'ui'" class="ui-pane">
|
||||
<iframe :key="plugin.id" :src="uiSrc" class="pui-frame" title="插件界面"
|
||||
sandbox="allow-scripts allow-same-origin allow-forms"></iframe>
|
||||
<iframe ref="uiFrame" :key="plugin.id" :src="uiSrc" class="pui-frame" title="插件界面"
|
||||
sandbox="allow-scripts allow-same-origin allow-forms" @load="onUiLoad"></iframe>
|
||||
</div>
|
||||
|
||||
<!-- 运行日志(当前/本次运行) -->
|
||||
@@ -67,12 +71,12 @@
|
||||
</div>
|
||||
<ul v-else class="hist-list">
|
||||
<li v-for="r in runs" :key="r.run_id" class="hist-item" @click="openReplay(r.run_id)">
|
||||
<i class="hist-dot" :class="r.ok ? 'ok' : 'err'"></i>
|
||||
<i class="hist-dot" :class="runState(r).cls"></i>
|
||||
<div class="hist-meta">
|
||||
<b>{{ triggerLabel(r.trigger) }}</b>
|
||||
<span class="hist-time">{{ fmtTime(r.started) }} · {{ durText(r.duration_sec) }}</span>
|
||||
</div>
|
||||
<span class="hist-state" :class="r.ok ? 'ok' : 'err'">{{ r.ok ? '成功' : '失败' }}</span>
|
||||
<span class="hist-state" :class="runState(r).cls">{{ runState(r).text }}</span>
|
||||
<el-icon class="hist-arrow"><ArrowRight /></el-icon>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -107,7 +111,7 @@ import { computed, ref, watch } from 'vue'
|
||||
import { Refresh, ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { store } from '../store'
|
||||
import { getRun, fetchRuns, fetchMeta, listRollbacks, rollbackPlugin } from '../api'
|
||||
import { getRun, fetchRuns, fetchMeta, listRollbacks, rollbackPlugin, fetchQueue } from '../api'
|
||||
import LogPanel from './LogPanel.vue'
|
||||
import RunIndicator from './RunIndicator.vue'
|
||||
import PageHead from './PageHead.vue'
|
||||
@@ -115,9 +119,92 @@ import { durText, fmtTime } from '../utils/format'
|
||||
|
||||
const plugin = computed(() => store.plugins.find((p) => p.id === store.selectedId) || null)
|
||||
|
||||
// 运行结论三态:成功 / 已取消(用户取消、排队超时、退出取消)/ 失败 / 已中断(客户端退出遗留)
|
||||
// 「取消」不能显示成「失败」——两者对用户的含义完全不同,也不该混进失败统计。
|
||||
function runState(r) {
|
||||
if (!r) return { text: '—', cls: 'mid' }
|
||||
if (r.ok) return { text: '成功', cls: 'ok' }
|
||||
if (r.status === 'cancelled') return { text: '已取消', cls: 'mid' }
|
||||
if (r.status === 'interrupted') return { text: '已中断', cls: 'mid' }
|
||||
return { text: '失败', cls: 'err' }
|
||||
}
|
||||
|
||||
// 本场景在队列里等待的任务数:连续点了几次「一键执行」时,页头直接给出排队提示
|
||||
const queuedCount = computed(() => {
|
||||
const pid = plugin.value?.id
|
||||
if (!pid) return 0
|
||||
return (store.queue.items || []).filter((it) => it.plugin_id === pid).length
|
||||
})
|
||||
|
||||
// 专属界面插件:插件 UI 直接内嵌在页面主体(同源自动携带会话 cookie,不再弹窗/外跳)。
|
||||
const uiSrc = computed(() => (plugin.value?.ui ? `/pui/${plugin.value.id}/` : ''))
|
||||
|
||||
// ===== 入队确认 =====
|
||||
// 插件界面里的「一键执行」直接 POST /api/runs(插件自己不知道队列的存在)。壳子在同源 iframe 的
|
||||
// window 上包一层 fetch:提交前先问一次队列状态,需要排队就弹确认框,用户点「加入队列」才真正提交;
|
||||
// 取消则返回 409,插件自身横幅会显示"启动执行失败:已取消加入队列…",不会误以为已经在跑。
|
||||
const uiFrame = ref(null)
|
||||
|
||||
async function queueSnapshotNow() {
|
||||
try {
|
||||
const snap = await fetchQueue()
|
||||
if (snap && Array.isArray(snap.items)) {
|
||||
return { busy: !!snap.busy, running: snap.running || null, waiting: snap.items.length }
|
||||
}
|
||||
} catch (_) { /* 后端不可达:退回 WS 快照,至少不会漏提示 */ }
|
||||
return { busy: store.queue.busy, running: store.queue.running, waiting: store.queue.waiting }
|
||||
}
|
||||
|
||||
// true = 继续提交;false = 用户取消,不入队
|
||||
async function confirmEnqueue() {
|
||||
const q = await queueSnapshotNow()
|
||||
if (!q.busy && !q.waiting) return true // 设备空闲:不打扰,直接开跑
|
||||
const bits = []
|
||||
if (q.running && q.running.name) bits.push(`「${q.running.name}」正在执行`)
|
||||
if (q.waiting) bits.push(`队列里还有 ${q.waiting} 个任务`)
|
||||
const pos = q.waiting + (q.busy ? 2 : 1)
|
||||
const name = plugin.value?.name || '当前场景'
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`${bits.join(',')}。执行「${name}」需要排队,确认后约排第 ${pos} 位,可在右侧「执行队列」随时取消。`,
|
||||
'当前有其他任务在执行,是否加入队列?',
|
||||
{ confirmButtonText: '加入队列', cancelButtonText: '取消', type: 'warning' }
|
||||
)
|
||||
return true
|
||||
} catch (_) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function onUiLoad() {
|
||||
const w = uiFrame.value && uiFrame.value.contentWindow
|
||||
if (!w || w.__queueConfirmPatched) return
|
||||
w.__queueConfirmPatched = true
|
||||
const origFetch = w.fetch ? w.fetch.bind(w) : null
|
||||
if (!origFetch) return
|
||||
w.fetch = async (input, init) => {
|
||||
let url = ''
|
||||
let method = 'GET'
|
||||
if (typeof input === 'string') {
|
||||
url = input
|
||||
method = (init && init.method) || 'GET'
|
||||
} else if (input && typeof input === 'object') {
|
||||
url = input.url || ''
|
||||
method = (init && init.method) || input.method || 'GET'
|
||||
}
|
||||
// 只拦"提交一次运行",配置/停止/轮询等其它接口原样放行
|
||||
if (String(method).toUpperCase() !== 'POST' || !/\/api\/runs\/?$/.test(url)) {
|
||||
return origFetch(input, init)
|
||||
}
|
||||
if (await confirmEnqueue()) return origFetch(input, init)
|
||||
const R = w.Response || Response
|
||||
return new R(JSON.stringify({ detail: '已取消加入队列(当前有其他任务在执行)' }), {
|
||||
status: 409,
|
||||
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 运行台标签页:插件界面(如有)/ 运行日志 / 历史运行 =====
|
||||
// 执行与参数配置收口在插件界面内(插件自包含前端+执行按钮),壳子不再提供参数表单与一键执行
|
||||
const tabs = computed(() => {
|
||||
@@ -196,7 +283,7 @@ watch(
|
||||
)
|
||||
|
||||
function triggerLabel(t) {
|
||||
return ({ manual: '手动执行', schedule: '定时任务' })[t] || t || '手动执行'
|
||||
return ({ manual: '手动执行', schedule: '定时任务', flow: '流程编排' })[t] || t || '手动执行'
|
||||
}
|
||||
|
||||
const platformLabel = computed(() => {
|
||||
@@ -287,6 +374,12 @@ function closeBanner() {
|
||||
.bdot { width: 6px; height: 6px; border-radius: 50%; background: var(--t5); }
|
||||
.badge.on .bdot { background: var(--good); }
|
||||
.rollback-btn { height: 28px; padding: 0 var(--space-3); font-size: 11.5px; }
|
||||
/* 本场景排队中:与运行中的进度胶囊并列,点击去看右侧队列明细 */
|
||||
.qchip {
|
||||
display: inline-flex; align-items: center; height: 20px; padding: 0 var(--space-2);
|
||||
border-radius: var(--r-pill); background: var(--brand-soft); color: var(--brand-ink);
|
||||
font: 500 10px/1 var(--f-cn); white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ---------- 结果横幅 ---------- */
|
||||
.banner {
|
||||
@@ -297,12 +390,14 @@ function closeBanner() {
|
||||
}
|
||||
.banner.ok { background: var(--good-soft); border: 1px solid var(--good-line); }
|
||||
.banner.err { background: var(--danger-soft); border: 1px solid var(--danger-line); }
|
||||
.banner.mid { background: var(--field); border: 1px solid var(--line); }
|
||||
.b-ic {
|
||||
width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
|
||||
display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--on-primary);
|
||||
}
|
||||
.banner.ok .b-ic { background: var(--good); }
|
||||
.banner.err .b-ic { background: var(--danger); }
|
||||
.banner.mid .b-ic { background: var(--t4); }
|
||||
.b-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
||||
.b-body b { font-size: 12.5px; color: var(--t1); font-weight: 600; }
|
||||
.b-body span { font-size: 11.5px; color: var(--t2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
@@ -370,12 +465,14 @@ function closeBanner() {
|
||||
.hist-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
|
||||
.hist-dot.ok { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
|
||||
.hist-dot.err { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
|
||||
.hist-dot.mid { background: var(--t4); box-shadow: 0 0 0 3px var(--field); }
|
||||
.hist-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
||||
.hist-meta b { font: 600 12.5px/18px var(--f-cn); color: var(--t1); }
|
||||
.hist-time { font: 400 10.5px/15px var(--f-num); color: var(--t4); }
|
||||
.hist-state { font: 600 11.5px/16px var(--f-cn); flex-shrink: 0; }
|
||||
.hist-state.ok { color: var(--good-ink); }
|
||||
.hist-state.err { color: var(--danger-ink); }
|
||||
.hist-state.mid { color: var(--t4); }
|
||||
.hist-arrow { color: var(--t5); font-size: 13px; flex-shrink: 0; }
|
||||
|
||||
.hist-replay { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
|
||||
|
||||
Reference in New Issue
Block a user