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:
+162
-2
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"name": "37du-webhost-frontend",
|
||||
"name": "37du-shell-frontend",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "37du-webhost-frontend",
|
||||
"name": "37du-shell-frontend",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.2",
|
||||
@@ -14,6 +14,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"electron": "^44.4.5",
|
||||
"vite": "^6.0.3"
|
||||
}
|
||||
},
|
||||
@@ -72,6 +73,37 @@
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/@electron-internal/extract-zip": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@electron-internal/extract-zip/-/extract-zip-1.0.5.tgz",
|
||||
"integrity": "sha512-+bqFCP98pLI0Tt0XQo1TmlXtwjWchISndDOxCkEcIuUgXWpBnLyRI+2DU+mesvnMMX6L1XDqYNA0lXNDHd/yiA==",
|
||||
"dev": true,
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=22.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@electron/get": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@electron/get/-/get-5.1.0.tgz",
|
||||
"integrity": "sha512-3kSBtG8ObcTVfXanm5vVJ6UnBLEVmVsRk1M+vGqCuMBV+XLCbJYuWQful+yIy0GQDsSlK0kHEriEHn7SPk4EnA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "^4.1.1",
|
||||
"env-paths": "^3.0.0",
|
||||
"graceful-fs": "^4.2.11",
|
||||
"progress": "^2.0.3",
|
||||
"semver": "^7.6.3",
|
||||
"sumchecker": "^3.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22.12.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"undici": "^7.24.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@element-plus/icons-vue": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@element-plus/icons-vue/-/icons-vue-2.3.2.tgz",
|
||||
@@ -996,6 +1028,16 @@
|
||||
"@types/lodash": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "24.13.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.6.tgz",
|
||||
"integrity": "sha512-SGrw/h3KPFshy3OE6ZL53LMBG5vGQQ8/gIpiqz/kRZhPJ7HgwCEs8LBuNtWLa8dvGZVpSF7+Bf+c11HUrCb/yg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~7.18.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/web-bluetooth": {
|
||||
"version": "0.0.21",
|
||||
"resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.21.tgz",
|
||||
@@ -1170,6 +1212,43 @@
|
||||
"integrity": "sha512-QDTCU0M0MxR3hQfnlDJfwekQiaanm1ubOD231u73WBckQ/fsamwRLiE2GBz6D3a/xF1NgfiDLJjXBa1hYOYTtQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.4.3",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
||||
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/electron": {
|
||||
"version": "44.4.5",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-44.4.5.tgz",
|
||||
"integrity": "sha512-SjgoaeYsSWZfJzubgQU7juvuXMTvn6/e1gAHdGFA/yuMbpF+I+skYqIJ6DdXBXHeWbkbpNpmwZCTpiivtlWZSw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@electron-internal/extract-zip": "^1.0.1",
|
||||
"@electron/get": "^5.0.0",
|
||||
"@types/node": "^24.9.0"
|
||||
},
|
||||
"bin": {
|
||||
"electron": "cli.js",
|
||||
"install-electron": "install.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 22.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/element-plus": {
|
||||
"version": "2.14.5",
|
||||
"resolved": "https://registry.npmjs.org/element-plus/-/element-plus-2.14.5.tgz",
|
||||
@@ -1208,6 +1287,19 @@
|
||||
"url": "https://github.com/fb55/entities?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/env-paths": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/env-paths/-/env-paths-3.0.0.tgz",
|
||||
"integrity": "sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.25.12",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz",
|
||||
@@ -1289,6 +1381,13 @@
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "4.18.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz",
|
||||
@@ -1327,6 +1426,13 @@
|
||||
"integrity": "sha512-rkpe71W0N0c0Xz6QD0eJETuWAJGnJ9afsl1srmwPrI+yBCkge5EycXXbYRyvL29zZVUWQCY7InPRCv3GDXuZNw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/nanoid": {
|
||||
"version": "3.3.18",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.18.tgz",
|
||||
@@ -1398,6 +1504,16 @@
|
||||
"node": "^10 || ^12 || >=14"
|
||||
}
|
||||
},
|
||||
"node_modules/progress": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
|
||||
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/rollup": {
|
||||
"version": "4.63.1",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.63.1.tgz",
|
||||
@@ -1444,6 +1560,19 @@
|
||||
"fsevents": "~2.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/semver": {
|
||||
"version": "7.8.5",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
|
||||
"integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
|
||||
"dev": true,
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/source-map-js": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
||||
@@ -1453,6 +1582,19 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/sumchecker": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz",
|
||||
"integrity": "sha512-MvjXzkz/BOfyVDkG0oFOtBxHX2u3gKbMHIF/dXblZsgD3BWOFLmHovIpZY7BykJdAjcqRCBi1WYBNdEC9yI7vg==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"debug": "^4.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyglobby": {
|
||||
"version": "0.2.17",
|
||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",
|
||||
@@ -1470,6 +1612,24 @@
|
||||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "7.29.1",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-7.29.1.tgz",
|
||||
"integrity": "sha512-RYONW2MeafgYlkVOKYKkA/Ag7BmXqgIWCa8t1m0JcxrQg9pI9lEqRhAOruOBCbAohOa/gkCF+iPi9hrgvTzu6Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=20.18.1"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "7.18.2",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz",
|
||||
"integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "6.4.3",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.3.tgz",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"electron": "^44.4.5",
|
||||
"vite": "^6.0.3"
|
||||
},
|
||||
"allowScripts": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div v-if="booting" class="boot">
|
||||
<span class="boot-logo">37</span>
|
||||
<span class="boot-txt">{{ syncing ? '正在同步插件,请稍候…' : (store.appName || '自动化工作台') }}</span>
|
||||
<span class="boot-txt">{{ bootStep }}</span>
|
||||
<span class="boot-dots"><i></i><i></i><i></i></span>
|
||||
</div>
|
||||
<LoginPage v-else-if="!store.current" :app-name="store.appName" @ok="onLogin" />
|
||||
@@ -161,15 +161,19 @@
|
||||
<i class="sb-dot"></i>{{ chromeLabel }}
|
||||
</span>
|
||||
<span v-if="chromeVis" class="sb-sep"></span>
|
||||
<span v-if="envVis" class="sb-item env-sb" :class="envCls"
|
||||
:title="envTip" @click="onEnvClick">
|
||||
<i v-if="envBusyState" class="sb-spin"></i>
|
||||
<i v-else class="sb-dot"></i>{{ envLabel }}
|
||||
</span>
|
||||
<span v-if="envVis" class="sb-sep"></span>
|
||||
<span class="sb-item" :class="licenseCls"><i class="sb-dot"></i>{{ licenseText }}</span>
|
||||
<span class="sb-sep"></span>
|
||||
<span class="sb-item" :class="store.wsOn ? 'ok' : 'warn'">
|
||||
<i class="sb-dot"></i>{{ store.wsOn ? '本地服务已连接' : '本地服务重连中' }}
|
||||
</span>
|
||||
<span class="sb-sep"></span>
|
||||
<span class="sb-item mono">{{ localAddr }}</span>
|
||||
<span class="sb-spacer"></span>
|
||||
<span class="sb-item">壳子 {{ shellUpdate.current ? 'v' + shellUpdate.current : '未打包' }}</span>
|
||||
<span class="sb-item">客户端 {{ shellUpdate.current ? 'v' + shellUpdate.current : '未打包' }}</span>
|
||||
<el-link type="primary" :underline="false" class="sb-link"
|
||||
:disabled="shellChecking" @click="onShellCheck">
|
||||
{{ shellChecking ? '检查中…' : '检查更新' }}
|
||||
@@ -191,15 +195,84 @@
|
||||
<span class="dl-dlg-err">下载失败:{{ updDl.error || '未知错误' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<template v-else-if="updDl.status === 'downloaded'">
|
||||
<div class="dl-dlg-body"><span>已下载完成</span></div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="dl-dlg-body"><span>正在准备下载…</span></div>
|
||||
</template>
|
||||
<template #footer>
|
||||
<el-button v-if="updDl.status === 'failed'" size="small" type="primary" round
|
||||
:loading="downloading" @click="onShellDownload">重试</el-button>
|
||||
<el-button size="small" round @click="updDlg = false">后台下载</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
<!-- 浏览器(Chrome)下载/安装进度弹窗:点击「装浏览器/立即安装」后弹出,进度经轮询展示 -->
|
||||
<el-dialog v-model="chromeDlg" :title="chromeDlgTitle" width="420px"
|
||||
:close-on-click-modal="false" align-center class="upd-dl-dialog">
|
||||
<template v-if="chrome.value.installing">
|
||||
<div class="dl-dlg-body"><span>正在静默安装 Chrome,请稍候…(可最小化到后台继续安装)</span></div>
|
||||
</template>
|
||||
<template v-else-if="chrome.value.dl?.status === 'downloading'">
|
||||
<div class="dl-dlg-body">
|
||||
<el-progress :percentage="chrome.value.dl?.pct || 0" :stroke-width="10" />
|
||||
<span class="dl-dlg-bytes">{{ fmtBytes(chrome.value.dl?.received) }}{{ chrome.value.dl?.total ? ' / ' + fmtBytes(chrome.value.dl?.total) : '' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="chrome.value.dl?.status === 'failed'">
|
||||
<div class="dl-dlg-body"><span class="dl-dlg-err">下载失败:{{ chrome.value.dl?.error || '未知错误' }}</span></div>
|
||||
</template>
|
||||
<template v-else-if="chrome.value.downloaded">
|
||||
<div class="dl-dlg-body"><span>Chrome 安装包已下载完成({{ fmtBytes(chrome.value.dl?.received) }}),点击「立即安装」。</span></div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="dl-dlg-body"><span>正在准备下载 Chrome 安装包…</span></div>
|
||||
</template>
|
||||
<template #footer>
|
||||
<el-button v-if="chrome.value.dl?.status === 'failed'" size="small" type="primary" round
|
||||
:loading="chromeBusy" @click="onChromeClick">重试下载</el-button>
|
||||
<el-button v-else-if="chrome.value.downloaded && !chrome.value.installing" size="small" type="primary" round
|
||||
:loading="chromeBusy" @click="onChromeClick">立即安装</el-button>
|
||||
<el-button size="small" round @click="chromeDlg = false">
|
||||
{{ chrome.value.dl?.status === 'downloading' ? '后台下载' : (chrome.value.installing ? '后台安装' : '关闭') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
<!-- 环境包(便携 Python 运行时)更新进度弹窗:点击状态栏环境项后弹出,进度经轮询展示 -->
|
||||
<el-dialog v-model="envDlg" title="环境包更新" width="420px"
|
||||
:close-on-click-modal="false" align-center class="upd-dl-dialog">
|
||||
<template v-if="env.value.dl?.status === 'downloading'">
|
||||
<div class="dl-dlg-body">
|
||||
<el-progress :percentage="env.value.dl?.pct || 0" :stroke-width="10" />
|
||||
<span class="dl-dlg-bytes">{{ fmtBytes(env.value.dl?.received) }}{{ env.value.dl?.total ? ' / ' + fmtBytes(env.value.dl?.total) : '' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="env.value.dl?.status === 'extracting'">
|
||||
<div class="dl-dlg-body">
|
||||
<el-progress :percentage="100" :stroke-width="10" status="warning" :indeterminate="true" :duration="2" />
|
||||
<span class="dl-dlg-bytes">下载完成,正在解压安装(约需几十秒)…</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="env.value.dl?.status === 'failed'">
|
||||
<div class="dl-dlg-body"><span class="dl-dlg-err">更新失败:{{ env.value.dl?.error || '未知错误' }}</span></div>
|
||||
</template>
|
||||
<template v-else-if="envInstalled">
|
||||
<div class="dl-dlg-body">
|
||||
<span>当前环境 v{{ envVersion }}
|
||||
{{ envHasUpdate ? `,云端 v${envCloud},点击下方按钮更新` : ',已是最新版本' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="dl-dlg-body"><span>环境包未安装,点击下方按钮安装</span></div>
|
||||
</template>
|
||||
<template #footer>
|
||||
<el-button v-if="env.value.dl?.status === 'failed'" size="small" type="primary" round
|
||||
:loading="envBusy" @click="onEnvClick">重试</el-button>
|
||||
<el-button v-else-if="!envBusyState && (envHasUpdate || (!envInstalled && env.value.cloud_available))"
|
||||
size="small" type="primary" round :loading="envBusy" @click="onEnvClick">立即更新</el-button>
|
||||
<el-button size="small" round @click="envDlg = false">关闭</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -213,7 +286,7 @@ import SchedulePage from './components/SchedulePage.vue'
|
||||
import LoginPage from './components/LoginPage.vue'
|
||||
import ChangePasswordDialog from './components/ChangePasswordDialog.vue'
|
||||
import { store, handleEvent, clearLogs, log, loadAvatar, clearAvatarCache, accountAvatar } from './store'
|
||||
import { connectWS, fetchMeta, adminLogout, adminMe, adminPassword, syncPlugins, getShellStatus, applyShellUpdate, checkShellUpdate, downloadShellUpdate, getChromeStatus, checkChrome, downloadChrome, installChrome } from './api'
|
||||
import { connectWS, fetchMeta, getBootStatus, adminLogout, adminMe, adminPassword, syncPlugins, getShellStatus, applyShellUpdate, checkShellUpdate, downloadShellUpdate, getChromeStatus, checkChrome, downloadChrome, installChrome, getEnvStatus, syncEnv } from './api'
|
||||
|
||||
// 场景图标:奶油系柔和渐变(与总览首页/场景页共用同一套色板)
|
||||
const GRADS = [
|
||||
@@ -261,8 +334,6 @@ const lastRunText = computed(() => {
|
||||
if (!r) return '本次会话暂无运行记录'
|
||||
return `上次 ${r.name} · ${r.time}`
|
||||
})
|
||||
const localAddr = computed(() => (typeof location !== 'undefined' ? location.host : ''))
|
||||
|
||||
// 授权票据概要(状态栏):后端 /api/meta 的 license 字段
|
||||
const licenseText = computed(() => {
|
||||
const l = store.license
|
||||
@@ -279,44 +350,63 @@ const licenseCls = computed(() => {
|
||||
return 'warn'
|
||||
})
|
||||
|
||||
let wsRetryCount = 0
|
||||
let wsRetryTimer = null
|
||||
function openWS() {
|
||||
if (window.__ws) window.__ws.close()
|
||||
const ws = connectWS(handleEvent)
|
||||
if (window.__ws) { try { window.__ws.close() } catch (_) {} }
|
||||
const ws = connectWS((ev) => {
|
||||
handleEvent(ev)
|
||||
// 插件同步完成事件:后台/手动同步结束后刷新清单,避免停留在"空场景/请授权"旧值
|
||||
if (ev && ev.t === 'plugins_synced' && store.current) refreshMeta()
|
||||
})
|
||||
window.__ws = ws
|
||||
ws.onopen = () => (store.wsOn = true)
|
||||
ws.onopen = () => { store.wsOn = true; wsRetryCount = 0 }
|
||||
ws.onclose = () => {
|
||||
store.wsOn = false
|
||||
// 仅登录态下自动重连刷新;未登录被拒(1008)时静默,避免 reload 死循环
|
||||
if (store.current) setTimeout(() => (location.reload()), 2500)
|
||||
// 未登录被拒(1008)时静默,避免死循环
|
||||
if (!store.current) return
|
||||
if (wsRetryCount >= 5) return // 连续 5 次失败:停止,状态栏保持"本地服务重连中"
|
||||
wsRetryCount++
|
||||
// 指数退避重连(1/2/4/8/16s 封顶),不再整页 reload(避免反复走启动引导)
|
||||
if (wsRetryTimer) clearTimeout(wsRetryTimer)
|
||||
wsRetryTimer = setTimeout(openWS, Math.min(1000 * Math.pow(2, wsRetryCount - 1), 16000))
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const meta = await fetchMeta()
|
||||
store.appName = meta.appName
|
||||
store.platforms = meta.platforms
|
||||
refreshBootStatus() // 启动页实时展示"当前在干嘛"
|
||||
// fetchMeta/checkSession 全部带超时:后端/中心机慢或不可达时也必须在几十秒内进入界面,
|
||||
// 不能无限等(否则就是"启动后毫无反馈的未响应")
|
||||
const meta = await withTimeout(fetchMeta(), 8000) || {}
|
||||
store.appName = meta.appName || store.appName
|
||||
store.platforms = meta.platforms || []
|
||||
store.plugins = meta.plugins || []
|
||||
store.authExpired = !!meta.authExpired
|
||||
store.license = meta.license || null
|
||||
store.selectedId = store.plugins[0]?.id || ''
|
||||
clearLogs()
|
||||
openWS()
|
||||
await checkSession()
|
||||
booting.value = false // 会话判定完成(登录/未登录/后端不可达均已定),再渲染首屏
|
||||
loadAvatar()
|
||||
loadShellStatus()
|
||||
loadChromeStatus()
|
||||
await withTimeout(checkSession(), 30000)
|
||||
// 首屏前预加载:头像/壳子/Chrome/环境包状态全部拉一遍再进入,
|
||||
// 保证状态栏信息一进来就是完整的(单次调用带超时兜底,避免后端异常卡在启动页)
|
||||
await Promise.all([loadAvatar(), loadShellStatus(), loadChromeStatus(), loadEnvStatus()]
|
||||
.map((p) => Promise.race([Promise.resolve(p), new Promise((r) => setTimeout(r, 6000))])))
|
||||
booting.value = false // 会话判定 + 首屏状态均就绪后再渲染
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (shellPollTimer) { clearTimeout(shellPollTimer); shellPollTimer = null }
|
||||
if (chromePollTimer) { clearTimeout(chromePollTimer); chromePollTimer = null }
|
||||
if (envPollTimer) { clearTimeout(envPollTimer); envPollTimer = null }
|
||||
})
|
||||
|
||||
// ===== 浏览器(Chrome)检测/下载/安装 =====
|
||||
const chrome = ref({})
|
||||
let chromePollTimer = null
|
||||
const chromeBusy = ref(false) // 正在轮询/下载/安装(按钮 loading)
|
||||
const chromeDlg = ref(false) // Chrome 下载/安装进度弹窗
|
||||
let lastChromeDl = '' // 上一轮下载状态,用于下载完成/失败一次性提示
|
||||
let lastChromeInstalling = false // 上一轮安装中标志,用于安装完成一次性提示
|
||||
|
||||
const chromeInstalled = computed(() => !!chrome.value.installed)
|
||||
const chromeVisible = computed(() => {
|
||||
@@ -348,6 +438,16 @@ const chromeTip = computed(() => {
|
||||
return '本机未安装 Chrome,点击下载安装'
|
||||
})
|
||||
|
||||
const chromeInstalling = computed(() => !!chrome.value.installing)
|
||||
const chromeDlgTitle = computed(() => {
|
||||
const c = chrome.value
|
||||
if (c.installing) return '安装 Chrome'
|
||||
if (c.dl?.status === 'downloading') return '下载 Chrome 安装包'
|
||||
if (c.dl?.status === 'failed') return 'Chrome 下载失败'
|
||||
if (c.downloaded) return 'Chrome 安装包已就绪'
|
||||
return '安装 Chrome'
|
||||
})
|
||||
|
||||
async function loadChromeStatus() {
|
||||
try { chrome.value = await getChromeStatus() } catch (_) {}
|
||||
// 未安装或操作中才轮询;已安装无需常驻
|
||||
@@ -360,7 +460,20 @@ async function refreshChromeStatus() {
|
||||
try {
|
||||
const s = await getChromeStatus()
|
||||
chrome.value = s
|
||||
if (chrome.value.installed && chrome.value.dl?.status !== 'downloading' && !chrome.value.installing) {
|
||||
const st = s.dl?.status || ''
|
||||
// 一次性提示:安装完成 / 下载完成 / 下载失败
|
||||
if (lastChromeInstalling && s.installed) {
|
||||
chromeDlg.value = false
|
||||
ElMessage.success(`Chrome ${s.version} 安装完成,可正常使用`)
|
||||
log('INFO', `Chrome 安装完成:${s.version}`)
|
||||
} else if (lastChromeDl === 'downloading' && st === 'downloaded') {
|
||||
ElMessage.success('Chrome 安装包已下载完成,点击「立即安装」')
|
||||
} else if (lastChromeDl === 'downloading' && st === 'failed') {
|
||||
ElMessage.warning('Chrome 安装包下载失败:' + (s.dl?.error || ''))
|
||||
}
|
||||
lastChromeInstalling = !!s.installing
|
||||
lastChromeDl = st
|
||||
if (chrome.value.installed && st !== 'downloading' && !chrome.value.installing) {
|
||||
if (chromePollTimer) { clearTimeout(chromePollTimer); chromePollTimer = null }
|
||||
return // 已装好,停止轮询
|
||||
}
|
||||
@@ -375,21 +488,39 @@ function startChromePoll() {
|
||||
async function onChromeClick() {
|
||||
if (chromeBusy.value) return
|
||||
const c = chrome.value
|
||||
// 安装中:仅刷新状态
|
||||
if (c.installing) { return }
|
||||
// 安装中:仅展示进度弹窗
|
||||
if (c.installing) { chromeDlg.value = true; return }
|
||||
// 已安装:优先重新检测(不再重复安装)
|
||||
if (c.installed) {
|
||||
chromeBusy.value = true
|
||||
try { await checkChrome(); loadChromeStatus() }
|
||||
catch (e) { ElMessage.error('检测失败:' + (e.message || e)) }
|
||||
chromeBusy.value = false
|
||||
return
|
||||
}
|
||||
// 已下载:直接安装
|
||||
if (c.downloaded) {
|
||||
chromeBusy.value = true
|
||||
try { await installChrome(); chrome.value.installing = true; startChromePoll() }
|
||||
catch (e) { ElMessage.error('安装失败:' + (e.message || e)) }
|
||||
chromeDlg.value = true
|
||||
try { await installChrome(); chrome.value.installing = true; lastChromeInstalling = true; startChromePoll() }
|
||||
catch (e) { chromeDlg.value = false; ElMessage.error('安装失败:' + (e.message || e)) }
|
||||
chromeBusy.value = false
|
||||
return
|
||||
}
|
||||
// 未装且中心机有登记:下载
|
||||
if (!c.installed && c.cloud_available) {
|
||||
chromeBusy.value = true
|
||||
chromeDlg.value = true // 点击即弹出进度弹窗
|
||||
// 点击即进入"下载中"反馈(不等轮询):内网直连下载很快,若靠 1.5s 轮询,进度条可能还没显示就已下完
|
||||
chrome.value = { ...chrome.value,
|
||||
dl: { status: 'downloading', received: 0, total: 0, pct: 0, error: '' } }
|
||||
lastChromeDl = 'downloading' // 兜底:即使立即下载完成,也能触发"已就绪"一次性提示
|
||||
try { await downloadChrome(); loadChromeStatus() }
|
||||
catch (e) { ElMessage.error('开始下载失败:' + (e.message || e)) }
|
||||
catch (e) {
|
||||
chrome.value = { ...chrome.value,
|
||||
dl: { status: 'failed', received: 0, total: 0, pct: 0, error: (e.message || e) } }
|
||||
ElMessage.error('开始下载失败:' + (e.message || e))
|
||||
}
|
||||
chromeBusy.value = false
|
||||
return
|
||||
}
|
||||
@@ -400,10 +531,128 @@ async function onChromeClick() {
|
||||
chromeBusy.value = false
|
||||
}
|
||||
|
||||
// ===== 环境包(便携 Python 运行时)检测/更新 =====
|
||||
const env = ref({})
|
||||
let envPollTimer = null
|
||||
const envBusy = ref(false)
|
||||
const envDlg = ref(false)
|
||||
let envDownloading = false // 轮询中识别"下载→完成/失败"转移,用于一次性提示
|
||||
|
||||
const envInstalled = computed(() => !!env.value.installed)
|
||||
const envVersion = computed(() => env.value.version || '')
|
||||
const envCloud = computed(() => env.value.cloud_version || '')
|
||||
const envHasUpdate = computed(() =>
|
||||
envInstalled.value && envCloud.value && envCloud.value !== envVersion.value)
|
||||
// 安装进行中(下载/解压):状态栏显示转圈,弹窗展示进度
|
||||
const envBusyState = computed(() =>
|
||||
env.value.dl?.status === 'downloading' || env.value.dl?.status === 'extracting')
|
||||
// 后端返回过 env 状态即展示(与 chrome 一致)
|
||||
const envVis = computed(() => 'installed' in env.value)
|
||||
const envCls = computed(() =>
|
||||
(envHasUpdate.value || (!envInstalled.value && env.value.cloud_available)) ? 'warn' : (envInstalled.value ? 'ok' : 'warn'))
|
||||
const envLabel = computed(() => {
|
||||
const e = env.value
|
||||
if (e.dl?.status === 'downloading') return (e.dl?.pct || 0) + '%'
|
||||
if (e.dl?.status === 'extracting') return '安装中'
|
||||
if (envHasUpdate.value) return '环境更新 v' + envCloud.value
|
||||
if (envInstalled.value) return '环境 v' + envVersion.value
|
||||
if (e.cloud_available) return '环境待装'
|
||||
return '环境'
|
||||
})
|
||||
const envTip = computed(() => {
|
||||
const e = env.value
|
||||
if (e.dl?.status === 'downloading') return '正在下载环境包 ' + (e.dl?.pct || 0) + '%'
|
||||
if (e.dl?.status === 'extracting') return '正在解压安装环境包,请稍候…'
|
||||
if (envHasUpdate.value) return `云端环境包 v${envCloud.value},点击更新`
|
||||
if (envInstalled.value) return `当前环境 v${envVersion.value},点击重新检查`
|
||||
if (e.cloud_available) return '环境包未安装,点击安装'
|
||||
return '中心机暂未登记环境包,点击重新检查'
|
||||
})
|
||||
|
||||
async function loadEnvStatus() {
|
||||
try { env.value = await getEnvStatus() } catch (_) {}
|
||||
if (!env.value.installed || env.value.dl?.status === 'downloading') startEnvPoll()
|
||||
}
|
||||
async function refreshEnvStatus() {
|
||||
try {
|
||||
const s = await getEnvStatus()
|
||||
env.value = s
|
||||
const st = s.dl?.status || ''
|
||||
// 一次性提示:下载/解压中 → 完成 / 失败
|
||||
if (st === 'downloading' || st === 'extracting') envDownloading = true
|
||||
else if (envDownloading && st === 'idle' && s.installed) {
|
||||
envDownloading = false
|
||||
envDlg.value = false
|
||||
ElMessage.success(`环境包已更新到 v${s.version}`)
|
||||
log('INFO', `环境包更新完成 v${s.version}`)
|
||||
} else if (envDownloading && st === 'failed') {
|
||||
envDownloading = false
|
||||
ElMessage.warning('环境包更新失败:' + (s.dl?.error || ''))
|
||||
}
|
||||
if (s.installed && st !== 'downloading' && st !== 'extracting') {
|
||||
if (envPollTimer) { clearTimeout(envPollTimer); envPollTimer = null }
|
||||
return // 已装好,停止轮询
|
||||
}
|
||||
} catch (_) {}
|
||||
envPollTimer = setTimeout(refreshEnvStatus, 1500)
|
||||
}
|
||||
function startEnvPoll() {
|
||||
if (envPollTimer) return
|
||||
refreshEnvStatus()
|
||||
}
|
||||
|
||||
async function onEnvClick() {
|
||||
if (envBusy.value) return
|
||||
const e = env.value
|
||||
// 下载中/解压中:展示进度弹窗
|
||||
if (envBusyState.value) { envDlg.value = true; return }
|
||||
// 有更新 或 未安装且云端有包:触发更新(后台下载+切换),弹窗展示进度
|
||||
if (envHasUpdate.value || (!e.installed && e.cloud_available)) {
|
||||
envBusy.value = true
|
||||
envDlg.value = true // 先弹窗("正在准备…"),下载进度由轮询驱动
|
||||
try {
|
||||
await syncEnv() // 后端后台执行,立即返回
|
||||
await loadEnvStatus() // 抢拉真实进度,避免停在"准备中"
|
||||
if (env.value.dl?.status !== 'downloading') {
|
||||
envDlg.value = false // 未真正开始(如已有同步在跑):关弹窗提示
|
||||
ElMessage.info(env.value.installed ? '环境包已是最新,无需更新' : '环境包暂不可用,请稍后重试')
|
||||
}
|
||||
} catch (err) {
|
||||
envDlg.value = false
|
||||
ElMessage.error('开始更新失败:' + (err.message || err))
|
||||
}
|
||||
envBusy.value = false
|
||||
return
|
||||
}
|
||||
// 已安装且最新:刷新状态并提示
|
||||
await loadEnvStatus()
|
||||
ElMessage.info(`当前环境 v${envVersion.value},已是最新`)
|
||||
}
|
||||
|
||||
const pwdDlg = ref(false)
|
||||
const booting = ref(true) // 鉴权判定中:未确定会话前先显示加载骨架,避免「闪一下登录页再进首页」
|
||||
const syncing = ref(false) // 首次启动/启动时:按账号权限自下载/更新插件(等待下载界面)
|
||||
|
||||
// 启动页"当前在干嘛":后端轮询 /api/boot/status 展示初始化步骤;
|
||||
// 进入 checkSession 后由前端各阶段接管文案(bootPhaseOwned=true 时后端轮询不再覆盖)
|
||||
const bootStep = ref('正在启动…')
|
||||
let bootPollTimer = null
|
||||
let bootPhaseOwned = false
|
||||
async function refreshBootStatus() {
|
||||
if (!bootPhaseOwned) {
|
||||
try {
|
||||
const b = await getBootStatus()
|
||||
// await 期间 checkSession 可能已接管文案(bootPhaseOwned 置真),迟到响应不得回写覆盖
|
||||
if (!bootPhaseOwned) {
|
||||
bootStep.value = b.done
|
||||
? (syncing.value ? '正在同步插件,请稍候…' : (store.appName || '自动化工作台'))
|
||||
: `正在初始化:${b.step || '…'}`
|
||||
}
|
||||
} catch (_) { /* 后端未就绪:保持当前文案,继续轮询 */ }
|
||||
}
|
||||
if (booting.value) bootPollTimer = setTimeout(refreshBootStatus, 1200)
|
||||
}
|
||||
|
||||
// ===== 壳子自动更新:检查 → 用户确认下载(带进度)→ 重启更新 =====
|
||||
const shellUpdate = ref({})
|
||||
const updating = ref(false)
|
||||
@@ -431,11 +680,14 @@ function fmtBytes(n) {
|
||||
|
||||
async function loadShellStatus() {
|
||||
try { shellUpdate.value = await getShellStatus() } catch (_) {}
|
||||
startShellPoll()
|
||||
// 壳子更新状态接口需登录;未登录时拉不到(401),不启动常驻轮询(登录后 onLogin 会补拉)
|
||||
if (store.current) startShellPoll()
|
||||
}
|
||||
|
||||
// 常驻状态轮询:驱动下载进度条与 available/downloaded 提示;下载完成/失败各提示一次
|
||||
async function refreshShellStatus() {
|
||||
// 未登录/登出后暂停轮询,避免持续打 401
|
||||
if (!store.current) { if (shellPollTimer) { clearTimeout(shellPollTimer); shellPollTimer = null } return }
|
||||
try {
|
||||
const s = await getShellStatus()
|
||||
shellUpdate.value = s
|
||||
@@ -443,7 +695,7 @@ async function refreshShellStatus() {
|
||||
if (lastDlStatus === 'downloading' && st === 'downloaded') {
|
||||
updDlg.value = false // 弹窗开着时自动收起,顶部提示条转为「重启更新」
|
||||
ElMessage.success(`新版本 v${s.new} 已下载完成,点击顶部「重启更新」完成升级`)
|
||||
log('INFO', `壳子新版本 v${s.new} 已就绪,可重启更新`)
|
||||
log('INFO', `客户端新版本 v${s.new} 已就绪,可重启更新`)
|
||||
} else if (lastDlStatus === 'downloading' && st === 'failed') {
|
||||
ElMessage.warning('新版本下载失败:' + (s.dl?.error || ''))
|
||||
}
|
||||
@@ -473,7 +725,7 @@ async function onShellDownload() {
|
||||
updDlg.value = true // 点击下载即弹出进度弹窗,不再用页头条展示进度
|
||||
// 点击即进入"下载中"反馈(不等轮询):内网直连下载很快,若靠 15s 轮询拉状态,
|
||||
// 进度条可能还没显示就已经下载完,用户会以为点了没反应
|
||||
const v = shellUpdate.value.latest || ''
|
||||
const v = shellUpdate.value.latest || shellUpdate.value.new || ''
|
||||
shellUpdate.value = { ...shellUpdate.value,
|
||||
dl: { status: 'downloading', version: v, received: 0, total: 0, pct: 0, error: '' } }
|
||||
lastDlStatus = 'downloading' // 兜底:即使立即下载完成,也能触发"已就绪"一次性提示
|
||||
@@ -517,7 +769,7 @@ async function onShellCheck() {
|
||||
|
||||
function handleCheckResult(s) {
|
||||
if (!s.current) {
|
||||
ElMessage.info('当前为源码开发模式,不参与壳子自更新')
|
||||
ElMessage.info('当前为源码开发模式,不参与客户端自更新')
|
||||
return
|
||||
}
|
||||
if (s.downloaded) {
|
||||
@@ -527,7 +779,7 @@ function handleCheckResult(s) {
|
||||
if (updDl.value.status === 'downloading') return // 正在下载,进度条展示中
|
||||
if (s.error) {
|
||||
ElMessage.warning('检查更新失败:' + s.error)
|
||||
log('WARN', `检查壳子更新失败:${s.error}`)
|
||||
log('WARN', `检查客户端更新失败:${s.error}`)
|
||||
return
|
||||
}
|
||||
if (s.available) {
|
||||
@@ -575,11 +827,30 @@ function showToast(msg, type = 'info') {
|
||||
ElMessage({ message: msg, type, duration: 2200 })
|
||||
}
|
||||
|
||||
// 带超时的 Promise:超时返回 undefined;失败/超时都打日志便于启动诊断(P7)
|
||||
function withTimeout(promise, ms) {
|
||||
let timer
|
||||
const timeout = new Promise((r) => {
|
||||
timer = setTimeout(() => {
|
||||
log('WARN', `启动请求超时(${ms}ms),已跳过`)
|
||||
r(undefined)
|
||||
}, ms)
|
||||
})
|
||||
const safe = Promise.resolve(promise).then(
|
||||
(v) => { clearTimeout(timer); return v },
|
||||
(e) => { clearTimeout(timer); log('WARN', `启动请求失败:${(e && e.message) || e}`); return undefined }
|
||||
)
|
||||
return Promise.race([safe, timeout])
|
||||
}
|
||||
|
||||
async function checkSession() {
|
||||
// 登录态一律以**后端会话 cookie** 为准(钉钉扫码/账号登录/后端重启后均从 admin/me 判定),
|
||||
// 不再以 localStorage 的 cp_account 早退——否则全新扫码流程(未写过 cp_account)回跳后无法进入插件页。
|
||||
// 各阶段由前端接管启动页文案(P2),且内层预算 8+15+5=28s 必须落在外层 30s 内(P1)
|
||||
bootPhaseOwned = true
|
||||
try {
|
||||
const me = await adminMe()
|
||||
bootStep.value = '正在校验登录会话…'
|
||||
const me = await withTimeout(adminMe(), 8000) || {}
|
||||
if (!me.account) {
|
||||
store.current = ''; store.dept = ''; store.nickname = ''; store.avatar = ''
|
||||
try { localStorage.removeItem('cp_account') } catch (_) {}
|
||||
@@ -590,12 +861,15 @@ async function checkSession() {
|
||||
store.nickname = me.nickname || ''
|
||||
store.avatar = me.avatar || ''
|
||||
try { localStorage.setItem('cp_account', me.account) } catch (_) {}
|
||||
// 会话确认后:按账号权限自下载/更新插件(首次启动等待下载完成;离线/失败直接跳过)
|
||||
// 会话确认后:按账号权限自下载/更新插件。预算 15s,中心机不可达/超时则后台继续、
|
||||
// 不卡启动页;手动「插件同步」按钮不受影响(onPluginSync 单独无超时等待结果)
|
||||
bootStep.value = '正在同步插件,请稍候…'
|
||||
syncing.value = true
|
||||
try { await syncPlugins() } catch (_) {}
|
||||
try { await withTimeout(syncPlugins(), 15000) } catch (_) {}
|
||||
syncing.value = false
|
||||
// 会话有效:补拉插件清单(未登录时 meta 不返回插件)
|
||||
await refreshMeta()
|
||||
bootStep.value = '正在加载插件清单…'
|
||||
await withTimeout(refreshMeta(), 5000)
|
||||
} catch (_) { /* 后端 down:无法校验,保持现状(可能为登录页或本地态) */ }
|
||||
}
|
||||
|
||||
@@ -754,9 +1028,9 @@ async function logout() {
|
||||
}
|
||||
.auth-expired-bar .ae-txt { flex: 1; }
|
||||
|
||||
/* 状态栏里的 Chrome 状态:可点击(检测/下载/安装) */
|
||||
.chrome-sb { cursor: pointer; }
|
||||
.chrome-sb:hover { color: var(--primary); }
|
||||
/* 状态栏里的 Chrome/环境包 状态:可点击(检测/下载/安装/更新) */
|
||||
.chrome-sb, .env-sb { cursor: pointer; }
|
||||
.chrome-sb:hover, .env-sb:hover { color: var(--primary); }
|
||||
|
||||
.body { flex: 1; display: flex; gap: 14px; min-height: 0; margin-top: 14px; }
|
||||
|
||||
@@ -871,6 +1145,13 @@ async function logout() {
|
||||
.sb-item.warn .sb-dot { background: var(--warn); }
|
||||
.sb-item.err { color: var(--danger); }
|
||||
.sb-item.err .sb-dot { background: var(--err); }
|
||||
/* 环境包下载/解压中:转圈替代状态点(跟随文字颜色,warn/ok 自适应) */
|
||||
.sb-spin {
|
||||
width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
|
||||
border: 2px solid currentColor; border-top-color: transparent;
|
||||
animation: sbSpin .8s linear infinite;
|
||||
}
|
||||
@keyframes sbSpin { to { transform: rotate(360deg); } }
|
||||
.sb-sep { width: 1px; height: 12px; background: var(--border); flex-shrink: 0; }
|
||||
.sb-spacer { flex: 1; }
|
||||
.sb-link { font-size: 11px; vertical-align: baseline; }
|
||||
|
||||
@@ -15,6 +15,11 @@ export async function fetchMeta() {
|
||||
return j('/api/meta')
|
||||
}
|
||||
|
||||
// 启动状态(启动页展示当前步骤,无需登录)
|
||||
export async function getBootStatus() {
|
||||
return j('/api/boot/status')
|
||||
}
|
||||
|
||||
export async function syncPlugins() {
|
||||
return j('/api/plugins/sync', { method: 'POST' })
|
||||
}
|
||||
@@ -72,6 +77,17 @@ export async function installChrome() {
|
||||
return j('/api/chrome/install', { method: 'POST' })
|
||||
}
|
||||
|
||||
// ===== 环境包(便携 Python 运行时) =====
|
||||
export async function getEnvStatus() {
|
||||
return j('/api/env/status')
|
||||
}
|
||||
export async function syncEnv() {
|
||||
return j('/api/env/sync', { method: 'POST' })
|
||||
}
|
||||
export async function rollbackEnv() {
|
||||
return j('/api/env/rollback', { method: 'POST' })
|
||||
}
|
||||
|
||||
export async function loginPlatform(id) {
|
||||
return j(`/api/platforms/${id}/login`, { method: 'POST' })
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -85,6 +85,7 @@ export function handleEvent(ev) {
|
||||
switch (ev.t) {
|
||||
case 'run_start':
|
||||
store.currentRun = ev.run_id
|
||||
store.lastRunId = ev.run_id
|
||||
store._runPlugins[ev.run_id] = ev.plugin_id || ''
|
||||
// 运行态由事件驱动:定时任务触发的运行没有本地点击,必须靠 run_start 点亮
|
||||
// (设备级单活,同时只会有一个 run)。日志归属本次运行,故开始时清空。
|
||||
|
||||
Reference in New Issue
Block a user