feat: 新增多插件 UI 支持及运行日志集中回传功能
本次提交包含多项功能更新: 1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持 2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储 3. 新增插件分类字段支持,用于场景库分组管理 4. 优化 xq0034/0037/0048 等插件的功能及描述 5. 修复控制面响应兼容问题,支持新旧版本数据格式 6. 新增 xq0033 插件的状态存储模块,用于历史记录管理 7. 优化 CRM 登录窗口模式,支持全屏置顶
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { store } from '../store'
|
||||
import { fetchRuns } from '../api'
|
||||
|
||||
// 左侧场景库:搜索 + 最近使用置顶 + 分类折叠分组。
|
||||
// 插件多起来后不再全量平铺靠滚动条:提供快速搜索、高频场景置顶、按分类折叠。
|
||||
// 分类来自 plugin.json 的 category(registry.pluginSchema 透传),未分类归「其他」。
|
||||
export const SHOW_SEARCH_MIN = 8 // 插件数超过该值才显示搜索框(少时保持清爽)
|
||||
const AUTO_COLLAPSE_MIN = 12 // 超过该值才默认折叠「非当前选中」的分组
|
||||
export const RECENT_KEY = '__recent__'
|
||||
const CAT_FALLBACK = '其他'
|
||||
const RECENT_MAX = 5 // 「最近使用」置顶条数
|
||||
|
||||
export function useSceneLibrary() {
|
||||
const sceneQuery = ref('')
|
||||
const recentRuns = ref([]) // 持久化最近运行(/api/runs,账号维度,新的在前)
|
||||
const groupOverride = ref({}) // 手动展开/折叠覆盖:{ groupKey: true=展开 false=折叠 }
|
||||
|
||||
function catLabel(c) { return (c || '').trim() || CAT_FALLBACK }
|
||||
|
||||
const filteredPlugins = computed(() => {
|
||||
const q = sceneQuery.value.trim().toLowerCase()
|
||||
if (!q) return store.plugins
|
||||
return store.plugins.filter((p) =>
|
||||
(p.name || '').toLowerCase().includes(q) ||
|
||||
(p.description || '').toLowerCase().includes(q) ||
|
||||
(p.id || '').toLowerCase().includes(q))
|
||||
})
|
||||
|
||||
const sceneGroups = computed(() => {
|
||||
const map = new Map()
|
||||
for (const p of filteredPlugins.value) {
|
||||
const key = catLabel(p.category)
|
||||
if (!map.has(key)) map.set(key, [])
|
||||
map.get(key).push(p)
|
||||
}
|
||||
// 大组靠前(按数量降序,再按名称),避免最常用的分组沉底
|
||||
return [...map.entries()]
|
||||
.map(([key, items]) => ({ key, label: key, items }))
|
||||
.sort((a, b) => b.items.length - a.items.length || a.label.localeCompare(b.label, 'zh'))
|
||||
})
|
||||
|
||||
// 最近使用:取持久化最近运行的「不同插件」,且仍在当前账号可用清单内
|
||||
const recentScenes = computed(() => {
|
||||
const seen = new Set()
|
||||
const out = []
|
||||
for (const r of recentRuns.value) {
|
||||
if (out.length >= RECENT_MAX) break
|
||||
if (!r.plugin_id || seen.has(r.plugin_id)) continue
|
||||
const p = store.plugins.find((x) => x.id === r.plugin_id)
|
||||
if (!p) continue
|
||||
seen.add(r.plugin_id)
|
||||
out.push(p)
|
||||
}
|
||||
return out
|
||||
})
|
||||
|
||||
// 场景色点按插件在总清单里的位置取(分组/搜索后颜色仍稳定不跳)
|
||||
function pluginIndex(p) {
|
||||
return store.plugins.findIndex((x) => x.id === p.id)
|
||||
}
|
||||
|
||||
function grpDefaultExpanded(key) {
|
||||
if (sceneQuery.value.trim()) return true // 搜索时全展开(命中即显示)
|
||||
if (key === RECENT_KEY) return true
|
||||
if (store.plugins.length <= AUTO_COLLAPSE_MIN) return true // 数量少不折叠
|
||||
const g = sceneGroups.value.find((x) => x.key === key)
|
||||
return !!(g && g.items.some((p) => p.id === store.selectedId)) // 大列表默认只展开当前选中所在组
|
||||
}
|
||||
function grpCollapsed(key) {
|
||||
const ov = groupOverride.value[key]
|
||||
if (ov !== undefined) return !ov
|
||||
return !grpDefaultExpanded(key)
|
||||
}
|
||||
function toggleGroup(key) {
|
||||
if (sceneQuery.value.trim()) return // 搜索态强制全展开,不响应折叠
|
||||
groupOverride.value = { ...groupOverride.value, [key]: grpCollapsed(key) }
|
||||
}
|
||||
|
||||
// 最近使用数据源:持久化运行历史(与右栏「最近运行」同源,重启不丢)
|
||||
async function loadRecentScenes() {
|
||||
if (!store.current) return
|
||||
try {
|
||||
const r = await fetchRuns(10)
|
||||
recentRuns.value = r.runs || []
|
||||
} catch (_) { /* 后端未就绪:静默,下次刷新再补 */ }
|
||||
}
|
||||
|
||||
return {
|
||||
sceneQuery, filteredPlugins, sceneGroups, recentScenes,
|
||||
pluginIndex, grpCollapsed, toggleGroup, loadRecentScenes,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { checkShellUpdate, getShellStatus } from '../api'
|
||||
|
||||
// 手动「检查更新」:触发秒级版本比对 → 轮询检查结束后交回结果处理。
|
||||
// statusRef 为壳子状态(useDownloadJob.state),轮询期间同步回写,保证顶栏/状态栏一致。
|
||||
export function useShellCheck(statusRef, onResult) {
|
||||
const checking = ref(false)
|
||||
|
||||
async function check() {
|
||||
if (checking.value) return
|
||||
try {
|
||||
await checkShellUpdate()
|
||||
} catch (e) {
|
||||
ElMessage.error('检查更新失败:' + (e.message || e))
|
||||
return
|
||||
}
|
||||
checking.value = true
|
||||
const timer = setInterval(async () => {
|
||||
try {
|
||||
const s = await getShellStatus()
|
||||
statusRef.value = s
|
||||
if (s.checking) return
|
||||
clearInterval(timer)
|
||||
checking.value = false
|
||||
onResult(s)
|
||||
} catch (_) { /* 首次拿不到状态:继续轮询 */ }
|
||||
}, 800)
|
||||
// 兜底:30s 仍未结束则停止轮询,避免无限等待
|
||||
setTimeout(() => {
|
||||
if (checking.value) {
|
||||
clearInterval(timer)
|
||||
checking.value = false
|
||||
}
|
||||
}, 30000)
|
||||
}
|
||||
|
||||
return { checking, check }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { connectWS } from '../api'
|
||||
import { handleEvent, store } from '../store'
|
||||
|
||||
// 本地服务 WebSocket:断线按 1/2/4/8/16s 指数退避重连(连续 5 次失败后停止),
|
||||
// 不整页 reload;被主动替换/关闭的旧连接不再触发重连(否则新旧交替形成死循环)。
|
||||
export function useSocket({ onPluginsSynced } = {}) {
|
||||
let retryCount = 0
|
||||
let retryTimer = null
|
||||
|
||||
function openWS() {
|
||||
// 主动新建连接时,取消上一次待执行的重连
|
||||
if (retryTimer) { clearTimeout(retryTimer); retryTimer = null }
|
||||
if (window.__ws) { try { window.__ws.close() } catch (_) {} }
|
||||
const ws = connectWS((ev) => {
|
||||
handleEvent(ev)
|
||||
// 插件同步完成事件:后台/手动同步结束后刷新清单,避免停留在「空场景/请授权」旧值
|
||||
if (ev && ev.t === 'plugins_synced' && store.current && onPluginsSynced) onPluginsSynced()
|
||||
})
|
||||
window.__ws = ws
|
||||
ws.onopen = () => { store.wsOn = true; retryCount = 0 }
|
||||
ws.onclose = () => {
|
||||
store.wsOn = false
|
||||
// 未登录被拒(1008)时静默,避免死循环
|
||||
if (!store.current) return
|
||||
if (window.__ws !== ws) return
|
||||
if (retryCount >= 5) return // 连续 5 次失败:停止,状态栏保持「本地服务重连中」
|
||||
retryCount++
|
||||
if (retryTimer) clearTimeout(retryTimer)
|
||||
retryTimer = setTimeout(openWS, Math.min(1000 * Math.pow(2, retryCount - 1), 16000))
|
||||
}
|
||||
}
|
||||
|
||||
return { openWS }
|
||||
}
|
||||
Reference in New Issue
Block a user