feat: 搭建控制面管理前端并剥离底座管理功能
1. 新增controlplane/frontend Vue3管理前端,实现登录、账号CRUD、插件上传/管理、权限授权 2. 为controlplane/app.py添加CORS中间件并挂载前端静态产物 3. 重构环境变量加载,统一使用app/common/env.load_app_env() 4. 剥离webhost/的管理UI与代理接口,仅保留基础登录能力 5. 新增环境隔离规范文档与架构蓝图说明
This commit is contained in:
+47
-1
@@ -21,18 +21,51 @@ import hashlib
|
||||
import os
|
||||
import secrets
|
||||
import sqlite3
|
||||
import sys
|
||||
from contextlib import asynccontextmanager
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from fastapi import FastAPI, File, Header, HTTPException, Query, UploadFile
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from pydantic import BaseModel
|
||||
|
||||
APP_DIR = Path(__file__).resolve().parent
|
||||
# 数据目录定位:打包成 exe(冻结) 时统一放 exe 同目录,保证 controlplane.db / packages/ 持久可写;
|
||||
# 源码运行时沿用 controlplane/ 目录。禁止用 PyInstaller 临时解压目录(重启会丢数据)。
|
||||
if getattr(sys, "frozen", False):
|
||||
_APP_BASE = Path(sys.executable).resolve().parent
|
||||
else:
|
||||
_APP_BASE = Path(__file__).resolve().parent
|
||||
APP_DIR = _APP_BASE
|
||||
DB_PATH = APP_DIR / "controlplane.db"
|
||||
PKG_DIR = APP_DIR / "packages"
|
||||
|
||||
|
||||
# ==================== 配置固化:加载本模块 env(controlplane/.env;免命令行传参;环境变量优先) ====================
|
||||
def _load_dotenv() -> None:
|
||||
"""源码模式读 controlplane/.env;exe 模式读 exe 同目录 .env。UTF-8、'#'/'空行'跳过。"""
|
||||
env_path = APP_DIR / ".env"
|
||||
# APP_DIR 源码态为 controlplane/,exe 态为 exe 同目录,均为本模块专属 env
|
||||
if not env_path.is_file():
|
||||
return
|
||||
try:
|
||||
for _ln in env_path.read_text(encoding="utf-8").splitlines():
|
||||
_line = _ln.strip()
|
||||
if not _line or _line.startswith("#") or "=" not in _line:
|
||||
continue
|
||||
_k, _v = _line.split("=", 1)
|
||||
_k, _v = _k.strip(), _v.strip()
|
||||
if _k and _k not in os.environ:
|
||||
os.environ[_k] = _v
|
||||
except OSError as _exc: # noqa: BLE001
|
||||
pass
|
||||
|
||||
|
||||
_load_dotenv()
|
||||
|
||||
CONTROLPLANE_TOKEN = os.getenv("CONTROLPLANE_TOKEN", "")
|
||||
|
||||
|
||||
@@ -162,6 +195,8 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
|
||||
app = FastAPI(title="37du 内网插件控制面", lifespan=lifespan)
|
||||
app.add_middleware(CORSMiddleware, allow_origins=["*"],
|
||||
allow_methods=["*"], allow_headers=["*"])
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
@@ -546,6 +581,17 @@ def admin_plugin_delete(d: PluginDelIn,
|
||||
return {"ok": True, "plugin_id": plugin_id}
|
||||
|
||||
|
||||
# ==================== 挂载控制面前端产物 ====================
|
||||
# 源码模式 => controlplane/frontend/dist;exe 模式 => sys._MEIPASS/frontend/dist(打进 exe)
|
||||
if getattr(sys, "frozen", False):
|
||||
DIST = Path(getattr(sys, "_MEIPASS", APP_DIR)) / "frontend" / "dist"
|
||||
else:
|
||||
DIST = APP_DIR / "frontend" / "dist"
|
||||
|
||||
if DIST.is_dir():
|
||||
app.mount("/", StaticFiles(directory=str(DIST), html=True), name="web")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>37du 内网插件控制面</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+1382
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "37du-controlplane-frontend",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^3.5.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"vite": "^6.0.3"
|
||||
},
|
||||
"allowScripts": {
|
||||
"esbuild@0.25.12": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<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>中心机控制面</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="spacer"></div>
|
||||
<div class="acct">
|
||||
<span class="acct-name">{{ store.current }}</span>
|
||||
<em v-if="store.isAdmin" class="acct-tag">管理员</em>
|
||||
<button class="btn" @click="logout">登出</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="page panel">
|
||||
<ManagementView />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted } from 'vue'
|
||||
import ManagementView from './components/ManagementView.vue'
|
||||
import LoginPage from './components/LoginPage.vue'
|
||||
import { store } from './store'
|
||||
import { adminMe } from './api'
|
||||
|
||||
function onLogin() {
|
||||
// store 已在 LoginPage 写入
|
||||
}
|
||||
function logout() {
|
||||
store.current = ''
|
||||
store.isAdmin = false
|
||||
try { localStorage.removeItem('cp_account') } catch (_) {}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// 已本地标记登录时,校验仍为管理员(控制面重启/权限变更后回登录页)
|
||||
if (!store.current) return
|
||||
try {
|
||||
const me = await adminMe()
|
||||
if (!me.account || !me.is_admin) { store.current = ''; store.isAdmin = false }
|
||||
else store.isAdmin = true
|
||||
} catch (_) { /* 后端 down:保持本地态 */ }
|
||||
})
|
||||
</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); }
|
||||
.spacer { flex: 1; }
|
||||
.acct { display: flex; align-items: center; gap: 8px; }
|
||||
.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; }
|
||||
.btn { padding: 6px 14px; font-size: 12.5px; }
|
||||
.page { flex: 1; min-height: 0; padding: 20px 24px; overflow: auto; margin-top: 14px; }
|
||||
</style>
|
||||
@@ -0,0 +1,99 @@
|
||||
// 与 FastAPI 后端交互,控制面前端直连 /api/*
|
||||
import { store } from './store.js'
|
||||
|
||||
async function j(url, opts) {
|
||||
const res = await fetch(url, opts)
|
||||
if (!res.ok) {
|
||||
let msg = `HTTP ${res.status}`
|
||||
try { msg = (await res.json()).detail || msg } catch (e) {}
|
||||
throw new Error(msg)
|
||||
}
|
||||
return res.json()
|
||||
}
|
||||
|
||||
async function jj(url, opts) {
|
||||
const r = await fetch(url, opts)
|
||||
if (!r.ok) {
|
||||
let m = `HTTP ${r.status}`
|
||||
try { m = (await r.json()).detail || m } catch (_) {}
|
||||
throw new Error(m)
|
||||
}
|
||||
return r.json()
|
||||
}
|
||||
|
||||
// 管理接口为无状态鉴权:控制面直接读取 X-Admin-User 头注入当前登录账号
|
||||
function adminHeaders(extra = {}) {
|
||||
return { 'X-Admin-User': store.current || '', ...extra }
|
||||
}
|
||||
|
||||
export async function adminLogin(account, password) {
|
||||
return jj('/api/admin/auth', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ account, password })
|
||||
})
|
||||
}
|
||||
export async function adminPassword(body) {
|
||||
return jj('/api/admin/password', {
|
||||
method: 'POST',
|
||||
headers: adminHeaders({ 'Content-Type': 'application/json' }),
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
}
|
||||
export async function adminMe() {
|
||||
return j('/api/admin/me', { headers: adminHeaders() })
|
||||
}
|
||||
export async function adminOverview() {
|
||||
return j('/api/admin/overview', { headers: adminHeaders() })
|
||||
}
|
||||
export async function adminGrant(body) {
|
||||
return jj('/api/admin/account_plugins', {
|
||||
method: 'POST',
|
||||
headers: adminHeaders({ 'Content-Type': 'application/json' }),
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
}
|
||||
export async function adminAccounts() {
|
||||
return j('/api/admin/accounts', { headers: adminHeaders() })
|
||||
}
|
||||
export async function adminAccountCreate(body) {
|
||||
return jj('/api/admin/account', {
|
||||
method: 'POST',
|
||||
headers: adminHeaders({ 'Content-Type': 'application/json' }),
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
}
|
||||
export async function adminAccountUpdate(body) {
|
||||
return jj('/api/admin/account/update', {
|
||||
method: 'POST',
|
||||
headers: adminHeaders({ 'Content-Type': 'application/json' }),
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
}
|
||||
export async function adminAccountReset(body) {
|
||||
return jj('/api/admin/account/reset_pwd', {
|
||||
method: 'POST',
|
||||
headers: adminHeaders({ 'Content-Type': 'application/json' }),
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
}
|
||||
export async function adminAccountDelete(body) {
|
||||
return jj('/api/admin/account/delete', {
|
||||
method: 'POST',
|
||||
headers: adminHeaders({ 'Content-Type': 'application/json' }),
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
}
|
||||
export async function adminPluginDelete(body) {
|
||||
return jj('/api/admin/plugin/delete', {
|
||||
method: 'POST',
|
||||
headers: adminHeaders({ 'Content-Type': 'application/json' }),
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
}
|
||||
export async function adminUpload(pluginId, name, version, file) {
|
||||
const fd = new FormData()
|
||||
fd.append('upload', file)
|
||||
const qs = new URLSearchParams({ plugin_id: pluginId, name, version })
|
||||
return jj('/api/admin/pkg?' + qs.toString(), { method: 'POST', headers: adminHeaders(), body: fd })
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<div class="login-wrap">
|
||||
<div class="card panel">
|
||||
<div class="brand">
|
||||
<span class="logo">37</span>
|
||||
<div class="brand-meta">
|
||||
<strong>{{ appName }}</strong>
|
||||
<span>中心机统一账户登录</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fields">
|
||||
<input v-model="account" class="input" placeholder="账号" @keyup.enter="doLogin">
|
||||
<input v-model="password" class="input" type="password" placeholder="密码" @keyup.enter="doLogin">
|
||||
</div>
|
||||
<p v-if="err" class="err">{{ err }}</p>
|
||||
<button class="btn primary" :disabled="busy" @click="doLogin">
|
||||
{{ busy ? '校验中…' : '登录' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { adminLogin } from '../api'
|
||||
import { store } from '../store.js'
|
||||
|
||||
const props = defineProps({ appName: { type: String, default: '37du 内网插件控制面' } })
|
||||
const emit = defineEmits(['ok'])
|
||||
|
||||
const account = ref('')
|
||||
const password = ref('')
|
||||
const busy = ref(false)
|
||||
const err = ref('')
|
||||
|
||||
async function doLogin() {
|
||||
if (busy.value) return
|
||||
const acct = account.value.trim()
|
||||
if (!acct || !password.value) { err.value = '请输入账号与密码'; return }
|
||||
busy.value = true
|
||||
err.value = ''
|
||||
try {
|
||||
const r = await adminLogin(acct, password.value)
|
||||
if (!r.ok) throw new Error('登录失败')
|
||||
if (!r.is_admin) { throw new Error('该账号无管理权限') }
|
||||
store.current = acct
|
||||
store.isAdmin = true
|
||||
try { localStorage.setItem('cp_account', acct) } catch (_) {}
|
||||
emit('ok', r)
|
||||
} catch (e) {
|
||||
err.value = e.message || String(e)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.login-wrap { flex: 1; display: grid; place-items: center; }
|
||||
.card { width: 340px; padding: 28px 26px; display: flex; flex-direction: column;
|
||||
gap: 16px; box-shadow: var(--shadow-md); }
|
||||
.brand { display: flex; align-items: center; gap: 11px; }
|
||||
.logo { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
|
||||
background: var(--primary-grad); color: #fff; font-size: 15px; font-weight: 800;
|
||||
box-shadow: 0 4px 14px -3px rgba(59,108,255,.6); }
|
||||
.brand-meta { display: flex; flex-direction: column; line-height: 1.3; }
|
||||
.brand-meta strong { font-size: 14px; }
|
||||
.brand-meta span { font-size: 11px; color: var(--text-faint); }
|
||||
.fields { display: flex; flex-direction: column; gap: 10px; }
|
||||
.input { width: 100%; }
|
||||
.err { color: var(--err); font-size: 12px; margin: 0; }
|
||||
</style>
|
||||
@@ -0,0 +1,225 @@
|
||||
<template>
|
||||
<div class="mgmt">
|
||||
<div class="m-head">
|
||||
<div>
|
||||
<h3>控制面管理</h3>
|
||||
<p class="m-sub">中心机 · 插件分发与账号权限 · 当前账号 {{ store.current }}</p>
|
||||
</div>
|
||||
<button class="btn primary" @click="load" :disabled="busy">{{ busy ? '读取中…' : '刷新' }}</button>
|
||||
</div>
|
||||
|
||||
<div class="toast-note" v-if="msg">{{ msg }}</div>
|
||||
|
||||
<section>
|
||||
<h4>上传插件包</h4>
|
||||
<div class="row">
|
||||
<input v-model="pid" placeholder="插件 ID,如 seal_check">
|
||||
<input v-model="pname" placeholder="插件名称">
|
||||
<input v-model="pver" placeholder="版本,如 1.1.0" style="width:110px">
|
||||
<input type="file" @change="e => pfile = e.target.files[0]">
|
||||
<button class="btn primary" @click="upload">上传发布</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h4>插件列表</h4>
|
||||
<table>
|
||||
<thead><tr><th>插件</th><th>名称</th><th>最新版</th><th>版本</th><th>授权账号</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-if="!data.plugins.length"><td colspan="6" class="muted">暂无插件,请先上传</td></tr>
|
||||
<tr v-for="p in data.plugins" :key="p.id">
|
||||
<td><b>{{ p.id }}</b></td>
|
||||
<td>{{ p.name }}</td>
|
||||
<td>{{ p.latest_version }}</td>
|
||||
<td class="muted">{{ (p.versions||[]).map(v=>v.version).join(' · ') || '—' }}</td>
|
||||
<td>{{ (p.accounts||[]).join('、') || '—' }}</td>
|
||||
<td><button class="link danger" @click="delPlugin(p.id)">删除</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h4>账号管理</h4>
|
||||
<div class="row" style="margin-bottom:14px">
|
||||
<input v-model="naAcct" placeholder="账号">
|
||||
<input v-model="naPwd" type="password" placeholder="初始密码">
|
||||
<input v-model="naDept" placeholder="部门" style="width:120px">
|
||||
<label class="ck"><input type="checkbox" v-model="naAdmin">管理员</label>
|
||||
<button class="btn primary" @click="createAccount">建号</button>
|
||||
</div>
|
||||
<table>
|
||||
<thead><tr><th>账号</th><th>部门</th><th>管理员</th><th>已授权插件</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="a in data.accounts" :key="a.account">
|
||||
<td><b>{{ a.account }}</b></td>
|
||||
<td>
|
||||
<input class="ipt-sm" :value="a.dept"
|
||||
@change="e => setDept(a.account, e.target.value)"
|
||||
:disabled="a.account===current">
|
||||
</td>
|
||||
<td>
|
||||
<button class="link" :class="{ 'on': a.is_admin, 'danger': !a.is_admin && a.account!==current }"
|
||||
@click="a.account!==current ? toggleAdmin(a) : null">
|
||||
{{ a.is_admin ? '是' : '否' }}
|
||||
</button>
|
||||
</td>
|
||||
<td class="muted">{{ (a.plugins||[]).join('、') || '—' }}</td>
|
||||
<td>
|
||||
<button class="link" @click="resetPwd(a.account)">重置密码</button>
|
||||
<button class="link danger" v-if="a.account!==current" @click="delAccount(a.account)">删除</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="row" style="margin-top:16px">
|
||||
<input v-model="grantAcc" placeholder="授权账号,如 alice">
|
||||
<button class="btn" @click="loadGrant">载入</button>
|
||||
<span v-if="grantAcc" class="muted">{{ grantAcc }} · 已授权 {{ checked.size }} 个</span>
|
||||
</div>
|
||||
<div class="checks" v-if="grantAcc && data.plugins.length">
|
||||
<label v-for="p in data.plugins" :key="p.id" class="ck">
|
||||
<input type="checkbox" :value="p.id" v-model="checked">
|
||||
{{ p.id }} · {{ p.name }}
|
||||
</label>
|
||||
</div>
|
||||
<button v-if="grantAcc" class="btn primary" style="margin-top:12px" @click="saveGrant">保存授权</button>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h4>修改密码</h4>
|
||||
<div class="row">
|
||||
<input v-model="oldPwd" type="password" placeholder="原密码">
|
||||
<input v-model="newPwd" type="password" placeholder="新密码">
|
||||
<button class="btn primary" @click="changePwd">保存新密码</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { store } from '../store.js'
|
||||
import { adminOverview, adminUpload, adminGrant, adminPassword,
|
||||
adminAccountCreate, adminAccountUpdate, adminAccountReset, adminAccountDelete, adminPluginDelete } from '../api.js'
|
||||
|
||||
const current = computed(() => store.current || '')
|
||||
const data = ref({ plugins: [], accounts: [], admins: [] })
|
||||
const busy = ref(false)
|
||||
const msgRef = ref('')
|
||||
const pid = ref(''); const pname = ref(''); const pver = ref(''); const pfile = ref(null)
|
||||
const grantAcc = ref(''); const checked = ref(new Set())
|
||||
const naAcct = ref(''); const naPwd = ref(''); const naDept = ref(''); const naAdmin = ref(false)
|
||||
const oldPwd = ref(''); const newPwd = ref('')
|
||||
let grantHeld = new Set()
|
||||
|
||||
const msg = computed(() => msgRef.value)
|
||||
function toast(msg) {
|
||||
msgRef.value = msg
|
||||
clearTimeout(msgRef._h)
|
||||
msgRef._h = setTimeout(() => (msgRef.value = ''), 2600)
|
||||
}
|
||||
async function changePwd() {
|
||||
if (!oldPwd.value || !newPwd.value) return toast('请输入原密码与新密码')
|
||||
try {
|
||||
await adminPassword({ account: store.current, old_password: oldPwd.value, new_password: newPwd.value })
|
||||
oldPwd.value = ''; newPwd.value = ''
|
||||
toast('密码已修改')
|
||||
} catch (e) { toast('修改失败:' + (e.message || e)) }
|
||||
}
|
||||
async function load() {
|
||||
busy.value = true
|
||||
try { data.value = await adminOverview() } catch (e) { toast('读取失败:' + (e.message || e)) }
|
||||
finally { busy.value = false }
|
||||
}
|
||||
async function upload() {
|
||||
if (!pid.value || !pver.value || !pfile.value) return toast('请填写 ID / 版本并选择包文件')
|
||||
try {
|
||||
await adminUpload(pid.value, pname.value || pid.value, pver.value, pfile.value)
|
||||
toast(`已发布 ${pid.value}@${pver.value}`)
|
||||
await load()
|
||||
} catch (e) { toast('上传失败:' + (e.message || e)) }
|
||||
}
|
||||
function loadGrant() {
|
||||
const acc = grantAcc.value.trim(); if (!acc) return toast('请输入账号')
|
||||
const a = data.value.accounts.find(x => x.account === acc)
|
||||
grantHeld = new Set(a ? a.plugins : [])
|
||||
checked.value = new Set(grantHeld)
|
||||
}
|
||||
async function saveGrant() {
|
||||
const acc = grantAcc.value.trim(); if (!acc) return
|
||||
const want = new Set(checked.value)
|
||||
let n = 0
|
||||
for (const pids of new Set([...want, ...grantHeld])) {
|
||||
const g = want.has(pids)
|
||||
if (g !== grantHeld.has(pids)) {
|
||||
try { await adminGrant({ account: acc, plugin_id: pids, granted: g }); n++ } catch (e) { toast((e.message||e)); }
|
||||
}
|
||||
}
|
||||
grantHeld = want
|
||||
await load()
|
||||
toast(n ? `已更新 ${n} 项` : '无需变更')
|
||||
}
|
||||
async function createAccount() {
|
||||
const acct = naAcct.value.trim(); const pwd = naPwd.value
|
||||
if (!acct || !pwd) return toast('账号与初始密码必填')
|
||||
try {
|
||||
await adminAccountCreate({ account: acct, password: pwd, dept: naDept.value.trim(), is_admin: naAdmin.value })
|
||||
toast(`已建号 ${acct}`); naAcct.value=''; naPwd.value=''; naDept.value=''; naAdmin.value=false
|
||||
await load()
|
||||
} catch (e) { toast('建号失败:' + (e.message || e)) }
|
||||
}
|
||||
async function setDept(acct, dept) {
|
||||
try { await adminAccountUpdate({ account: acct, dept }); toast(`已更新 ${acct} 部门`) }
|
||||
catch (e) { toast(e.message || e) }
|
||||
}
|
||||
async function toggleAdmin(a) {
|
||||
try { await adminAccountUpdate({ account: a.account, is_admin: !a.is_admin }); await load() }
|
||||
catch (e) { toast(e.message || e) }
|
||||
}
|
||||
async function resetPwd(acct) {
|
||||
if (acct === current.value) return toast('请用「修改密码」改自己的密码')
|
||||
const newp = prompt(`重置 ${acct} 的新密码:`)
|
||||
if (!newp) return
|
||||
try { await adminAccountReset({ account: acct, new_password: newp }); toast(`已重置 ${acct} 密码`) }
|
||||
catch (e) { toast(e.message || e) }
|
||||
}
|
||||
async function delAccount(acct) {
|
||||
if (!confirm(`确认删除账号 ${acct}?其插件授权将一并清除`)) return
|
||||
try { await adminAccountDelete({ account: acct }); toast(`已删除 ${acct}`); await load() }
|
||||
catch (e) { toast(e.message || e) }
|
||||
}
|
||||
async function delPlugin(pid) {
|
||||
if (!confirm(`确认删除插件 ${pid}?版本与授权将一并清除`)) return
|
||||
try { await adminPluginDelete({ plugin_id: pid }); toast(`已删除插件 ${pid}`); await load() }
|
||||
catch (e) { toast(e.message || e) }
|
||||
}
|
||||
load()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mgmt { display: flex; flex-direction: column; gap: 26px; }
|
||||
.m-head { display: flex; justify-content: space-between; align-items: flex-start; }
|
||||
h3 { font-size: 16px; margin: 0; }
|
||||
p { margin: 0; }
|
||||
h4 { font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 14px; }
|
||||
.m-sub, .muted { color: var(--text-faint); font-size: 12px; }
|
||||
.toast-note { color: #fff; background: #3a3f4a; font-size: 12px; padding: 7px 12px; border-radius: 6px; margin-top: 10px; width: fit-content; }
|
||||
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
|
||||
input, button { font: inherit; }
|
||||
input { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 6px 10px; background: var(--surface); color: var(--text); }
|
||||
input:focus { outline: none; border-color: var(--primary); }
|
||||
button { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 14px; cursor: pointer; color: var(--text-sub); }
|
||||
button:disabled { opacity: .5; cursor: not-allowed; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
|
||||
th { color: var(--text-faint); font-weight: 600; font-size: 12px; }
|
||||
.checks { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; }
|
||||
.ck { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
|
||||
.ck input[type=checkbox] { accent-color: var(--primary); }
|
||||
.link { border: none; background: none; color: var(--primary); padding: 0; margin-left: 4px; font-size: 12px; cursor: pointer; }
|
||||
.link.danger { color: #e5484d; }
|
||||
.link.on { color: var(--primary); font-weight: 600; }
|
||||
.ipt-sm { width: 90px; padding: 4px 6px; font-size: 12px; }
|
||||
</style>
|
||||
@@ -0,0 +1,5 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import './style.css'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
@@ -0,0 +1,9 @@
|
||||
import { reactive } from 'vue'
|
||||
|
||||
export const store = reactive({
|
||||
appName: '37du 内网插件控制面',
|
||||
isAdmin: false,
|
||||
current: (() => {
|
||||
try { return localStorage.getItem('cp_account') || '' } catch (_) { return '' }
|
||||
})(),
|
||||
})
|
||||
@@ -0,0 +1,111 @@
|
||||
/* ============ 37du 内网插件控制面 设计系统(亮色) ============ */
|
||||
:root {
|
||||
--bg: #eef2f9;
|
||||
--bg-grad: linear-gradient(180deg, #f4f7fc 0%, #e9eef7 100%);
|
||||
--surface: #ffffff;
|
||||
--surface-2: #f7f9fd;
|
||||
--border: #e5eaf3;
|
||||
--border-strong: #cdd6e6;
|
||||
|
||||
--text: #1f2633;
|
||||
--text-sub: #5b6477;
|
||||
--text-faint: #98a0b3;
|
||||
|
||||
--primary: #3b6cff;
|
||||
--primary-2: #6f8dff;
|
||||
--primary-grad: linear-gradient(135deg, #4c79ff 0%, #3b6cff 100%);
|
||||
--primary-weak: #eef2ff;
|
||||
--primary-weak-2: #e2e9ff;
|
||||
|
||||
--ok: #22b07a;
|
||||
--ok-weak: #e6f7f0;
|
||||
--err: #e5484d;
|
||||
--err-weak: #fdecec;
|
||||
--warn: #d99a1b;
|
||||
|
||||
--shadow-sm: 0 1px 2px rgba(24, 39, 75, 0.05);
|
||||
--shadow-md: 0 6px 24px -8px rgba(24, 39, 75, 0.18);
|
||||
--radius: 14px;
|
||||
--radius-sm: 9px;
|
||||
--mono: "JetBrains Mono", "Consolas", "Courier New", monospace;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
html, body, #app { height: 100%; margin: 0; }
|
||||
|
||||
body {
|
||||
font-family: "Inter", "Microsoft YaHei UI", "PingFang SC", -apple-system, sans-serif;
|
||||
font-size: 13px;
|
||||
color: var(--text);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
.__app {
|
||||
height: 100%;
|
||||
background: var(--bg-grad);
|
||||
padding: 16px 18px 18px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar { width: 10px; height: 10px; }
|
||||
::-webkit-scrollbar-thumb { background: #d4dae8; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
|
||||
::-webkit-scrollbar-thumb:hover { background: #c1c9dc; background-clip: content-box; border: 2px solid transparent; }
|
||||
::-webkit-scrollbar-track { background: transparent; }
|
||||
|
||||
.panel {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.sec-title {
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-faint);
|
||||
}
|
||||
|
||||
.btn {
|
||||
border: 1px solid var(--border-strong);
|
||||
background: var(--surface);
|
||||
color: var(--text-sub);
|
||||
border-radius: 8px;
|
||||
padding: 7px 16px;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
transition: all .15s ease;
|
||||
}
|
||||
.btn:hover { color: var(--text); border-color: #b9c3d8; background: var(--surface-2); }
|
||||
.btn:active { transform: translateY(1px); }
|
||||
.btn:disabled { color: #c0c6d4; border-color: var(--border); background: #f4f6fb; cursor: not-allowed; transform: none; }
|
||||
|
||||
.btn.primary {
|
||||
background: var(--primary-grad);
|
||||
color: #fff;
|
||||
border: 1px solid transparent;
|
||||
font-weight: 600;
|
||||
box-shadow: 0 4px 14px -4px rgba(59, 108, 255, 0.55);
|
||||
}
|
||||
.btn.primary:hover:not(:disabled) { box-shadow: 0 8px 20px -6px rgba(59, 108, 255, 0.65); color: #fff; }
|
||||
.btn.primary:disabled { background: #b9c6f0; box-shadow: none; }
|
||||
|
||||
.input {
|
||||
height: 34px;
|
||||
border: 1px solid var(--border-strong);
|
||||
border-radius: 8px;
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
padding: 0 12px;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
outline: none;
|
||||
transition: border-color .15s, box-shadow .15s;
|
||||
}
|
||||
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
|
||||
|
||||
.fade-enter-active, .fade-leave-active { transition: opacity .18s ease, transform .18s ease; }
|
||||
.fade-enter-from { opacity: 0; transform: translateY(4px); }
|
||||
.fade-leave-to { opacity: 0; }
|
||||
@@ -0,0 +1,18 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// dev 时把 /api 代理到控制面后端(8800),实现前后端分离开发;生产由 FastAPI 挂载 dist
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
proxy: {
|
||||
'/api': { target: 'http://127.0.0.1:8800', changeOrigin: true },
|
||||
},
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
emptyOutDir: true,
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user