- 新增通知推送模块:支持 WebSocket 实时推送与轮询兜底,新增通知管理界面 - 新增离线登录功能:断网时凭本地 7 天授权票据自动登录或手动登录 - 优化 Electron 客户端 WebSocket 重连逻辑,避免死循环 - 调整工作流脚本,拆分重构合同相关分支逻辑 - 新增设备上报客户端版本字段,用于升级追踪与关旧依据
249 lines
9.4 KiB
Vue
249 lines
9.4 KiB
Vue
<template>
|
|
<LoginPage v-if="!store.current" :app-name="store.appName" @ok="onLogin" />
|
|
<div class="console" v-else>
|
|
<header class="topbar">
|
|
<div class="brand">
|
|
<span class="logo">37</span>
|
|
<div class="brand-meta">
|
|
<strong>{{ store.appName }}</strong>
|
|
<span>中心机 · 控制面</span>
|
|
</div>
|
|
</div>
|
|
<div class="spacer"></div>
|
|
<el-dropdown trigger="click" @command="onCommand">
|
|
<div class="acct">
|
|
<span class="avatar">{{ initial }}</span>
|
|
<span class="acct-name">{{ store.nickname || store.current }}</span>
|
|
<el-tag v-if="store.isAdmin" size="small" type="primary" round effect="light" class="admin-tag">管理员</el-tag>
|
|
<el-icon class="caret"><ArrowDown /></el-icon>
|
|
</div>
|
|
<template #dropdown>
|
|
<el-dropdown-menu>
|
|
<el-dropdown-item command="pwd"><el-icon><Lock /></el-icon>修改密码</el-dropdown-item>
|
|
<el-dropdown-item divided command="logout"><el-icon><SwitchButton /></el-icon>退出登录</el-dropdown-item>
|
|
</el-dropdown-menu>
|
|
</template>
|
|
</el-dropdown>
|
|
</header>
|
|
|
|
<div class="body">
|
|
<aside class="aside">
|
|
<div class="aside-inner">
|
|
<el-menu :default-active="activeKey" @select="onMenu">
|
|
<el-menu-item v-for="m in menu" :key="m.key" :index="m.key">
|
|
<el-icon><component :is="m.icon" /></el-icon>
|
|
<span>{{ m.label }}</span>
|
|
</el-menu-item>
|
|
</el-menu>
|
|
</div>
|
|
</aside>
|
|
<main class="main">
|
|
<transition name="view-fade" mode="out-in">
|
|
<component :is="viewComp" :key="route" />
|
|
</transition>
|
|
</main>
|
|
</div>
|
|
<PasswordDialog v-model="pwdOpen" :force="pwdForce" />
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed, onMounted, ref } from 'vue'
|
|
import { ArrowDown, Lock, SwitchButton, Odometer, TrendCharts, Box, User, Key, Document, Files, Monitor, Bell } from '@element-plus/icons-vue'
|
|
import { ElMessage as message } from 'element-plus'
|
|
import LoginPage from './components/LoginPage.vue'
|
|
import PasswordDialog from './components/PasswordDialog.vue'
|
|
import OverviewView from './views/OverviewView.vue'
|
|
import PluginManageView from './views/PluginManageView.vue'
|
|
import AccountManageView from './views/AccountManageView.vue'
|
|
import GrantManageView from './views/GrantManageView.vue'
|
|
import StatsView from './views/StatsView.vue'
|
|
import AuditView from './views/AuditView.vue'
|
|
import CredsManageView from './views/CredsManageView.vue'
|
|
import FileSourceManageView from './views/FileSourceManageView.vue'
|
|
import UpgradeView from './views/UpgradeView.vue'
|
|
import NotifyManageView from './views/NotifyManageView.vue'
|
|
import { store, clearSession } from './store'
|
|
import { adminMe } from './api'
|
|
|
|
const menuOptions = [
|
|
{ label: '概览', key: 'overview', icon: Odometer },
|
|
{ label: '数据看板', key: 'stats', icon: TrendCharts },
|
|
{ label: '升级进度', key: 'upgrade', icon: Monitor, admin: true },
|
|
{ label: '通知推送', key: 'notify', icon: Bell, admin: true },
|
|
{ label: '插件管理', key: 'plugins', icon: Box },
|
|
{ label: '账号管理', key: 'accounts', icon: User },
|
|
{ label: '权限授权', key: 'grants', icon: Key },
|
|
{ label: '敏感凭证', key: 'creds', icon: Lock, admin: true },
|
|
{ label: '大文件源', key: 'files', icon: Files, admin: true },
|
|
{ label: '审计报表', key: 'audit', icon: Document },
|
|
]
|
|
const menu = computed(() => menuOptions.filter(m => !m.admin || store.isAdmin))
|
|
|
|
// 轻量 hash 路由:静态站刷新安全,零后端改动
|
|
const KEY = {
|
|
'#/overview': 'overview',
|
|
'#/stats': 'stats',
|
|
'#/upgrade': 'upgrade',
|
|
'#/notify': 'notify',
|
|
'#/plugins': 'plugins',
|
|
'#/accounts': 'accounts',
|
|
'#/grants': 'grants',
|
|
'#/creds': 'creds',
|
|
'#/files': 'files',
|
|
'#/audit': 'audit',
|
|
}
|
|
const VIEWS = {
|
|
'#/overview': OverviewView,
|
|
'#/stats': StatsView,
|
|
'#/upgrade': UpgradeView,
|
|
'#/notify': NotifyManageView,
|
|
'#/plugins': PluginManageView,
|
|
'#/accounts': AccountManageView,
|
|
'#/grants': GrantManageView,
|
|
'#/creds': CredsManageView,
|
|
'#/files': FileSourceManageView,
|
|
'#/audit': AuditView,
|
|
}
|
|
const route = ref(VIEWS[location.hash] ? location.hash : '#/overview')
|
|
window.addEventListener('hashchange', () => {
|
|
if (VIEWS[location.hash]) route.value = location.hash
|
|
})
|
|
const viewComp = computed(() => VIEWS[route.value] || OverviewView)
|
|
const activeKey = computed(() => KEY[route.value] || 'overview')
|
|
|
|
function onMenu(key) {
|
|
const h = '#/' + key
|
|
location.hash = h
|
|
route.value = h
|
|
}
|
|
|
|
const initial = computed(() => (store.nickname || store.current || '')[0]?.toUpperCase() || '?')
|
|
|
|
const pwdOpen = ref(false)
|
|
const pwdForce = ref(false)
|
|
function onCommand(cmd) {
|
|
if (cmd === 'pwd') { pwdForce.value = false; pwdOpen.value = true }
|
|
else if (cmd === 'logout') {
|
|
clearSession()
|
|
message.success('已退出登录')
|
|
}
|
|
}
|
|
|
|
function onLogin(r) {
|
|
route.value = '#/overview'
|
|
location.hash = '#/overview'
|
|
// 服务端强制:仍持初始密码(must_change_pwd=1)时拒绝一切管理操作,必须先改密
|
|
if (r && r.must_change_pwd) {
|
|
pwdForce.value = true
|
|
pwdOpen.value = true
|
|
message.warning('首次登录请先修改初始密码,修改成功后才能使用管理功能')
|
|
}
|
|
}
|
|
|
|
onMounted(async () => {
|
|
// 已本地标记登录时,校验登录票据仍有效且为管理员(票据过期/权限变更后回登录页)
|
|
if (!store.current) return
|
|
try {
|
|
const me = await adminMe()
|
|
if (!me.account || !me.is_admin) clearSession()
|
|
else {
|
|
store.isAdmin = true; store.nickname = me.nickname || ''
|
|
// 刷新后仍需先改初始密码(服务端拒绝一切管理操作)
|
|
if (me.must_change_pwd) {
|
|
pwdForce.value = true
|
|
pwdOpen.value = true
|
|
message.warning('请先修改初始密码,修改成功后才能使用管理功能')
|
|
}
|
|
}
|
|
} catch (_) { /* 后端 down:保持本地态 */ }
|
|
})
|
|
</script>
|
|
|
|
<style scoped>
|
|
.console { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
|
|
|
|
/* ---------- 顶栏:纸白面板 ---------- */
|
|
.topbar {
|
|
height: 64px; flex-shrink: 0;
|
|
display: flex; align-items: center; gap: 16px;
|
|
padding: 0 26px;
|
|
background: rgba(255, 253, 248, .86);
|
|
backdrop-filter: blur(14px);
|
|
-webkit-backdrop-filter: blur(14px);
|
|
border-bottom: 1px solid var(--cp-line);
|
|
box-shadow: 0 6px 20px -18px rgba(35, 42, 58, .3);
|
|
position: relative; z-index: 20;
|
|
}
|
|
.topbar::after {
|
|
content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
|
|
background: linear-gradient(90deg, transparent, rgba(47, 92, 240, .4), rgba(15, 159, 155, .4), transparent);
|
|
}
|
|
.brand { display: flex; align-items: center; gap: 12px; }
|
|
.logo {
|
|
width: 38px; height: 38px; border-radius: 12px;
|
|
display: grid; place-items: center; position: relative;
|
|
background: linear-gradient(135deg, var(--cp-blue) 0%, var(--cp-teal) 140%);
|
|
color: #fff; font-size: 14px; font-weight: 800; letter-spacing: .5px;
|
|
box-shadow: 0 8px 18px -8px rgba(47, 92, 240, .55);
|
|
}
|
|
.logo::after { content: ''; position: absolute; inset: 2px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .3); }
|
|
.brand-meta { display: flex; flex-direction: column; line-height: 1.25; }
|
|
.brand-meta strong { font-size: 15px; color: var(--cp-ink-1); letter-spacing: .2px; }
|
|
.brand-meta span { font-size: 11px; color: var(--cp-ink-3); letter-spacing: .4px; }
|
|
.spacer { flex: 1; }
|
|
|
|
.acct {
|
|
display: flex; align-items: center; gap: 9px; cursor: pointer;
|
|
padding: 6px 12px; border-radius: 12px; border: 1px solid transparent;
|
|
transition: background .18s, border-color .18s;
|
|
}
|
|
.acct:hover { background: rgba(47, 92, 240, .06); border-color: rgba(47, 92, 240, .16); }
|
|
.avatar {
|
|
width: 30px; height: 30px; border-radius: 50%;
|
|
display: grid; place-items: center;
|
|
background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal));
|
|
color: #fff; font-size: 13px; font-weight: 700;
|
|
}
|
|
.acct-name { font-size: 13px; font-weight: 700; color: var(--cp-ink-1); }
|
|
.admin-tag { margin-left: 2px; }
|
|
.caret { color: var(--cp-ink-3); }
|
|
|
|
/* ---------- 主体:侧栏 + 内容区(紧凑间距,避免挤压表格) ---------- */
|
|
.body { flex: 1; display: flex; gap: 12px; padding: 14px 18px 22px; min-height: 0; }
|
|
.aside {
|
|
width: 192px; flex-shrink: 0;
|
|
display: flex; flex-direction: column;
|
|
background: rgba(255, 253, 248, .8);
|
|
backdrop-filter: blur(12px);
|
|
-webkit-backdrop-filter: blur(12px);
|
|
border: 1px solid var(--cp-line);
|
|
border-radius: 16px;
|
|
box-shadow: var(--cp-shadow);
|
|
padding: 12px 8px;
|
|
}
|
|
.aside-inner { flex: 1; }
|
|
.main { flex: 1; min-width: 0; overflow: auto; padding: 0 2px 8px; }
|
|
|
|
/* 页面切换过渡:轻微上浮淡入 */
|
|
.view-fade-enter-active { transition: opacity .22s ease, transform .22s ease; }
|
|
.view-fade-leave-active { transition: opacity .12s ease; }
|
|
.view-fade-enter-from { opacity: 0; transform: translateY(8px); }
|
|
.view-fade-leave-to { opacity: 0; }
|
|
|
|
/* ---------- 侧栏菜单:纸面导航 ---------- */
|
|
.aside :deep(.el-menu-item) {
|
|
height: 44px; margin-bottom: 4px;
|
|
border-radius: 11px;
|
|
font-weight: 600; color: var(--cp-ink-2);
|
|
}
|
|
.aside :deep(.el-menu-item:hover) { background: rgba(47, 92, 240, .06); color: var(--cp-blue); }
|
|
.aside :deep(.el-menu-item.is-active) {
|
|
background: linear-gradient(90deg, rgba(47, 92, 240, .12), rgba(47, 92, 240, .04));
|
|
color: var(--cp-blue);
|
|
font-weight: 700;
|
|
box-shadow: inset 3px 0 0 var(--cp-blue);
|
|
}
|
|
.aside :deep(.el-menu-item .el-icon) { font-size: 17px; }
|
|
</style>
|