feat(electron-shell): 补录壳子源码(排除运行环境与构建产物)

This commit is contained in:
2026-09-24 16:14:24 +08:00
parent 08a9b962b4
commit f3311339e5
56 changed files with 17858 additions and 0 deletions
+903
View File
@@ -0,0 +1,903 @@
<template>
<div v-if="booting" class="boot">
<span class="boot-logo">37</span>
<span class="boot-txt">{{ syncing ? '正在同步插件,请稍候…' : (store.appName || '自动化工作台') }}</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 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>
<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>
<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>
</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, adminLogout, adminMe, adminPassword, syncPlugins, getShellStatus, applyShellUpdate, checkShellUpdate, downloadShellUpdate, getChromeStatus, checkChrome, downloadChrome, installChrome } 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}`
})
const localAddr = computed(() => (typeof location !== 'undefined' ? location.host : ''))
// 授权票据概要(状态栏):后端 /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'
})
function openWS() {
if (window.__ws) window.__ws.close()
const ws = connectWS(handleEvent)
window.__ws = ws
ws.onopen = () => (store.wsOn = true)
ws.onclose = () => {
store.wsOn = false
// 仅登录态下自动重连刷新;未登录被拒(1008)时静默,避免 reload 死循环
if (store.current) setTimeout(() => (location.reload()), 2500)
}
}
onMounted(async () => {
const meta = await fetchMeta()
store.appName = meta.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()
})
onUnmounted(() => {
if (shellPollTimer) { clearTimeout(shellPollTimer); shellPollTimer = null }
if (chromePollTimer) { clearTimeout(chromePollTimer); chromePollTimer = null }
})
// ===== 浏览器(Chrome)检测/下载/安装 =====
const chrome = ref({})
let chromePollTimer = null
const chromeBusy = ref(false) // 正在轮询/下载/安装(按钮 loading)
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,点击下载安装'
})
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
if (chrome.value.installed && chrome.value.dl?.status !== '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) { return }
// 已下载:直接安装
if (c.downloaded) {
chromeBusy.value = true
try { await installChrome(); chrome.value.installing = true; startChromePoll() }
catch (e) { ElMessage.error('安装失败:' + (e.message || e)) }
chromeBusy.value = false
return
}
// 未装且中心机有登记:下载
if (!c.installed && c.cloud_available) {
chromeBusy.value = true
try { await downloadChrome(); loadChromeStatus() }
catch (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
}
const pwdDlg = ref(false)
const booting = ref(true) // 鉴权判定中:未确定会话前先显示加载骨架,避免「闪一下登录页再进首页」
const syncing = ref(false) // 首次启动/启动时:按账号权限自下载/更新插件(等待下载界面)
// ===== 壳子自动更新:检查 → 用户确认下载(带进度)→ 重启更新 =====
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 (_) {}
startShellPoll()
}
// 常驻状态轮询:驱动下载进度条与 available/downloaded 提示;下载完成/失败各提示一次
async function refreshShellStatus() {
try {
const s = await getShellStatus()
shellUpdate.value = s
const st = s.dl?.status || ''
if (lastDlStatus === 'downloading' && st === 'downloaded') {
updDlg.value = false // 弹窗开着时自动收起,顶部提示条转为「重启更新」
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' ? 1200 : 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 = { ...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 })
}
async function checkSession() {
// 登录态一律以**后端会话 cookie** 为准(钉钉扫码/账号登录/后端重启后均从 admin/me 判定),
// 不再以 localStorage 的 cp_account 早退——否则全新扫码流程(未写过 cp_account)回跳后无法进入插件页。
try {
const me = await adminMe()
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 (_) {}
// 会话确认后:按账号权限自下载/更新插件(首次启动等待下载完成;离线/失败直接跳过)
syncing.value = true
try { await syncPlugins() } catch (_) {}
syncing.value = false
// 会话有效:补拉插件清单(未登录时 meta 不返回插件)
await refreshMeta()
} 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 { cursor: pointer; }
.chrome-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); }
.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>