Files
37duAutomation/webhost/frontend/src/api.js
T
puddy 3f901d3882 feat: 搭建控制面管理前端并剥离底座管理功能
1. 新增controlplane/frontend Vue3管理前端,实现登录、账号CRUD、插件上传/管理、权限授权
2. 为controlplane/app.py添加CORS中间件并挂载前端静态产物
3. 重构环境变量加载,统一使用app/common/env.load_app_env()
4. 剥离webhost/的管理UI与代理接口,仅保留基础登录能力
5. 新增环境隔离规范文档与架构蓝图说明
2026-09-09 17:10:12 +08:00

63 lines
1.8 KiB
JavaScript

// 与 FastAPI 后端交互 + WebSocket 实时流
const WS_BASE = (location.protocol === 'https:' ? 'wss://' : 'ws://') + location.host
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()
}
export async function fetchMeta() {
return j('/api/meta')
}
export async function loginPlatform(id) {
return j(`/api/platforms/${id}/login`, { method: 'POST' })
}
export async function startRun(pluginId, fields) {
return j('/api/runs', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ plugin_id: pluginId, fields }),
})
}
export async function getRun(runId) {
return j(`/api/runs/${runId}`)
}
export function connectWS(onEvent) {
const ws = new WebSocket(WS_BASE + '/ws')
ws.onmessage = (e) => {
try { onEvent(JSON.parse(e.data)) } catch (_) {}
}
return ws
}
// ===== 统一账户登录/会话(底座仅保留认证与个人密码,管理走中心机控制面) =====
export async function adminMe() {
return j('/api/admin/me')
}
export async function adminLogin(account, password) {
return jj('/api/admin/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ account, password }) })
}
export async function adminLogout() {
return j('/api/admin/logout', { method: 'POST' })
}
export async function adminPassword(body) {
return jj('/api/admin/password', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) })
}
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()
}