1. 新增controlplane/frontend Vue3管理前端,实现登录、账号CRUD、插件上传/管理、权限授权 2. 为controlplane/app.py添加CORS中间件并挂载前端静态产物 3. 重构环境变量加载,统一使用app/common/env.load_app_env() 4. 剥离webhost/的管理UI与代理接口,仅保留基础登录能力 5. 新增环境隔离规范文档与架构蓝图说明
224 lines
8.5 KiB
Vue
224 lines
8.5 KiB
Vue
<template>
|
||
<LoginPage v-if="!store.current" :app-name="store.appName" @ok="onLogin" />
|
||
<div class="__app" v-else>
|
||
<!-- 顶部:品牌 + 平台登录态 + 当前账号/登出 + 进度 -->
|
||
<header class="topbar panel">
|
||
<div class="brand">
|
||
<span class="logo">37</span>
|
||
<div class="brand-meta">
|
||
<strong>{{ store.appName }}</strong>
|
||
<span>{{ wsText }}</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="divider"></div>
|
||
|
||
<div class="band">
|
||
<span class="band-label">平台登录态</span>
|
||
<button
|
||
v-for="p in store.platforms"
|
||
:key="p.id"
|
||
class="chip"
|
||
:class="{ online: p.online }"
|
||
:disabled="busyLogin === p.id"
|
||
@click="login(p.id)"
|
||
:title="p.online ? '已登录,点击刷新' : '未登录,点击登录'"
|
||
>
|
||
<i class="dot"></i>
|
||
<span>{{ busyLogin === p.id ? '登录中…' : p.label }}</span>
|
||
</button>
|
||
</div>
|
||
|
||
<div class="spacer"></div>
|
||
|
||
<div class="run-state">
|
||
<span v-if="store.running" class="run-label">{{ store.progress }}%</span>
|
||
<div v-show="store.running" class="progress"><div :style="{ width: store.progress + '%' }"></div></div>
|
||
</div>
|
||
|
||
<div class="acct">
|
||
<span class="acct-name">{{ store.current }}</span>
|
||
<em v-if="store.isAdmin" class="acct-tag">管理员</em>
|
||
<button class="chip" @click="logout">登出</button>
|
||
</div>
|
||
</header>
|
||
|
||
<!-- 主体:左场景 | 右插件页 + 日志 -->
|
||
<div class="body">
|
||
<aside class="panel side">
|
||
<div class="side-head">
|
||
<span class="sec-title">场景</span>
|
||
<span class="count">{{ store.plugins.length }}</span>
|
||
</div>
|
||
<ul class="scene-list">
|
||
<li
|
||
v-for="(p, i) in store.plugins"
|
||
:key="p.id"
|
||
:class="{ active: p.id === store.selectedId && store.view === 'plugin' }"
|
||
@click="openPlugin(p.id)"
|
||
>
|
||
<span class="scene-icon" :style="{ background: PALETTE[i % PALETTE.length] }">
|
||
{{ p.name.slice(0, 1) }}
|
||
</span>
|
||
<span class="scene-name">{{ p.name }}</span>
|
||
<em>v{{ p.version }}</em>
|
||
</li>
|
||
</ul>
|
||
<div class="side-foot">场景以插件方式接入</div>
|
||
</aside>
|
||
|
||
<main class="main">
|
||
<div class="page-scroll panel">
|
||
<PluginPage v-if="store.view === 'plugin'" />
|
||
</div>
|
||
<LogPanel />
|
||
</main>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed, onMounted, ref } from 'vue'
|
||
import PluginPage from './components/PluginPage.vue'
|
||
import LogPanel from './components/LogPanel.vue'
|
||
import LoginPage from './components/LoginPage.vue'
|
||
import { store, handleEvent, clearLogs } from './store'
|
||
import { connectWS, fetchMeta, loginPlatform, adminLogout } from './api'
|
||
|
||
const PALETTE = ['#3b6cff', '#7c5cff', '#12a4d8', '#22b07a', '#e88a3a', '#e5484d']
|
||
|
||
const wsText = computed(() =>
|
||
store.wsOn ? '服务已连接' : '连接中断,正在重连…')
|
||
|
||
function openPlugin(id) {
|
||
store.selectedId = id
|
||
store.view = 'plugin'
|
||
}
|
||
|
||
onMounted(async () => {
|
||
const meta = await fetchMeta()
|
||
store.appName = meta.appName
|
||
store.platforms = meta.platforms
|
||
store.plugins = meta.plugins
|
||
store.selectedId = meta.plugins[0]?.id || ''
|
||
clearLogs()
|
||
if (window.__ws) window.__ws.close()
|
||
const ws = connectWS(handleEvent)
|
||
window.__ws = ws
|
||
ws.onopen = () => (store.wsOn = true)
|
||
ws.onclose = () => { store.wsOn = false; setTimeout(() => (location.reload()), 2500) }
|
||
checkSession()
|
||
})
|
||
|
||
const busyLogin = ref('')
|
||
|
||
async function checkSession() {
|
||
// 已在本地标记登录:与后端会话 cookie 是否一致(后端重启会失效,此时回登录页)
|
||
if (!store.current) return
|
||
try {
|
||
const me = await fetch('/api/admin/me').then((r) => r.json())
|
||
if (!me.account) { store.current = ''; store.isAdmin = false }
|
||
else store.isAdmin = !!me.is_admin
|
||
} catch (_) { /* 后端 down:暂保持本地态 */
|
||
}
|
||
}
|
||
|
||
function onLogin(ok) {
|
||
store.current = ok.account
|
||
store.isAdmin = !!ok.is_admin
|
||
try { localStorage.setItem('cp_account', ok.account) } catch (_) {}
|
||
}
|
||
async function logout() {
|
||
try { await adminLogout() } catch (_) {}
|
||
store.current = ''
|
||
store.isAdmin = false
|
||
try { localStorage.removeItem('cp_account') } catch (_) {}
|
||
}
|
||
|
||
async function login(id) {
|
||
if (busyLogin.value) return
|
||
busyLogin.value = id
|
||
try {
|
||
const r = await loginPlatform(id)
|
||
const p = store.platforms.find((x) => x.id === id)
|
||
if (p) p.online = !!r.online
|
||
} catch (e) {
|
||
alert('登录失败:' + (e.message || e))
|
||
} finally {
|
||
busyLogin.value = ''
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.topbar {
|
||
display: flex; align-items: center; gap: 16px;
|
||
padding: 12px 18px;
|
||
flex-shrink: 0;
|
||
}
|
||
.brand { display: flex; align-items: center; gap: 11px; }
|
||
.logo {
|
||
width: 36px; height: 36px; border-radius: 10px;
|
||
display: grid; place-items: center;
|
||
background: var(--primary-grad); color: #fff;
|
||
font-size: 14px; font-weight: 800;
|
||
box-shadow: 0 4px 12px -3px rgba(59,108,255,.6);
|
||
}
|
||
.brand-meta { display: flex; flex-direction: column; line-height: 1.2; }
|
||
.brand-meta strong { font-size: 14px; }
|
||
.brand-meta span { font-size: 11px; color: var(--text-faint); }
|
||
|
||
.divider { width: 1px; height: 26px; background: var(--border); }
|
||
|
||
.band { display: flex; align-items: center; gap: 6px; }
|
||
.band-label { font-size: 12px; color: var(--text-faint); margin-right: 4px; }
|
||
.chip {
|
||
display: inline-flex; align-items: center; gap: 7px;
|
||
border: 1px solid var(--border-strong); background: var(--surface);
|
||
color: var(--text-sub); padding: 5px 12px; border-radius: 999px;
|
||
cursor: pointer; font-size: 12.5px; transition: all .15s;
|
||
}
|
||
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: #c6ccdc; }
|
||
.chip.online { border-color: transparent; background: var(--ok-weak); color: #1a8f63; }
|
||
.chip.online .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(34,176,122,.18); }
|
||
.chip:hover { border-color: var(--primary); color: var(--primary); }
|
||
.chip:disabled { opacity: .55; cursor: not-allowed; }
|
||
.chip:disabled:hover { border-color: var(--border-strong); color: var(--text-sub); }
|
||
|
||
.spacer { flex: 1; }
|
||
.run-state { display: flex; align-items: center; gap: 10px; }
|
||
.run-label { font-size: 12px; color: var(--primary); font-weight: 600; min-width: 38px; text-align: right; }
|
||
|
||
.acct { display: flex; align-items: center; gap: 8px; margin-left: 12px; }
|
||
.acct-name { font-size: 13px; font-weight: 600; color: var(--text-sub); }
|
||
.acct-tag { font-style: normal; font-size: 10px; color: var(--primary);
|
||
border: 1px solid var(--primary-weak); background: var(--primary-weak); border-radius: 999px; padding: 1px 7px; }
|
||
|
||
.body { flex: 1; display: flex; gap: 14px; min-height: 0; margin-top: 14px; }
|
||
|
||
.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; }
|
||
.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;
|
||
transition: background .13s;
|
||
}
|
||
.scene-list li:hover { background: var(--surface-2); }
|
||
.scene-list li.active { background: var(--primary-weak); }
|
||
.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: #fff; font-size: 12px; font-weight: 700;
|
||
}
|
||
.scene-name { flex: 1; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||
.scene-list li.active .scene-name { color: var(--primary); }
|
||
.scene-list li.admin-entry { border-top: 1px dashed var(--border); margin-top: 6px; border-radius: 0; }
|
||
.scene-list li.admin-entry.active .scene-name { color: var(--primary); font-weight: 600; }
|
||
.scene-list em { font-style: normal; font-size: 10px; color: var(--text-faint); }
|
||
.side-foot { font-size: 10px; color: var(--text-faint); text-align: center; padding-top: 10px; border-top: 1px dashed var(--border); margin-top: 8px; }
|
||
|
||
.main { flex: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
|
||
.page-scroll { flex: 1; min-height: 0; padding: 20px 24px; overflow: auto; }
|
||
</style> |