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:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user