feat(electron-shell): 1.8.0 执行队列、流程编排、流程定时与版本回滚
- 执行队列:多任务串行排队,可单独取消,超时自动放弃,异常退出后标记已中断 - 流程编排:画布多场景依赖图,内置确保登录/等待/通知/人工确认节点 - 流程定时:场景与流程统一配置定时(每天/工作日/每周/每月/每隔N小时) - 流程版本历史:自动留档 20 版,画布一键回滚且回滚可撤销 - 流程配置云备份:随定时任务备份到中心机,换机自动恢复 - 总览页/场景库布局调整,通知浮窗右下角堆叠显示
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="sched-page">
|
||||
<PageHead eyebrow="SCHEDULE · 计划" title="定时任务" sub="客户端内置定时:按 cron 到点自动执行插件,配置自动备份到中心机防丢失">
|
||||
<PageHead eyebrow="SCHEDULE · 计划" title="定时任务" sub="客户端内置定时:场景与流程都能按 cron 到点自动执行,场景任务的配置会自动备份到中心机">
|
||||
<template #actions>
|
||||
<el-button type="primary" :icon="Plus" @click="openCreate">新建任务</el-button>
|
||||
</template>
|
||||
@@ -42,12 +42,23 @@
|
||||
<span>{{ nextWhen(row).sub }}</span>
|
||||
</div>
|
||||
<div class="sr-main">
|
||||
<b>{{ row.name }}<em v-if="!row.enabled" class="off-pill">停用</em></b>
|
||||
<span>{{ pluginName(row.plugin_id) }}</span>
|
||||
<b>
|
||||
<span class="kind-pill" :class="row.kind">{{ row.kind === 'flow' ? '流程' : '场景' }}</span>
|
||||
{{ row.name }}<em v-if="!row.enabled" class="off-pill">停用</em>
|
||||
</b>
|
||||
<span v-if="row.kind === 'flow'">{{ row.node_count }} 个节点 · 按依赖串行执行</span>
|
||||
<span v-else>{{ pluginName(row.plugin_id) }}</span>
|
||||
</div>
|
||||
<code class="cron-chip">{{ row.cron }}</code>
|
||||
<div class="sr-last">
|
||||
<template v-if="row.last_run_at">
|
||||
<!-- 队列态优先:本次触发的运行还排在队列里时,比"上次成功 · 3 天前"更有信息量 -->
|
||||
<template v-if="queueState(row)">
|
||||
<span class="st-pill mid">
|
||||
<i class="dot"></i>{{ queueState(row).text }}
|
||||
</span>
|
||||
<span class="sr-last-time">{{ queueState(row).sub }}</span>
|
||||
</template>
|
||||
<template v-else-if="row.last_run_at">
|
||||
<span class="st-pill" :class="row.last_status === 'ok' ? 'ok' : (row.last_status === 'error' ? 'err' : 'mid')">
|
||||
<i class="dot"></i>
|
||||
<template v-if="row.last_status === 'ok'">成功<template v-if="row.last_duration"> · {{ row.last_duration }}s</template></template>
|
||||
@@ -60,6 +71,7 @@
|
||||
</div>
|
||||
<div class="sr-acts">
|
||||
<el-switch :model-value="row.enabled" size="small" @change="(v) => onToggle(row, v)" />
|
||||
<el-button v-if="row.kind === 'flow'" link type="primary" @click="onRunFlow(row)">运行</el-button>
|
||||
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" @click="onDelete(row)">删除</el-button>
|
||||
</div>
|
||||
@@ -76,13 +88,26 @@
|
||||
<el-form-item label="任务名称">
|
||||
<el-input v-model="form.name" placeholder="如:每日考勤封存检查" maxlength="32" />
|
||||
</el-form-item>
|
||||
<el-form-item label="执行插件">
|
||||
<!-- 执行对象:场景(单个插件)或流程(多节点编排),共用同一套定时规则 -->
|
||||
<el-form-item label="执行对象">
|
||||
<el-radio-group v-model="target" :disabled="!!editing" @change="onTargetChange">
|
||||
<el-radio-button value="scene">场景</el-radio-button>
|
||||
<el-radio-button value="flow">流程</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="target === 'flow'" label="执行流程">
|
||||
<el-select v-model="flowId" placeholder="选择要定时运行的流程" class="w-full" :disabled="!!editing">
|
||||
<el-option v-for="f in flows" :key="f.id" :value="f.id"
|
||||
:label="`${f.name}(${(f.nodes || []).length} 个节点)`" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-else label="执行插件">
|
||||
<el-select v-model="form.plugin_id" placeholder="选择要定时执行的插件" class="w-full" @change="onPluginChange">
|
||||
<el-option v-for="p in store.plugins" :key="p.id" :value="p.id"
|
||||
:label="`${p.name}(${p.id})`" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.plugin_id" label="执行配置">
|
||||
<el-form-item v-if="target === 'scene' && form.plugin_id" label="执行配置">
|
||||
<div class="w-full">
|
||||
<el-select v-model="cfgSel" class="w-full" placeholder="插件当前配置">
|
||||
<el-option label="插件当前配置" value="" />
|
||||
@@ -174,10 +199,37 @@ import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus } from '@element-plus/icons-vue'
|
||||
import { store } from '../store'
|
||||
import PageHead from './PageHead.vue'
|
||||
import { listSchedules, createSchedule, updateSchedule, deleteSchedule, toggleSchedule, listPluginConfigs } from '../api'
|
||||
import {
|
||||
listSchedules, createSchedule, updateSchedule, deleteSchedule, toggleSchedule,
|
||||
listPluginConfigs, listFlows, updateFlow, runFlow,
|
||||
} from '../api'
|
||||
import { fmtShort } from '../utils/format'
|
||||
|
||||
const list = ref([])
|
||||
// 计划页是"通用定时"入口:场景(插件)与流程(编排)都能在这里排期
|
||||
const flows = ref([])
|
||||
const target = ref('scene') // scene | flow
|
||||
const flowId = ref('')
|
||||
|
||||
// 切换执行对象:清掉另一边的选择,避免保存时串数据
|
||||
function onTargetChange() {
|
||||
cfgSel.value = ''
|
||||
if (target.value === 'flow') form.value.plugin_id = ''
|
||||
else flowId.value = ''
|
||||
}
|
||||
|
||||
// 该定时任务在队列里的实时状态:执行中 / 排队第 N 位 / 无
|
||||
// 定时触发不像手动点击有 run_start 即时反馈,撞车时全靠这里看出"它已经在排队了"
|
||||
function queueState(row) {
|
||||
const q = store.queue
|
||||
if (!q || !row) return null
|
||||
if (q.running && q.running.schedule_id === row.id) {
|
||||
return { text: '执行中', sub: '本次已开始' }
|
||||
}
|
||||
const it = (q.items || []).find((x) => x.schedule_id === row.id)
|
||||
if (it) return { text: `排队 ${it.position}`, sub: '等待执行' }
|
||||
return null
|
||||
}
|
||||
const dlg = ref(false)
|
||||
const editing = ref(null)
|
||||
const saving = ref(false)
|
||||
@@ -355,8 +407,33 @@ function onPreset(cron) {
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const r = await listSchedules()
|
||||
list.value = r.schedules || []
|
||||
const [rs, rf] = await Promise.all([
|
||||
listSchedules().catch(() => ({ schedules: [] })),
|
||||
listFlows().catch(() => ({ flows: [] })),
|
||||
])
|
||||
flows.value = rf.flows || []
|
||||
const taskRows = (rs.schedules || []).map((s) => ({ ...s, kind: 'scene' }))
|
||||
// 流程的定时挂在流程记录上:这里映射成同样的行结构,列表/开关/编辑共用一套交互
|
||||
const flowRows = flows.value
|
||||
.filter((f) => f.schedule && f.schedule.cron)
|
||||
.map((f) => ({
|
||||
id: `flow:${f.id}`,
|
||||
kind: 'flow',
|
||||
flow_id: f.id,
|
||||
name: f.name,
|
||||
cron: f.schedule.cron,
|
||||
enabled: !!f.schedule.enabled,
|
||||
last_run_at: f.schedule.last_run_at || '',
|
||||
last_status: f.schedule.last_status || '',
|
||||
last_duration: '',
|
||||
next_run_at: f.next_run_at || '',
|
||||
node_count: (f.nodes || []).length,
|
||||
}))
|
||||
// 启用中的按下次触发时间靠前,停用的沉底
|
||||
list.value = [...taskRows, ...flowRows].sort((a, b) => {
|
||||
if (!!a.enabled !== !!b.enabled) return a.enabled ? -1 : 1
|
||||
return String(a.next_run_at || '9999').localeCompare(String(b.next_run_at || '9999'))
|
||||
})
|
||||
} catch (e) {
|
||||
ElMessage.error('加载定时任务失败:' + (e.message || e))
|
||||
}
|
||||
@@ -364,6 +441,8 @@ async function load() {
|
||||
|
||||
function openCreate() {
|
||||
editing.value = null
|
||||
target.value = 'scene'
|
||||
flowId.value = ''
|
||||
form.value = { name: '', plugin_id: '', cron: '', enabled: true }
|
||||
cfgSel.value = ''
|
||||
configs.value = []
|
||||
@@ -380,6 +459,9 @@ function openCreate() {
|
||||
|
||||
function openEdit(row) {
|
||||
editing.value = row
|
||||
const isFlow = row.kind === 'flow'
|
||||
target.value = isFlow ? 'flow' : 'scene'
|
||||
flowId.value = isFlow ? row.flow_id : ''
|
||||
form.value = {
|
||||
name: row.name || '',
|
||||
plugin_id: row.plugin_id || '',
|
||||
@@ -387,7 +469,8 @@ function openEdit(row) {
|
||||
enabled: !!row.enabled,
|
||||
}
|
||||
cfgSel.value = row.config_id || ''
|
||||
loadConfigs(row.plugin_id)
|
||||
if (isFlow) configs.value = []
|
||||
else loadConfigs(row.plugin_id)
|
||||
// 把已有 cron 解析回可视化选择状态
|
||||
const st = cronToState(row.cron || '')
|
||||
freq.value = st.freq
|
||||
@@ -401,18 +484,31 @@ function openEdit(row) {
|
||||
}
|
||||
|
||||
async function onSave() {
|
||||
if (!form.value.plugin_id) { ElMessage.warning('请选择执行插件'); return }
|
||||
if (!form.value.cron.trim()) { ElMessage.warning('请填写 cron 表达式'); return }
|
||||
if (target.value === 'flow') {
|
||||
if (!flowId.value) { ElMessage.warning('请选择要定时执行的流程'); return }
|
||||
} else if (!form.value.plugin_id) {
|
||||
ElMessage.warning('请选择执行插件')
|
||||
return
|
||||
}
|
||||
if (!form.value.cron.trim()) { ElMessage.warning('请配合触发时间生成表达式'); return }
|
||||
saving.value = true
|
||||
try {
|
||||
// 引用插件界面维护的多配置方案(config_id),到点取方案最新参数;不选 = 插件当前配置
|
||||
const payload = { ...form.value, config_id: cfgSel.value }
|
||||
if (editing.value) {
|
||||
await updateSchedule(editing.value.id, payload)
|
||||
ElMessage.success('已保存')
|
||||
if (target.value === 'flow') {
|
||||
// 流程的定时保存在流程自己身上(flows.json),与流程编辑器里的开关是同一份数据
|
||||
await updateFlow(flowId.value, {
|
||||
schedule: { enabled: !!form.value.enabled, cron: form.value.cron },
|
||||
})
|
||||
ElMessage.success(editing.value ? '已保存' : '已创建')
|
||||
} else {
|
||||
await createSchedule(payload)
|
||||
ElMessage.success('已创建,配置已备份到中心机')
|
||||
// 引用插件界面维护的多配置方案(config_id),到点取方案最新参数;不选 = 插件当前配置
|
||||
const payload = { ...form.value, config_id: cfgSel.value }
|
||||
if (editing.value) {
|
||||
await updateSchedule(editing.value.id, payload)
|
||||
ElMessage.success('已保存')
|
||||
} else {
|
||||
await createSchedule(payload)
|
||||
ElMessage.success('已创建,配置已备份到中心机')
|
||||
}
|
||||
}
|
||||
dlg.value = false
|
||||
await load()
|
||||
@@ -425,28 +521,52 @@ async function onSave() {
|
||||
|
||||
async function onToggle(row, v) {
|
||||
try {
|
||||
await toggleSchedule(row.id, v)
|
||||
if (row.kind === 'flow') {
|
||||
// 流程定时挂在流程记录上:只改 enabled,cron 原样保留
|
||||
await updateFlow(row.flow_id, { schedule: { enabled: !!v, cron: row.cron } })
|
||||
} else {
|
||||
await toggleSchedule(row.id, v)
|
||||
}
|
||||
row.enabled = v
|
||||
ElMessage.success(v ? '已启用' : '已停用')
|
||||
await load()
|
||||
} catch (e) {
|
||||
ElMessage.error('操作失败:' + (e.message || e))
|
||||
}
|
||||
}
|
||||
|
||||
async function onDelete(row) {
|
||||
const isFlow = row.kind === 'flow'
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除定时任务「${row.name}」?删除后其配置备份会一并移除。`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
await ElMessageBox.confirm(
|
||||
isFlow
|
||||
? `确定取消流程「${row.name}」的定时?流程本身会保留,随时可以重新排期。`
|
||||
: `确定删除定时任务「${row.name}」?删除后其配置备份会一并移除。`,
|
||||
isFlow ? '取消定时' : '删除确认',
|
||||
{ type: 'warning', confirmButtonText: isFlow ? '取消定时' : '删除', cancelButtonText: '再想想' }
|
||||
)
|
||||
} catch (_) { return }
|
||||
try {
|
||||
await deleteSchedule(row.id)
|
||||
ElMessage.success('已删除')
|
||||
if (isFlow) {
|
||||
// 清空 cron 即视为取消排期(流程记录保留)
|
||||
await updateFlow(row.flow_id, { schedule: { enabled: false, cron: '' } })
|
||||
} else {
|
||||
await deleteSchedule(row.id)
|
||||
}
|
||||
ElMessage.success(isFlow ? '已取消定时' : '已删除')
|
||||
await load()
|
||||
} catch (e) {
|
||||
ElMessage.error('删除失败:' + (e.message || e))
|
||||
ElMessage.error('操作失败:' + (e.message || e))
|
||||
}
|
||||
}
|
||||
|
||||
// 流程行:立即运行一次(与流程页的「运行」等价)
|
||||
async function onRunFlow(row) {
|
||||
try {
|
||||
await runFlow(row.flow_id)
|
||||
ElMessage.success(`流程「${row.name}」已开始执行`)
|
||||
} catch (e) {
|
||||
ElMessage.error(e.message || '启动失败')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,7 +577,7 @@ load()
|
||||
.sched-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
gap: var(--space-4);
|
||||
padding: var(--page-pad);
|
||||
flex-shrink: 0; /* 自然高度,超出由中栏上下文区整体滚动 */
|
||||
}
|
||||
@@ -501,6 +621,13 @@ load()
|
||||
.sr-main b { display: flex; align-items: center; gap: var(--space-1-5); font: 600 12.5px/18px var(--f-cn); color: var(--t1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.sr-main span { font-size: 11px; color: var(--t4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.sched-row.off .sr-when, .sched-row.off .sr-main span, .sched-row.off .cron-chip { opacity: .55; }
|
||||
/* 执行对象标签:场景 / 流程 */
|
||||
.kind-pill {
|
||||
flex-shrink: 0; font: 500 9.5px/15px var(--f-cn);
|
||||
color: var(--t3); background: var(--field);
|
||||
border-radius: var(--r-pill); padding: 0 var(--space-1-5);
|
||||
}
|
||||
.kind-pill.flow { color: var(--brand-ink); background: var(--brand-soft); }
|
||||
.off-pill {
|
||||
flex-shrink: 0; font-style: normal; font: 500 10px/17px var(--f-cn);
|
||||
color: var(--t3); background: var(--field);
|
||||
|
||||
Reference in New Issue
Block a user