新增 FastAPI 文件服务器核心模块(配置、鉴权、存储、心跳上报),新增 HTTP 路由接口(健康检查、文件上传/下载/删除、管理登录/密码修改/统计),新增 Vue3 管理页面源码;新增 MySQL 元数据存储支持,新增 PyMySQL 依赖;新增 .gitignore 忽略 IDE 与备份文件;新增文件服务器工具脚本;删除旧的 build/ 脚本与 exe 构建产物,优化 Electron 平台登录逻辑为纯接口模式,新增平台账号环境变量注入,优化试用期异常检查逻辑,拆分服务岗转正流程为独立脚本。
1185 lines
55 KiB
Vue
1185 lines
55 KiB
Vue
<template>
|
||
<div v-if="booting" class="boot">
|
||
<span class="boot-logo">37</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" />
|
||
<div class="__app" v-else>
|
||
<!-- 壳子更新提示:已就绪重启更新 / 下载失败重试 / 发现新版本可下载(下载进度改用弹窗) -->
|
||
<div v-if="updBarVisible" class="update-bar">
|
||
<template v-if="shellUpdate.downloaded">
|
||
<span class="upd-txt">发现新版本 <b>v{{ shellUpdate.new }}</b><em v-if="shellUpdate.notes">{{ shellUpdate.notes }}</em></span>
|
||
<el-button size="small" type="primary" round :loading="updating" @click="doShellUpdate">重启更新</el-button>
|
||
</template>
|
||
<template v-else-if="updDl.status === 'failed'">
|
||
<span class="upd-txt">新版本下载失败<em>{{ updDl.error }}</em></span>
|
||
<el-button size="small" type="primary" round :loading="downloading" @click="onShellDownload">重试</el-button>
|
||
</template>
|
||
<template v-else-if="shellUpdate.available">
|
||
<span class="upd-txt">发现新版本 <b>v{{ shellUpdate.latest }}</b><em v-if="shellUpdate.notes">{{ shellUpdate.notes }}</em></span>
|
||
<div class="upd-actions">
|
||
<el-button size="small" type="primary" round :loading="downloading" @click="onShellDownload">立即下载</el-button>
|
||
<el-button size="small" round @click="shellDismissed = true">暂不</el-button>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
<!-- 授权已过期:离线超 7 天须联网刷新票据后才能继续使用 -->
|
||
<div v-if="store.authExpired" class="auth-expired-bar">
|
||
<span class="ae-txt">授权已过期(最长离线 7 天),需联网刷新授权后才能继续使用</span>
|
||
<el-button size="small" type="primary" round :loading="syncingPlugins" @click="onPluginSync">立即刷新</el-button>
|
||
</div>
|
||
<!-- 顶栏已拆分融入三栏:品牌→左轨 / 账号→右轨 / Chrome→状态栏 -->
|
||
<!-- 主体:左场景轨 | 中上下文(总览/运行台/计划)| 右活动流 -->
|
||
<div class="body">
|
||
<!-- 左:品牌 + 场景轨(主导航 + 场景库) -->
|
||
<aside class="rail side">
|
||
<div class="side-brand">
|
||
<span class="logo">37</span>
|
||
<strong>{{ store.appName }}</strong>
|
||
</div>
|
||
<nav class="nav-main">
|
||
<div class="nav-item" :class="{ active: store.view === 'overview' }" @click="openOverview">
|
||
<el-icon><HomeFilled /></el-icon><span>总览</span>
|
||
</div>
|
||
<div class="nav-item" :class="{ active: store.view === 'scenes' }" @click="openScenes">
|
||
<el-icon><Grid /></el-icon><span>场景</span>
|
||
</div>
|
||
<div class="nav-item" :class="{ active: store.view === 'plans' }" @click="openPlans">
|
||
<el-icon><Clock /></el-icon><span>计划</span>
|
||
</div>
|
||
</nav>
|
||
|
||
<!-- 场景库 -->
|
||
<div class="side-head">
|
||
<span class="sec-title">场景</span>
|
||
<div class="side-head-r">
|
||
<span class="count">{{ store.plugins.length }}</span>
|
||
<el-tooltip content="插件同步" placement="top">
|
||
<el-button class="sync-btn" text :icon="Refresh" :loading="syncingPlugins"
|
||
:disabled="store.running" @click="onPluginSync" />
|
||
</el-tooltip>
|
||
</div>
|
||
</div>
|
||
<ul class="scene-list">
|
||
<li
|
||
v-for="(p, i) in store.plugins"
|
||
:key="p.id"
|
||
:class="{ active: p.id === store.selectedId && store.view === 'run' }"
|
||
@click="openRun(p.id)"
|
||
>
|
||
<span class="scene-icon" :style="{ background: grad(i) }">
|
||
{{ p.name.slice(0, 1) }}
|
||
</span>
|
||
<span class="scene-name">{{ p.name }}</span>
|
||
<em>v{{ p.version }}</em>
|
||
</li>
|
||
</ul>
|
||
<div v-if="!store.plugins.length" class="scene-empty">当前账号暂无可用场景<br><span>请联系管理员进行授权</span></div>
|
||
</aside>
|
||
|
||
<!-- 中:上下文区(视图路由) -->
|
||
<main class="rail main">
|
||
<div class="page-scroll">
|
||
<HomePage v-if="store.view === 'overview'" />
|
||
<ScenesPage v-else-if="store.view === 'scenes'" />
|
||
<PluginPage v-else-if="store.view === 'run'" />
|
||
<SchedulePage v-else-if="store.view === 'plans'" />
|
||
</div>
|
||
</main>
|
||
|
||
<!-- 右:账号 + 活动流(当前运行 + 最近运行;只回显,细节在运行台) -->
|
||
<aside class="rail activity">
|
||
<div class="act-acct">
|
||
<span class="acct-display">
|
||
<el-avatar :size="26" class="acct-avatar" :src="accountAvatar()" :key="accountAvatar()" @error="onAvatarError">
|
||
<span class="acct-avatar-fb">{{ (store.nickname || store.current).slice(0, 1).toUpperCase() }}</span>
|
||
</el-avatar>
|
||
<span class="acct-name">{{ store.nickname || store.current }}</span>
|
||
</span>
|
||
<div class="acct-ops">
|
||
<el-tooltip content="修改密码" placement="top">
|
||
<el-button size="small" text :icon="Key" @click="pwdDlg = true" />
|
||
</el-tooltip>
|
||
<el-button size="small" round @click="logout">登出</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="act-head">
|
||
<span class="sec-title">活动</span>
|
||
<span v-if="store.running" class="act-live">● 运行中</span>
|
||
</div>
|
||
|
||
<div class="act-now" :class="{ on: store.running }">
|
||
<template v-if="store.running">
|
||
<div class="an-top">
|
||
<span class="an-name">{{ runningName }}</span>
|
||
<span class="an-pct">{{ store.progress }}%</span>
|
||
</div>
|
||
<el-progress :percentage="store.progress" :show-text="false" :stroke-width="6" color="var(--primary)" />
|
||
<div class="an-tail">
|
||
<div v-for="(l, i) in tailLogs" :key="i" class="an-line">
|
||
<span class="lv" :class="'s-' + (l.level || 'INFO')">{{ l.level || 'INFO' }}</span>
|
||
<span class="an-msg">{{ l.msg }}</span>
|
||
</div>
|
||
<div v-if="!tailLogs.length" class="an-wait">等待输出…</div>
|
||
</div>
|
||
</template>
|
||
<template v-else>
|
||
<div class="an-idle">
|
||
<span class="an-idle-ic">✓</span>
|
||
<div class="an-idle-meta">
|
||
<b>当前空闲</b>
|
||
<span>{{ lastRunText }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
|
||
<div class="act-head act-head-2">
|
||
<span class="sec-title">最近运行</span>
|
||
<span v-if="store.recents.length" class="count">{{ store.recents.length }}</span>
|
||
</div>
|
||
<ul class="act-list">
|
||
<li v-for="(r, i) in store.recents" :key="i" @click="openRun(r.pluginId, r.runId)">
|
||
<span class="act-dot" :class="r.ok ? 'ok' : 'err'"></span>
|
||
<div class="act-meta">
|
||
<b>{{ r.name }}</b>
|
||
<span>{{ r.ok ? '完成' : (r.error || '失败') }}</span>
|
||
</div>
|
||
<em>{{ r.time }}</em>
|
||
</li>
|
||
</ul>
|
||
<div v-if="!store.recents.length" class="act-empty">本次会话暂无运行记录</div>
|
||
</aside>
|
||
</div>
|
||
|
||
<!-- 状态栏:机器与授权事实(品牌/账号已融入左右轨;Chrome 状态也在此) -->
|
||
<footer class="statusbar">
|
||
<span v-if="chromeVis" class="sb-item chrome-sb" :class="chromeInstalled ? 'ok' : 'warn'"
|
||
:title="chromeTip" @click="onChromeClick">
|
||
<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-spacer"></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 ? '检查中…' : '检查更新' }}
|
||
</el-link>
|
||
</footer>
|
||
</div>
|
||
<ChangePasswordDialog v-if="pwdDlg" @close="pwdDlg = false" />
|
||
<!-- 壳子更新下载进度弹窗:点击「立即下载」后弹出,可最小化到后台继续下载 -->
|
||
<el-dialog v-model="updDlg" :title="`下载更新 v${updDl.version || ''}`" width="420px"
|
||
:close-on-click-modal="false" align-center class="upd-dl-dialog">
|
||
<template v-if="updDl.status === 'downloading'">
|
||
<div class="dl-dlg-body">
|
||
<el-progress :percentage="updDl.pct || 0" :stroke-width="10" />
|
||
<span class="dl-dlg-bytes">{{ fmtBytes(updDl.received) }}{{ updDl.total ? ' / ' + fmtBytes(updDl.total) : '' }}</span>
|
||
</div>
|
||
</template>
|
||
<template v-else-if="updDl.status === 'failed'">
|
||
<div class="dl-dlg-body">
|
||
<span class="dl-dlg-err">下载失败:{{ updDl.error || '未知错误' }}</span>
|
||
</div>
|
||
</template>
|
||
<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>
|
||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { Clock, HomeFilled, Refresh, Key, Grid } from '@element-plus/icons-vue'
|
||
import HomePage from './components/HomePage.vue'
|
||
import ScenesPage from './components/ScenesPage.vue'
|
||
import PluginPage from './components/PluginPage.vue'
|
||
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, getBootStatus, adminLogout, adminMe, adminPassword, syncPlugins, getShellStatus, applyShellUpdate, checkShellUpdate, downloadShellUpdate, getChromeStatus, checkChrome, downloadChrome, installChrome, getEnvStatus, syncEnv } from './api'
|
||
|
||
// 场景图标:奶油系柔和渐变(与总览首页/场景页共用同一套色板)
|
||
const GRADS = [
|
||
'var(--grad-sky)', 'var(--grad-peach)', 'var(--grad-mint)',
|
||
'var(--grad-lilac)', 'var(--grad-honey)', 'var(--grad-blush)',
|
||
]
|
||
function grad(i) { return GRADS[i % GRADS.length] }
|
||
|
||
// 顶栏头像加载失败:清除缓存返回首字符兜底
|
||
function onAvatarError() {
|
||
clearAvatarCache()
|
||
}
|
||
|
||
// ===== 三栏骨架:视图路由(总览 / 运行台 / 计划)=====
|
||
function openRun(id, runId) {
|
||
store.selectedId = id
|
||
store.view = 'run'
|
||
// 活动流「最近运行」点击:直达该次运行的回看(运行台消费后清空);
|
||
// 左栏场景点击不带 runId,顺带清掉可能残留的回看意图
|
||
store.pendingReplay = runId ? { pluginId: id, runId } : null
|
||
}
|
||
|
||
function openOverview() {
|
||
store.view = 'overview'
|
||
}
|
||
|
||
function openScenes() {
|
||
store.view = 'scenes'
|
||
}
|
||
|
||
function openPlans() {
|
||
store.view = 'plans'
|
||
}
|
||
|
||
// ===== 右栏活动流 + 底栏状态:由现有 store 派生,不引入新请求 =====
|
||
// 当前运行中的场景名(run_start 已把 run_id→plugin_id 登记在 store._runPlugins)
|
||
const runningName = computed(() => {
|
||
const pid = store._runPlugins[store.currentRun] || store.selectedId
|
||
return (store.plugins.find((p) => p.id === pid) || {}).name || '正在执行'
|
||
})
|
||
// 运行中:右栏只回显最近几条日志,细节仍在运行台「运行日志」标签页
|
||
const tailLogs = computed(() => store.logs.slice(-4))
|
||
const lastRunText = computed(() => {
|
||
const r = store.recents[0]
|
||
if (!r) return '本次会话暂无运行记录'
|
||
return `上次 ${r.name} · ${r.time}`
|
||
})
|
||
// 授权票据概要(状态栏):后端 /api/meta 的 license 字段
|
||
const licenseText = computed(() => {
|
||
const l = store.license
|
||
if (!l || !l.status || l.status === 'missing') return '未授权'
|
||
if (l.status === 'invalid') return '授权无效'
|
||
if (l.status === 'expired') return '授权已过期'
|
||
if (l.days_left === null || l.days_left === undefined) return '授权有效'
|
||
return `授权有效 · 剩余 ${l.days_left} 天`
|
||
})
|
||
const licenseCls = computed(() => {
|
||
const s = store.license && store.license.status
|
||
if (s === 'ok') return 'ok'
|
||
if (s === 'expired' || s === 'invalid') return 'err'
|
||
return 'warn'
|
||
})
|
||
|
||
let wsRetryCount = 0
|
||
let wsRetryTimer = null
|
||
function openWS() {
|
||
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; wsRetryCount = 0 }
|
||
ws.onclose = () => {
|
||
store.wsOn = false
|
||
// 未登录被拒(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 () => {
|
||
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 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(() => {
|
||
// 下载中/已下载待安装/未安装但中心机有登记 → 显示;已装则不显示(已可用不占用空间)
|
||
return chrome.value.installed || chrome.value.downloaded || chrome.value.cloud_available
|
||
})
|
||
// 常驻显示:只要后端返回过 Chrome 状态就展示(已安装绿色版本号 / 未安装橙色入口)
|
||
const chromeVis = computed(() => 'installed' in chrome.value)
|
||
|
||
const chromeLabel = computed(() => {
|
||
const c = chrome.value
|
||
if (c.installing) return '安装中…'
|
||
if (!c.installed) {
|
||
if (c.dl?.status === 'downloading') return c.dl?.pct + '%'
|
||
if (c.downloaded) return '点击安装'
|
||
if (c.cloud_available) return '装浏览器'
|
||
return '浏览器'
|
||
}
|
||
return c.version ? 'Chrome ' + c.version : 'Chrome'
|
||
})
|
||
|
||
const chromeTip = computed(() => {
|
||
const c = chrome.value
|
||
if (c.installed) return `本机已安装 Chrome ${c.version},点击重新检测`
|
||
if (c.installing) return '已弹出 Chrome 安装器,请在弹出的窗口中完成安装'
|
||
if (c.downloaded) return 'Chrome 安装包已下载,点击安装'
|
||
if (c.dl?.status === 'downloading') return '正在下载 Chrome 安装包 ' + c.dl?.pct + '%'
|
||
if (!c.cloud_available) return '中心机暂未登记浏览器安装包,点击重新检测'
|
||
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 (_) {}
|
||
// 未安装或操作中才轮询;已安装无需常驻
|
||
if (!chrome.value.installed || chrome.value.installing || chrome.value.dl?.status === 'downloading') {
|
||
startChromePoll()
|
||
}
|
||
}
|
||
|
||
async function refreshChromeStatus() {
|
||
try {
|
||
const s = await getChromeStatus()
|
||
chrome.value = s
|
||
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 // 已装好,停止轮询
|
||
}
|
||
} catch (_) {}
|
||
chromePollTimer = setTimeout(refreshChromeStatus, 1500)
|
||
}
|
||
function startChromePoll() {
|
||
if (chromePollTimer) return
|
||
refreshChromeStatus()
|
||
}
|
||
|
||
async function onChromeClick() {
|
||
if (chromeBusy.value) return
|
||
const c = chrome.value
|
||
// 安装中:仅展示进度弹窗
|
||
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
|
||
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) {
|
||
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
|
||
}
|
||
// 其余:重新检测
|
||
chromeBusy.value = true
|
||
try { await checkChrome(); loadChromeStatus() }
|
||
catch (e) { ElMessage.error('检测失败:' + (e.message || e)) }
|
||
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)
|
||
const downloading = ref(false)
|
||
const shellChecking = ref(false) // 手动检查请求进行中(秒级)
|
||
const shellDismissed = ref(false) // 用户点了"暂不",本会话内隐藏"立即下载"提示
|
||
let shellPollTimer = null // 状态轮询(setTimeout 递归,下载中 1.2s / 常态 15s)
|
||
let lastDlStatus = '' // 上一轮下载状态,用于下载完成/失败时的一次性提示
|
||
|
||
const updDl = computed(() => shellUpdate.value.dl || {})
|
||
const updDlg = ref(false) // 下载进度弹窗(点击「立即下载」后弹出)
|
||
const updBarVisible = computed(() =>
|
||
shellUpdate.value.downloaded ||
|
||
(updDl.value.status === 'failed' && !updDlg.value) ||
|
||
(shellUpdate.value.available && !shellDismissed.value)
|
||
)
|
||
|
||
function fmtBytes(n) {
|
||
if (!n) return '0 B'
|
||
const u = ['B', 'KB', 'MB', 'GB']
|
||
let i = 0
|
||
while (n >= 1024 && i < u.length - 1) { n /= 1024; i++ }
|
||
return (n >= 100 || i === 0 ? n.toFixed(0) : n.toFixed(1)) + ' ' + u[i]
|
||
}
|
||
|
||
async function loadShellStatus() {
|
||
try { shellUpdate.value = await getShellStatus() } catch (_) {}
|
||
// 壳子更新状态接口需登录;未登录时拉不到(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
|
||
const st = s.dl?.status || ''
|
||
if (lastDlStatus === 'downloading' && st === 'downloaded') {
|
||
// 内网直链下载很快(80MB 秒下),延迟收窗让人看清 100% 完成态,再转顶部「重启更新」条
|
||
setTimeout(() => { updDlg.value = false }, 1500)
|
||
ElMessage.success(`新版本 v${s.new} 已下载完成,点击顶部「重启更新」完成升级`)
|
||
log('INFO', `客户端新版本 v${s.new} 已就绪,可重启更新`)
|
||
} else if (lastDlStatus === 'downloading' && st === 'failed') {
|
||
ElMessage.warning('新版本下载失败:' + (s.dl?.error || ''))
|
||
}
|
||
lastDlStatus = st
|
||
} catch (_) {}
|
||
shellPollTimer = setTimeout(refreshShellStatus, updDl.value.status === 'downloading' ? 400 : 15000)
|
||
}
|
||
function startShellPoll() {
|
||
if (shellPollTimer) return
|
||
refreshShellStatus()
|
||
}
|
||
|
||
async function doShellUpdate() {
|
||
updating.value = true
|
||
try {
|
||
await applyShellUpdate() // 后端运行静默安装并退出进程,升级后自动重启
|
||
} catch (e) {
|
||
updating.value = false
|
||
ElMessage.error('更新失败:' + (e.message || e))
|
||
}
|
||
}
|
||
|
||
async function onShellDownload() {
|
||
if (downloading.value) return
|
||
downloading.value = true
|
||
shellDismissed.value = false
|
||
updDlg.value = true // 点击下载即弹出进度弹窗,不再用页头条展示进度
|
||
// 点击即进入"下载中"反馈(不等轮询):内网直连下载很快,若靠 15s 轮询拉状态,
|
||
// 进度条可能还没显示就已经下载完,用户会以为点了没反应
|
||
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' // 兜底:即使立即下载完成,也能触发"已就绪"一次性提示
|
||
try {
|
||
await downloadShellUpdate() // 后端后台流式下载,进度经轮询展示
|
||
try { shellUpdate.value = await getShellStatus() } catch (_) {} // 抢拉真实进度,避免卡在 0%
|
||
} catch (e) {
|
||
shellUpdate.value = { ...shellUpdate.value,
|
||
dl: { status: 'failed', version: v, received: 0, total: 0, pct: 0, error: (e.message || e) } }
|
||
ElMessage.error('开始下载失败:' + (e.message || e))
|
||
}
|
||
downloading.value = false
|
||
}
|
||
|
||
// 手动"检查更新":触发秒级版本比对 → 轮询检查结束后按结果提示
|
||
async function onShellCheck() {
|
||
if (shellChecking.value) return
|
||
try { await checkShellUpdate() } catch (e) {
|
||
ElMessage.error('检查更新失败:' + (e.message || e))
|
||
return
|
||
}
|
||
shellChecking.value = true
|
||
const timer = setInterval(async () => {
|
||
try {
|
||
const s = await getShellStatus()
|
||
shellUpdate.value = s
|
||
if (s.checking) return
|
||
clearInterval(timer)
|
||
shellChecking.value = false
|
||
handleCheckResult(s)
|
||
} catch (_) {}
|
||
}, 800)
|
||
// 兜底:30s 仍未结束则停止轮询,避免无限等待
|
||
setTimeout(() => {
|
||
if (shellChecking.value) {
|
||
clearInterval(timer)
|
||
shellChecking.value = false
|
||
}
|
||
}, 30000)
|
||
}
|
||
|
||
function handleCheckResult(s) {
|
||
if (!s.current) {
|
||
ElMessage.info('当前为源码开发模式,不参与客户端自更新')
|
||
return
|
||
}
|
||
if (s.downloaded) {
|
||
ElMessage.info(`新版本 v${s.new} 已就绪,点击顶部「重启更新」完成升级`)
|
||
return
|
||
}
|
||
if (updDl.value.status === 'downloading') return // 正在下载,进度条展示中
|
||
if (s.error) {
|
||
ElMessage.warning('检查更新失败:' + s.error)
|
||
log('WARN', `检查客户端更新失败:${s.error}`)
|
||
return
|
||
}
|
||
if (s.available) {
|
||
ElMessageBox.confirm(
|
||
`发现新版本 v${s.latest},是否立即下载?${s.notes ? '\n\n更新说明:' + s.notes : ''}`,
|
||
'发现新版本',
|
||
{ confirmButtonText: '立即下载', cancelButtonText: '稍后再说', type: 'info' }
|
||
).then(() => onShellDownload()).catch(() => {})
|
||
} else {
|
||
ElMessage.info(`已是最新版本 v${s.current}`)
|
||
}
|
||
}
|
||
|
||
// ===== 插件同步:按当前账号权限重新同步(新装/更新/清理已删除),完成后刷新清单 =====
|
||
// 登录成功与手动刷新共用;同步失败也补拉清单,保证离线时沿用本地已装插件
|
||
const syncingPlugins = ref(false)
|
||
async function onPluginSync() {
|
||
if (syncingPlugins.value || store.running) return
|
||
syncingPlugins.value = true
|
||
try {
|
||
const r = await syncPlugins()
|
||
const parts = []
|
||
if (r.downloaded?.length) parts.push(`新装 ${r.downloaded.length} 个`)
|
||
if (r.updated?.length) parts.push(`更新 ${r.updated.length} 个`)
|
||
if (r.removed?.length) parts.push(`清理 ${r.removed.length} 个`)
|
||
if (r.failed?.length) parts.push(`失败 ${r.failed.length} 个`)
|
||
if (parts.length) {
|
||
ElMessage.success('插件同步完成:' + parts.join(','))
|
||
const detail = [...(r.downloaded || []), ...(r.updated || []), ...(r.removed || [])].join('、')
|
||
if (detail) log('INFO', `插件同步完成:${parts.join(',')}(${detail})`)
|
||
} else {
|
||
ElMessage.info('插件已是最新')
|
||
}
|
||
if (r.failed?.length) log('ERROR', `插件同步失败:${r.failed.join('、')}`)
|
||
} catch (e) {
|
||
ElMessage.error('插件同步失败:' + (e.message || e))
|
||
} finally {
|
||
await refreshMeta()
|
||
syncingPlugins.value = false
|
||
}
|
||
}
|
||
|
||
// 平台登录等轻量操作反馈:统一走 element-plus 全局消息
|
||
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 {
|
||
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 (_) {}
|
||
return
|
||
}
|
||
store.current = me.account
|
||
store.dept = me.dept || ''
|
||
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 withTimeout(syncPlugins(), 15000) } catch (_) {}
|
||
syncing.value = false
|
||
// 会话有效:补拉插件清单(未登录时 meta 不返回插件)
|
||
bootStep.value = '正在加载插件清单…'
|
||
await withTimeout(refreshMeta(), 5000)
|
||
} catch (_) { /* 后端 down:无法校验,保持现状(可能为登录页或本地态) */ }
|
||
}
|
||
|
||
async function refreshMeta() {
|
||
try {
|
||
const meta = await fetchMeta()
|
||
store.platforms = meta.platforms
|
||
store.plugins = meta.plugins || []
|
||
store.authExpired = !!meta.authExpired
|
||
store.license = meta.license || null
|
||
// 选中场景不存在(被同步清理/授权收回)时回落到第一个可用场景
|
||
if (!store.plugins.find((p) => p.id === store.selectedId)) {
|
||
store.selectedId = store.plugins[0]?.id || ''
|
||
}
|
||
} catch (_) {}
|
||
}
|
||
|
||
async function onLogin(ok) {
|
||
store.current = ok.account
|
||
store.dept = ok.dept || ''
|
||
store.nickname = ok.nickname || ''
|
||
store.avatar = ok.avatar || ''
|
||
try { localStorage.setItem('cp_account', ok.account) } catch (_) {}
|
||
// 登录成功后立即按该账号权限同步插件(新装机首次登录即下载授权插件),再刷新平台/清单
|
||
await onPluginSync()
|
||
openWS()
|
||
loadAvatar()
|
||
loadShellStatus() // 挂载时未登录拉不到更新状态,登录后补拉(版本显示/更新提示)
|
||
loadChromeStatus() // 浏览器状态同此
|
||
// 首次登录/钉钉自动建号的默认密码:提示立即改密
|
||
if (ok.must_change_pwd) { promptChangePwd(ok.account) }
|
||
}
|
||
|
||
async function promptChangePwd(account) {
|
||
try {
|
||
// 旧密码 = 钉钉通知下发的初始密码,必须输入校验(与个人中心改密一致)
|
||
let op = ''
|
||
try {
|
||
const { value } = await ElMessageBox.prompt(
|
||
'当前账号正使用默认密码,请输入钉钉通知中的初始密码',
|
||
'首次登录 · 身份验证',
|
||
{ inputType: 'password', inputPlaceholder: '请输入初始密码',
|
||
confirmButtonText: '下一步', cancelButtonText: '稍后再说' })
|
||
op = value
|
||
} catch (_) { return /* 用户取消 */ }
|
||
const { value: np } = await ElMessageBox.prompt(
|
||
'请设置新密码(至少 6 位),避免他人误登录',
|
||
'首次登录 · 设置新密码',
|
||
{ inputType: 'password', inputPattern: /^.{6,}$/, inputErrorMessage: '密码至少 6 位',
|
||
confirmButtonText: '设置新密码', cancelButtonText: '稍后再说' })
|
||
try {
|
||
await adminPassword({ account, old_password: op, new_password: np })
|
||
ElMessage.success('密码已更新')
|
||
} catch (e) {
|
||
ElMessage.warning('改密失败:' + (e.message || e))
|
||
}
|
||
} catch (_) { /* 用户取消 */ }
|
||
}
|
||
async function logout() {
|
||
try { await adminLogout() } catch (_) {}
|
||
store.current = ''
|
||
store.nickname = ''
|
||
store.avatar = ''
|
||
store.avatarUrl = ''
|
||
store.authExpired = false
|
||
try { localStorage.removeItem('cp_account') } catch (_) {}
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.boot {
|
||
min-height: 100vh;
|
||
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||
gap: 14px; background: var(--bg);
|
||
}
|
||
.boot-logo {
|
||
width: 54px; height: 54px; border-radius: 18px;
|
||
display: grid; place-items: center;
|
||
background: var(--primary-grad); color: var(--on-primary);
|
||
font-size: 20px; font-weight: 800;
|
||
box-shadow: 0 10px 26px -8px rgba(var(--primary-rgb),.65);
|
||
animation: bootpop .4s ease;
|
||
}
|
||
.boot-txt { font-size: 13px; color: var(--text-faint); letter-spacing: .06em; }
|
||
.boot-dots { display: flex; gap: 5px; }
|
||
.boot-dots i {
|
||
width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
|
||
animation: bootblink 1s infinite ease-in-out;
|
||
}
|
||
.boot-dots i:nth-child(2) { animation-delay: .15s; }
|
||
.boot-dots i:nth-child(3) { animation-delay: .3s; }
|
||
@keyframes bootpop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
|
||
@keyframes bootblink { 0%,80%,100% { opacity: .25; } 40% { opacity: 1; transform: translateY(-2px); } }
|
||
|
||
.update-bar {
|
||
display: flex; align-items: center; justify-content: space-between; gap: 12px;
|
||
padding: 8px 14px; margin-bottom: 12px; flex-shrink: 0;
|
||
background: var(--primary-weak);
|
||
border: 1px solid rgba(var(--primary-rgb), .5);
|
||
border-radius: var(--radius-sm);
|
||
font-size: 13px; color: var(--text-sub);
|
||
}
|
||
.update-bar b { color: var(--primary); }
|
||
.update-bar em { font-style: normal; color: var(--text-faint); margin-left: 6px; }
|
||
.update-bar .upd-actions { display: flex; align-items: center; gap: 8px; }
|
||
|
||
/* 壳子更新下载进度弹窗 */
|
||
.dl-dlg-body { display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; }
|
||
.dl-dlg-bytes { font-size: 12px; color: var(--text-faint); text-align: right; }
|
||
.dl-dlg-err { color: var(--danger); font-size: 13px; line-height: 1.6; }
|
||
|
||
/* ---------- 左轨:品牌(原顶栏品牌区融入) ---------- */
|
||
.side-brand {
|
||
display: flex; align-items: center; gap: 9px;
|
||
padding: 2px 8px 12px;
|
||
}
|
||
.side-brand .logo {
|
||
width: 28px; height: 28px; border-radius: 8px;
|
||
display: grid; place-items: center;
|
||
background: var(--primary-grad); color: var(--on-primary);
|
||
font-size: 12px; font-weight: 800;
|
||
box-shadow: 0 4px 12px -3px rgba(var(--primary-rgb),.6);
|
||
flex-shrink: 0;
|
||
}
|
||
.side-brand strong { font-size: 13.5px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
|
||
/* ---------- 右轨:账号条(原顶栏账号区融入) ---------- */
|
||
.act-acct {
|
||
display: flex; align-items: center; justify-content: space-between; gap: 8px;
|
||
padding: 2px 4px 10px;
|
||
}
|
||
.act-acct {
|
||
display: flex; align-items: center; justify-content: space-between; gap: 8px;
|
||
padding: 2px 4px 10px;
|
||
min-width: 0;
|
||
}
|
||
.act-acct .acct-display {
|
||
display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1;
|
||
}
|
||
.act-acct .acct-avatar { flex-shrink: 0; }
|
||
.act-acct .acct-avatar-fb { font-size: 12px; font-weight: 700; }
|
||
.act-acct .acct-name {
|
||
font-size: 12.5px; font-weight: 600; color: var(--text);
|
||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
||
}
|
||
.act-acct .acct-ops { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
|
||
.act-acct .acct-ops .el-button + .el-button { margin-left: 0; }
|
||
|
||
.auth-expired-bar {
|
||
display: flex; align-items: center; justify-content: space-between; gap: 12px;
|
||
padding: 8px 14px; margin-bottom: 12px; flex-shrink: 0;
|
||
background: var(--warn-bg);
|
||
border: 1px solid rgba(var(--warn-rgb), .45);
|
||
border-radius: var(--radius-sm);
|
||
font-size: 13px; color: var(--warn-text);
|
||
}
|
||
.auth-expired-bar .ae-txt { flex: 1; }
|
||
|
||
/* 状态栏里的 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; }
|
||
|
||
/* 三栏骨架的结构面板:静态面板不做 hover 上浮(大面板浮动会晃) */
|
||
.rail {
|
||
background: var(--surface);
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius);
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
|
||
.side { width: 232px; flex-shrink: 0; display: flex; flex-direction: column; padding: 14px 12px; }
|
||
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 10px; }
|
||
.side-head-r { display: flex; align-items: center; gap: 2px; }
|
||
.sync-btn { padding: 5px 6px; font-size: 14px; color: var(--text-faint); }
|
||
.sync-btn:hover { color: var(--primary); }
|
||
.count { font-size: 11px; color: var(--text-faint); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; }
|
||
.scene-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
|
||
.scene-list li {
|
||
display: flex; align-items: center; gap: 10px;
|
||
padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer;
|
||
position: relative;
|
||
transition: background .13s, transform .13s ease;
|
||
}
|
||
.scene-list li:hover { background: var(--surface-2); transform: translateX(2px); }
|
||
.scene-list li.active { background: var(--primary-weak); }
|
||
.scene-list li.active::before {
|
||
content: ''; position: absolute; left: 0; top: 9px; bottom: 9px;
|
||
width: 3px; border-radius: 3px; background: var(--primary);
|
||
}
|
||
.scene-list li.active .scene-name { color: var(--primary); font-weight: 600; }
|
||
.scene-icon {
|
||
width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
|
||
display: grid; place-items: center; color: var(--tile-fg); font-size: 12px; font-weight: 700;
|
||
}
|
||
.scene-name { flex: 1; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
.scene-list em { font-style: normal; font-size: 10px; color: var(--text-faint); }
|
||
.scene-empty {
|
||
flex: 1; display: grid; place-items: center; text-align: center;
|
||
font-size: 12.5px; color: var(--text-sub); line-height: 1.9; padding: 20px 12px;
|
||
}
|
||
.scene-empty span { font-size: 11px; color: var(--text-faint); }
|
||
/* ---------- 右栏:活动流 ---------- */
|
||
.activity {
|
||
width: 268px; flex-shrink: 0;
|
||
display: flex; flex-direction: column;
|
||
padding: 14px 12px; min-height: 0;
|
||
}
|
||
.act-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 10px; }
|
||
.act-head-2 { padding-top: 14px; margin-top: 12px; border-top: 1px dashed var(--border); }
|
||
.act-live { font-size: 10.5px; color: var(--ok); animation: actBlink 1s infinite; }
|
||
@keyframes actBlink { 50% { opacity: .25; } }
|
||
|
||
.act-now {
|
||
border: 1px solid var(--border); border-radius: var(--radius-sm);
|
||
background: var(--surface-2); padding: 11px 12px;
|
||
display: flex; flex-direction: column; gap: 9px;
|
||
}
|
||
.act-now.on { background: var(--primary-tint); border-color: var(--primary-line); }
|
||
.an-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||
.an-name { font-size: 12.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
.an-pct { font-size: 12px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; flex-shrink: 0; }
|
||
.an-tail { display: flex; flex-direction: column; gap: 3px; max-height: 88px; overflow: hidden; }
|
||
.an-line { display: flex; gap: 6px; font-size: 11px; line-height: 1.5; font-family: var(--mono); }
|
||
.an-line .lv { flex-shrink: 0; font-weight: 700; }
|
||
.an-line .s-INFO { color: var(--primary); }
|
||
.an-line .s-WARN { color: var(--warn); }
|
||
.an-line .s-ERROR { color: var(--err); }
|
||
.an-msg { color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
.an-wait { font-size: 11px; color: var(--text-faint); }
|
||
.an-idle { display: flex; align-items: center; gap: 10px; }
|
||
.an-idle-ic {
|
||
width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
|
||
display: grid; place-items: center; font-size: 12px; font-weight: 700;
|
||
background: var(--ok-weak); color: var(--ok);
|
||
}
|
||
.an-idle-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
|
||
.an-idle-meta b { font-size: 12.5px; color: var(--text); }
|
||
.an-idle-meta span { font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
|
||
.act-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
|
||
.act-list li {
|
||
display: flex; align-items: center; gap: 9px;
|
||
padding: 8px 9px; border-radius: var(--radius-sm); cursor: pointer;
|
||
transition: background .13s;
|
||
}
|
||
.act-list li:hover { background: var(--surface-2); }
|
||
.act-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
|
||
.act-dot.ok { background: var(--ok); }
|
||
.act-dot.err { background: var(--err); }
|
||
.act-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
|
||
.act-meta b { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
.act-meta span { font-size: 10.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
.act-list em { font-style: normal; font-size: 10px; color: var(--text-faint); font-variant-numeric: tabular-nums; flex-shrink: 0; }
|
||
.act-empty { font-size: 11.5px; color: var(--text-faint); text-align: center; padding: 18px 8px; line-height: 1.8; }
|
||
|
||
/* ---------- 底栏:状态栏 ---------- */
|
||
.statusbar {
|
||
flex-shrink: 0; margin-top: 12px;
|
||
display: flex; align-items: center; gap: 10px;
|
||
padding: 7px 14px;
|
||
background: var(--surface); border: 1px solid var(--border);
|
||
border-radius: var(--radius-sm);
|
||
font-size: 11.5px; color: var(--text-sub);
|
||
}
|
||
.sb-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
|
||
.sb-item.mono { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
|
||
.sb-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot-off); flex-shrink: 0; }
|
||
.sb-item.ok { color: var(--ok-text); }
|
||
.sb-item.ok .sb-dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-weak); }
|
||
.sb-item.warn { color: var(--warn-text); }
|
||
.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; }
|
||
|
||
/* 窄窗(如分屏):收起右栏,保证中栏可用宽度 */
|
||
@media (max-width: 1240px) {
|
||
.activity { display: none; }
|
||
}
|
||
.nav-main {
|
||
display: flex; flex-direction: column; gap: 2px;
|
||
padding: 0 4px 12px; margin-bottom: 10px;
|
||
border-bottom: 1px dashed var(--border);
|
||
}
|
||
.nav-item {
|
||
display: flex; align-items: center; gap: 10px;
|
||
padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer;
|
||
color: var(--text-sub); font-size: 13px; position: relative;
|
||
transition: background .13s, transform .13s ease;
|
||
}
|
||
.nav-item:hover { background: var(--surface-2); transform: translateX(2px); }
|
||
.nav-item.active { background: var(--primary-weak); color: var(--primary); font-weight: 600; }
|
||
.nav-item.active::before {
|
||
content: ''; position: absolute; left: 0; top: 9px; bottom: 9px;
|
||
width: 3px; border-radius: 3px; background: var(--primary);
|
||
}
|
||
.nav-item .el-icon { font-size: 15px; }
|
||
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
|
||
/* 中栏上下文区:视图自己决定是否填满(总览/计划自然高度并整体滚动,运行台填满内部滚) */
|
||
.page-scroll { flex: 1; min-height: 0; padding: 20px 24px; overflow: auto; display: flex; flex-direction: column; }
|
||
</style> |