779 lines
33 KiB
Vue
779 lines
33 KiB
Vue
<template>
|
||
<div v-if="plugin" class="plugin-page">
|
||
<!-- 页头:场景身份 + 平台状态 + 运行中/回滚入口(与其它一级视图共用 PageHead) -->
|
||
<PageHead eyebrow="CONSOLE · 运行台">
|
||
<template #title>
|
||
<span class="p-name">{{ plugin.name }}<span class="ver-tag">v{{ plugin.version }}</span></span>
|
||
</template>
|
||
<!-- 副标题:剥掉「XQxxxx 名称:」前缀,最多两行;悬停看全文,完整描述走「详情」弹窗 -->
|
||
<template #sub>
|
||
<span class="p-sub" :title="fullDesc">{{ shortDesc }}</span>
|
||
</template>
|
||
<template #actions>
|
||
<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 }}
|
||
</button>
|
||
<button v-if="hasDesc" class="btn desc-btn" @click="descDialog = true">详情</button>
|
||
</template>
|
||
</PageHead>
|
||
|
||
<div class="page-body">
|
||
<!-- 结果横幅 -->
|
||
<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 || '执行完成') : (store.lastResult.cancelled ? '任务已取消' : '执行失败') }}</b>
|
||
<span v-if="!store.lastResult.ok">{{ store.lastResult.error }}</span>
|
||
</div>
|
||
<button class="b-close" @click="closeBanner" title="关闭">✕</button>
|
||
</section>
|
||
|
||
<!-- 运行备注:账号 × 插件 唯一,本机保存并回传中心机;执行时随本次运行记录上报
|
||
备注可能较长(多行),列表只放一行摘要,查看/编辑统一走弹窗 -->
|
||
<div class="note-bar">
|
||
<span class="nb-label">运行备注</span>
|
||
<span class="nb-preview" :class="{ empty: !noteText }" :title="noteText || ''">
|
||
{{ noteText || ('给 ' + (plugin.name || '当前场景') + ' 写点备注') }}
|
||
</span>
|
||
<el-button size="small" text :disabled="!noteText" @click="openNote('view')">查看</el-button>
|
||
<el-button size="small" text @click="openNote('edit')">编辑</el-button>
|
||
<span class="nb-state" :class="{ ok: noteSavedAt && !noteSaving }">
|
||
{{ noteSaving ? '保存中…' : (noteSavedAt ? '已保存 ' + noteSavedAt : '') }}
|
||
</span>
|
||
</div>
|
||
|
||
<!-- 备注弹窗:查看只读,编辑可改(保存即回传中心机,执行时随运行一起上报) -->
|
||
<el-dialog v-model="noteDialog" :title="'运行备注 · ' + (plugin.name || '当前场景')"
|
||
width="560px" append-to-body class="note-dialog">
|
||
<el-input v-if="noteEdit" v-model="noteDraft" type="textarea" :rows="8" maxlength="500"
|
||
show-word-limit resize="vertical"
|
||
:placeholder="'给 ' + (plugin.name || '当前场景') + ' 写点备注'" />
|
||
<div v-else class="note-view">{{ noteText || '暂无备注' }}</div>
|
||
<template #footer>
|
||
<div class="note-foot">
|
||
<el-button v-if="noteEdit && noteText" text type="danger" :disabled="noteSaving"
|
||
@click="clearNote">清空</el-button>
|
||
<span class="spacer" />
|
||
<el-button @click="noteDialog = false">{{ noteEdit ? '取消' : '关闭' }}</el-button>
|
||
<el-button v-if="noteEdit" type="primary" :loading="noteSaving" @click="saveNote">保存</el-button>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 场景描述详情:manifest 里的完整描述按「;」拆段展示,页头只给两行摘要 -->
|
||
<el-dialog v-model="descDialog" :title="'场景说明 · ' + (plugin.name || '当前场景')"
|
||
width="600px" append-to-body class="desc-dialog">
|
||
<div class="desc-body">
|
||
<p v-for="(row, i) in descRows" :key="i" class="desc-p">{{ row }}</p>
|
||
<p v-if="!descRows.length" class="desc-p desc-empty">该场景暂无说明</p>
|
||
</div>
|
||
<template #footer>
|
||
<div class="note-foot">
|
||
<span class="spacer" />
|
||
<el-button @click="descDialog = false">关闭</el-button>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 运行台:插件界面 / 运行日志 / 历史运行
|
||
执行与参数配置收口在插件界面内(插件自包含前端+执行);日志归属"本次运行" -->
|
||
<div class="run-tabs">
|
||
<div class="rt-head">
|
||
<div class="rt-tabs">
|
||
<button v-for="t in tabs" :key="t.k" class="rt-tab" :class="{ on: tab === t.k }" @click="tab = t.k">
|
||
{{ t.label }}
|
||
<span v-if="t.k === 'log' && store.logs.length" class="rt-n">{{ store.logs.length }}</span>
|
||
<RunIndicator v-if="t.k === 'log' && store.running" variant="dot" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="rt-body">
|
||
<!-- 插件专属界面(同源 iframe,自动携带会话 cookie)
|
||
sandbox 白名单加固:允许脚本/同源/表单,禁用 top 跳转与弹窗
|
||
仅一层容器承载尺寸,不再叠提示条/卡片 -->
|
||
<div v-if="plugin.ui" v-show="tab === 'ui'" class="ui-pane">
|
||
<iframe ref="uiFrame" :key="plugin.id" :src="uiSrc" class="pui-frame" title="插件界面"
|
||
sandbox="allow-scripts allow-same-origin allow-forms" @load="onUiLoad"></iframe>
|
||
</div>
|
||
|
||
<!-- 运行日志(当前/本次运行) -->
|
||
<div v-show="tab === 'log'" class="rt-log"><LogPanel /></div>
|
||
|
||
<!-- 历史运行:本场景已完成的运行,点击回看该次日志 -->
|
||
<section v-show="tab === 'history'" class="history">
|
||
<div v-if="!replay" class="hist-view">
|
||
<div class="hist-head">
|
||
<div class="hist-titles">
|
||
<span class="hist-title">本场景最近运行</span>
|
||
<span class="hist-sub">共 {{ runs.length }} 条 · 成功 {{ histOk }} · 失败 {{ histFail }}</span>
|
||
</div>
|
||
<el-button size="small" text :icon="Refresh" :loading="loadingRuns" @click="loadRuns">刷新</el-button>
|
||
</div>
|
||
<div v-if="!runs.length" class="hist-empty">
|
||
<b>{{ loadingRuns ? '正在加载运行记录…' : '还没有运行记录' }}</b>
|
||
<span>执行一次后,这里可以回看当时的结果与日志</span>
|
||
</div>
|
||
<ul v-else class="hist-list">
|
||
<li v-for="r in runs" :key="r.run_id" class="hist-row" @click="openReplay(r.run_id)">
|
||
<i class="h-dot" :class="runState(r).cls"></i>
|
||
<span class="h-trig">{{ triggerLabel(r.trigger) }}</span>
|
||
<span class="h-time">{{ fmtTime(r.started) }}</span>
|
||
<span class="h-dur">{{ durText(r.duration_sec) }}</span>
|
||
<span class="h-sum" :title="runSummary(r)">{{ runSummary(r) }}</span>
|
||
<span class="tag-badge" :class="badgeCls(r)"><i></i>{{ runState(r).text }}</span>
|
||
<el-icon class="h-arrow"><ArrowRight /></el-icon>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
|
||
<!-- 回看单次运行(结论 + 该次日志) -->
|
||
<div v-else class="hist-replay">
|
||
<div class="replay-head">
|
||
<el-button size="small" text :icon="ArrowLeft" :disabled="replayBusy" @click="replay = null">返回列表</el-button>
|
||
<div class="replay-tags">
|
||
<span class="tag-badge" :class="badgeCls(replay)"><i></i>{{ runState(replay).text }}</span>
|
||
<span class="replay-tag">{{ triggerLabel(replay.trigger) }}</span>
|
||
<span class="replay-tag">{{ fmtTime(replay.started) }}</span>
|
||
<span class="replay-tag">耗时 {{ durText(replay.duration_sec) }}</span>
|
||
<span v-if="replay.note" class="replay-tag">备注:{{ replay.note }}</span>
|
||
<span v-if="replay.summary" class="replay-sum">{{ replay.summary }}</span>
|
||
</div>
|
||
</div>
|
||
<div class="rt-log"><LogPanel :static-logs="replay.logs || []" /></div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-else-if="!store.plugins.length" class="empty-note">
|
||
<b>当前账号暂无可用场景</b><br>请联系管理员在控制面进行授权,授权后点左栏「插件同步」刷新
|
||
</div>
|
||
<div v-else class="empty-note"><b>未选择场景</b></div>
|
||
</template>
|
||
|
||
<script setup>
|
||
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, fetchQueue,
|
||
fetchPluginNotes, savePluginNote } from '../api'
|
||
import LogPanel from './LogPanel.vue'
|
||
import RunIndicator from './RunIndicator.vue'
|
||
import PageHead from './PageHead.vue'
|
||
import { durText, fmtTime, cleanDesc, splitDesc } from '../utils/format'
|
||
|
||
const plugin = computed(() => store.plugins.find((p) => p.id === store.selectedId) || null)
|
||
|
||
// ===== 场景描述(页头副标题 + 「详情」弹窗)=====
|
||
// manifest 的 description 常写成「XQ0034 续签电子签:干这个;再干那个」,页头标题已显示场景名,
|
||
// 前缀重复且正文偏长:页头只留剥掉前缀后的摘要(CSS 限两行,悬停给全文),完整内容进「详情」弹窗按句分段。
|
||
const descDialog = ref(false)
|
||
const fullDesc = computed(() => cleanDesc(plugin.value?.description) || '暂无描述')
|
||
const hasDesc = computed(() => !!cleanDesc(plugin.value?.description))
|
||
const shortDesc = computed(() => {
|
||
const s = cleanDesc(plugin.value?.description)
|
||
return s || '暂无描述'
|
||
})
|
||
const descRows = computed(() => splitDesc(plugin.value?.description))
|
||
|
||
// 运行结论三态:成功 / 已取消(用户取消、排队超时、退出取消)/ 失败 / 已中断(客户端退出遗留)
|
||
// 「取消」不能显示成「失败」——两者对用户的含义完全不同,也不该混进失败统计。
|
||
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' }
|
||
}
|
||
|
||
// 历史列表:状态胶囊配色(成功绿 / 失败红 / 取消中断灰)
|
||
function badgeCls(r) {
|
||
if (!r) return 'idle'
|
||
if (r.ok) return 'ok'
|
||
if (r.status === 'cancelled' || r.status === 'interrupted') return 'idle'
|
||
return 'bad'
|
||
}
|
||
|
||
// 历史行摘要:优先后端 summary,其次失败原因,都没有给个占位(整行加 title 看全文)
|
||
function runSummary(r) {
|
||
if (!r) return '—'
|
||
const s = String(r.summary || '').trim()
|
||
if (s) return s
|
||
const e = String(r.error || '').trim()
|
||
if (e) return e
|
||
if (r.status === 'cancelled') return '已取消'
|
||
if (r.status === 'interrupted') return '已中断'
|
||
return r.ok ? '执行完成' : '无输出'
|
||
}
|
||
|
||
// 本场景在队列里等待的任务数:连续点了几次「一键执行」时,页头直接给出排队提示
|
||
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)
|
||
|
||
// ===== 运行备注(账号 × 插件 唯一;本机保存 + 回传中心机,执行时随本次运行一起上报)=====
|
||
// 备注是壳子层统一能力:17 个插件不用各自实现,新增插件自动具备。
|
||
const noteText = ref('')
|
||
const noteSavedAt = ref('')
|
||
const noteSaving = ref(false)
|
||
const noteMap = ref({}) // 本机全部备注 { plugin_id: {note, at} }
|
||
const noteDialog = ref(false)
|
||
const noteEdit = ref(false)
|
||
const noteDraft = ref('')
|
||
let notesLoaded = false
|
||
|
||
function syncNoteFromMap() {
|
||
const cur = plugin.value
|
||
if (!cur) { noteText.value = ''; noteSavedAt.value = ''; return }
|
||
const row = noteMap.value[cur.id]
|
||
noteText.value = (row && row.note) || ''
|
||
noteSavedAt.value = row && row.at
|
||
? new Date(row.at * 1000).toLocaleTimeString('zh-CN', { hour12: false })
|
||
: ''
|
||
}
|
||
|
||
async function loadNotes() {
|
||
try {
|
||
const r = await fetchPluginNotes()
|
||
noteMap.value = (r && r.notes) || {}
|
||
} catch (_) { /* 备注是辅助能力:拉取失败静默,仍可用本机缓存 */ }
|
||
syncNoteFromMap()
|
||
}
|
||
|
||
// 查看 / 编辑:备注可能多行长文本,统一在弹窗里看和改
|
||
function openNote(mode) {
|
||
if (!plugin.value) return
|
||
noteEdit.value = mode === 'edit'
|
||
noteDraft.value = noteText.value
|
||
noteDialog.value = true
|
||
}
|
||
|
||
async function saveNote() {
|
||
const cur = plugin.value
|
||
if (!cur) return
|
||
noteSaving.value = true
|
||
try {
|
||
const r = await savePluginNote(cur.id, noteDraft.value)
|
||
const note = (r && r.note) || ''
|
||
noteText.value = note
|
||
noteDraft.value = note
|
||
const m = { ...noteMap.value }
|
||
if (note) m[cur.id] = { note, at: Math.floor(Date.now() / 1000) }
|
||
else delete m[cur.id]
|
||
noteMap.value = m
|
||
noteSavedAt.value = note ? new Date().toLocaleTimeString('zh-CN', { hour12: false }) : ''
|
||
noteDialog.value = false
|
||
ElMessage.success(note ? '备注已保存' : '备注已清空')
|
||
} catch (e) {
|
||
ElMessage.warning('备注保存失败:' + (e.message || e))
|
||
} finally {
|
||
noteSaving.value = false
|
||
}
|
||
}
|
||
|
||
function clearNote() {
|
||
noteDraft.value = ''
|
||
saveNote()
|
||
}
|
||
|
||
watch(() => plugin.value?.id, (id) => {
|
||
syncNoteFromMap()
|
||
if (id && !notesLoaded) { notesLoaded = true; loadNotes() }
|
||
}, { immediate: true })
|
||
|
||
// 把备注注入插件提交的 /api/runs(插件本身无需感知备注的存在)
|
||
function withRunNote(init) {
|
||
const note = String(noteText.value || '').trim()
|
||
if (!note) return init
|
||
const opt = { ...(init || {}) }
|
||
try {
|
||
const body = typeof opt.body === 'string' ? JSON.parse(opt.body) : null
|
||
if (body && typeof body === 'object') {
|
||
body.note = note
|
||
opt.body = JSON.stringify(body)
|
||
}
|
||
} catch (_) { /* body 非 JSON:原样提交,不影响执行 */ }
|
||
return opt
|
||
}
|
||
|
||
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
|
||
}
|
||
}
|
||
|
||
// 插件界面是独立文档(同源 iframe),壳子的 ::-webkit-scrollbar 只作用于壳子自身文档、
|
||
// 不会穿透到 iframe 里,插件内容区滚动条会退回 Chromium 原生粗灰条 → 载入时注入同款细滚动条。
|
||
const FRAME_SCROLLBAR_CSS = `
|
||
::-webkit-scrollbar { width: 8px; height: 8px; }
|
||
::-webkit-scrollbar-thumb { background: #C6CBD6; border-radius: 4px; border: 2px solid transparent; background-clip: content-box; }
|
||
::-webkit-scrollbar-thumb:hover { background: #A3AAB8; }
|
||
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
|
||
`
|
||
|
||
function injectFrameScrollbarStyle(doc) {
|
||
if (!doc || doc.getElementById('__shell-scrollbar')) return
|
||
const st = doc.createElement('style')
|
||
st.id = '__shell-scrollbar'
|
||
st.textContent = FRAME_SCROLLBAR_CSS
|
||
;(doc.head || doc.documentElement).appendChild(st)
|
||
}
|
||
|
||
function onUiLoad() {
|
||
const w = uiFrame.value && uiFrame.value.contentWindow
|
||
if (!w) return
|
||
injectFrameScrollbarStyle(w.document)
|
||
if (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, withRunNote(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(() => {
|
||
const t = plugin.value?.ui ? [{ k: 'ui', label: '插件界面' }] : []
|
||
return [...t, { k: 'log', label: '运行日志' }, { k: 'history', label: '历史运行' }]
|
||
})
|
||
const tab = ref('log')
|
||
|
||
watch(
|
||
() => plugin.value?.id,
|
||
() => {
|
||
tab.value = plugin.value?.ui ? 'ui' : 'log'
|
||
resetHistory()
|
||
consumePendingReplay()
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
|
||
// ===== 历史运行 =====
|
||
const runs = ref([]) // 本场景最近运行(brief 列表)
|
||
const loadingRuns = ref(false)
|
||
const runsLoaded = ref(false) // 本场景是否已拉过(切换场景后重置)
|
||
const replay = ref(null) // 正在回看的单次运行 {brief..., logs:[...]}
|
||
const replayBusy = ref(false)
|
||
// 历史列表顶部统计(成功 / 失败;取消与中断不计入失败)
|
||
const histOk = computed(() => runs.value.filter((r) => r.ok).length)
|
||
const histFail = computed(() => runs.value.filter((r) => badgeCls(r) === 'bad').length)
|
||
|
||
async function loadRuns() {
|
||
if (!plugin.value || loadingRuns.value) return
|
||
loadingRuns.value = true
|
||
try {
|
||
const data = await fetchRuns(60)
|
||
const mine = (data.runs || []).filter((r) => r.plugin_id === plugin.value.id)
|
||
runs.value = mine.slice(0, 30)
|
||
runsLoaded.value = true
|
||
} catch (_) { /* 历史是辅助能力,加载失败静默(列表保持上次/空) */ }
|
||
finally { loadingRuns.value = false }
|
||
}
|
||
|
||
async function openReplay(runId) {
|
||
if (!runId || replayBusy.value) return
|
||
replayBusy.value = true
|
||
try {
|
||
const data = await getRun(runId)
|
||
replay.value = { ...(data || {}), logs: (data && data.logs) || [] }
|
||
} catch (e) {
|
||
ElMessage.error('加载运行记录失败:' + (e.message || e))
|
||
} finally {
|
||
replayBusy.value = false
|
||
}
|
||
}
|
||
|
||
function resetHistory() {
|
||
runs.value = []
|
||
runsLoaded.value = false
|
||
replay.value = null
|
||
}
|
||
|
||
// 活动流「最近运行」点击 → 直达本场景回看:匹配当前场景则消费,否则等场景切换后消费
|
||
function consumePendingReplay() {
|
||
const p = store.pendingReplay
|
||
if (!p || !plugin.value || plugin.value.id !== p.pluginId) return false
|
||
store.pendingReplay = null
|
||
tab.value = 'history'
|
||
openReplay(p.runId)
|
||
return true
|
||
}
|
||
watch(() => store.pendingReplay, consumePendingReplay)
|
||
|
||
// 打开「历史运行」标签页且未拉过 → 拉取;运行结束(recents 变化)→ 若已拉过则刷新
|
||
watch(
|
||
() => tab.value,
|
||
(t) => { if (t === 'history' && !runsLoaded.value && !loadingRuns.value) loadRuns() }
|
||
)
|
||
watch(
|
||
() => store.recents.length,
|
||
() => { if (runsLoaded.value && !replay.value) loadRuns() }
|
||
)
|
||
|
||
function triggerLabel(t) {
|
||
return ({ manual: '手动执行', schedule: '定时任务', flow: '流程编排' })[t] || t || '手动执行'
|
||
}
|
||
|
||
const platformLabel = computed(() => {
|
||
const p = store.platforms.find((x) => x.id === plugin.value?.platform)
|
||
return p?.label || plugin.value?.platform || ''
|
||
})
|
||
const platformOnline = computed(() =>
|
||
!!(store.platforms.find((x) => x.id === plugin.value?.platform) || {}).online
|
||
)
|
||
|
||
// ===== 插件回滚(升级前自动备份上一版,坏包可回退) =====
|
||
const rollbackVer = ref('')
|
||
async function loadRollbackInfo() {
|
||
if (!plugin.value) return
|
||
rollbackVer.value = ''
|
||
try {
|
||
const r = await listRollbacks()
|
||
const item = (r.items || []).find((i) => i.id === plugin.value.id)
|
||
rollbackVer.value = item ? item.version : ''
|
||
} catch (_) { /* 本地能力,失败静默 */ }
|
||
}
|
||
watch(() => plugin.value?.id, loadRollbackInfo, { immediate: true })
|
||
|
||
async function doRollback() {
|
||
if (!plugin.value || !rollbackVer.value) return
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`将「${plugin.value.name}」回滚到 v${rollbackVer.value}(当前 v${plugin.value.version})。` +
|
||
'回滚后如需最新版,再次点左栏「插件同步」即可。确定回滚?',
|
||
'插件回滚',
|
||
{ type: 'warning', confirmButtonText: '回滚', cancelButtonText: '取消' }
|
||
)
|
||
} catch (_) { return }
|
||
try {
|
||
await rollbackPlugin(plugin.value.id)
|
||
ElMessage.success(`已回滚到 v${rollbackVer.value}`)
|
||
// 刷新插件列表:版本号等元数据由 /api/meta 重新下发
|
||
const meta = await fetchMeta()
|
||
store.plugins = meta.plugins || []
|
||
rollbackVer.value = ''
|
||
} catch (e) {
|
||
ElMessage.error('回滚失败:' + (e.message || e))
|
||
}
|
||
}
|
||
|
||
// 完成时拉取后端摘要填充横幅(触发源无关:插件界面/定时任务触发的运行同样回填)
|
||
watch(
|
||
() => store.lastResult,
|
||
async (res) => {
|
||
if (res && res.ok && store.lastRunId) {
|
||
try {
|
||
const run = await getRun(store.lastRunId)
|
||
store.lastSummary = run.result?.summary || ''
|
||
} catch (e) { }
|
||
}
|
||
}
|
||
)
|
||
|
||
function closeBanner() {
|
||
store.lastResult = null
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.plugin-page {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 0;
|
||
padding: 0;
|
||
flex: 1 1 auto; /* 填满中栏上下文区,运行台内部自己滚 */
|
||
min-height: 0;
|
||
}
|
||
/* 页头固定,下面这层才滚动。
|
||
左右内边距与页头一致(24px),tab 栏 / 内容都贴同一条基线,看起来是一整块 */
|
||
.page-body {
|
||
flex: 1 1 auto; min-height: 0;
|
||
display: flex; flex-direction: column; gap: 0;
|
||
padding: 0 24px 18px;
|
||
}
|
||
.banner { margin: 14px 0 12px; }
|
||
|
||
/* ---------- 页头内的场景身份 ---------- */
|
||
.p-name { display: inline-flex; align-items: center; gap: var(--space-2); }
|
||
.ver-tag {
|
||
font: 500 10.5px/16px var(--f-num); color: var(--t3);
|
||
background: var(--field); border: 1px solid var(--line);
|
||
padding: 0 var(--space-2); border-radius: var(--r-pill);
|
||
}
|
||
.badge {
|
||
display: inline-flex; align-items: center; gap: var(--space-1-5);
|
||
font: 500 10.5px/16px var(--f-cn);
|
||
padding: 1px var(--space-2-5); border-radius: var(--r-pill);
|
||
}
|
||
.badge.on { color: var(--good-ink); background: var(--good-soft); }
|
||
.badge.off { color: var(--t3); background: var(--field); }
|
||
.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; }
|
||
/* 场景说明:页头摘要(限两行,悬停看全文)+「详情」入口(全文按「;」拆段) */
|
||
.p-sub { display: block; }
|
||
.desc-btn { height: 28px; padding: 0 var(--space-3); font-size: 11.5px; color: var(--t3); }
|
||
.desc-btn:hover { color: var(--t1); }
|
||
.desc-body { max-height: 52vh; overflow-y: auto; }
|
||
.desc-p {
|
||
margin: 0 0 10px; padding-left: 10px;
|
||
border-left: 2px solid var(--line);
|
||
font: 400 12.5px/1.7 var(--f-cn); color: var(--t2);
|
||
word-break: break-word;
|
||
}
|
||
.desc-p:last-child { margin-bottom: 0; }
|
||
.desc-empty { color: var(--t3); border-left-color: var(--line); }
|
||
/* 本场景排队中:与运行中的进度胶囊并列,点击去看右侧队列明细 */
|
||
.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 {
|
||
display: flex; align-items: center; gap: var(--space-3);
|
||
padding: var(--space-3) var(--space-4); border-radius: var(--r-card);
|
||
flex-shrink: 0;
|
||
animation: riseIn .3s var(--ease) both;
|
||
}
|
||
.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; }
|
||
.b-close {
|
||
border: none; background: transparent; color: var(--t4);
|
||
cursor: pointer; font-size: 12px; padding: 4px; border-radius: 50%;
|
||
}
|
||
.b-close:hover { color: var(--t1); background: var(--field); }
|
||
|
||
/* ---------- 运行备注(账号 × 插件 唯一,随运行回传中心机) ---------- */
|
||
.note-bar {
|
||
display: flex; align-items: center; gap: var(--space-2-5);
|
||
margin: 14px 0 2px; flex-shrink: 0;
|
||
}
|
||
.nb-label {
|
||
flex: 0 0 auto; font: 600 11.5px/1 var(--f-cn); color: var(--t3);
|
||
letter-spacing: .5px;
|
||
}
|
||
.nb-preview {
|
||
flex: 1 1 auto; min-width: 0;
|
||
height: 30px; display: flex; align-items: center;
|
||
padding: 0 10px;
|
||
background: var(--field); border: 1px solid var(--line);
|
||
border-radius: var(--r-field);
|
||
font: 400 12px/1.5 var(--f-cn); color: var(--t2);
|
||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||
}
|
||
.nb-preview.empty { color: var(--t4); }
|
||
.nb-state {
|
||
flex: 0 0 auto; min-width: 74px; text-align: right;
|
||
font: 500 11px/1 var(--f-num); color: var(--t4);
|
||
}
|
||
.nb-state.ok { color: var(--good-ink); }
|
||
|
||
/* 备注弹窗:查看态用可滚动的等宽留白块,编辑态用 textarea */
|
||
.note-view {
|
||
min-height: 130px; max-height: 320px; overflow: auto;
|
||
padding: 10px 12px;
|
||
background: var(--field); border: 1px solid var(--line);
|
||
border-radius: var(--r-field);
|
||
font: 400 12.5px/1.75 var(--f-cn); color: var(--t2);
|
||
white-space: pre-wrap; word-break: break-word;
|
||
}
|
||
.note-foot { display: flex; align-items: center; gap: var(--space-2); }
|
||
.note-foot .spacer { flex: 1; }
|
||
|
||
/* ---------- 运行台:不套框,tab 栏直接贴在中栏里(只留一条细分隔线) ---------- */
|
||
.run-tabs {
|
||
flex: 1 1 auto; min-height: 300px;
|
||
display: flex; flex-direction: column; overflow: hidden;
|
||
background: transparent;
|
||
}
|
||
.rt-head {
|
||
display: flex; align-items: center; justify-content: space-between; gap: var(--space-2-5);
|
||
padding: 0; flex-shrink: 0;
|
||
border-bottom: 1px solid var(--line-soft);
|
||
}
|
||
.rt-tabs { display: flex; align-items: center; gap: 20px; }
|
||
.rt-tab {
|
||
display: inline-flex; align-items: center; gap: var(--space-1-5);
|
||
border: none; background: transparent; cursor: pointer; font-family: inherit;
|
||
padding: 12px 0; font: 500 12.5px/18px var(--f-cn); color: var(--t3);
|
||
border-bottom: 2px solid transparent; margin-bottom: -1px;
|
||
transition: color var(--dur), border-color var(--dur);
|
||
}
|
||
.rt-tab:hover { color: var(--t1); }
|
||
.rt-tab.on { color: var(--brand-ink); font-weight: 600; border-bottom-color: var(--brand); }
|
||
.rt-n {
|
||
font: 500 10px/16px var(--f-num); color: var(--t3);
|
||
background: var(--field); border-radius: var(--r-pill); padding: 0 var(--space-2);
|
||
}
|
||
.rt-tab.on .rt-n { color: var(--brand-ink); background: var(--brand-soft); }
|
||
|
||
.rt-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
|
||
.rt-log { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding-top: 14px; }
|
||
|
||
/* ---------- 专属界面插件:不再给 iframe 描边(插件界面自己带边界会显得"框套框") ---------- */
|
||
.ui-pane { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding: 14px 0 0; }
|
||
.pui-frame {
|
||
display: block; width: 100%; flex: 1 1 auto; min-height: 340px;
|
||
border: 0; border-radius: 0; background: var(--surface);
|
||
}
|
||
|
||
/* ---------- 历史运行 ---------- */
|
||
.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; }
|
||
.hist-head {
|
||
display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
|
||
padding: 14px 0 10px; flex-shrink: 0;
|
||
border-bottom: 1px solid var(--line-soft);
|
||
}
|
||
.hist-titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
||
.hist-title { font: 600 13px/18px var(--f-cn); color: var(--t1); }
|
||
.hist-sub { font: 400 11.5px/16px var(--f-cn); color: var(--t4); }
|
||
.hist-empty {
|
||
flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
|
||
padding: var(--space-6) var(--space-5); text-align: center;
|
||
color: var(--t4); font: 400 12px/18px var(--f-cn);
|
||
}
|
||
.hist-empty b { color: var(--t2); font: 600 13px/19px var(--f-cn); }
|
||
.hist-list { flex: 1 1 auto; min-height: 0; overflow: auto; list-style: none; margin: 0; padding: 6px 0 8px; }
|
||
|
||
/* 行:状态点 / 触发源 / 开始时间 / 耗时 / 摘要(占满剩余宽度)/ 状态胶囊 / 箭头 */
|
||
.hist-row {
|
||
display: grid;
|
||
grid-template-columns: 8px 92px 150px 74px minmax(0, 1fr) 88px 14px;
|
||
align-items: center; gap: var(--space-3);
|
||
padding: 9px 12px; border-radius: var(--r-row); cursor: pointer;
|
||
transition: background var(--dur);
|
||
}
|
||
.hist-row:hover { background: var(--field); }
|
||
.h-dot { width: 8px; height: 8px; border-radius: 50%; }
|
||
.h-dot.ok { background: var(--good); }
|
||
.h-dot.err { background: var(--danger); }
|
||
.h-dot.mid { background: var(--t4); }
|
||
.h-trig { font: 500 12px/16px var(--f-cn); color: var(--t2); white-space: nowrap; }
|
||
.h-time { font: 400 11.5px/16px var(--f-num); color: var(--t3); font-variant-numeric: tabular-nums; }
|
||
.h-dur { font: 400 11.5px/16px var(--f-num); color: var(--t4); font-variant-numeric: tabular-nums; }
|
||
.h-sum {
|
||
min-width: 0; font: 400 11.5px/16px var(--f-cn); color: var(--t4);
|
||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||
}
|
||
.h-arrow { color: var(--t5); font-size: 12px; }
|
||
|
||
/* 状态胶囊(与壳子表格状态列同款) */
|
||
.tag-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;
|
||
}
|
||
.tag-badge i { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
|
||
.tag-badge.ok { color: var(--good-ink); background: var(--good-soft); border-color: var(--good-line); }
|
||
.tag-badge.ok i { background: var(--good); }
|
||
.tag-badge.bad { color: var(--danger-ink); background: var(--danger-soft); border-color: var(--danger-line); }
|
||
.tag-badge.bad i { background: var(--danger); }
|
||
.tag-badge.idle { color: var(--t3); background: var(--field); border-color: var(--line); }
|
||
.tag-badge.idle i { background: var(--t5); }
|
||
|
||
.hist-replay { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
|
||
.replay-head {
|
||
display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
|
||
padding: 12px 0 10px; border-bottom: 1px solid var(--line-soft); flex-shrink: 0;
|
||
}
|
||
.replay-tags { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }
|
||
.replay-tag {
|
||
font: 400 10.5px/16px var(--f-num); color: var(--t3);
|
||
background: var(--field); border: 1px solid var(--line);
|
||
padding: 0 var(--space-2); border-radius: var(--r-pill);
|
||
}
|
||
.replay-sum {
|
||
font-size: 11px; color: var(--t2); white-space: nowrap;
|
||
overflow: hidden; text-overflow: ellipsis; max-width: 340px;
|
||
}
|
||
|
||
@keyframes riseIn {
|
||
from { opacity: 0; transform: translateY(6px); }
|
||
to { opacity: 1; transform: none; }
|
||
}
|
||
</style>
|