This commit is contained in:
commit
db82325ed7
216 files changed
+33718
No files matched your search
@@ -0,0 +1,184 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useSession } from "./store";
|
||||
import AdminLayout from "./layouts/AdminLayout.vue";
|
||||
import {
|
||||
LayoutDashboard,
|
||||
FolderKanban,
|
||||
ShieldCheck,
|
||||
Settings2,
|
||||
LogOut,
|
||||
Moon,
|
||||
Sun,
|
||||
PanelLeftClose,
|
||||
ChevronRight,
|
||||
Cloud,
|
||||
ArrowUpRight,
|
||||
BookOpen,
|
||||
Activity,
|
||||
Server,
|
||||
Wallet,
|
||||
Code2,
|
||||
HardDrive,
|
||||
Globe,
|
||||
LifeBuoy,
|
||||
Puzzle,
|
||||
} from "lucide-vue-next";
|
||||
const store = useSession(),
|
||||
route = useRoute(),
|
||||
router = useRouter();
|
||||
const dark = ref(localStorage.getItem("theme") === "dark"),
|
||||
mobile = ref(false),
|
||||
brandError = ref("");
|
||||
function theme() {
|
||||
document.documentElement.dataset.theme = dark.value ? "dark" : "light";
|
||||
localStorage.setItem("theme", dark.value ? "dark" : "light");
|
||||
}
|
||||
onMounted(async () => {
|
||||
theme();
|
||||
void store.refreshTheme().catch(() => {});
|
||||
try {
|
||||
await store.brand();
|
||||
} catch {
|
||||
brandError.value = "无法读取平台配置,请检查后端连接";
|
||||
}
|
||||
});
|
||||
async function logout() {
|
||||
try {
|
||||
await store.logout();
|
||||
} finally {
|
||||
router.push("/login");
|
||||
}
|
||||
}
|
||||
const nav = [
|
||||
{ to: "/console", label: "数据概览", icon: LayoutDashboard },
|
||||
{ to: "/projects", label: "我的项目", icon: FolderKanban },
|
||||
{ to: "/develop", label: "AI 开发", icon: Code2 },
|
||||
{ to: "/wallet", label: "钱包与账本", icon: Wallet },
|
||||
{ to: "/hosting", label: "云托管", icon: Server },
|
||||
{ to: "/storage", label: "对象存储", icon: HardDrive },
|
||||
{ to: "/domains", label: "项目域名", icon: Globe },
|
||||
{ to: "/tickets", label: "支持工单", icon: LifeBuoy },
|
||||
{ to: "/extensions", label: "扩展工具", icon: Puzzle },
|
||||
{ to: "/account", label: "账户与安全", icon: ShieldCheck },
|
||||
];
|
||||
</script>
|
||||
<template>
|
||||
<div
|
||||
v-if="route.meta.public"
|
||||
class="public-root"
|
||||
:key="route.path"
|
||||
:style="route.path === '/' ? store.themeStyle('light', true) : undefined"
|
||||
>
|
||||
<RouterView />
|
||||
</div>
|
||||
<AdminLayout v-else-if="route.path.startsWith('/admin')"
|
||||
><RouterView
|
||||
/></AdminLayout>
|
||||
<div
|
||||
v-else
|
||||
class="shell member-shell"
|
||||
:style="store.themeStyle(dark ? 'dark' : 'light')"
|
||||
>
|
||||
<aside :class="{ open: mobile }">
|
||||
<RouterLink to="/" class="brand"
|
||||
><img
|
||||
v-if="store.settings.logoUrl"
|
||||
:src="store.settings.logoUrl"
|
||||
alt="平台 Logo"
|
||||
/><span v-else class="brand-mark"><Cloud :size="23" /></span
|
||||
><strong>{{ store.settings.siteName || "控制台" }}</strong
|
||||
><span class="beta">BETA</span></RouterLink
|
||||
>
|
||||
<div class="workspace">
|
||||
<span class="avatar small">{{
|
||||
store.user?.displayName.slice(0, 1)
|
||||
}}</span>
|
||||
<div>
|
||||
<b>个人工作空间</b><small>{{ store.user?.email }}</small>
|
||||
</div>
|
||||
<ChevronRight :size="15" />
|
||||
</div>
|
||||
<p class="nav-label">工作空间</p>
|
||||
<nav>
|
||||
<RouterLink
|
||||
v-for="n in nav"
|
||||
:key="n.to"
|
||||
:to="n.to"
|
||||
@click="mobile = false"
|
||||
active-class="active"
|
||||
><component :is="n.icon" :size="18" />{{ n.label }}</RouterLink
|
||||
>
|
||||
</nav>
|
||||
<div class="sidebar-bottom">
|
||||
<div class="help-box">
|
||||
<BookOpen :size="20" /><b>构建你的下一个想法</b>
|
||||
<p>创建项目,整理需求。<br />让每个好想法都有起点。</p>
|
||||
<RouterLink to="/projects"
|
||||
>前往项目空间 <ArrowUpRight :size="15"
|
||||
/></RouterLink>
|
||||
</div>
|
||||
<button class="logout" @click="logout">
|
||||
<LogOut :size="17" />退出登录</button
|
||||
><small>{{
|
||||
store.settings.filing || "独立、安全的个人工作空间"
|
||||
}}</small>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="main-wrap">
|
||||
<header>
|
||||
<div class="breadcrumb">
|
||||
<button
|
||||
class="icon-button"
|
||||
@click="mobile = !mobile"
|
||||
aria-label="切换导航"
|
||||
>
|
||||
<PanelLeftClose :size="18" /></button
|
||||
><span>工作空间</span><ChevronRight :size="14" /><b>{{
|
||||
route.path.startsWith("/admin")
|
||||
? "管理控制台"
|
||||
: nav.find(
|
||||
(n) =>
|
||||
route.path === n.to || route.path.startsWith(n.to + "/"),
|
||||
)?.label
|
||||
}}</b>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<RouterLink
|
||||
v-if="store.user?.permissions.length"
|
||||
to="/admin"
|
||||
class="text-link"
|
||||
>管理后台 ↗</RouterLink
|
||||
><span class="env"><i />控制面</span
|
||||
><button
|
||||
class="icon-button"
|
||||
@click="
|
||||
dark = !dark;
|
||||
theme();
|
||||
"
|
||||
aria-label="切换深色模式"
|
||||
>
|
||||
<Sun v-if="dark" :size="18" /><Moon v-else :size="18" /></button
|
||||
><RouterLink to="/account" class="avatar">{{
|
||||
store.user?.displayName.slice(0, 1)
|
||||
}}</RouterLink>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<div v-if="store.settings.previewMode === 'true'" class="alert info">
|
||||
本地测试预览:测试余额不代表真实资金。执行环境就绪后,AI
|
||||
任务会实际调用已配置的模型并在本机隔离环境执行;模型调用可能产生供应商费用。
|
||||
</div>
|
||||
<div v-if="brandError" class="alert error">{{ brandError }}</div>
|
||||
<RouterView />
|
||||
</main>
|
||||
<footer>
|
||||
<span>{{
|
||||
store.settings.footer || store.settings.siteDescription
|
||||
}}</span
|
||||
><span>控制面 v0.2 · AI 开发与计费</span>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
export class ApiError extends Error {
|
||||
constructor(
|
||||
public status: number,
|
||||
message: string,
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
export async function api<T = any>(
|
||||
path: string,
|
||||
options: RequestInit = {},
|
||||
): Promise<T> {
|
||||
const token = sessionStorage.getItem("session");
|
||||
let res: Response;
|
||||
try {
|
||||
res = await fetch("/api" + path, {
|
||||
signal: AbortSignal.timeout(15000),
|
||||
...options,
|
||||
headers: {
|
||||
...(options.body instanceof FormData
|
||||
? {}
|
||||
: { "Content-Type": "application/json" }),
|
||||
...(token ? { Authorization: "Bearer " + token } : {}),
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
throw new ApiError(503, "无法连接后端服务,请检查服务是否启动");
|
||||
}
|
||||
const data = await res.json().catch(() => ({
|
||||
message:
|
||||
res.status >= 500
|
||||
? "后端服务未就绪,请检查服务与数据库连接"
|
||||
: "服务响应格式异常",
|
||||
}));
|
||||
if (!res.ok)
|
||||
throw new ApiError(res.status, data.message || "操作失败,请稍后重试");
|
||||
return data;
|
||||
}
|
||||
export const body = (v: unknown) => JSON.stringify(v);
|
||||
@@ -0,0 +1,27 @@
|
||||
export const themeTokens = {
|
||||
accent: "--blue",
|
||||
accentSoft: "--blue-light",
|
||||
background: "--bg",
|
||||
surface: "--surface",
|
||||
text: "--text",
|
||||
muted: "--muted",
|
||||
border: "--line",
|
||||
soft: "--soft",
|
||||
} as const;
|
||||
|
||||
export type Palette = Partial<Record<keyof typeof themeTokens, string>>;
|
||||
export type Palettes = Partial<Record<"light" | "dark", Palette>>;
|
||||
export type Plugin = {
|
||||
id: string;
|
||||
slug: string;
|
||||
version: string;
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
export type Extension = Plugin & {
|
||||
kind: "plugin" | "theme";
|
||||
enabled: boolean;
|
||||
sha256: string;
|
||||
created_at: string;
|
||||
palettes?: Palettes;
|
||||
};
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,297 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useSession } from "../store";
|
||||
import {
|
||||
ShieldCheck,
|
||||
LayoutDashboard,
|
||||
Users,
|
||||
Code2,
|
||||
Server,
|
||||
Activity,
|
||||
Settings2,
|
||||
History,
|
||||
LogOut,
|
||||
ArrowUpRight,
|
||||
Menu,
|
||||
Cloud,
|
||||
Globe,
|
||||
LifeBuoy,
|
||||
Puzzle,
|
||||
} from "lucide-vue-next";
|
||||
const store = useSession(),
|
||||
route = useRoute(),
|
||||
router = useRouter(),
|
||||
mobile = ref(false);
|
||||
const links = [
|
||||
{
|
||||
to: "/admin/overview",
|
||||
name: "运营总览",
|
||||
icon: LayoutDashboard,
|
||||
permission: "",
|
||||
},
|
||||
{
|
||||
to: "/admin/extensions",
|
||||
name: "插件与主题",
|
||||
icon: Puzzle,
|
||||
permission: "extensions:manage",
|
||||
},
|
||||
{
|
||||
to: "/admin/tickets",
|
||||
name: "工单管理",
|
||||
icon: LifeBuoy,
|
||||
permission: "tickets:manage",
|
||||
},
|
||||
{
|
||||
to: "/admin/domains",
|
||||
name: "域名与 HTTPS",
|
||||
icon: Globe,
|
||||
permission: "domains:write",
|
||||
},
|
||||
{
|
||||
to: "/admin/sites",
|
||||
name: "网站管理 / 人工审核",
|
||||
icon: Server,
|
||||
permission: "hosting:write|moderation:write|users:read",
|
||||
},
|
||||
{
|
||||
to: "/admin/nodes",
|
||||
name: "服务器与节点",
|
||||
icon: Server,
|
||||
permission: "nodes:write",
|
||||
},
|
||||
{
|
||||
to: "/admin/integrations",
|
||||
name: "邮件 / 短信 / CDN / ESA",
|
||||
icon: Cloud,
|
||||
permission: "integrations:write",
|
||||
},
|
||||
{
|
||||
to: "/admin/users",
|
||||
name: "用户管理",
|
||||
icon: Users,
|
||||
permission: "users:read",
|
||||
},
|
||||
{
|
||||
to: "/admin/models",
|
||||
name: "模型与供应商",
|
||||
icon: Code2,
|
||||
permission: "models:write",
|
||||
},
|
||||
{
|
||||
to: "/admin/tasks",
|
||||
name: "开发任务运营",
|
||||
icon: Activity,
|
||||
permission: "tasks:manage|finance:write|audit:read",
|
||||
},
|
||||
{
|
||||
to: "/admin/plans",
|
||||
name: "托管套餐",
|
||||
icon: Server,
|
||||
permission: "finance:write",
|
||||
},
|
||||
{
|
||||
to: "/admin/settings",
|
||||
name: "系统设置",
|
||||
icon: Settings2,
|
||||
permission: "settings:write",
|
||||
},
|
||||
{
|
||||
to: "/admin/audit",
|
||||
name: "操作审计",
|
||||
icon: History,
|
||||
permission: "audit:read",
|
||||
},
|
||||
];
|
||||
const visible = computed(() =>
|
||||
links.filter(
|
||||
(l) =>
|
||||
!l.permission ||
|
||||
l.permission.split("|").some((p) => store.user?.permissions.includes(p)),
|
||||
),
|
||||
);
|
||||
async function logout() {
|
||||
try {
|
||||
await store.logout();
|
||||
} finally {
|
||||
router.push("/admin/login");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div class="shell admin-portal">
|
||||
<aside :class="{ open: mobile }">
|
||||
<RouterLink to="/admin/overview" class="brand"
|
||||
><img
|
||||
v-if="store.settings.logoUrl"
|
||||
:src="store.settings.logoUrl"
|
||||
alt="WebUp Logo"
|
||||
/><span v-else class="admin-brand-icon"
|
||||
><ShieldCheck :size="22"
|
||||
/></span>
|
||||
<div>
|
||||
<strong>{{ store.settings.siteName || "平台管理" }}</strong
|
||||
><small>ADMIN CONSOLE</small>
|
||||
</div></RouterLink
|
||||
>
|
||||
<div class="admin-space">
|
||||
<span class="avatar">{{ store.user?.displayName.slice(0, 1) }}</span>
|
||||
<div>
|
||||
<b>{{ store.user?.displayName }}</b
|
||||
><small>{{ store.user?.email }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<p class="nav-label">管理中心</p>
|
||||
<nav>
|
||||
<RouterLink
|
||||
v-for="l in visible"
|
||||
:key="l.to"
|
||||
:to="l.to"
|
||||
:class="{
|
||||
active:
|
||||
route.path === l.to ||
|
||||
(l.to === '/admin/tickets' && route.path.startsWith(l.to + '/')),
|
||||
}"
|
||||
@click="mobile = false"
|
||||
><component :is="l.icon" :size="18" />{{ l.name }}</RouterLink
|
||||
>
|
||||
</nav>
|
||||
<div class="sidebar-bottom">
|
||||
<div class="admin-security">
|
||||
<ShieldCheck :size="18" />
|
||||
<p>管理操作由后端校验权限<br />敏感变更记录审计日志</p>
|
||||
</div>
|
||||
<RouterLink to="/console" class="logout"
|
||||
><ArrowUpRight :size="17" />进入用户工作台</RouterLink
|
||||
><RouterLink to="/" class="logout"
|
||||
><Cloud :size="17" />返回网站首页</RouterLink
|
||||
><button class="logout" @click="logout">
|
||||
<LogOut :size="17" />退出管理员登录
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="main-wrap">
|
||||
<header>
|
||||
<div class="breadcrumb">
|
||||
<button
|
||||
class="icon-button"
|
||||
@click="mobile = !mobile"
|
||||
aria-label="切换管理导航"
|
||||
>
|
||||
<Menu :size="18" /></button
|
||||
><span>管理后台</span><span>/</span
|
||||
><b>{{
|
||||
links.find(
|
||||
(l) =>
|
||||
route.path === l.to ||
|
||||
(l.to === "/admin/tickets" &&
|
||||
route.path.startsWith(l.to + "/")),
|
||||
)?.name || "平台管理"
|
||||
}}</b>
|
||||
</div>
|
||||
<span class="badge"><ShieldCheck :size="14" />管理员专用</span>
|
||||
</header>
|
||||
<main>
|
||||
<div v-if="store.settings.previewMode === 'true'" class="alert info">
|
||||
本地测试管理后台 · 独立测试数据库,测试余额非真实资金。
|
||||
</div>
|
||||
<slot />
|
||||
</main>
|
||||
<footer>
|
||||
<span>{{ store.settings.siteName }} · 平台管理</span
|
||||
><span>RBAC 权限控制 · 操作可追溯</span>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.admin-portal > aside {
|
||||
background: #17243d;
|
||||
border-right: 0;
|
||||
color: #eef3ff;
|
||||
}
|
||||
.admin-portal .brand {
|
||||
gap: 11px;
|
||||
}
|
||||
.admin-portal .brand strong {
|
||||
font-size: 16px;
|
||||
max-width: 155px;
|
||||
display: block;
|
||||
}
|
||||
.brand small {
|
||||
display: block;
|
||||
letter-spacing: 2px;
|
||||
font-size: 8px;
|
||||
color: #8195b5;
|
||||
margin-top: 5px;
|
||||
}
|
||||
.admin-brand-icon {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
background: #2c436a;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 10px;
|
||||
color: #a3bdff;
|
||||
}
|
||||
.admin-space {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
padding: 18px 10px;
|
||||
margin: 27px 0 24px;
|
||||
border-top: 1px solid #2a3750;
|
||||
border-bottom: 1px solid #2a3750;
|
||||
min-width: 0;
|
||||
}
|
||||
.admin-space > div {
|
||||
min-width: 0;
|
||||
}
|
||||
.admin-space b {
|
||||
font-size: 11px;
|
||||
}
|
||||
.admin-space small {
|
||||
display: block;
|
||||
font-size: 9px;
|
||||
color: #8598b8;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.admin-space .avatar {
|
||||
background: #314568;
|
||||
border-color: #425a83;
|
||||
color: #b2c5e8;
|
||||
}
|
||||
.nav-label {
|
||||
color: #6d83a6;
|
||||
}
|
||||
.admin-portal nav > a {
|
||||
color: #9bacc7;
|
||||
}
|
||||
.admin-portal nav > a:hover {
|
||||
background: #233655;
|
||||
color: #eef3ff;
|
||||
}
|
||||
.admin-portal nav > a.active {
|
||||
background: #2d4875;
|
||||
color: #e7efff;
|
||||
}
|
||||
.admin-portal .logout {
|
||||
color: #95a9c8;
|
||||
font-size: 10px;
|
||||
padding: 12px;
|
||||
}
|
||||
.admin-security {
|
||||
padding: 16px 12px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
color: #7189b1;
|
||||
}
|
||||
.admin-security p {
|
||||
font-size: 9px;
|
||||
line-height: 1.8;
|
||||
}
|
||||
.admin-security svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,106 @@
|
||||
import { createApp } from "vue";
|
||||
import { createPinia } from "pinia";
|
||||
import { createRouter, createWebHistory } from "vue-router";
|
||||
import { useSession } from "./store";
|
||||
import App from "./App.vue";
|
||||
import Login from "./views/Login.vue";
|
||||
import Dashboard from "./views/Dashboard.vue";
|
||||
import Projects from "./views/Projects.vue";
|
||||
import Account from "./views/Account.vue";
|
||||
import Admin from "./views/Admin.vue";
|
||||
import Models from "./views/Models.vue";
|
||||
import Wallet from "./views/Wallet.vue";
|
||||
import Develop from "./views/Develop.vue";
|
||||
import AdminTasks from "./views/AdminTasks.vue";
|
||||
import Hosting from "./views/Hosting.vue";
|
||||
import Plans from "./views/Plans.vue";
|
||||
import Landing from "./views/Landing.vue";
|
||||
import AdminOverview from "./views/AdminOverview.vue";
|
||||
import Integrations from "./views/Integrations.vue";
|
||||
import Nodes from "./views/Nodes.vue";
|
||||
import AdminSites from "./views/AdminSites.vue";
|
||||
import Storage from "./views/Storage.vue";
|
||||
import Domains from "./views/Domains.vue";
|
||||
import AdminDomains from "./views/AdminDomains.vue";
|
||||
import Tickets from "./views/Tickets.vue";
|
||||
import AdminExtensions from "./views/AdminExtensions.vue";
|
||||
import PluginTools from "./views/PluginTools.vue";
|
||||
import "./style.css";
|
||||
import "./landing.css";
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{ path: "/admin/nodes", component: Nodes, meta: { admin: true } },
|
||||
{ path: "/admin/sites", component: AdminSites, meta: { admin: true } },
|
||||
{ path: "/login", component: Login, meta: { public: true } },
|
||||
{ path: "/admin/login", component: Login, meta: { public: true } },
|
||||
{ path: "/", component: Landing, meta: { public: true } },
|
||||
{ path: "/console", component: Dashboard },
|
||||
{ path: "/admin", redirect: { name: "admin-overview" } },
|
||||
{
|
||||
path: "/admin/overview",
|
||||
name: "admin-overview",
|
||||
component: AdminOverview,
|
||||
meta: { admin: true },
|
||||
},
|
||||
{
|
||||
path: "/admin/integrations",
|
||||
component: Integrations,
|
||||
meta: { admin: true },
|
||||
},
|
||||
{ path: "/projects", component: Projects },
|
||||
{ path: "/account", component: Account },
|
||||
{ path: "/wallet", component: Wallet },
|
||||
{ path: "/hosting", component: Hosting },
|
||||
{ path: "/storage", component: Storage },
|
||||
{ path: "/domains", component: Domains },
|
||||
{ path: "/tickets/:ticketId?", component: Tickets },
|
||||
{ path: "/extensions/:pluginSlug?", component: PluginTools },
|
||||
{
|
||||
path: "/admin/extensions",
|
||||
component: AdminExtensions,
|
||||
meta: { admin: true, permission: "extensions:manage" },
|
||||
},
|
||||
{
|
||||
path: "/admin/tickets/:ticketId?",
|
||||
component: Tickets,
|
||||
meta: { admin: true, permission: "tickets:manage" },
|
||||
},
|
||||
{ path: "/admin/domains", component: AdminDomains, meta: { admin: true } },
|
||||
{ path: "/admin/plans", component: Plans, meta: { admin: true } },
|
||||
{ path: "/develop", component: Develop },
|
||||
{ path: "/admin/models", component: Models, meta: { admin: true } },
|
||||
{ path: "/admin/tasks", component: AdminTasks, meta: { admin: true } },
|
||||
{
|
||||
path: "/admin/:section(users|settings|audit)",
|
||||
sensitive: true,
|
||||
component: Admin,
|
||||
meta: { admin: true },
|
||||
},
|
||||
{ path: "/admin/:pathMatch(.*)*", redirect: { name: "admin-overview" } },
|
||||
{ path: "/:pathMatch(.*)*", redirect: "/" },
|
||||
],
|
||||
});
|
||||
const app = createApp(App);
|
||||
app.use(createPinia());
|
||||
router.beforeEach(async (to) => {
|
||||
const store = useSession();
|
||||
if (to.meta.public) return true;
|
||||
const login = to.path.startsWith("/admin") ? "/admin/login" : "/login";
|
||||
if (!sessionStorage.getItem("session")) return login;
|
||||
try {
|
||||
await store.load();
|
||||
} catch {
|
||||
store.clear();
|
||||
return login;
|
||||
}
|
||||
if (to.meta.admin && !store.user?.permissions.length) return "/console";
|
||||
if (
|
||||
typeof to.meta.permission === "string" &&
|
||||
!store.user?.permissions.includes(to.meta.permission)
|
||||
)
|
||||
return { name: "admin-overview" };
|
||||
return true;
|
||||
});
|
||||
app.use(router);
|
||||
app.mount("#app");
|
||||
@@ -0,0 +1,75 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { api } from "./api";
|
||||
import { themeTokens, type Palettes } from "./extensions";
|
||||
export type User = {
|
||||
id: string;
|
||||
email: string;
|
||||
displayName: string;
|
||||
status: string;
|
||||
roles: string[];
|
||||
permissions: string[];
|
||||
};
|
||||
export const useSession = defineStore("session", () => {
|
||||
const user = ref<User | null>(null);
|
||||
const settings = ref<Record<string, string>>({});
|
||||
const palettes = ref<Palettes>({});
|
||||
async function refreshTheme() {
|
||||
const theme = await api<{ palettes?: Palettes }>(
|
||||
"/public/extensions/theme",
|
||||
);
|
||||
palettes.value = theme.palettes ?? {};
|
||||
}
|
||||
function themeStyle(mode: "light" | "dark", landing = false) {
|
||||
const palette = palettes.value[mode];
|
||||
const style: Record<string, string> = {};
|
||||
for (const [token, property] of Object.entries(themeTokens)) {
|
||||
const value = palette?.[token as keyof typeof themeTokens];
|
||||
if (value && /^#[0-9a-f]{6}$/i.test(value)) {
|
||||
style[property] = value;
|
||||
if (landing) style[`--landing-${token}`] = value;
|
||||
}
|
||||
}
|
||||
return style;
|
||||
}
|
||||
async function load() {
|
||||
user.value = await api<User>("/me");
|
||||
}
|
||||
async function brand() {
|
||||
settings.value = await api("/public/settings");
|
||||
document.title =
|
||||
(settings.value.englishName || settings.value.siteName) +
|
||||
" · " +
|
||||
(settings.value.tagline || "控制台");
|
||||
if (settings.value.faviconUrl) {
|
||||
let link = document.querySelector<HTMLLinkElement>('link[rel="icon"]');
|
||||
if (!link) {
|
||||
link = document.createElement("link");
|
||||
link.rel = "icon";
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
link.href = settings.value.faviconUrl;
|
||||
}
|
||||
}
|
||||
function clear() {
|
||||
sessionStorage.removeItem("session");
|
||||
user.value = null;
|
||||
}
|
||||
async function logout() {
|
||||
try {
|
||||
await api("/auth/logout", { method: "POST" });
|
||||
} finally {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
return {
|
||||
user,
|
||||
settings,
|
||||
load,
|
||||
brand,
|
||||
clear,
|
||||
logout,
|
||||
refreshTheme,
|
||||
themeStyle,
|
||||
};
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,203 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { api, body } from "../api";
|
||||
import { useSession } from "../store";
|
||||
import { ShieldCheck, Monitor, History, KeyRound } from "lucide-vue-next";
|
||||
const store = useSession(),
|
||||
router = useRouter(),
|
||||
name = ref(store.user?.displayName || ""),
|
||||
current = ref(""),
|
||||
password = ref(""),
|
||||
sessions = ref<any[]>([]),
|
||||
logs = ref<any[]>([]),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false);
|
||||
async function load() {
|
||||
try {
|
||||
[sessions.value, logs.value] = await Promise.all([
|
||||
api("/account/sessions"),
|
||||
api("/account/logins"),
|
||||
]);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function action(fn: () => Promise<void>) {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
success.value = "";
|
||||
try {
|
||||
await fn();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
function profile() {
|
||||
return action(async () => {
|
||||
await api("/account/profile", {
|
||||
method: "PUT",
|
||||
body: body({ displayName: name.value }),
|
||||
});
|
||||
await store.load();
|
||||
success.value = "个人资料已更新";
|
||||
});
|
||||
}
|
||||
function changePassword() {
|
||||
return action(async () => {
|
||||
await api("/account/password", {
|
||||
method: "POST",
|
||||
body: body({
|
||||
currentPassword: current.value,
|
||||
newPassword: password.value,
|
||||
}),
|
||||
});
|
||||
store.clear();
|
||||
router.push("/login");
|
||||
});
|
||||
}
|
||||
function revoke(s: any) {
|
||||
if (!confirm("撤销该设备会话?如果是当前设备,需要重新登录。")) return;
|
||||
return action(async () => {
|
||||
await api("/account/sessions/" + s.id, { method: "DELETE" });
|
||||
try {
|
||||
await store.load();
|
||||
await load();
|
||||
success.value = "会话已撤销";
|
||||
} catch {
|
||||
store.clear();
|
||||
router.push("/login");
|
||||
}
|
||||
});
|
||||
}
|
||||
function expired(s: any) {
|
||||
return new Date(s.expires_at).getTime() <= Date.now();
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">ACCOUNT & SECURITY</span>
|
||||
<h1>账户与安全</h1>
|
||||
<p>管理你的个人资料,掌控每一次访问。</p>
|
||||
</div>
|
||||
<span class="badge"><ShieldCheck :size="15" />安全工作空间</span>
|
||||
</div>
|
||||
<div class="alert error" v-if="error">{{ error }}</div>
|
||||
<div class="alert success" v-if="success">{{ success }}</div>
|
||||
<div class="two-columns">
|
||||
<section class="panel form-panel">
|
||||
<h3>个人资料</h3>
|
||||
<p class="muted">你的账户信息与公开称呼</p>
|
||||
<form @submit.prevent="profile">
|
||||
<label>邮箱地址<input :value="store.user?.email" disabled /></label
|
||||
><label>显示名称<input v-model="name" required maxlength="80" /></label
|
||||
><button class="primary" :disabled="busy">保存更改</button>
|
||||
</form>
|
||||
</section>
|
||||
<section class="panel form-panel">
|
||||
<h3><KeyRound :size="18" />修改密码</h3>
|
||||
<p class="muted">修改后所有设备会话会被撤销</p>
|
||||
<form @submit.prevent="changePassword">
|
||||
<label
|
||||
>当前密码<input
|
||||
v-model="current"
|
||||
type="password"
|
||||
required
|
||||
autocomplete="current-password"
|
||||
maxlength="72" /></label
|
||||
><label
|
||||
>新密码<input
|
||||
v-model="password"
|
||||
type="password"
|
||||
minlength="12"
|
||||
maxlength="72"
|
||||
required
|
||||
autocomplete="new-password"
|
||||
/><small>12–72 字节,包含字母和数字</small></label
|
||||
><button class="secondary" :disabled="busy">更新密码</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
<section class="panel table-panel">
|
||||
<div class="panel-heading">
|
||||
<h3><Monitor :size="19" />设备会话</h3>
|
||||
<span class="muted">最近 100 条</span>
|
||||
</div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>访问来源</th>
|
||||
<th>设备信息</th>
|
||||
<th>创建时间</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="s in sessions" :key="s.id">
|
||||
<td>{{ s.ip }}</td>
|
||||
<td class="ua" :title="s.user_agent">{{ s.user_agent }}</td>
|
||||
<td>{{ new Date(s.created_at).toLocaleString() }}</td>
|
||||
<td>
|
||||
<span class="status">{{
|
||||
s.revoked_at ? "已撤销" : expired(s) ? "已过期" : "有效"
|
||||
}}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
v-if="!s.revoked_at && !expired(s)"
|
||||
class="link danger"
|
||||
:disabled="busy"
|
||||
@click="revoke(s)"
|
||||
>
|
||||
撤销
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!sessions.length">
|
||||
<td colspan="5" class="empty">暂无会话记录</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section class="panel table-panel">
|
||||
<div class="panel-heading">
|
||||
<h3><History :size="19" />登录记录</h3>
|
||||
<span class="muted">最近 100 条</span>
|
||||
</div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>来源 IP</th>
|
||||
<th>设备信息</th>
|
||||
<th>时间</th>
|
||||
<th>结果</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="l in logs" :key="l.id">
|
||||
<td>{{ l.ip }}</td>
|
||||
<td class="ua" :title="l.user_agent">{{ l.user_agent }}</td>
|
||||
<td>{{ new Date(l.created_at).toLocaleString() }}</td>
|
||||
<td>
|
||||
<span :class="l.result === 'SUCCESS' ? 'good' : 'danger'">{{
|
||||
l.result === "SUCCESS" ? "成功" : "失败"
|
||||
}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!logs.length">
|
||||
<td colspan="4" class="empty">暂无登录记录</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,305 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, onMounted } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { api, body } from "../api";
|
||||
import { useSession } from "../store";
|
||||
import { Search, ShieldCheck, Settings2, History } from "lucide-vue-next";
|
||||
const route = useRoute(),
|
||||
store = useSession(),
|
||||
items = ref<any[]>([]),
|
||||
settings = ref<Record<string, string>>({}),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false),
|
||||
search = ref(""),
|
||||
page = ref(0),
|
||||
total = ref(0);
|
||||
async function load() {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
success.value = "";
|
||||
try {
|
||||
if (route.params.section === "settings") {
|
||||
settings.value = await api("/admin/settings");
|
||||
} else if (route.params.section === "audit") {
|
||||
items.value = await api("/admin/audit");
|
||||
} else {
|
||||
const result = await api(
|
||||
"/admin/users?search=" +
|
||||
encodeURIComponent(search.value) +
|
||||
"&page=" +
|
||||
page.value,
|
||||
);
|
||||
items.value = result.items;
|
||||
total.value = result.total;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
items.value = [];
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function save() {
|
||||
if (!confirm("确认保存平台设置?更改将立即生效并写入审计日志。")) return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
await api("/admin/settings", { method: "PUT", body: body(settings.value) });
|
||||
await store.brand();
|
||||
success.value = "平台设置已更新,操作已记录";
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function toggle(u: any) {
|
||||
const reason = prompt(
|
||||
"请输入" +
|
||||
(u.status === "ACTIVE" ? "停用" : "启用") +
|
||||
"用户 " +
|
||||
u.email +
|
||||
" 的原因",
|
||||
);
|
||||
if (!reason) return;
|
||||
try {
|
||||
await api("/admin/users/" + u.id + "/status", {
|
||||
method: "PUT",
|
||||
body: body({
|
||||
status: u.status === "ACTIVE" ? "DISABLED" : "ACTIVE",
|
||||
reason,
|
||||
}),
|
||||
});
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function logout(u: any) {
|
||||
if (!confirm("强制注销 " + u.email + " 的全部会话?")) return;
|
||||
try {
|
||||
await api("/admin/users/" + u.id + "/sessions", { method: "DELETE" });
|
||||
success.value = "该用户所有会话已撤销";
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => route.params.section,
|
||||
() => {
|
||||
page.value = 0;
|
||||
load();
|
||||
},
|
||||
);
|
||||
onMounted(load);
|
||||
const fields = [
|
||||
["siteName", "中文品牌名称"],
|
||||
["englishName", "英文名称"],
|
||||
["tagline", "平台主标语"],
|
||||
["heroHeadline", "首页主标题(换行分隔)"],
|
||||
["siteDescription", "平台简介"],
|
||||
["logoUrl", "Logo HTTPS 地址"],
|
||||
["mainDomain", "官网域名"],
|
||||
["deploymentDomain", "用户部署根域名"],
|
||||
["domainDeliveryTarget", "项目入口 CNAME 目标(已接入的 Ingress 域名)"],
|
||||
["domainTemplate", "用户域名模板({project} 为项目名)"],
|
||||
["faviconUrl", "Favicon HTTPS 地址"],
|
||||
["filing", "备案信息"],
|
||||
["footer", "平台官网页脚文字"],
|
||||
["hostedFooterText", "用户网站服务标识文字"],
|
||||
["hostedFooterLink", "用户网站服务标识链接"],
|
||||
["announcement", "控制台公告"],
|
||||
];
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">PLATFORM ADMINISTRATION</span>
|
||||
<h1>
|
||||
{{
|
||||
route.params.section === "settings"
|
||||
? "系统设置"
|
||||
: route.params.section === "audit"
|
||||
? "操作审计"
|
||||
: "用户管理"
|
||||
}}
|
||||
</h1>
|
||||
<p>由后端验证权限,敏感操作全程留痕。</p>
|
||||
</div>
|
||||
<span class="badge"><ShieldCheck :size="15" />管理控制台</span>
|
||||
</div>
|
||||
<div class="alert error" v-if="error" role="alert">{{ error }}</div>
|
||||
<div class="alert success" v-if="success">{{ success }}</div>
|
||||
<section
|
||||
v-if="route.params.section === 'settings'"
|
||||
class="panel form-panel settings-form"
|
||||
>
|
||||
<h3><Settings2 :size="18" />平台基础配置</h3>
|
||||
<p class="muted">品牌和站点信息通过数据库动态配置</p>
|
||||
<form @submit.prevent="save">
|
||||
<label v-for="f in fields" :key="f[0]"
|
||||
>{{ f[1]
|
||||
}}<textarea
|
||||
v-if="['announcement', 'heroHeadline', 'footer'].includes(f[0])"
|
||||
v-model="settings[f[0]]"
|
||||
rows="3"
|
||||
maxlength="2000" /><input
|
||||
v-else
|
||||
v-model="settings[f[0]]"
|
||||
:required="f[0] === 'siteName'"
|
||||
:maxlength="
|
||||
f[0] === 'siteName'
|
||||
? 80
|
||||
: f[0] === 'siteDescription'
|
||||
? 200
|
||||
: f[0] === 'logoUrl'
|
||||
? 1000
|
||||
: f[0] === 'mainDomain'
|
||||
? 253
|
||||
: f[0] === 'filing'
|
||||
? 100
|
||||
: 500
|
||||
" /></label
|
||||
><label
|
||||
>用户网站底部服务标识<select v-model="settings.hostedFooterEnabled">
|
||||
<option value="true">显示(后续发布生效)</option>
|
||||
<option value="false">不显示</option>
|
||||
</select></label
|
||||
><label
|
||||
>开放用户注册<select v-model="settings.registrationEnabled">
|
||||
<option value="true">开放注册(图形验证码)</option>
|
||||
<option value="false">关闭注册</option>
|
||||
</select></label
|
||||
><button class="primary" :disabled="busy">
|
||||
{{ busy ? "保存中…" : "保存设置" }}
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
<section
|
||||
v-else-if="route.params.section === 'audit'"
|
||||
class="panel table-panel"
|
||||
>
|
||||
<div class="panel-heading">
|
||||
<h3><History :size="18" />管理员操作日志</h3>
|
||||
<span class="muted">最近 100 条</span>
|
||||
</div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>操作人 / 时间</th>
|
||||
<th>操作类型</th>
|
||||
<th>对象</th>
|
||||
<th>变化详情</th>
|
||||
<th>来源 IP</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="a in items" :key="a.id">
|
||||
<td>
|
||||
{{ a.actor
|
||||
}}<small class="block">{{
|
||||
new Date(a.created_at).toLocaleString()
|
||||
}}</small>
|
||||
</td>
|
||||
<td>{{ a.action }}</td>
|
||||
<td class="truncate" :title="a.target">{{ a.target }}</td>
|
||||
<td class="audit-detail">{{ a.details }}</td>
|
||||
<td>{{ a.ip }}</td>
|
||||
</tr>
|
||||
<tr v-if="!items.length">
|
||||
<td colspan="5" class="empty">
|
||||
{{ busy ? "加载中…" : "暂无可显示的记录" }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<template v-else
|
||||
><form
|
||||
class="toolbar"
|
||||
@submit.prevent="
|
||||
page = 0;
|
||||
load();
|
||||
"
|
||||
>
|
||||
<div class="search-input">
|
||||
<Search :size="17" /><input
|
||||
v-model="search"
|
||||
placeholder="搜索邮箱或名称"
|
||||
maxlength="254"
|
||||
/>
|
||||
</div>
|
||||
<button class="secondary" :disabled="busy">搜索</button
|
||||
><span class="muted push">{{ total }} 个用户</span>
|
||||
</form>
|
||||
<section class="panel table-panel">
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>用户</th>
|
||||
<th>邮箱</th>
|
||||
<th>注册时间</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="u in items" :key="u.id">
|
||||
<td>{{ u.display_name }}</td>
|
||||
<td>{{ u.email }}</td>
|
||||
<td>{{ new Date(u.created_at).toLocaleString() }}</td>
|
||||
<td>
|
||||
<span class="status">{{
|
||||
u.status === "ACTIVE" ? "正常" : "已停用"
|
||||
}}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div
|
||||
v-if="store.user?.permissions.includes('users:write')"
|
||||
class="table-actions"
|
||||
>
|
||||
<button class="link" @click="toggle(u)">
|
||||
{{ u.status === "ACTIVE" ? "停用" : "启用" }}</button
|
||||
><button class="link danger" @click="logout(u)">
|
||||
强制下线
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!items.length">
|
||||
<td colspan="5" class="empty">
|
||||
{{ busy ? "正在加载…" : "暂无用户" }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="pagination">
|
||||
<button
|
||||
class="secondary"
|
||||
:disabled="page === 0 || busy"
|
||||
@click="
|
||||
page--;
|
||||
load();
|
||||
"
|
||||
>
|
||||
上一页</button
|
||||
><span>第 {{ page + 1 }} 页</span
|
||||
><button
|
||||
class="secondary"
|
||||
:disabled="(page + 1) * 20 >= total || busy"
|
||||
@click="
|
||||
page++;
|
||||
load();
|
||||
"
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
</div>
|
||||
</section></template
|
||||
>
|
||||
</template>
|
||||
@@ -0,0 +1,140 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { api, body } from "../api";
|
||||
const rows = ref<any[]>([]),
|
||||
events = ref<any[]>([]),
|
||||
search = ref(""),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false);
|
||||
async function load() {
|
||||
error.value = "";
|
||||
try {
|
||||
rows.value = await api(
|
||||
"/admin/domains?search=" + encodeURIComponent(search.value),
|
||||
);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function action(row: any, operation: string) {
|
||||
if (operation === "EVENTS") {
|
||||
try {
|
||||
events.value = await api(`/admin/domains/${row.id}/events`);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
return;
|
||||
}
|
||||
const reason = prompt(
|
||||
operation === "REMOVE"
|
||||
? "填写解绑原因,入口将被移除,项目数据保留。"
|
||||
: "填写重试配置原因",
|
||||
);
|
||||
if (!reason?.trim()) return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const result = await api(`/admin/domains/${row.id}/actions`, {
|
||||
method: "POST",
|
||||
body: body({ action: operation, reason }),
|
||||
});
|
||||
success.value = result.message;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">DOMAIN OPERATIONS</span>
|
||||
<h1>域名管理</h1>
|
||||
<p>查看用户域名、解析与证书状态,按原因重试配置或解绑入口。</p>
|
||||
</div>
|
||||
<button :disabled="busy" @click="load">刷新</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<div v-if="success" class="alert success">{{ success }}</div>
|
||||
<form class="toolbar" @submit.prevent="load">
|
||||
<input
|
||||
v-model="search"
|
||||
maxlength="253"
|
||||
placeholder="搜索域名或用户邮箱"
|
||||
aria-label="搜索域名"
|
||||
/><button class="primary" :disabled="busy">查询</button>
|
||||
</form>
|
||||
<section class="panel table-panel">
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>域名 / 项目</th>
|
||||
<th>所属用户</th>
|
||||
<th>状态</th>
|
||||
<th>入口目标 / 错误</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="!rows.length">
|
||||
<td colspan="5" class="empty">尚无匹配域名</td>
|
||||
</tr>
|
||||
<tr v-for="d in rows" :key="d.id">
|
||||
<td>
|
||||
<strong>{{ d.hostname }}</strong>
|
||||
<p class="muted">
|
||||
{{ d.project_name }} ·
|
||||
{{ d.kind === "PLATFORM" ? "平台域名" : "自定义域名" }}
|
||||
{{ d.is_primary ? "· 主域名" : "" }}
|
||||
</p>
|
||||
</td>
|
||||
<td>{{ d.email }}</td>
|
||||
<td>
|
||||
<span class="status">{{ d.status }}</span
|
||||
><small style="display: block">{{
|
||||
new Date(d.updated_at).toLocaleString()
|
||||
}}</small>
|
||||
</td>
|
||||
<td style="max-width: 300px; overflow-wrap: anywhere">
|
||||
<code>{{ d.expected_cname || "尚未配置" }}</code>
|
||||
<p v-if="d.error">{{ d.error }}</p>
|
||||
</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button :disabled="busy" @click="action(d, 'EVENTS')">
|
||||
日志</button
|
||||
><button :disabled="busy" @click="action(d, 'CONFIGURE')">
|
||||
重试配置</button
|
||||
><button
|
||||
v-if="d.status !== 'REMOVED'"
|
||||
:disabled="busy"
|
||||
@click="action(d, 'REMOVE')"
|
||||
>
|
||||
解绑
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section
|
||||
v-if="events.length"
|
||||
class="panel form-panel"
|
||||
style="margin-top: 22px"
|
||||
>
|
||||
<h3>执行日志</h3>
|
||||
<div v-for="(e, i) in events" :key="i" style="padding: 12px 0">
|
||||
<small
|
||||
>{{ new Date(e.created_at).toLocaleString() }} · {{ e.phase }}</small
|
||||
>
|
||||
<p>{{ e.detail }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,290 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { BookOpen, Palette, Puzzle, Upload } from "lucide-vue-next";
|
||||
import { api, body } from "../api";
|
||||
import type { Extension } from "../extensions";
|
||||
import { useSession } from "../store";
|
||||
|
||||
const store = useSession();
|
||||
const items = ref<Extension[]>([]);
|
||||
const kind = ref<"plugin" | "theme">("plugin");
|
||||
const file = ref<File>();
|
||||
const picker = ref<HTMLInputElement>();
|
||||
const loading = ref(false),
|
||||
busy = ref(false);
|
||||
const error = ref(""),
|
||||
notice = ref("");
|
||||
const rows = computed(() =>
|
||||
items.value.filter((item) => item.kind === kind.value),
|
||||
);
|
||||
const theme = computed(() =>
|
||||
items.value.find((item) => item.kind === "theme" && item.enabled),
|
||||
);
|
||||
const activePlugins = computed(
|
||||
() =>
|
||||
items.value.filter((item) => item.kind === "plugin" && item.enabled).length,
|
||||
);
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
try {
|
||||
items.value = await api("/admin/extensions");
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
async function upload() {
|
||||
if (!file.value || busy.value) return;
|
||||
if (file.value.size > 512 * 1024) {
|
||||
error.value = "扩展包不能超过 512 KiB";
|
||||
return;
|
||||
}
|
||||
const data = new FormData();
|
||||
data.set("file", file.value);
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
notice.value = "";
|
||||
try {
|
||||
const item = await api<Extension>("/admin/extensions", {
|
||||
method: "POST",
|
||||
body: data,
|
||||
});
|
||||
notice.value = `${item.name} ${item.version} 已安装,当前${item.enabled ? "启用" : "停用"}。`;
|
||||
kind.value = item.kind;
|
||||
file.value = undefined;
|
||||
if (picker.value) picker.value.value = "";
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function change(item: Extension, remove = false) {
|
||||
if (busy.value) return;
|
||||
if (
|
||||
remove &&
|
||||
!confirm(
|
||||
`移除 ${item.name} ${item.version}?要再次使用此版本,需要重新上传 ZIP。`,
|
||||
)
|
||||
)
|
||||
return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
notice.value = "";
|
||||
try {
|
||||
const path = "/admin/extensions/" + item.id;
|
||||
if (remove) {
|
||||
await api(path, { method: "DELETE" });
|
||||
notice.value = "已移除该版本";
|
||||
} else {
|
||||
await api(path + "/activation", {
|
||||
method: "PUT",
|
||||
body: body({ enabled: !item.enabled }),
|
||||
});
|
||||
notice.value = item.enabled ? "已停用" : "已启用";
|
||||
}
|
||||
await load();
|
||||
if (item.kind === "theme") await store.refreshTheme();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">EXTENSIONS</span>
|
||||
<h1>插件与主题</h1>
|
||||
<p>上传自制扩展,切换版本,为用户工作台添加工具或更换外观。</p>
|
||||
</div>
|
||||
<a class="secondary guide-link" href="/extension-development.md" download>
|
||||
<BookOpen :size="16" />开发文档
|
||||
</a>
|
||||
</div>
|
||||
<div v-if="error" class="alert error" role="alert">{{ error }}</div>
|
||||
<div v-if="notice" class="alert success" role="status">{{ notice }}</div>
|
||||
<div class="two-columns extension-overview">
|
||||
<form class="panel form-panel" @submit.prevent="upload">
|
||||
<h3><Upload :size="17" />上传扩展包</h3>
|
||||
<p class="muted">
|
||||
支持带 manifest.json 的 ZIP,最大 512 KiB。上传通过校验后可手动启用。
|
||||
</p>
|
||||
<label
|
||||
>ZIP 文件
|
||||
<input
|
||||
ref="picker"
|
||||
type="file"
|
||||
accept=".zip,application/zip"
|
||||
required
|
||||
:disabled="busy"
|
||||
@change="file = ($event.target as HTMLInputElement).files?.[0]"
|
||||
/>
|
||||
</label>
|
||||
<button class="primary" :disabled="busy || !file">上传并校验</button>
|
||||
</form>
|
||||
<section class="panel form-panel extension-current">
|
||||
<h3>当前生效</h3>
|
||||
<p>
|
||||
<Puzzle :size="16" /><span
|
||||
>插件 <b>{{ activePlugins }}</b> 个</span
|
||||
>
|
||||
<RouterLink to="/extensions" class="text-link"
|
||||
>查看工作台工具 ↗</RouterLink
|
||||
>
|
||||
</p>
|
||||
<p>
|
||||
<Palette :size="16" /><span
|
||||
>主题 <b>{{ theme?.name ?? "WebUp 默认" }}</b>
|
||||
<small v-if="theme"> · {{ theme.version }}</small></span
|
||||
>
|
||||
<RouterLink to="/" class="text-link">查看首页 ↗</RouterLink>
|
||||
</p>
|
||||
<small class="muted"
|
||||
>启用另一个版本会切换当前版本。停用主题可恢复默认配色。</small
|
||||
>
|
||||
</section>
|
||||
</div>
|
||||
<div class="toolbar extension-tabs">
|
||||
<button :aria-pressed="kind === 'plugin'" @click="kind = 'plugin'">
|
||||
插件
|
||||
</button>
|
||||
<button :aria-pressed="kind === 'theme'" @click="kind = 'theme'">
|
||||
主题
|
||||
</button>
|
||||
<button
|
||||
class="secondary"
|
||||
:disabled="loading || busy"
|
||||
@click="
|
||||
error = '';
|
||||
load();
|
||||
"
|
||||
>
|
||||
刷新
|
||||
</button>
|
||||
</div>
|
||||
<section class="panel table-panel" :aria-busy="loading">
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>扩展 / 标识</th>
|
||||
<th>版本</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in rows" :key="item.id">
|
||||
<td class="extension-summary">
|
||||
<strong>{{ item.name }}</strong>
|
||||
<code class="block muted">{{ item.slug }}</code>
|
||||
<p v-if="item.description">{{ item.description }}</p>
|
||||
<div v-if="item.palettes" class="extension-palettes">
|
||||
<div v-for="(colors, mode) in item.palettes" :key="mode">
|
||||
<span>{{ mode === "light" ? "浅色" : "深色" }}</span>
|
||||
<span
|
||||
v-for="(color, token) in colors"
|
||||
:key="token"
|
||||
class="swatch"
|
||||
:style="{ backgroundColor: color }"
|
||||
:title="`${token} ${color}`"
|
||||
:aria-label="`${token} ${color}`"
|
||||
></span>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{{ item.version
|
||||
}}<small class="block muted" :title="item.sha256"
|
||||
>SHA-256 {{ item.sha256.slice(0, 12) }}…</small
|
||||
>
|
||||
</td>
|
||||
<td>
|
||||
<span class="status" :class="{ enabled: item.enabled }">{{
|
||||
item.enabled ? "已启用" : "已停用"
|
||||
}}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button :disabled="busy || loading" @click="change(item)">
|
||||
{{ item.enabled ? "停用" : "启用此版本" }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!item.enabled"
|
||||
:disabled="busy || loading"
|
||||
@click="change(item, true)"
|
||||
>
|
||||
移除
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!rows.length">
|
||||
<td colspan="4" class="empty">
|
||||
{{ loading ? "正在读取扩展…" : "还没有上传此类扩展" }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.guide-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
}
|
||||
.extension-current p {
|
||||
display: flex;
|
||||
gap: 9px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
margin: 16px 0;
|
||||
}
|
||||
.extension-tabs [aria-pressed="true"] {
|
||||
color: var(--blue);
|
||||
background: var(--blue-light);
|
||||
}
|
||||
.extension-summary {
|
||||
max-width: 440px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.extension-summary p {
|
||||
margin-top: 6px;
|
||||
}
|
||||
.extension-palettes {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 7px 13px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
.extension-palettes > div {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.swatch {
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 4px;
|
||||
}
|
||||
.status.enabled {
|
||||
color: #258561;
|
||||
background: #25856114;
|
||||
}
|
||||
@media (max-width: 720px) {
|
||||
.extension-overview {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,401 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, computed } from "vue";
|
||||
import { api } from "../api";
|
||||
import { useSession } from "../store";
|
||||
const store = useSession(),
|
||||
data = ref<Record<string, any>>({}),
|
||||
error = ref(""),
|
||||
loading = ref(true);
|
||||
const metrics = [
|
||||
["users", "平台用户"],
|
||||
["projects", "开发项目"],
|
||||
["tasks", "AI 任务"],
|
||||
["runningTasks", "正在执行"],
|
||||
["activeDeployments", "当前发布"],
|
||||
["reviewTasks", "待核对任务"],
|
||||
["providers", "模型供应商"],
|
||||
["models", "模型配置"],
|
||||
];
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
data.value = await api("/admin/overview");
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
type DailyActivity = {
|
||||
date: string;
|
||||
users: number;
|
||||
projects: number;
|
||||
tasks: number;
|
||||
};
|
||||
const trend = computed<DailyActivity[]>(() => data.value.trend ?? []);
|
||||
const recentDays = computed(() => [...trend.value].reverse());
|
||||
const maximum = computed(() =>
|
||||
Math.max(1, ...trend.value.flatMap((d) => [d.users, d.projects, d.tasks])),
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">PLATFORM OPERATIONS</span>
|
||||
<h1>运营总览</h1>
|
||||
<p>查看平台规模、业务趋势、任务状态与发布情况。</p>
|
||||
</div>
|
||||
<button class="secondary" @click="load" :disabled="loading">
|
||||
刷新数据
|
||||
</button>
|
||||
</div>
|
||||
<div class="alert error" v-if="error">{{ error }}</div>
|
||||
<section class="stats">
|
||||
<div v-for="m in metrics" :key="m[0]" class="stat-card">
|
||||
<div>{{ m[1] }}</div>
|
||||
<strong>{{ loading ? "—" : (data[m[0]] ?? "—") }}</strong
|
||||
><small>平台数据库实时汇总</small>
|
||||
</div>
|
||||
</section>
|
||||
<div class="analytics-grid">
|
||||
<section class="panel form-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<h3>近 14 天增长趋势</h3>
|
||||
<p>新增用户、项目和 AI 任务 · 北京时间</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-legend">
|
||||
<span><i class="users"></i>用户</span
|
||||
><span><i class="projects"></i>项目</span
|
||||
><span><i class="tasks"></i>任务</span>
|
||||
</div>
|
||||
<div class="growth-chart">
|
||||
<div v-for="day in trend" :key="day.date" class="chart-day">
|
||||
<div class="chart-bars">
|
||||
<i
|
||||
class="users"
|
||||
:style="{ height: (day.users / maximum) * 150 + 'px' }"
|
||||
:title="day.date + ' 新增用户 ' + day.users"
|
||||
></i
|
||||
><i
|
||||
class="projects"
|
||||
:style="{ height: (day.projects / maximum) * 150 + 'px' }"
|
||||
:title="day.date + ' 新增项目 ' + day.projects"
|
||||
></i
|
||||
><i
|
||||
class="tasks"
|
||||
:style="{ height: (day.tasks / maximum) * 150 + 'px' }"
|
||||
:title="day.date + ' 新增任务 ' + day.tasks"
|
||||
></i>
|
||||
</div>
|
||||
<small>{{ day.date.slice(5) }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<p class="muted" v-if="!trend.length">
|
||||
{{ loading ? "正在加载统计…" : "暂无统计数据" }}
|
||||
</p>
|
||||
</section>
|
||||
<section class="panel form-panel">
|
||||
<h3>任务状态分布</h3>
|
||||
<p class="muted">按数据库当前状态汇总</p>
|
||||
<div class="distribution">
|
||||
<div v-for="d in data.taskDistribution || []" :key="d.status">
|
||||
<span>{{ d.status }}</span
|
||||
><b>{{ d.count }}</b>
|
||||
<div>
|
||||
<i
|
||||
:style="{
|
||||
width:
|
||||
(data.tasks ? (Number(d.count) / data.tasks) * 100 : 0) + '%',
|
||||
}"
|
||||
></i>
|
||||
</div>
|
||||
</div>
|
||||
<p class="empty" v-if="!data.taskDistribution?.length">暂无 AI 任务</p>
|
||||
</div>
|
||||
<div class="analytics-billing" v-if="data.usageBilling">
|
||||
<small>按精确 usage 结算的 AI 费用</small
|
||||
><strong>¥ {{ data.usageBilling.amount }}</strong>
|
||||
<p>
|
||||
输入 {{ data.usageBilling.input_tokens }} / 输出
|
||||
{{ data.usageBilling.output_tokens }} Token
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<section class="panel table-panel">
|
||||
<div class="panel-heading">
|
||||
<h3>每日运营数据</h3>
|
||||
<span class="muted">近 14 天 · 北京时间</span>
|
||||
</div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">日期</th>
|
||||
<th scope="col">新增用户</th>
|
||||
<th scope="col">新增项目</th>
|
||||
<th scope="col">新增 AI 任务</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="day in recentDays" :key="day.date">
|
||||
<td>{{ day.date }}</td>
|
||||
<td>{{ day.users }}</td>
|
||||
<td>{{ day.projects }}</td>
|
||||
<td>{{ day.tasks }}</td>
|
||||
</tr>
|
||||
<tr v-if="!recentDays.length">
|
||||
<td colspan="4" class="empty">
|
||||
{{ loading ? "正在加载统计…" : "暂无统计数据" }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="data.recentTasks" class="panel table-panel">
|
||||
<div class="panel-heading">
|
||||
<h3>最近开发任务</h3>
|
||||
<RouterLink to="/admin/tasks" class="text-link"
|
||||
>查看全部任务 →</RouterLink
|
||||
>
|
||||
</div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>项目</th>
|
||||
<th>状态</th>
|
||||
<th>执行轮次</th>
|
||||
<th>时间</th>
|
||||
<th>异常信息</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="t in data.recentTasks" :key="t.id">
|
||||
<td>{{ t.project }}</td>
|
||||
<td>{{ t.status }}</td>
|
||||
<td>{{ t.step_count }}</td>
|
||||
<td>{{ new Date(t.created_at).toLocaleString() }}</td>
|
||||
<td>{{ t.error || "—" }}</td>
|
||||
</tr>
|
||||
<tr v-if="!data.recentTasks.length">
|
||||
<td colspan="5" class="empty">暂无任务</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="data.recentDeployments" class="panel table-panel">
|
||||
<div class="panel-heading"><h3>最近网站发布</h3></div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>项目</th>
|
||||
<th>部署状态</th>
|
||||
<th>创建时间</th>
|
||||
<th>错误信息</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="d in data.recentDeployments" :key="d.id">
|
||||
<td>{{ d.project }}</td>
|
||||
<td>{{ d.status }}</td>
|
||||
<td>{{ new Date(d.created_at).toLocaleString() }}</td>
|
||||
<td>{{ d.error || "—" }}</td>
|
||||
</tr>
|
||||
<tr v-if="!data.recentDeployments.length">
|
||||
<td colspan="4" class="empty">暂无发布记录</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<div class="two-columns">
|
||||
<section class="panel form-panel">
|
||||
<h3>运营入口</h3>
|
||||
<p class="muted">根据你的角色权限显示可用功能</p>
|
||||
<div class="admin-shortcuts">
|
||||
<RouterLink
|
||||
v-if="store.user?.permissions.includes('users:read')"
|
||||
to="/admin/users"
|
||||
>用户与账户 →</RouterLink
|
||||
><RouterLink
|
||||
v-if="store.user?.permissions.includes('models:write')"
|
||||
to="/admin/models"
|
||||
>AI 供应商与模型 →</RouterLink
|
||||
><RouterLink
|
||||
v-if="store.user?.permissions.includes('finance:write')"
|
||||
to="/admin/plans"
|
||||
>托管套餐与定价 →</RouterLink
|
||||
><RouterLink
|
||||
v-if="store.user?.permissions.includes('settings:write')"
|
||||
to="/admin/settings"
|
||||
>品牌与系统设置 →</RouterLink
|
||||
>
|
||||
</div>
|
||||
</section>
|
||||
<section class="panel form-panel">
|
||||
<h3>需要关注</h3>
|
||||
<p class="muted">系统保留异常状态,避免重复调用和重复扣费</p>
|
||||
<div class="notice">
|
||||
<div>
|
||||
<b>待自动核算:{{ data.reviewTasks ?? "—" }} 个任务</b>
|
||||
<p>
|
||||
系统自动结算已确认费用、释放剩余预算,内部记录与 AI
|
||||
分析报告在开发任务运营中查看。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<RouterLink
|
||||
v-if="
|
||||
store.user?.permissions.includes('tasks:manage') ||
|
||||
store.user?.permissions.includes('finance:write')
|
||||
"
|
||||
class="text-link"
|
||||
to="/admin/tasks"
|
||||
>查看开发任务运营 →</RouterLink
|
||||
>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.analytics-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1.65fr 1fr;
|
||||
gap: 22px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.analytics-grid .panel-heading {
|
||||
padding: 0 0 15px;
|
||||
}
|
||||
.analytics-grid .panel-heading p {
|
||||
font-size: 10px;
|
||||
color: var(--muted);
|
||||
margin-top: 7px;
|
||||
}
|
||||
.chart-legend {
|
||||
display: flex;
|
||||
gap: 17px;
|
||||
font-size: 9px;
|
||||
color: var(--muted);
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.chart-legend > span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
.chart-legend i {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.users {
|
||||
background: #7396e9;
|
||||
}
|
||||
.projects {
|
||||
background: #8abda8;
|
||||
}
|
||||
.tasks {
|
||||
background: #b5a7d8;
|
||||
}
|
||||
.growth-chart {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 7px;
|
||||
overflow-x: auto;
|
||||
padding-top: 22px;
|
||||
}
|
||||
.chart-day {
|
||||
flex: 1;
|
||||
min-width: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
.chart-bars {
|
||||
height: 155px;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: center;
|
||||
gap: 3px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.chart-bars > i {
|
||||
width: 8px;
|
||||
max-width: 9px;
|
||||
border-radius: 3px 3px 0 0;
|
||||
}
|
||||
.chart-day > small {
|
||||
display: block;
|
||||
font-size: 7px;
|
||||
white-space: nowrap;
|
||||
margin-top: 9px;
|
||||
}
|
||||
.distribution {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.distribution > div {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto;
|
||||
gap: 8px;
|
||||
margin: 15px 0;
|
||||
font-size: 10px;
|
||||
color: #8496b2;
|
||||
}
|
||||
.distribution b {
|
||||
font-size: 12px;
|
||||
color: var(--text);
|
||||
}
|
||||
.distribution > div > div {
|
||||
grid-column: 1/-1;
|
||||
height: 5px;
|
||||
background: var(--soft);
|
||||
border-radius: 3px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.distribution i {
|
||||
display: block;
|
||||
height: 5px;
|
||||
background: #92ace2;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.analytics-billing {
|
||||
border-top: 1px solid var(--line);
|
||||
padding-top: 18px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.analytics-billing strong {
|
||||
display: block;
|
||||
margin: 8px 0;
|
||||
font-size: 23px;
|
||||
}
|
||||
.analytics-billing p {
|
||||
font-size: 9px;
|
||||
color: var(--muted);
|
||||
}
|
||||
@media (max-width: 1000px) {
|
||||
.analytics-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
.admin-shortcuts {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 14px;
|
||||
}
|
||||
.admin-shortcuts a {
|
||||
background: var(--soft);
|
||||
padding: 18px;
|
||||
border-radius: 8px;
|
||||
font-size: 12px;
|
||||
color: #6787b7;
|
||||
}
|
||||
.admin-shortcuts a:hover {
|
||||
background: var(--blue-light);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,191 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { api, body } from "../api";
|
||||
import { useSession } from "../store";
|
||||
const store = useSession(),
|
||||
sites = ref<any[]>([]),
|
||||
search = ref(""),
|
||||
status = ref("ALL"),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false),
|
||||
operations = ref<any[]>([]);
|
||||
const labels: Record<string, string> = {
|
||||
PENDING: "待审核",
|
||||
APPROVED: "审核通过",
|
||||
REJECTED: "已驳回",
|
||||
BANNED: "已封禁",
|
||||
};
|
||||
async function load() {
|
||||
busy.value = true;
|
||||
try {
|
||||
sites.value = await api(
|
||||
"/admin/sites?search=" +
|
||||
encodeURIComponent(search.value) +
|
||||
"&status=" +
|
||||
status.value,
|
||||
);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function review(p: any, next: string) {
|
||||
const reason = prompt(
|
||||
"将「" + p.name + "」设为“" + labels[next] + "”,请填写原因:",
|
||||
);
|
||||
if (!reason) return;
|
||||
if (
|
||||
next === "BANNED" &&
|
||||
!confirm("确认封禁?将阻止发布与恢复,并排队暂停运行。")
|
||||
)
|
||||
return;
|
||||
try {
|
||||
const r = await api("/admin/sites/" + p.id + "/review", {
|
||||
method: "POST",
|
||||
body: body({ status: next, reason }),
|
||||
});
|
||||
success.value = r.message;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function history(p: any) {
|
||||
try {
|
||||
operations.value = await api("/admin/sites/" + p.id + "/operations");
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">WEBSITE MODERATION</span>
|
||||
<h1>网站管理与人工审核</h1>
|
||||
<p>查看用户网站、审核发布资格、封禁与解除封禁,全部保留审计。</p>
|
||||
</div>
|
||||
<button class="secondary" :disabled="busy" @click="load">刷新</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<div v-if="success" class="alert success">{{ success }}</div>
|
||||
<form class="toolbar" @submit.prevent="load">
|
||||
<input
|
||||
v-model="search"
|
||||
placeholder="搜索网站或用户邮箱"
|
||||
maxlength="200"
|
||||
/><select v-model="status" @change="load">
|
||||
<option value="ALL">全部状态</option>
|
||||
<option v-for="(label, key) in labels" :key="key" :value="key">
|
||||
{{ label }}
|
||||
</option></select
|
||||
><button class="primary" :disabled="busy">查询</button>
|
||||
</form>
|
||||
<section class="panel table-panel">
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>网站项目</th>
|
||||
<th>所属用户</th>
|
||||
<th>审核状态</th>
|
||||
<th>发布 / 套餐</th>
|
||||
<th>运行操作</th>
|
||||
<th>审核原因</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="p in sites" :key="p.id">
|
||||
<td>
|
||||
{{ p.name
|
||||
}}<small class="block"
|
||||
>{{ p.stack }} · {{ p.services }} 服务</small
|
||||
>
|
||||
</td>
|
||||
<td>
|
||||
{{ p.display_name }}<small class="block">{{ p.email }}</small>
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
class="status"
|
||||
:class="{ danger: p.review_status === 'BANNED' }"
|
||||
>{{ labels[p.review_status] }}</span
|
||||
>
|
||||
</td>
|
||||
<td>
|
||||
{{ p.active_deployments ? "有发布版本" : "未发布"
|
||||
}}<small class="block">{{
|
||||
p.subscription_status || "无套餐"
|
||||
}}</small>
|
||||
</td>
|
||||
<td>{{ p.operation_status || "—" }}</td>
|
||||
<td class="audit-detail">{{ p.review_reason || "—" }}</td>
|
||||
<td>
|
||||
<div
|
||||
class="table-actions"
|
||||
v-if="store.user?.permissions.includes('moderation:write')"
|
||||
>
|
||||
<button
|
||||
v-if="p.review_status !== 'APPROVED'"
|
||||
class="link"
|
||||
@click="review(p, 'APPROVED')"
|
||||
>
|
||||
{{
|
||||
p.review_status === "BANNED" ? "解除封禁" : "通过"
|
||||
}}</button
|
||||
><button
|
||||
v-if="p.review_status === 'PENDING'"
|
||||
class="link"
|
||||
@click="review(p, 'REJECTED')"
|
||||
>
|
||||
驳回</button
|
||||
><button
|
||||
v-if="p.review_status !== 'BANNED'"
|
||||
class="link danger"
|
||||
@click="review(p, 'BANNED')"
|
||||
>
|
||||
封禁</button
|
||||
><button class="link" @click="history(p)">执行记录</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!sites.length">
|
||||
<td colspan="7" class="empty">暂无匹配的网站项目</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<div class="alert info">
|
||||
封禁不删除项目数据。审核状态与实际暂停执行状态分别记录,未连接运行网关时不会伪造已下线。
|
||||
</div>
|
||||
<section v-if="operations.length" class="panel table-panel">
|
||||
<div class="panel-heading"><h3>运行操作记录</h3></div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>动作</th>
|
||||
<th>状态</th>
|
||||
<th>原因</th>
|
||||
<th>错误</th>
|
||||
<th>时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="o in operations" :key="o.id">
|
||||
<td>{{ o.action }}</td>
|
||||
<td>{{ o.status }}</td>
|
||||
<td>{{ o.reason }}</td>
|
||||
<td>{{ o.error || "—" }}</td>
|
||||
<td>{{ new Date(o.created_at).toLocaleString() }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,602 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, reactive, ref } from "vue";
|
||||
import { api, body } from "../api";
|
||||
import { useSession } from "../store";
|
||||
const store = useSession(),
|
||||
tasks = ref<any[]>([]),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false);
|
||||
const reportTask = ref<any>(null),
|
||||
reports = ref<any[]>([]),
|
||||
codeReviews = ref<any[]>([]),
|
||||
reportBusy = ref(false);
|
||||
const reviewModels = ref<any[]>([]),
|
||||
reviewConfiguration = reactive({
|
||||
enabled: true,
|
||||
modelId: "",
|
||||
version: 1,
|
||||
reason: "",
|
||||
});
|
||||
const reviewKeys = new Map<string, string>();
|
||||
async function loadReviewConfiguration() {
|
||||
const [configuration, models] = await Promise.all([
|
||||
api("/admin/code-reviews/config"),
|
||||
api("/models"),
|
||||
]);
|
||||
Object.assign(reviewConfiguration, {
|
||||
enabled: configuration.enabled,
|
||||
modelId: configuration.model_id || "",
|
||||
version: configuration.version,
|
||||
});
|
||||
reviewModels.value = models;
|
||||
}
|
||||
async function saveReviewConfiguration() {
|
||||
busy.value = true;
|
||||
try {
|
||||
const result = await api("/admin/code-reviews/config", {
|
||||
method: "PUT",
|
||||
body: body({
|
||||
...reviewConfiguration,
|
||||
modelId: reviewConfiguration.modelId || null,
|
||||
}),
|
||||
});
|
||||
success.value = result.message;
|
||||
reviewConfiguration.reason = "";
|
||||
await loadReviewConfiguration();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function requestCodeReview() {
|
||||
const task = reportTask.value;
|
||||
if (!task) return;
|
||||
const reason = prompt(
|
||||
"填写重新验收当前源码的原因。验收使用独立隔离副本,不改动用户文件,模型费用由平台承担。",
|
||||
);
|
||||
if (!reason?.trim()) return;
|
||||
if (!reviewKeys.has(task.id)) reviewKeys.set(task.id, crypto.randomUUID());
|
||||
busy.value = true;
|
||||
try {
|
||||
await api(`/admin/tasks/${task.id}/code-reviews`, {
|
||||
method: "POST",
|
||||
body: body({ reason, idempotencyKey: reviewKeys.get(task.id) }),
|
||||
});
|
||||
reviewKeys.delete(task.id);
|
||||
success.value = "独立验收已排队,历史报告会保留。";
|
||||
await viewReports(task);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
function reviewVerdict(value: string) {
|
||||
return (
|
||||
(
|
||||
{
|
||||
PASS: "通过",
|
||||
PARTIAL: "部分通过 / 尚有未验证项",
|
||||
FAIL: "未通过",
|
||||
UNVERIFIED: "无法验证",
|
||||
STALE: "源码已变化,需重新验收",
|
||||
} as Record<string, string>
|
||||
)[value] || value
|
||||
);
|
||||
}
|
||||
function evidence(value: string) {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(value), null, 2);
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
function actualChecks(value: string) {
|
||||
try {
|
||||
return JSON.parse(value).checks?.steps || [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
function checkStatus(value: string) {
|
||||
return (
|
||||
(
|
||||
{
|
||||
PASSED: "已通过",
|
||||
FAILED: "未通过",
|
||||
NOT_APPLICABLE: "无需执行",
|
||||
NOT_CONFIGURED: "未配置",
|
||||
NOT_RUN: "未执行",
|
||||
TIMEOUT: "超时,未通过验收",
|
||||
UNSUPPORTED: "当前环境不支持",
|
||||
} as Record<string, string>
|
||||
)[value] || value
|
||||
);
|
||||
}
|
||||
async function viewReports(task: any) {
|
||||
if (reportTask.value?.id !== task.id) {
|
||||
reports.value = [];
|
||||
codeReviews.value = [];
|
||||
}
|
||||
reportTask.value = task;
|
||||
reportBusy.value = true;
|
||||
try {
|
||||
const [result, reviews] = await Promise.all([
|
||||
api(`/admin/tasks/${task.id}/reports`),
|
||||
api(`/admin/tasks/${task.id}/code-reviews`),
|
||||
]);
|
||||
if (reportTask.value?.id === task.id) {
|
||||
reports.value = result;
|
||||
codeReviews.value = reviews;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
reportBusy.value = false;
|
||||
}
|
||||
}
|
||||
function downloadReport(report: any) {
|
||||
const url = URL.createObjectURL(
|
||||
new Blob([JSON.stringify(report, null, 2)], { type: "application/json" }),
|
||||
);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = `webup-task-report-${report.id}.json`;
|
||||
link.click();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
}
|
||||
const queue = ref<any>(null),
|
||||
config = reactive({
|
||||
maxConcurrent: 2,
|
||||
priorityEnabled: false,
|
||||
priorityPrice: "1",
|
||||
reason: "",
|
||||
});
|
||||
let initialized = false,
|
||||
timer: ReturnType<typeof setInterval> | undefined;
|
||||
async function load() {
|
||||
try {
|
||||
[tasks.value, queue.value] = await Promise.all([
|
||||
api("/admin/tasks"),
|
||||
api("/queue"),
|
||||
]);
|
||||
if (!initialized) {
|
||||
Object.assign(config, {
|
||||
maxConcurrent: queue.value.config.max_concurrent,
|
||||
priorityEnabled: queue.value.config.priority_enabled,
|
||||
priorityPrice: queue.value.config.priority_price,
|
||||
});
|
||||
initialized = true;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function saveQueue() {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const result = await api("/admin/queue/config", {
|
||||
method: "PUT",
|
||||
body: body(config),
|
||||
});
|
||||
success.value = result.message;
|
||||
config.reason = "";
|
||||
initialized = false;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function prioritize(task: any, next = false) {
|
||||
const value = next
|
||||
? String(task.admin_priority)
|
||||
: prompt(
|
||||
"设置人工优先级(-100 到 100,0 为默认;高值先执行)",
|
||||
String(task.admin_priority),
|
||||
);
|
||||
if (value === null) return;
|
||||
if (!/^-?\d+$/.test(value) || Number(value) < -100 || Number(value) > 100) {
|
||||
error.value = "优先级必须为 -100 到 100 的整数";
|
||||
return;
|
||||
}
|
||||
const reason = prompt(
|
||||
next ? "填写指定该任务优先执行的原因" : "填写调整排队顺序的原因",
|
||||
);
|
||||
if (!reason?.trim()) return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const result = await api(`/admin/tasks/${task.id}/priority`, {
|
||||
method: "POST",
|
||||
body: body({ priority: Number(value), runNext: next, reason }),
|
||||
});
|
||||
success.value = result.message;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
await load();
|
||||
try {
|
||||
await loadReviewConfiguration();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
timer = setInterval(() => {
|
||||
if (!busy.value && !document.hidden) {
|
||||
void load();
|
||||
if (reportTask.value && !reportBusy.value)
|
||||
void viewReports(reportTask.value);
|
||||
}
|
||||
}, 3000);
|
||||
});
|
||||
onUnmounted(() => clearInterval(timer));
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">TASK OPERATIONS</span>
|
||||
<h1>开发任务运营</h1>
|
||||
<p>管理开发队列,查看费用核算与独立 AI 代码验收报告。</p>
|
||||
</div>
|
||||
<button class="secondary" @click="load">刷新</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<div v-if="success" class="alert success">{{ success }}</div>
|
||||
<section class="panel form-panel" style="margin-bottom: 22px">
|
||||
<h3>独立 AI 代码验收</h3>
|
||||
<p class="muted">
|
||||
开发完成后自动复制实际源码,在独立 gVisor 环境检查、构建和测试,再由独立
|
||||
AI 会话审核。费用报告与代码验收分别保留,仅管理员可见。
|
||||
</p>
|
||||
<form
|
||||
v-if="
|
||||
store.user?.permissions.some((p) =>
|
||||
['models:write', 'settings:write'].includes(p),
|
||||
)
|
||||
"
|
||||
@submit.prevent="saveReviewConfiguration"
|
||||
>
|
||||
<div class="form-row">
|
||||
<label
|
||||
>自动验收<select v-model="reviewConfiguration.enabled">
|
||||
<option :value="true">启用</option>
|
||||
<option :value="false">关闭新任务自动验收</option>
|
||||
</select></label
|
||||
><label
|
||||
>验收模型<select v-model="reviewConfiguration.modelId">
|
||||
<option value="">跟随开发模型,使用独立验收会话</option>
|
||||
<option
|
||||
v-for="model in reviewModels"
|
||||
:key="model.id"
|
||||
:value="model.id"
|
||||
>
|
||||
{{ model.name }} · {{ model.provider_name }}
|
||||
</option>
|
||||
</select></label
|
||||
>
|
||||
</div>
|
||||
<label
|
||||
>配置原因<input
|
||||
v-model="reviewConfiguration.reason"
|
||||
required
|
||||
maxlength="500" /></label
|
||||
><button class="secondary" :disabled="busy">保存验收配置</button>
|
||||
</form>
|
||||
<p v-else class="muted">
|
||||
{{
|
||||
reviewConfiguration.enabled ? "已启用自动代码验收" : "自动验收已关闭"
|
||||
}},你可查看历史记录与报告。
|
||||
</p>
|
||||
</section>
|
||||
<section v-if="queue" class="panel form-panel" style="margin-bottom: 22px">
|
||||
<h3>开发队列与并发</h3>
|
||||
<p style="margin-top: 12px">
|
||||
执行中 {{ queue.running }} · 排队 {{ queue.queued }} · 待核对占用
|
||||
{{ queue.reviewSlots }} 个执行位,系统将在安全等待期后自动核算释放
|
||||
</p>
|
||||
<p class="muted">
|
||||
平台上限 {{ queue.config.max_concurrent }} 个项目 · 当前就绪执行端容量
|
||||
{{ queue.execution.workerCapacity || 0 }} ·
|
||||
实际并行数量同时受这两个额度限制。
|
||||
</p>
|
||||
<div
|
||||
class="alert"
|
||||
:class="queue.execution.ready ? 'success' : 'info'"
|
||||
style="margin-top: 14px"
|
||||
>
|
||||
{{ queue.execution.reason }}
|
||||
</div>
|
||||
<form
|
||||
v-if="store.user?.permissions.includes('queue:manage')"
|
||||
@submit.prevent="saveQueue"
|
||||
style="margin-top: 18px"
|
||||
>
|
||||
<div class="form-row">
|
||||
<label
|
||||
>同时执行的项目数<input
|
||||
v-model.number="config.maxConcurrent"
|
||||
type="number"
|
||||
min="1"
|
||||
max="64"
|
||||
required /></label
|
||||
><label
|
||||
>付费优先<select v-model="config.priorityEnabled">
|
||||
<option :value="false">关闭</option>
|
||||
<option :value="true">开放购买</option>
|
||||
</select></label
|
||||
><label
|
||||
>每个任务优先费 · CNY<input
|
||||
v-model="config.priorityPrice"
|
||||
type="number"
|
||||
min="0.00000001"
|
||||
step="0.00000001"
|
||||
required
|
||||
/></label>
|
||||
</div>
|
||||
<label
|
||||
>变更原因<input
|
||||
v-model="config.reason"
|
||||
maxlength="500"
|
||||
required
|
||||
placeholder="填写本次调度配置调整原因" /></label
|
||||
><button class="primary" :disabled="busy">保存调度规则</button>
|
||||
</form>
|
||||
<p class="muted" style="margin-top: 14px">
|
||||
排序:管理员指定下一位 → 人工优先级 → 已购买优先权 →
|
||||
同级按提交时间。降低并发不打断正在运行的项目;异常任务进入自动核算,核算结束后释放执行位。
|
||||
</p>
|
||||
</section>
|
||||
<section class="panel table-panel">
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>项目 / 用户</th>
|
||||
<th>任务 ID</th>
|
||||
<th>状态</th>
|
||||
<th>队列优先级</th>
|
||||
<th>已结算 / 预算</th>
|
||||
<th>错误</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="t in tasks" :key="t.id">
|
||||
<td>
|
||||
{{ t.project_name }}<small class="block">{{ t.email }}</small>
|
||||
</td>
|
||||
<td class="truncate" :title="t.id">{{ t.id }}</td>
|
||||
<td>{{ t.status }}</td>
|
||||
<td>
|
||||
{{
|
||||
t.run_next
|
||||
? "管理员指定下一位"
|
||||
: t.paid_priority
|
||||
? "付费优先"
|
||||
: "普通"
|
||||
}}<small class="block">人工权重 {{ t.admin_priority }}</small>
|
||||
</td>
|
||||
<td>¥{{ t.spent }} / ¥{{ t.budget }}</td>
|
||||
<td class="audit-detail">{{ t.error }}</td>
|
||||
<td>
|
||||
<div
|
||||
v-if="
|
||||
t.status === 'QUEUED' &&
|
||||
store.user?.permissions.includes('tasks:manage')
|
||||
"
|
||||
class="table-actions"
|
||||
>
|
||||
<button class="link" :disabled="busy" @click="prioritize(t)">
|
||||
调整优先级
|
||||
</button>
|
||||
<button
|
||||
class="link"
|
||||
:disabled="busy || !queue?.execution.ready"
|
||||
@click="prioritize(t, true)"
|
||||
>
|
||||
下一位执行
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
class="link"
|
||||
:disabled="reportBusy"
|
||||
@click="viewReports(t)"
|
||||
>
|
||||
核算记录与报告
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!tasks.length">
|
||||
<td class="empty" colspan="7">暂无开发任务</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="reportTask" class="panel form-panel" style="margin-top: 22px">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<h3>费用核算 · {{ reportTask.project_name }}</h3>
|
||||
<p class="muted">
|
||||
报告和内部凭据仅管理员可见。核算不代表网站已生成或测试通过。
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
class="secondary"
|
||||
:disabled="reportBusy"
|
||||
@click="viewReports(reportTask)"
|
||||
>
|
||||
刷新报告
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="reportBusy" class="muted">正在加载…</p>
|
||||
<p v-else-if="!reports.length" class="empty">
|
||||
本轮暂未生成报告。开发结束或暂停后自动生成,异常任务先等待工具安全退出。
|
||||
</p>
|
||||
<article
|
||||
v-for="r in reports"
|
||||
:key="r.id"
|
||||
style="
|
||||
margin-top: 18px;
|
||||
border-top: 1px solid var(--border);
|
||||
padding-top: 18px;
|
||||
"
|
||||
>
|
||||
<div class="panel-heading">
|
||||
<b
|
||||
>第 {{ r.task_attempt }} 次执行 ·
|
||||
{{
|
||||
r.status === "COMPLETED"
|
||||
? "报告已生成"
|
||||
: r.status === "RUNNING"
|
||||
? "AI 分析中"
|
||||
: "报告生成异常"
|
||||
}}</b
|
||||
><button class="secondary" @click="downloadReport(r)">
|
||||
下载 JSON 报告
|
||||
</button>
|
||||
</div>
|
||||
<p>
|
||||
用户已确认费用 ¥{{ r.confirmed_amount }} · 自动核算
|
||||
{{
|
||||
r.automatic_settlement ? "已完成,剩余预留已释放" : "无异常追加核算"
|
||||
}}
|
||||
· 报告模型成本
|
||||
{{ r.model_cost == null ? "未确认" : "¥" + r.model_cost }}(平台承担)
|
||||
</p>
|
||||
<div v-if="r.error" class="alert info">{{ r.error }}</div>
|
||||
<pre style="white-space: pre-wrap; overflow-wrap: anywhere">{{
|
||||
r.report || "AI 报告尚不可用,下面的系统凭据可供核查。"
|
||||
}}</pre>
|
||||
<details>
|
||||
<summary>查看系统核算与工作区检查凭据</summary>
|
||||
<pre style="white-space: pre-wrap; overflow-wrap: anywhere">{{
|
||||
evidence(r.evidence)
|
||||
}}</pre>
|
||||
</details>
|
||||
</article>
|
||||
</section>
|
||||
<section v-if="reportTask" class="panel form-panel" style="margin-top: 22px">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<h3>独立代码验收 · {{ reportTask.project_name }}</h3>
|
||||
<p class="muted">
|
||||
结论绑定源码指纹;开发 AI 自述不能代替实际检查。重新验收会新增版本。
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
v-if="
|
||||
reportTask.status === 'COMPLETED' &&
|
||||
store.user?.permissions.some((p) =>
|
||||
['tasks:manage', 'models:write'].includes(p),
|
||||
)
|
||||
"
|
||||
class="secondary"
|
||||
:disabled="
|
||||
busy ||
|
||||
codeReviews.some((r) => ['QUEUED', 'RUNNING'].includes(r.status))
|
||||
"
|
||||
@click="requestCodeReview"
|
||||
>
|
||||
重新验收当前代码
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="!codeReviews.length" class="empty">
|
||||
暂未生成代码验收记录。项目最新一轮开发完成后自动排队。
|
||||
</p>
|
||||
<article
|
||||
v-for="review in codeReviews"
|
||||
:key="review.id"
|
||||
style="
|
||||
margin-top: 18px;
|
||||
border-top: 1px solid var(--border);
|
||||
padding-top: 18px;
|
||||
"
|
||||
>
|
||||
<div class="panel-heading">
|
||||
<b
|
||||
>第 {{ review.revision }} 版 ·
|
||||
{{
|
||||
review.status === "QUEUED"
|
||||
? "等待验收"
|
||||
: review.status === "RUNNING"
|
||||
? "正在隔离环境验收"
|
||||
: reviewVerdict(review.verdict)
|
||||
}}</b
|
||||
><button class="secondary" @click="downloadReport(review)">
|
||||
下载验收 JSON
|
||||
</button>
|
||||
</div>
|
||||
<p class="muted">
|
||||
源码指纹
|
||||
<code style="overflow-wrap: anywhere">{{
|
||||
review.source_hash || "等待创建快照"
|
||||
}}</code>
|
||||
</p>
|
||||
<p>
|
||||
AI 建议:{{ reviewVerdict(review.ai_verdict) }} · 验收模型费用
|
||||
{{
|
||||
review.model_cost == null ? "未确认" : "¥" + review.model_cost
|
||||
}}(平台承担)
|
||||
</p>
|
||||
<div v-if="review.error" class="alert info">{{ review.error }}</div>
|
||||
<div v-if="actualChecks(review.evidence).length" class="table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>独立检查</th>
|
||||
<th>实际结果</th>
|
||||
<th>退出码</th>
|
||||
<th>说明</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="step in actualChecks(review.evidence)" :key="step.name">
|
||||
<td>{{ step.name }}</td>
|
||||
<td>{{ checkStatus(step.status) }}</td>
|
||||
<td>{{ step.exitCode ?? "—" }}</td>
|
||||
<td>
|
||||
{{
|
||||
step.reason ||
|
||||
(step.truncated
|
||||
? "日志已截断,详见原始凭据"
|
||||
: "详见原始检查凭据")
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="muted">
|
||||
以下为 AI
|
||||
分析建议;构建与测试是否执行、是否通过,以以上独立检查及原始记录为准。未执行的浏览器检查不算通过。
|
||||
</p>
|
||||
<pre style="white-space: pre-wrap; overflow-wrap: anywhere">{{
|
||||
review.report
|
||||
? evidence(review.report)
|
||||
: "验收报告尚未生成,可查看当前阶段与系统检查凭据。"
|
||||
}}</pre>
|
||||
<details>
|
||||
<summary>查看实际源码、构建与测试证据</summary>
|
||||
<pre style="white-space: pre-wrap; overflow-wrap: anywhere">{{
|
||||
evidence(review.evidence)
|
||||
}}</pre>
|
||||
</details>
|
||||
</article>
|
||||
</section>
|
||||
<div class="alert info">
|
||||
系统只按已确认 usage
|
||||
向用户结算,未知上游费用及报告模型成本由平台承担,不根据 AI
|
||||
估算追加扣款。异常任务等待 3 分钟后自动释放剩余预算并结束;AI
|
||||
只生成内部分析报告,不执行项目工具。
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,200 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, computed } from "vue";
|
||||
import { useSession } from "../store";
|
||||
import { api } from "../api";
|
||||
import {
|
||||
ArrowUpRight,
|
||||
Plus,
|
||||
FolderKanban,
|
||||
Code2,
|
||||
Server,
|
||||
ShieldCheck,
|
||||
ArrowRight,
|
||||
Check,
|
||||
Layers,
|
||||
Cloud as CloudIcon,
|
||||
} from "lucide-vue-next";
|
||||
const store = useSession(),
|
||||
projects = ref<any[]>([]),
|
||||
error = ref(""),
|
||||
loading = ref(true);
|
||||
const active = computed(() =>
|
||||
projects.value.filter((p) => p.status === "DRAFT"),
|
||||
);
|
||||
onMounted(async () => {
|
||||
try {
|
||||
projects.value = await api("/projects");
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
const modules = [
|
||||
{
|
||||
icon: Code2,
|
||||
name: "AI 开发中心",
|
||||
text: "多模型协作,从需求到代码",
|
||||
tag: "已接入 · 需配置模型与隔离环境",
|
||||
available: true,
|
||||
},
|
||||
{
|
||||
icon: Server,
|
||||
name: "云托管与 Pages",
|
||||
text: "持续运行、版本部署与域名",
|
||||
tag: "第三至五阶段",
|
||||
},
|
||||
{
|
||||
icon: Layers,
|
||||
name: "数据库与存储",
|
||||
text: "持久化数据、独立资源与备份",
|
||||
tag: "第四阶段",
|
||||
},
|
||||
];
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<div class="eyebrow">WORKSPACE OVERVIEW</div>
|
||||
<h1>你好,{{ store.user?.displayName }} <span class="wave">✦</span></h1>
|
||||
<p>从一个想法开始,构建属于你的下一步。</p>
|
||||
</div>
|
||||
<RouterLink to="/projects?new=1" class="primary"
|
||||
><Plus :size="17" />创建项目</RouterLink
|
||||
>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<section class="welcome-banner">
|
||||
<div>
|
||||
<span class="banner-tag"><i />你的创造空间,已就绪</span>
|
||||
<h2>让想法,有一个开始。</h2>
|
||||
<p>
|
||||
整理需求,管理项目,在同一个工作空间中持续创造。<br />下一次灵感,从这里生长。
|
||||
</p>
|
||||
<RouterLink to="/projects?new=1"
|
||||
>创建你的项目 <ArrowUpRight :size="17"
|
||||
/></RouterLink>
|
||||
</div>
|
||||
<div class="banner-art" aria-hidden="true">
|
||||
<div class="orbit one"></div>
|
||||
<div class="orbit two"></div>
|
||||
<div class="art-card back"><span></span><span></span><span></span></div>
|
||||
<div class="art-card front">
|
||||
<div class="art-icon"></></div>
|
||||
<b>Build something great.</b><span></span><span></span>
|
||||
<div class="art-check"><Check :size="12" />Workspace ready</div>
|
||||
</div>
|
||||
<div class="spark a">✦</div>
|
||||
<div class="spark b">✧</div>
|
||||
<div class="art-float"><CloudIcon /></div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="stats">
|
||||
<div class="stat-card">
|
||||
<div><span>我的项目</span><FolderKanban :size="18" /></div>
|
||||
<strong>{{ loading ? "—" : projects.length }}</strong
|
||||
><small>已保存到你的工作空间</small>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div><span>待开发项目</span><Code2 :size="18" /></div>
|
||||
<strong>{{ loading ? "—" : active.length }}</strong
|
||||
><small>需求已记录,等待下一步</small>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div><span>云端运行服务</span><Server :size="18" /></div>
|
||||
<strong class="text-stat">未接入</strong
|
||||
><small>基础设施服务尚未连接</small>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div><span>账户安全</span><ShieldCheck :size="18" /></div>
|
||||
<strong class="text-stat good">已保护 <Check :size="17" /></strong
|
||||
><small>密码加密 · 可撤销会话</small>
|
||||
</div>
|
||||
</section>
|
||||
<div class="dashboard-grid">
|
||||
<section class="panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<h3>
|
||||
最近项目 <span class="count">{{ projects.length }}</span>
|
||||
</h3>
|
||||
<p>你的创意与正在酝酿的计划</p>
|
||||
</div>
|
||||
<RouterLink to="/projects" class="text-link"
|
||||
>查看全部 <ArrowUpRight :size="14"
|
||||
/></RouterLink>
|
||||
</div>
|
||||
<div v-if="loading" class="empty">正在加载项目…</div>
|
||||
<div class="empty project-empty" v-else-if="!projects.length">
|
||||
<div class="empty-icon"><FolderKanban :size="29" /></div>
|
||||
<h4>你的下一个作品,从这里开始</h4>
|
||||
<p>创建第一个项目,保存需求与技术方案。</p>
|
||||
<RouterLink to="/projects?new=1" class="secondary"
|
||||
><Plus :size="16" />创建第一个项目</RouterLink
|
||||
>
|
||||
</div>
|
||||
<RouterLink
|
||||
v-for="p in projects.slice(0, 4)"
|
||||
:key="p.id"
|
||||
:to="'/projects?edit=' + p.id"
|
||||
class="project-row"
|
||||
><span class="project-icon"><FolderKanban :size="20" /></span>
|
||||
<div>
|
||||
<b>{{ p.name }}</b
|
||||
><small
|
||||
>{{ p.stack }} ·
|
||||
{{ new Date(p.created_at).toLocaleDateString() }}</small
|
||||
>
|
||||
</div>
|
||||
<span class="status">{{
|
||||
p.status === "DRAFT" ? "草稿" : "已归档"
|
||||
}}</span
|
||||
><ArrowUpRight :size="16"
|
||||
/></RouterLink>
|
||||
</section>
|
||||
<section class="panel getting-started">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<h3>开始使用</h3>
|
||||
<p>为你的工作空间做好准备</p>
|
||||
</div>
|
||||
<span class="step-badge">使用指南</span>
|
||||
</div>
|
||||
<RouterLink to="/account" class="guide-step"
|
||||
><span class="step done"><Check :size="15" /></span>
|
||||
<div><b>创建你的账户</b><small>独立、安全的个人空间</small></div>
|
||||
<Check :size="15" class="good" /></RouterLink
|
||||
><RouterLink to="/projects?new=1" class="guide-step"
|
||||
><span class="step">2</span>
|
||||
<div><b>创建第一个项目</b><small>描述需求,选择技术栈</small></div>
|
||||
<ArrowRight :size="15" /></RouterLink
|
||||
><RouterLink to="/account" class="guide-step"
|
||||
><span class="step">3</span>
|
||||
<div><b>检查账户安全</b><small>查看登录记录与设备会话</small></div>
|
||||
<ArrowRight :size="15"
|
||||
/></RouterLink>
|
||||
<div class="notice">
|
||||
<span class="notice-dot"></span>
|
||||
<div>
|
||||
<b>工作空间公告</b>
|
||||
<p>{{ store.settings.announcement || "暂无公告" }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div class="section-title">
|
||||
<h3>一个工作空间,更多可能</h3>
|
||||
<span>按计划逐步开放</span>
|
||||
</div>
|
||||
<section class="capabilities">
|
||||
<div class="capability" v-for="m in modules" :key="m.name">
|
||||
<span class="cap-icon"><component :is="m.icon" :size="21" /></span>
|
||||
<h4>{{ m.name }}</h4>
|
||||
<p>{{ m.text }}</p>
|
||||
<RouterLink v-if="m.available" to="/develop" class="text-link"
|
||||
>前往 AI 开发 <ArrowUpRight :size="14"
|
||||
/></RouterLink>
|
||||
<span class="phase-tag" v-else>{{ m.tag }} · 尚未开放</span>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,626 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, reactive, ref, watch } from "vue";
|
||||
import { api, body } from "../api";
|
||||
const projects = ref<any[]>([]),
|
||||
models = ref<any[]>([]),
|
||||
tasks = ref<any[]>([]),
|
||||
events = ref<any[]>([]),
|
||||
selected = ref<any>(null),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false),
|
||||
filePath = ref("."),
|
||||
files = ref<any[]>([]),
|
||||
content = ref(""),
|
||||
editingPath = ref(""),
|
||||
versions = ref<any[]>([]);
|
||||
const fileBusy = ref(false),
|
||||
fileLoaded = ref(false),
|
||||
fileError = ref("");
|
||||
let fileGeneration = 0;
|
||||
let fileTaskSignature = "";
|
||||
const execution = ref<any>({
|
||||
ready: false,
|
||||
state: "CHECKING",
|
||||
reason: "正在检查开发执行环境…",
|
||||
filesConfigured: false,
|
||||
});
|
||||
const queue = ref<any>({
|
||||
config: { priority_enabled: false, priority_price: "0", max_concurrent: 0 },
|
||||
positions: [],
|
||||
running: 0,
|
||||
reviewSlots: 0,
|
||||
queued: 0,
|
||||
});
|
||||
const priorityKeys = new Map<string, string>();
|
||||
function position(id: string) {
|
||||
return queue.value.positions.find((p: any) => p.id === id)?.position;
|
||||
}
|
||||
const sandboxApi = (path: string, options: RequestInit = {}) =>
|
||||
api(path, { signal: AbortSignal.timeout(150000), ...options });
|
||||
const form = reactive({
|
||||
projectId: "",
|
||||
modelId: "",
|
||||
prompt: "",
|
||||
budget: "20",
|
||||
idempotencyKey: crypto.randomUUID(),
|
||||
});
|
||||
let timer: ReturnType<typeof setInterval> | undefined;
|
||||
const labels: Record<string, string> = {
|
||||
QUEUED: "排队中",
|
||||
RUNNING: "执行中",
|
||||
PAUSED: "已暂停",
|
||||
COMPLETED: "已结束",
|
||||
CANCELLED: "已取消",
|
||||
FAILED: "失败",
|
||||
REVIEW_REQUIRED: "自动核算中",
|
||||
};
|
||||
async function load() {
|
||||
try {
|
||||
[tasks.value, queue.value] = await Promise.all([
|
||||
api("/tasks"),
|
||||
api("/queue"),
|
||||
]);
|
||||
execution.value = queue.value.execution;
|
||||
const projectTasks = tasks.value.filter(
|
||||
(t) => t.project_id === form.projectId,
|
||||
);
|
||||
const signature = projectTasks
|
||||
.map((t) => `${t.id}:${t.status}:${t.step_count}`)
|
||||
.join("|");
|
||||
if (
|
||||
signature !== fileTaskSignature ||
|
||||
projectTasks.some((t) => t.status === "RUNNING")
|
||||
) {
|
||||
fileTaskSignature = signature;
|
||||
if (execution.value.filesConfigured && !fileBusy.value) void list();
|
||||
}
|
||||
const id = selected.value?.id;
|
||||
if (id) {
|
||||
const [task, log] = await Promise.all([
|
||||
api("/tasks/" + id),
|
||||
api("/tasks/" + id + "/events"),
|
||||
]);
|
||||
if (selected.value?.id === id) {
|
||||
const changed =
|
||||
selected.value.status !== task.status ||
|
||||
events.value.at(-1)?.id !== log.at(-1)?.id;
|
||||
selected.value = task;
|
||||
events.value = log;
|
||||
if (changed && execution.value.filesConfigured && !fileBusy.value)
|
||||
void list();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
execution.value = {
|
||||
ready: false,
|
||||
state: "UNKNOWN",
|
||||
reason: "暂时无法确认执行服务状态,请刷新后重试。",
|
||||
filesConfigured: false,
|
||||
};
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function select(t: any) {
|
||||
selected.value = t;
|
||||
events.value = [];
|
||||
form.projectId = t.project_id;
|
||||
await load();
|
||||
}
|
||||
async function start() {
|
||||
if (!execution.value.ready) {
|
||||
error.value = execution.value.reason;
|
||||
return;
|
||||
}
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
selected.value = await api("/tasks", { method: "POST", body: body(form) });
|
||||
form.idempotencyKey = crypto.randomUUID();
|
||||
success.value = "执行服务已连接,任务已提交并预留预算。";
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function action(a: string) {
|
||||
if (a === "cancel" && !confirm("确认取消任务?当前调用会先结算实际费用。"))
|
||||
return;
|
||||
busy.value = true;
|
||||
try {
|
||||
await api("/tasks/" + selected.value.id + "/" + a, { method: "POST" });
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function buyPriority() {
|
||||
const task = selected.value;
|
||||
if (!task || !execution.value.ready) return;
|
||||
const price = queue.value.config.priority_price;
|
||||
if (
|
||||
!confirm(
|
||||
`为当前任务支付 ¥${price} 购买排队优先权?优先费独立于 AI 开发预算,管理员人工调度优先于付费优先,不抢占正在执行的任务。首次执行前取消会自动退费,开始执行后不自动退费;不保证具体开始时间。`,
|
||||
)
|
||||
)
|
||||
return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
if (!priorityKeys.has(task.id))
|
||||
priorityKeys.set(task.id, crypto.randomUUID());
|
||||
const order = await api(`/tasks/${task.id}/priority`, {
|
||||
method: "POST",
|
||||
body: body({
|
||||
expectedPrice: price,
|
||||
idempotencyKey: priorityKeys.get(task.id),
|
||||
}),
|
||||
});
|
||||
success.value =
|
||||
order.status === "REFUNDED"
|
||||
? "该优先权订单已退款"
|
||||
: "已获得本任务排队优先权,费用 ¥" + order.amount;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function list() {
|
||||
if (!form.projectId || fileBusy.value || !execution.value.filesConfigured)
|
||||
return;
|
||||
const project = form.projectId,
|
||||
directory = filePath.value,
|
||||
generation = fileGeneration;
|
||||
fileBusy.value = true;
|
||||
fileError.value = "";
|
||||
try {
|
||||
const result = await sandboxApi(
|
||||
"/projects/" + project + "/files?path=" + encodeURIComponent(directory),
|
||||
);
|
||||
if (result.error) throw new Error(result.error);
|
||||
if (
|
||||
generation === fileGeneration &&
|
||||
project === form.projectId &&
|
||||
directory === filePath.value
|
||||
) {
|
||||
files.value = result.files || [];
|
||||
fileLoaded.value = true;
|
||||
if (!editingPath.value && !content.value) {
|
||||
const first =
|
||||
files.value.find(
|
||||
(f) => !f.directory && !f.symlink && f.name === "index.html",
|
||||
) ||
|
||||
files.value.find(
|
||||
(f) =>
|
||||
!f.directory &&
|
||||
!f.symlink &&
|
||||
/\.(html|css|vue|svelte|tsx?|jsx?|py|java|go|rs|php)$/i.test(
|
||||
f.name,
|
||||
),
|
||||
);
|
||||
if (first) void openFile(first);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (generation === fileGeneration) fileError.value = (e as Error).message;
|
||||
} finally {
|
||||
fileBusy.value = false;
|
||||
if (
|
||||
generation !== fileGeneration ||
|
||||
project !== form.projectId ||
|
||||
directory !== filePath.value
|
||||
)
|
||||
void list();
|
||||
}
|
||||
}
|
||||
async function openFile(f: any) {
|
||||
const project = form.projectId,
|
||||
generation = fileGeneration;
|
||||
const path = (filePath.value === "." ? "" : filePath.value + "/") + f.name;
|
||||
if (f.directory) {
|
||||
filePath.value = path;
|
||||
await list();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await sandboxApi(
|
||||
"/projects/" + project + "/file?path=" + encodeURIComponent(path),
|
||||
);
|
||||
if (result.error) throw new Error(result.error);
|
||||
if (generation === fileGeneration && project === form.projectId) {
|
||||
content.value = result.content;
|
||||
editingPath.value = path;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function saveFile() {
|
||||
try {
|
||||
const r = await sandboxApi("/projects/" + form.projectId + "/file", {
|
||||
method: "PUT",
|
||||
body: body({ path: editingPath.value, content: content.value }),
|
||||
});
|
||||
if (r.error) throw new Error(r.error);
|
||||
success.value = "文件已写入隔离工作区";
|
||||
await list();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function version(save = false) {
|
||||
try {
|
||||
let result;
|
||||
if (save) {
|
||||
const message = prompt("版本说明");
|
||||
if (!message) return;
|
||||
result = await sandboxApi("/projects/" + form.projectId + "/versions", {
|
||||
method: "POST",
|
||||
body: body({ message }),
|
||||
});
|
||||
} else
|
||||
result = await sandboxApi("/projects/" + form.projectId + "/versions");
|
||||
if (result.error) throw new Error(result.error);
|
||||
versions.value = result.versions || [];
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function download() {
|
||||
if (!form.projectId) return;
|
||||
busy.value = true;
|
||||
try {
|
||||
const res = await fetch("/api/projects/" + form.projectId + "/source", {
|
||||
headers: { Authorization: "Bearer " + sessionStorage.getItem("session") },
|
||||
signal: AbortSignal.timeout(150000),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json();
|
||||
throw new Error(data.message || "下载失败");
|
||||
}
|
||||
const url = URL.createObjectURL(await res.blob()),
|
||||
a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = "project-" + form.projectId + ".zip";
|
||||
a.click();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => form.projectId,
|
||||
() => {
|
||||
fileGeneration++;
|
||||
files.value = [];
|
||||
content.value = "";
|
||||
editingPath.value = "";
|
||||
versions.value = [];
|
||||
filePath.value = ".";
|
||||
fileLoaded.value = false;
|
||||
fileError.value = "";
|
||||
void list();
|
||||
},
|
||||
);
|
||||
watch(
|
||||
() => execution.value.filesConfigured,
|
||||
(configured) => {
|
||||
if (configured) void list();
|
||||
},
|
||||
);
|
||||
onMounted(async () => {
|
||||
try {
|
||||
[projects.value, models.value] = await Promise.all([
|
||||
api("/projects"),
|
||||
api("/models"),
|
||||
]);
|
||||
form.projectId = projects.value.find((p) => p.status === "DRAFT")?.id || "";
|
||||
form.modelId = models.value.find((m) => m.tools_enabled)?.id || "";
|
||||
await load();
|
||||
timer = setInterval(() => {
|
||||
if (!document.hidden) load();
|
||||
}, 3000);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
});
|
||||
onUnmounted(() => clearInterval(timer));
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">AI DEVELOPMENT WORKSPACE</span>
|
||||
<h1>AI 开发</h1>
|
||||
<p>模型、工具、文件与预算,在同一个持久化任务中协作。</p>
|
||||
</div>
|
||||
<button class="secondary" @click="load">刷新状态</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error" role="alert">
|
||||
{{ error }} <button class="link" @click="error = ''">关闭</button>
|
||||
</div>
|
||||
<div v-if="success" class="alert success">{{ success }}</div>
|
||||
<div
|
||||
class="alert"
|
||||
:class="execution.ready ? 'success' : 'info'"
|
||||
role="status"
|
||||
>
|
||||
<strong
|
||||
>开发执行环境 ·
|
||||
{{
|
||||
execution.ready
|
||||
? "已就绪"
|
||||
: execution.state === "CHECKING"
|
||||
? "检查中"
|
||||
: "未就绪"
|
||||
}}</strong
|
||||
>
|
||||
<p>{{ execution.reason }}</p>
|
||||
<p v-if="queue.config.max_concurrent">
|
||||
正在执行 {{ queue.running }} / 平台并发
|
||||
{{ queue.config.max_concurrent }} · 排队 {{ queue.queued }} 项<span
|
||||
v-if="queue.reviewSlots"
|
||||
>
|
||||
· 待核对占用 {{ queue.reviewSlots }} 个执行位</span
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
<div class="two-columns">
|
||||
<section class="panel form-panel">
|
||||
<h3>发起开发任务</h3>
|
||||
<p class="muted">预算先预留,每轮按任务价格快照结算实际 usage。</p>
|
||||
<form @submit.prevent="start">
|
||||
<label
|
||||
>项目<select v-model="form.projectId" required>
|
||||
<option value="" disabled>先在项目管理创建项目</option>
|
||||
<option
|
||||
v-for="p in projects.filter((p) => p.status === 'DRAFT')"
|
||||
:key="p.id"
|
||||
:value="p.id"
|
||||
>
|
||||
{{ p.name }} · {{ p.stack }}
|
||||
</option>
|
||||
</select></label
|
||||
><label
|
||||
>开发模型<select v-model="form.modelId" required>
|
||||
<option value="" disabled>等待管理员开放支持工具的模型</option>
|
||||
<option
|
||||
v-for="m in models.filter((m) => m.tools_enabled)"
|
||||
:key="m.id"
|
||||
:value="m.id"
|
||||
>
|
||||
{{ m.name }} · {{ m.provider_name }}
|
||||
</option></select
|
||||
><small v-if="form.modelId"
|
||||
>输入 {{ models.find((m) => m.id === form.modelId)?.input_price }} /
|
||||
输出
|
||||
{{ models.find((m) => m.id === form.modelId)?.output_price }} CNY /
|
||||
百万 Token</small
|
||||
></label
|
||||
><label
|
||||
>本轮需求<textarea
|
||||
v-model="form.prompt"
|
||||
rows="4"
|
||||
maxlength="10000"
|
||||
required
|
||||
placeholder="描述要开发或修改的功能。任务会保留该项目最近已完成的对话历史。"
|
||||
/></label
|
||||
><label
|
||||
>预算上限 · CNY<input
|
||||
v-model="form.budget"
|
||||
type="number"
|
||||
min="0.00000001"
|
||||
step="0.00000001"
|
||||
required /></label
|
||||
><button
|
||||
class="primary"
|
||||
:disabled="
|
||||
busy || !form.modelId || !form.projectId || !execution.ready
|
||||
"
|
||||
>
|
||||
预留预算并提交
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
<section class="panel">
|
||||
<div class="panel-heading">
|
||||
<h3>我的任务</h3>
|
||||
<span class="muted">最近 100 条</span>
|
||||
</div>
|
||||
<div class="task-list">
|
||||
<button
|
||||
v-for="t in tasks"
|
||||
:key="t.id"
|
||||
class="task-item"
|
||||
:class="{ chosen: selected?.id === t.id }"
|
||||
@click="select(t)"
|
||||
>
|
||||
<b>{{ t.project_name }}</b
|
||||
><span class="status">{{ labels[t.status] || t.status }}</span>
|
||||
<small v-if="t.status === 'QUEUED'"
|
||||
>当前第 {{ position(t.id) || "—" }} 位 ·
|
||||
{{
|
||||
t.run_next
|
||||
? "管理员指定下一位"
|
||||
: t.paid_priority
|
||||
? "付费优先"
|
||||
: "普通队列"
|
||||
}}</small
|
||||
>
|
||||
<p>{{ t.prompt }}</p>
|
||||
<small
|
||||
>费用 ¥{{ t.spent }} / 预算 ¥{{ t.budget }} ·
|
||||
{{ t.step_count }} 轮</small
|
||||
>
|
||||
</button>
|
||||
<div v-if="!tasks.length" class="empty">尚无开发任务</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<section v-if="selected" class="panel table-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<h3>任务日志 · {{ labels[selected.status] }}</h3>
|
||||
<p>当前消费 ¥{{ selected.spent }} / 预算 ¥{{ selected.budget }}</p>
|
||||
<p v-if="selected.status === 'QUEUED'">
|
||||
当前排队第 {{ position(selected.id) || "—" }} 位<span
|
||||
v-if="selected.paid_priority"
|
||||
>
|
||||
· 已购买优先权(独立计费)</span
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
<div class="table-actions">
|
||||
<button
|
||||
v-if="
|
||||
selected.status === 'QUEUED' &&
|
||||
!selected.paid_priority &&
|
||||
queue.config.priority_enabled
|
||||
"
|
||||
class="primary"
|
||||
:disabled="busy || !execution.ready"
|
||||
@click="buyPriority"
|
||||
>
|
||||
¥{{ queue.config.priority_price }} 购买优先权
|
||||
</button>
|
||||
<button
|
||||
v-if="['QUEUED', 'RUNNING'].includes(selected.status)"
|
||||
class="secondary"
|
||||
:disabled="busy"
|
||||
@click="action('pause')"
|
||||
>
|
||||
暂停</button
|
||||
><button
|
||||
v-if="selected.status === 'PAUSED'"
|
||||
class="primary"
|
||||
:disabled="busy || !execution.ready"
|
||||
@click="action('resume')"
|
||||
>
|
||||
继续</button
|
||||
><button
|
||||
v-if="['QUEUED', 'RUNNING', 'PAUSED'].includes(selected.status)"
|
||||
class="secondary"
|
||||
:disabled="busy"
|
||||
@click="action('cancel')"
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="selected.error" class="alert info">{{ selected.error }}</div>
|
||||
<div class="event-log">
|
||||
<div v-for="e in events" :key="e.id">
|
||||
<small
|
||||
>{{ new Date(e.created_at).toLocaleTimeString() }} ·
|
||||
{{ e.event }}</small
|
||||
>
|
||||
<pre>{{ e.detail }}</pre>
|
||||
</div>
|
||||
<p v-if="!events.length" class="empty">等待任务事件</p>
|
||||
</div>
|
||||
</section>
|
||||
<section class="panel form-panel">
|
||||
<div class="panel-heading">
|
||||
<h3>项目文件与版本</h3>
|
||||
<button
|
||||
class="secondary"
|
||||
:disabled="busy || !form.projectId"
|
||||
@click="download"
|
||||
>
|
||||
下载源码 ZIP
|
||||
</button>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<select v-model="form.projectId">
|
||||
<option v-for="p in projects" :key="p.id" :value="p.id">
|
||||
{{ p.name }}
|
||||
</option></select
|
||||
><input
|
||||
v-model="filePath"
|
||||
placeholder="相对目录,例如 src"
|
||||
aria-label="目录路径"
|
||||
/><button
|
||||
class="secondary"
|
||||
:disabled="!form.projectId || fileBusy || !execution.filesConfigured"
|
||||
@click="list"
|
||||
>
|
||||
{{ fileBusy ? "读取中…" : "刷新目录" }}</button
|
||||
><button
|
||||
class="secondary"
|
||||
:disabled="!form.projectId"
|
||||
@click="
|
||||
filePath = '.';
|
||||
list();
|
||||
"
|
||||
>
|
||||
根目录
|
||||
</button>
|
||||
</div>
|
||||
<div class="two-columns">
|
||||
<div class="file-tree">
|
||||
<button
|
||||
v-for="f in files"
|
||||
:key="f.name"
|
||||
class="file-entry"
|
||||
@click="openFile(f)"
|
||||
>
|
||||
{{ f.directory ? "▸" : "·" }} {{ f.name
|
||||
}}{{ f.symlink ? "(符号链接)" : "" }}
|
||||
</button>
|
||||
<p v-if="fileBusy" class="muted">正在读取工作区文件…</p>
|
||||
<p v-else-if="fileError" class="alert error">{{ fileError }}</p>
|
||||
<p v-else-if="!files.length" class="muted">
|
||||
{{
|
||||
fileLoaded
|
||||
? "当前目录没有文件。AI 尚未写入源码时,这里会保持为空;任务有费用记录不代表已经生成代码。"
|
||||
: "选择项目后自动读取真实工作区文件。"
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="muted"
|
||||
>文件路径<input
|
||||
v-model="editingPath"
|
||||
placeholder="新建文件路径,例如 src/main.ts" /></label
|
||||
><textarea
|
||||
v-model="content"
|
||||
class="code-editor"
|
||||
rows="14"
|
||||
placeholder="读取或编辑项目文件"
|
||||
maxlength="64000"
|
||||
/><button
|
||||
class="secondary"
|
||||
:disabled="!editingPath || !form.projectId"
|
||||
@click="saveFile"
|
||||
>
|
||||
保存文件
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<button class="secondary" :disabled="!form.projectId" @click="version()">
|
||||
查看版本</button
|
||||
><button
|
||||
class="primary"
|
||||
:disabled="!form.projectId"
|
||||
@click="version(true)"
|
||||
>
|
||||
保存 Git 版本
|
||||
</button>
|
||||
</div>
|
||||
<div v-for="v in versions" :key="v.commit" class="version-row">
|
||||
<code>{{ v.commit.slice(0, 12) }}</code> {{ v.message }}
|
||||
</div>
|
||||
<div class="alert info">
|
||||
文件、终端和版本操作需要连接 Kubernetes Sandbox
|
||||
Gateway。未配置或集群未就绪会返回真实错误,不会在控制面执行命令。
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,413 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref } from "vue";
|
||||
import { api, body } from "../api";
|
||||
import { Globe, RefreshCw, ExternalLink, Copy } from "lucide-vue-next";
|
||||
const projects = ref<any[]>([]),
|
||||
project = ref(""),
|
||||
services = ref<any[]>([]),
|
||||
service = ref(""),
|
||||
domains = ref<any[]>([]),
|
||||
claims = ref<any[]>([]),
|
||||
events = ref<any[]>([]),
|
||||
root = ref(""),
|
||||
target = ref(""),
|
||||
slug = ref(""),
|
||||
custom = ref(""),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false);
|
||||
const labels: Record<string, string> = {
|
||||
VERIFIED: "已验证 · 待配置",
|
||||
QUEUED: "等待配置",
|
||||
PROVISIONING: "正在配置",
|
||||
WAITING_DNS: "等待解析",
|
||||
WAITING_TLS: "等待证书",
|
||||
WAITING_ROUTE: "等待入口",
|
||||
ACTIVE: "已生效",
|
||||
ERROR: "配置异常",
|
||||
REMOVING: "解绑中",
|
||||
REMOVED: "已解绑",
|
||||
};
|
||||
let timer: ReturnType<typeof setInterval> | undefined,
|
||||
request = 0;
|
||||
async function load() {
|
||||
if (!project.value) return;
|
||||
const id = ++request,
|
||||
p = project.value;
|
||||
try {
|
||||
const [data, list] = await Promise.all([
|
||||
api(`/projects/${p}/domains`),
|
||||
api(`/projects/${p}/services`),
|
||||
]);
|
||||
if (id !== request) return;
|
||||
domains.value = data.domains;
|
||||
claims.value = data.claims;
|
||||
root.value = data.platformRoot;
|
||||
target.value = data.deliveryTarget;
|
||||
services.value = list.filter((s: any) => s.enabled);
|
||||
if (!services.value.some((s) => s.id === service.value))
|
||||
service.value = services.value[0]?.id || "";
|
||||
} catch (e) {
|
||||
if (id === request) error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
function changed() {
|
||||
service.value = "";
|
||||
domains.value = [];
|
||||
claims.value = [];
|
||||
events.value = [];
|
||||
slug.value = "";
|
||||
custom.value = "";
|
||||
error.value = "";
|
||||
success.value = "";
|
||||
load();
|
||||
}
|
||||
async function submit(kind: string) {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
success.value = "";
|
||||
try {
|
||||
await api(
|
||||
`/projects/${project.value}/domains/` +
|
||||
(kind === "platform" ? "platform" : "claims"),
|
||||
{
|
||||
method: "POST",
|
||||
body: body(
|
||||
kind === "platform"
|
||||
? { serviceId: service.value, slug: slug.value }
|
||||
: { hostname: custom.value },
|
||||
),
|
||||
},
|
||||
);
|
||||
success.value =
|
||||
kind === "platform"
|
||||
? "平台域名已分配,成功发布服务后点击配置上线。"
|
||||
: "验证记录已生成,请添加 TXT 后验证所有权。";
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function action(row: any, kind: string) {
|
||||
if (
|
||||
kind === "remove" &&
|
||||
!confirm(
|
||||
`确认解绑「${row.hostname}」?入口会移除,项目文件和服务保留。平台只删除明确由自己创建的解析记录。`,
|
||||
)
|
||||
)
|
||||
return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
success.value = "";
|
||||
try {
|
||||
const path = `/projects/${project.value}/domains/`;
|
||||
if (kind === "events") events.value = await api(path + row.id + "/events");
|
||||
else {
|
||||
const data = await api(
|
||||
path +
|
||||
(kind === "verify"
|
||||
? `claims/${row.id}/verify`
|
||||
: row.id + (kind === "remove" ? "" : "/" + kind)),
|
||||
{
|
||||
method: kind === "remove" ? "DELETE" : "POST",
|
||||
...(kind === "verify"
|
||||
? { body: body({ serviceId: service.value }) }
|
||||
: {}),
|
||||
},
|
||||
);
|
||||
success.value =
|
||||
data.message ||
|
||||
(kind === "verify" ? "所有权已验证,请点击配置上线。" : "操作已提交");
|
||||
await load();
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function copy(text: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
success.value = "已复制";
|
||||
} catch {
|
||||
error.value = "无法自动复制,请选中记录内容手动复制。";
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
try {
|
||||
projects.value = await api("/projects");
|
||||
project.value = projects.value[0]?.id || "";
|
||||
await load();
|
||||
timer = setInterval(() => {
|
||||
if (!busy.value && !document.hidden) load();
|
||||
}, 5000);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
});
|
||||
onUnmounted(() => clearInterval(timer));
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">PROJECT DOMAINS</span>
|
||||
<h1>项目域名</h1>
|
||||
<p>为项目设置稳定地址,绑定自己的域名,跟踪解析与 HTTPS 状态。</p>
|
||||
</div>
|
||||
<Globe :size="30" />
|
||||
</div>
|
||||
<div v-if="error" class="alert error" role="alert">{{ error }}</div>
|
||||
<div v-if="success" class="alert success" role="status">{{ success }}</div>
|
||||
<div class="toolbar">
|
||||
<label
|
||||
>当前项目<select v-model="project" :disabled="busy" @change="changed">
|
||||
<option v-for="p in projects" :key="p.id" :value="p.id">
|
||||
{{ p.name }}
|
||||
</option>
|
||||
</select></label
|
||||
><button :disabled="busy || !project" @click="load">
|
||||
<RefreshCw :size="16" />刷新
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="!project" class="panel empty">
|
||||
<h3>先创建一个项目</h3>
|
||||
<RouterLink to="/projects" class="text-link">前往我的项目</RouterLink>
|
||||
</div>
|
||||
<template v-else>
|
||||
<section class="panel domain-service">
|
||||
<label
|
||||
>域名指向的项目服务<select v-model="service" :disabled="busy">
|
||||
<option value="" disabled>请先在云托管中配置服务</option>
|
||||
<option v-for="s in services" :key="s.id" :value="s.id">
|
||||
{{ s.name }} · 端口 {{ s.port }}
|
||||
</option>
|
||||
</select></label
|
||||
>
|
||||
<p class="muted">
|
||||
开通入口需要有效托管套餐、网站审核通过,以及成功发布的服务版本。
|
||||
</p>
|
||||
</section>
|
||||
<div class="two-columns">
|
||||
<section class="panel form-panel">
|
||||
<h3>分配平台域名</h3>
|
||||
<p class="muted">正式地址在后续发布时保持稳定。</p>
|
||||
<form @submit.prevent="submit('platform')">
|
||||
<label
|
||||
>项目域名前缀<input
|
||||
v-model="slug"
|
||||
required
|
||||
minlength="3"
|
||||
maxlength="63"
|
||||
pattern="[a-z0-9][a-z0-9-]{1,61}[a-z0-9]"
|
||||
placeholder="例如 my-project"
|
||||
/></label>
|
||||
<p>
|
||||
<code>{{ slug || "项目名" }}.{{ root }}</code>
|
||||
</p>
|
||||
<button class="primary" :disabled="busy || !service || !root">
|
||||
分配地址
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
<section class="panel form-panel">
|
||||
<h3>绑定自定义域名</h3>
|
||||
<p class="muted">先验证域名所有权,再配置入口。支持国际化域名。</p>
|
||||
<form @submit.prevent="submit('custom')">
|
||||
<label
|
||||
>域名<input
|
||||
v-model="custom"
|
||||
required
|
||||
maxlength="253"
|
||||
placeholder="例如 www.example.com" /></label
|
||||
><button class="primary" :disabled="busy">生成 TXT 验证记录</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
<section
|
||||
v-if="claims.some((c) => !c.verified_at)"
|
||||
class="panel domain-table"
|
||||
>
|
||||
<h3>待验证的域名</h3>
|
||||
<p class="muted">
|
||||
在域名 DNS 服务商处添加下列 TXT
|
||||
记录。验证申请有效期为二十四小时,过期后重新生成。
|
||||
</p>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>域名 / TXT 主机记录</th>
|
||||
<th>记录值</th>
|
||||
<th>有效期</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="c in claims.filter((c) => !c.verified_at)" :key="c.id">
|
||||
<td>
|
||||
<strong>{{ c.hostname }}</strong
|
||||
><small>_webup-challenge.{{ c.hostname }}</small>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ c.proof_token }}</code
|
||||
><button
|
||||
class="icon-button"
|
||||
@click="copy(c.proof_token)"
|
||||
aria-label="复制验证记录"
|
||||
>
|
||||
<Copy :size="15" />
|
||||
</button>
|
||||
</td>
|
||||
<td>{{ new Date(c.expires_at).toLocaleString() }}</td>
|
||||
<td>
|
||||
<button
|
||||
:disabled="busy || !service"
|
||||
@click="action(c, 'verify')"
|
||||
>
|
||||
验证所有权
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section class="panel domain-table">
|
||||
<h3>域名与 HTTPS</h3>
|
||||
<p v-if="target" class="muted">
|
||||
自定义域名请添加 CNAME 指向 <code>{{ target }}</code
|
||||
>。根域名可以使用 DNS 服务商支持的别名解析。
|
||||
</p>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>域名</th>
|
||||
<th>类型</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="!domains.length">
|
||||
<td colspan="4" class="empty">还没有绑定域名</td>
|
||||
</tr>
|
||||
<tr v-for="d in domains" :key="d.id">
|
||||
<td>
|
||||
<a
|
||||
v-if="d.status === 'ACTIVE'"
|
||||
:href="'https://' + d.hostname"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>{{ d.hostname }} <ExternalLink :size="13" /></a
|
||||
><strong v-else>{{ d.hostname }}</strong
|
||||
><span v-if="d.is_primary" class="badge">主域名</span
|
||||
><small v-if="d.expected_cname"
|
||||
>CNAME → {{ d.expected_cname }}</small
|
||||
><small v-if="d.error">{{ d.error }}</small>
|
||||
</td>
|
||||
<td>{{ d.kind === "PLATFORM" ? "平台域名" : "自定义域名" }}</td>
|
||||
<td>
|
||||
<span class="status">{{ labels[d.status] || d.status }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button :disabled="busy" @click="action(d, 'events')">
|
||||
日志</button
|
||||
><button
|
||||
v-if="
|
||||
!['REMOVING', 'QUEUED', 'PROVISIONING'].includes(d.status)
|
||||
"
|
||||
:disabled="busy"
|
||||
@click="action(d, 'configure')"
|
||||
>
|
||||
{{
|
||||
d.status === "REMOVED" ? "重新配置" : "配置 / 重试"
|
||||
}}</button
|
||||
><button
|
||||
v-if="!d.is_primary && d.desired_state === 'ACTIVE'"
|
||||
:disabled="busy"
|
||||
@click="action(d, 'primary')"
|
||||
>
|
||||
设为主域名</button
|
||||
><button
|
||||
v-if="!['REMOVED', 'REMOVING'].includes(d.status)"
|
||||
:disabled="busy"
|
||||
@click="action(d, 'remove')"
|
||||
>
|
||||
解绑
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="events.length" class="panel domain-table">
|
||||
<h3>域名执行日志</h3>
|
||||
<div v-for="(event, index) in events" :key="index" class="domain-event">
|
||||
<small
|
||||
>{{ new Date(event.created_at).toLocaleString() }} ·
|
||||
{{ event.phase }}</small
|
||||
>
|
||||
<p>{{ event.detail }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
</template>
|
||||
<style scoped>
|
||||
.toolbar select {
|
||||
margin-top: 8px;
|
||||
min-width: 250px;
|
||||
}
|
||||
.domain-service,
|
||||
.domain-table {
|
||||
padding: 24px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
.domain-service label {
|
||||
max-width: 440px;
|
||||
display: block;
|
||||
}
|
||||
.domain-service p {
|
||||
margin-top: 12px;
|
||||
}
|
||||
.domain-table h3 {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.domain-table small {
|
||||
display: block;
|
||||
max-width: 420px;
|
||||
overflow-wrap: anywhere;
|
||||
margin-top: 7px;
|
||||
}
|
||||
.domain-table code {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.domain-table td {
|
||||
min-width: 140px;
|
||||
}
|
||||
.domain-table td:first-child {
|
||||
min-width: 240px;
|
||||
}
|
||||
.domain-table .badge {
|
||||
margin-left: 8px;
|
||||
}
|
||||
.domain-table .table-actions {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.domain-table a {
|
||||
color: var(--blue);
|
||||
}
|
||||
.table-scroll {
|
||||
overflow: auto;
|
||||
}
|
||||
.domain-event {
|
||||
padding: 14px 0;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,389 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, reactive, ref } from "vue";
|
||||
import { api, body } from "../api";
|
||||
const projects = ref<any[]>([]),
|
||||
project = ref(""),
|
||||
services = ref<any[]>([]),
|
||||
plans = ref<any[]>([]),
|
||||
subscription = ref<any>({ status: "NONE" }),
|
||||
deployments = ref<any[]>([]),
|
||||
events = ref<any[]>([]),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false),
|
||||
editing = ref(""),
|
||||
open = ref(false),
|
||||
output = ref("");
|
||||
const form = reactive({
|
||||
name: "",
|
||||
image: "",
|
||||
port: 3000,
|
||||
cpuMillis: 250,
|
||||
memoryMb: 256,
|
||||
replicas: 1,
|
||||
healthPath: "/",
|
||||
enabled: true,
|
||||
});
|
||||
const command = ref("[]"),
|
||||
environment = ref("");
|
||||
let timer: ReturnType<typeof setInterval> | undefined;
|
||||
async function load() {
|
||||
if (!project.value) return;
|
||||
try {
|
||||
[services.value, subscription.value, deployments.value] = await Promise.all(
|
||||
[
|
||||
api("/projects/" + project.value + "/services"),
|
||||
api("/projects/" + project.value + "/subscription"),
|
||||
api("/projects/" + project.value + "/deployments"),
|
||||
],
|
||||
);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
function edit(s?: any) {
|
||||
editing.value = s?.id || "";
|
||||
command.value = s?.command_json || "[]";
|
||||
environment.value = "";
|
||||
Object.assign(
|
||||
form,
|
||||
s
|
||||
? {
|
||||
name: s.name,
|
||||
image: s.image,
|
||||
port: s.port,
|
||||
cpuMillis: s.cpu_millis,
|
||||
memoryMb: s.memory_mb,
|
||||
replicas: s.replicas,
|
||||
healthPath: s.health_path,
|
||||
enabled: s.enabled,
|
||||
}
|
||||
: {
|
||||
name: "",
|
||||
image: "",
|
||||
port: 3000,
|
||||
cpuMillis: 250,
|
||||
memoryMb: 256,
|
||||
replicas: 1,
|
||||
healthPath: "/",
|
||||
enabled: true,
|
||||
},
|
||||
);
|
||||
open.value = true;
|
||||
}
|
||||
async function save() {
|
||||
busy.value = true;
|
||||
try {
|
||||
await api(
|
||||
"/projects/" +
|
||||
project.value +
|
||||
"/services" +
|
||||
(editing.value ? "/" + editing.value : ""),
|
||||
{
|
||||
method: editing.value ? "PUT" : "POST",
|
||||
body: body({
|
||||
...form,
|
||||
command: JSON.parse(command.value),
|
||||
environment: environment.value.trim()
|
||||
? JSON.parse(environment.value)
|
||||
: null,
|
||||
}),
|
||||
},
|
||||
);
|
||||
open.value = false;
|
||||
success.value = "配置已保存,发布后生效";
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function buy(p: any) {
|
||||
if (
|
||||
!confirm("确认支付 ¥" + p.monthly_price + " 购买一个月「" + p.name + "」?")
|
||||
)
|
||||
return;
|
||||
busy.value = true;
|
||||
try {
|
||||
await api("/projects/" + project.value + "/subscription", {
|
||||
method: "POST",
|
||||
body: body({ planId: p.id, idempotencyKey: crypto.randomUUID() }),
|
||||
});
|
||||
success.value = "套餐购买成功";
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function deploy(rollbackId?: string) {
|
||||
if (!confirm(rollbackId ? "确认重新发布历史版本?" : "确认发布当前配置?"))
|
||||
return;
|
||||
try {
|
||||
await api("/projects/" + project.value + "/deployments", {
|
||||
method: "POST",
|
||||
body: body({
|
||||
idempotencyKey: crypto.randomUUID(),
|
||||
rollbackId: rollbackId || null,
|
||||
}),
|
||||
});
|
||||
success.value = "部署已入队";
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function inspect(d: any) {
|
||||
try {
|
||||
events.value = await api(
|
||||
"/projects/" + project.value + "/deployments/" + d.id + "/events",
|
||||
);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function runtime(s: any, action: string) {
|
||||
busy.value = true;
|
||||
try {
|
||||
output.value = JSON.stringify(
|
||||
await api(
|
||||
"/projects/" +
|
||||
project.value +
|
||||
"/runtime/services/" +
|
||||
s.id +
|
||||
(action === "status" ? "" : "/" + action),
|
||||
{
|
||||
method: action === "restart" ? "POST" : "GET",
|
||||
signal: AbortSignal.timeout(125000),
|
||||
},
|
||||
),
|
||||
null,
|
||||
2,
|
||||
);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
try {
|
||||
[projects.value, plans.value] = await Promise.all([
|
||||
api("/projects"),
|
||||
api("/plans"),
|
||||
]);
|
||||
project.value = projects.value[0]?.id || "";
|
||||
await load();
|
||||
timer = setInterval(() => {
|
||||
if (!document.hidden) load();
|
||||
}, 5000);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
});
|
||||
onUnmounted(() => clearInterval(timer));
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">CLOUD RUNTIME</span>
|
||||
<h1>云托管</h1>
|
||||
<p>OCI 多服务、健康发布与版本回滚。</p>
|
||||
</div>
|
||||
<button class="primary" :disabled="!project || busy" @click="deploy()">
|
||||
发布当前配置
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<div v-if="success" class="alert success">{{ success }}</div>
|
||||
<div class="toolbar">
|
||||
<select v-model="project" @change="load">
|
||||
<option value="" disabled>选择项目</option>
|
||||
<option v-for="p in projects" :key="p.id" :value="p.id">
|
||||
{{ p.name }}
|
||||
</option></select
|
||||
><span class="status">套餐 {{ subscription.status }}</span
|
||||
><button class="secondary" :disabled="!project" @click="edit()">
|
||||
添加服务
|
||||
</button>
|
||||
</div>
|
||||
<section class="project-grid">
|
||||
<article class="panel project-card" v-for="s in services" :key="s.id">
|
||||
<div class="project-card-top">
|
||||
<h3>{{ s.name }}</h3>
|
||||
<span class="status">{{ s.enabled ? "启用" : "停用" }}</span>
|
||||
</div>
|
||||
<p>{{ s.image }}</p>
|
||||
<small
|
||||
>{{ s.cpu_millis }}m CPU / {{ s.memory_mb }}MiB / {{ s.replicas }} 副本
|
||||
/ 端口 {{ s.port }}</small
|
||||
>
|
||||
<div class="project-actions">
|
||||
<button class="link" @click="edit(s)">配置</button
|
||||
><button class="link" :disabled="busy" @click="runtime(s, 'status')">
|
||||
状态</button
|
||||
><button class="link" :disabled="busy" @click="runtime(s, 'logs')">
|
||||
日志</button
|
||||
><button class="link" :disabled="busy" @click="runtime(s, 'restart')">
|
||||
重启
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
<div v-if="!services.length" class="panel empty">
|
||||
尚无服务,添加已有 OCI 镜像开始。
|
||||
</div>
|
||||
<section v-if="output" class="panel event-log">
|
||||
<pre style="white-space: pre-wrap; overflow-wrap: anywhere">{{
|
||||
output
|
||||
}}</pre>
|
||||
</section>
|
||||
<div class="section-title" style="margin-top: 26px">
|
||||
<h3>托管套餐</h3>
|
||||
<span>购买快照,保护既有资源与价格</span>
|
||||
</div>
|
||||
<section class="project-grid">
|
||||
<article v-for="p in plans" :key="p.id" class="panel project-card">
|
||||
<h3>{{ p.name }}</h3>
|
||||
<h2 style="margin: 15px 0">
|
||||
¥ {{ p.monthly_price }} <small>/ 月</small>
|
||||
</h2>
|
||||
<p>
|
||||
{{ p.cpu_millis }}m CPU / {{ p.memory_mb }}MiB<br />{{
|
||||
p.max_services
|
||||
}}
|
||||
服务 / {{ p.max_replicas }} 副本<br />{{ p.disk_gb }}GB 存储额度 /
|
||||
{{ p.traffic_gb }}GB 流量额度
|
||||
</p>
|
||||
<button class="primary" :disabled="!project || busy" @click="buy(p)">
|
||||
购买 / 续期
|
||||
</button>
|
||||
</article>
|
||||
</section>
|
||||
<div v-if="!plans.length" class="alert info">管理员尚未开放套餐。</div>
|
||||
<section class="panel table-panel" style="margin-top: 24px">
|
||||
<div class="panel-heading">
|
||||
<h3>发布历史</h3>
|
||||
<button class="secondary" @click="load">刷新</button>
|
||||
</div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>版本</th>
|
||||
<th>时间</th>
|
||||
<th>状态</th>
|
||||
<th>错误</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="d in deployments" :key="d.id">
|
||||
<td class="truncate" :title="d.id">{{ d.id }}</td>
|
||||
<td>{{ new Date(d.created_at).toLocaleString() }}</td>
|
||||
<td>{{ d.status }}</td>
|
||||
<td>{{ d.error }}</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button class="link" @click="inspect(d)">事件</button
|
||||
><button
|
||||
v-if="['ACTIVE', 'ROLLED_BACK'].includes(d.status)"
|
||||
class="link"
|
||||
@click="deploy(d.id)"
|
||||
>
|
||||
发布此版本
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!deployments.length">
|
||||
<td colspan="5" class="empty">暂无部署</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="events.length" class="panel event-log">
|
||||
<div v-for="e in events" :key="e.id">
|
||||
<small
|
||||
>{{ e.phase }} · {{ new Date(e.created_at).toLocaleString() }}</small
|
||||
>
|
||||
<pre>{{ e.detail }}</pre>
|
||||
</div>
|
||||
</section>
|
||||
<div v-if="open" class="modal-backdrop" @click.self="open = false">
|
||||
<section class="modal" role="dialog" aria-modal="true">
|
||||
<div class="modal-heading">
|
||||
<h2>服务配置</h2>
|
||||
<button class="secondary" @click="open = false">关闭</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<form @submit.prevent="save">
|
||||
<label
|
||||
>名称<input
|
||||
v-model="form.name"
|
||||
required
|
||||
pattern="[a-z][a-z0-9-]{0,62}" /></label
|
||||
><label
|
||||
>OCI 镜像<input
|
||||
v-model="form.image"
|
||||
required
|
||||
maxlength="500" /></label
|
||||
><label>启动命令 JSON 数组<textarea v-model="command" rows="2" /></label
|
||||
><label
|
||||
>环境变量 JSON<textarea
|
||||
v-model="environment"
|
||||
rows="3"
|
||||
placeholder='{"NODE_ENV":"production"}'
|
||||
/><small
|
||||
>加密保存,不回显。编辑留空保持原值,填 {} 清除。</small
|
||||
></label
|
||||
>
|
||||
<div class="two-columns">
|
||||
<label
|
||||
>端口<input
|
||||
v-model.number="form.port"
|
||||
type="number"
|
||||
min="1"
|
||||
max="65535"
|
||||
required /></label
|
||||
><label
|
||||
>副本<input
|
||||
v-model.number="form.replicas"
|
||||
type="number"
|
||||
min="1"
|
||||
max="20"
|
||||
required /></label
|
||||
><label
|
||||
>CPU 毫核<input
|
||||
v-model.number="form.cpuMillis"
|
||||
type="number"
|
||||
min="50"
|
||||
max="64000"
|
||||
required /></label
|
||||
><label
|
||||
>内存 MiB<input
|
||||
v-model.number="form.memoryMb"
|
||||
type="number"
|
||||
min="64"
|
||||
max="262144"
|
||||
required
|
||||
/></label>
|
||||
</div>
|
||||
<label
|
||||
>健康路径<input
|
||||
v-model="form.healthPath"
|
||||
placeholder="/health;留空使用 TCP"
|
||||
maxlength="500" /></label
|
||||
><label
|
||||
>状态<select v-model="form.enabled">
|
||||
<option :value="true">启用</option>
|
||||
<option :value="false">停用(发布后生效)</option>
|
||||
</select></label
|
||||
><button class="primary wide" :disabled="busy">保存服务</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,408 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, computed, reactive } from "vue";
|
||||
import { api, body } from "../api";
|
||||
import {
|
||||
Mail,
|
||||
MessageSquare,
|
||||
Cloud,
|
||||
Globe,
|
||||
HardDrive,
|
||||
ShieldCheck,
|
||||
RefreshCw,
|
||||
} from "lucide-vue-next";
|
||||
const configs = ref<any[]>([]),
|
||||
selectedKind = ref("SMTP"),
|
||||
values = ref<Record<string, string>>({}),
|
||||
enabled = ref(false),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false),
|
||||
logs = ref<any[]>([]),
|
||||
messages = ref<any[]>([]),
|
||||
tab = ref("config");
|
||||
const icons: Record<string, any> = {
|
||||
SMTP: Mail,
|
||||
ALIYUN_SMS: MessageSquare,
|
||||
ALIYUN_ESA: Cloud,
|
||||
ALIYUN_CDN: Globe,
|
||||
ALIYUN_DNS: Globe,
|
||||
S3: HardDrive,
|
||||
};
|
||||
const current = computed(() =>
|
||||
configs.value.find((c) => c.kind === selectedKind.value),
|
||||
);
|
||||
const test = reactive({
|
||||
target: "",
|
||||
subject: "WebUp 云测试邮件",
|
||||
text: "这是一封由 WebUp 云管理后台发出的测试邮件。",
|
||||
templateParams: '{"code":"123456"}',
|
||||
idempotencyKey: crypto.randomUUID(),
|
||||
});
|
||||
function select(kind: string) {
|
||||
selectedKind.value = kind;
|
||||
const c = configs.value.find((c) => c.kind === kind);
|
||||
values.value = { ...(c?.values || {}) };
|
||||
for (const f of c?.schema || []) if (f.secret) values.value[f.key] = "";
|
||||
enabled.value = c?.enabled || false;
|
||||
success.value = "";
|
||||
error.value = "";
|
||||
}
|
||||
async function load() {
|
||||
try {
|
||||
configs.value = await api("/admin/integrations");
|
||||
select(selectedKind.value);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function save() {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
await api("/admin/integrations/" + selectedKind.value, {
|
||||
method: "PUT",
|
||||
body: body({ values: values.value, enabled: enabled.value }),
|
||||
});
|
||||
await load();
|
||||
success.value = "配置已加密保存,凭证不会回显";
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function connect() {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const r = await api("/admin/integrations/" + selectedKind.value + "/test", {
|
||||
method: "POST",
|
||||
signal: AbortSignal.timeout(65000),
|
||||
});
|
||||
await load();
|
||||
success.value = r.message;
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function send() {
|
||||
if (
|
||||
!confirm(
|
||||
"确认向 " +
|
||||
test.target +
|
||||
" 发送测试" +
|
||||
(selectedKind.value === "SMTP" ? "邮件" : "短信") +
|
||||
"?短信可能产生供应商费用。",
|
||||
)
|
||||
)
|
||||
return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const r = await api(
|
||||
"/admin/integrations/" + selectedKind.value + "/send-test",
|
||||
{ method: "POST", body: body(test), signal: AbortSignal.timeout(65000) },
|
||||
);
|
||||
success.value = r.message || "发送状态:" + r.status;
|
||||
test.idempotencyKey = crypto.randomUUID();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function history() {
|
||||
tab.value = "logs";
|
||||
try {
|
||||
[logs.value, messages.value] = await Promise.all([
|
||||
api("/admin/integrations/logs"),
|
||||
api("/admin/integrations/messages"),
|
||||
]);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">SERVICE INTEGRATIONS</span>
|
||||
<h1>服务集成与配置</h1>
|
||||
<p>SMTP、短信、CDN、ESA、DNS 与对象存储,分别管理、加密保存。</p>
|
||||
</div>
|
||||
<div class="table-actions">
|
||||
<button class="secondary" @click="tab = 'config'">服务配置</button
|
||||
><button class="secondary" @click="history">测试与发送日志</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<div v-if="success" class="alert success">{{ success }}</div>
|
||||
<template v-if="tab === 'config'"
|
||||
><section class="integration-grid">
|
||||
<button
|
||||
v-for="c in configs"
|
||||
:key="c.kind"
|
||||
:class="{ selected: selectedKind === c.kind }"
|
||||
@click="select(c.kind)"
|
||||
>
|
||||
<component :is="icons[c.kind] || Cloud" :size="23" /><b>{{ c.name }}</b
|
||||
><small>{{
|
||||
c.configured ? (c.enabled ? "已启用" : "已配置,停用") : "尚未配置"
|
||||
}}</small
|
||||
><span class="status">{{ c.connection_status }}</span>
|
||||
</button>
|
||||
</section>
|
||||
<section v-if="current" class="panel form-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<h3>
|
||||
<component :is="icons[current.kind] || Cloud" :size="20" />{{
|
||||
current.name
|
||||
}}
|
||||
</h3>
|
||||
<p>{{ current.description }}</p>
|
||||
</div>
|
||||
<button
|
||||
class="secondary"
|
||||
:disabled="!current.configured || busy"
|
||||
@click="connect"
|
||||
>
|
||||
<RefreshCw :size="14" />测试连接
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="current.last_error" class="alert error">
|
||||
上次测试:{{ current.last_error }}
|
||||
</div>
|
||||
<form @submit.prevent="save" class="integration-form">
|
||||
<label v-for="f in current.schema" :key="f.key"
|
||||
>{{ f.label
|
||||
}}<input
|
||||
v-model="values[f.key]"
|
||||
:type="
|
||||
f.type === 'password'
|
||||
? 'password'
|
||||
: f.type === 'number'
|
||||
? 'number'
|
||||
: f.type === 'email'
|
||||
? 'email'
|
||||
: 'text'
|
||||
"
|
||||
:required="f.required && !current.configuredSecrets.includes(f.key)"
|
||||
:placeholder="
|
||||
f.secret && current.configuredSecrets.includes(f.key)
|
||||
? '已设置,留空保持原值'
|
||||
: f.defaultValue
|
||||
"
|
||||
maxlength="4000"
|
||||
autocomplete="off"
|
||||
/><small v-if="f.secret">密钥加密存储,不通过接口返回。</small></label
|
||||
><label
|
||||
>服务状态<select v-model="enabled">
|
||||
<option :value="false">停用</option>
|
||||
<option :value="true">启用</option>
|
||||
</select></label
|
||||
>
|
||||
<div class="integration-save">
|
||||
<span><ShieldCheck :size="15" />保存、测试与发送均记录审计</span
|
||||
><button class="primary" :disabled="busy">
|
||||
{{ busy ? "处理中…" : "保存配置" }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<section
|
||||
v-if="['SMTP', 'ALIYUN_SMS'].includes(selectedKind)"
|
||||
class="panel form-panel"
|
||||
style="margin-top: 23px"
|
||||
>
|
||||
<h3>发送测试{{ selectedKind === "SMTP" ? "邮件" : "短信" }}</h3>
|
||||
<p class="muted" style="margin: 10px 0 20px">
|
||||
需要先保存并启用配置。调用失败或超时会保留发送记录,不自动重复发送。
|
||||
</p>
|
||||
<form @submit.prevent="send">
|
||||
<div class="two-columns">
|
||||
<label
|
||||
>接收{{ selectedKind === "SMTP" ? "邮箱" : "手机号"
|
||||
}}<input
|
||||
v-model="test.target"
|
||||
:type="selectedKind === 'SMTP' ? 'email' : 'text'"
|
||||
required
|
||||
maxlength="254" /></label
|
||||
><label v-if="selectedKind === 'SMTP'"
|
||||
>邮件主题<input v-model="test.subject" required maxlength="200"
|
||||
/></label>
|
||||
</div>
|
||||
<label v-if="selectedKind === 'SMTP'"
|
||||
>邮件正文<textarea
|
||||
v-model="test.text"
|
||||
rows="4"
|
||||
required
|
||||
maxlength="20000"
|
||||
/></label
|
||||
><label v-else
|
||||
>模板变量 JSON<textarea
|
||||
v-model="test.templateParams"
|
||||
rows="3"
|
||||
required
|
||||
maxlength="4000"
|
||||
/></label
|
||||
><button class="secondary" :disabled="!current?.enabled || busy">
|
||||
发送测试
|
||||
</button>
|
||||
</form>
|
||||
</section></template
|
||||
><template v-else
|
||||
><section class="panel table-panel">
|
||||
<div class="panel-heading"><h3>连接测试记录</h3></div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>类型</th>
|
||||
<th>状态</th>
|
||||
<th>结果</th>
|
||||
<th>请求 ID</th>
|
||||
<th>时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="l in logs" :key="l.id">
|
||||
<td>{{ l.kind }}</td>
|
||||
<td>{{ l.status }}</td>
|
||||
<td>{{ l.message }}</td>
|
||||
<td class="truncate">{{ l.request_id || "—" }}</td>
|
||||
<td>{{ new Date(l.created_at).toLocaleString() }}</td>
|
||||
</tr>
|
||||
<tr v-if="!logs.length">
|
||||
<td colspan="5" class="empty">暂无连接测试</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section class="panel table-panel">
|
||||
<div class="panel-heading"><h3>消息发送记录</h3></div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>通道</th>
|
||||
<th>接收地址</th>
|
||||
<th>状态</th>
|
||||
<th>错误</th>
|
||||
<th>时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="m in messages" :key="m.id">
|
||||
<td>{{ m.channel }}</td>
|
||||
<td>{{ m.recipient }}</td>
|
||||
<td>{{ m.status }}</td>
|
||||
<td>{{ m.error || "—" }}</td>
|
||||
<td>{{ new Date(m.created_at).toLocaleString() }}</td>
|
||||
</tr>
|
||||
<tr v-if="!messages.length">
|
||||
<td colspan="5" class="empty">暂无发送记录</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section></template
|
||||
>
|
||||
</template>
|
||||
<style scoped>
|
||||
.integration-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 15px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
.integration-grid > button {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 9px;
|
||||
padding: 20px;
|
||||
text-align: left;
|
||||
color: var(--text);
|
||||
position: relative;
|
||||
}
|
||||
.integration-grid > button.selected {
|
||||
border-color: #88a6f3;
|
||||
background: var(--blue-light);
|
||||
}
|
||||
.integration-grid svg {
|
||||
display: block;
|
||||
color: #8da7d6;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.integration-grid b {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
font-weight: 550;
|
||||
}
|
||||
.integration-grid small {
|
||||
display: block;
|
||||
margin-top: 7px;
|
||||
font-size: 10px;
|
||||
}
|
||||
.integration-grid .status {
|
||||
position: absolute;
|
||||
right: 12px;
|
||||
top: 17px;
|
||||
font-size: 8px;
|
||||
}
|
||||
.integration-form {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0 25px;
|
||||
padding-top: 15px;
|
||||
}
|
||||
.integration-save {
|
||||
grid-column: 1/-1;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-top: 15px;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
.integration-save > span {
|
||||
display: flex;
|
||||
gap: 7px;
|
||||
align-items: center;
|
||||
color: var(--muted);
|
||||
font-size: 10px;
|
||||
}
|
||||
.panel-heading {
|
||||
padding: 0 0 10px;
|
||||
}
|
||||
.panel-heading p {
|
||||
font-size: 10px;
|
||||
color: var(--muted);
|
||||
margin-top: 8px;
|
||||
}
|
||||
.panel-heading h3 {
|
||||
display: flex;
|
||||
gap: 9px;
|
||||
align-items: center;
|
||||
}
|
||||
.panel-heading h3 svg {
|
||||
color: #839cc6;
|
||||
}
|
||||
@media (max-width: 700px) {
|
||||
.integration-grid {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
.integration-form {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.integration-save > span {
|
||||
display: none;
|
||||
}
|
||||
.integration-save {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,449 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { useSession } from "../store";
|
||||
import { api } from "../api";
|
||||
import {
|
||||
Cloud,
|
||||
ArrowUpRight,
|
||||
ArrowRight,
|
||||
Code2,
|
||||
Terminal,
|
||||
ShieldCheck,
|
||||
Wallet,
|
||||
GitBranch,
|
||||
Layers,
|
||||
Check,
|
||||
ChevronDown,
|
||||
Server,
|
||||
Sparkles,
|
||||
} from "lucide-vue-next";
|
||||
const store = useSession(),
|
||||
plans = ref<any[]>([]),
|
||||
pricingError = ref(""),
|
||||
faq = ref(-1),
|
||||
menu = ref(false);
|
||||
const features = [
|
||||
{
|
||||
icon: Code2,
|
||||
title: "选择适合你的 AI",
|
||||
text: "国内外模型与自定义中转站统一接入。同一份项目,在你的模型与开发思路之间自由延续。",
|
||||
detail: "模型可选 · 价格透明",
|
||||
},
|
||||
{
|
||||
icon: Terminal,
|
||||
title: "让 AI 真正动手开发",
|
||||
text: "从编写文件到运行命令,再到构建与检查。每一步都有上下文,每一次操作都有记录。",
|
||||
detail: "文件工具 · 终端 · 执行日志",
|
||||
},
|
||||
{
|
||||
icon: Wallet,
|
||||
title: "把每一轮预算握在手里",
|
||||
text: "开始前预留预算,按实际 Token 使用量结算。随时查看费用,暂停任务,掌握开发节奏。",
|
||||
detail: "预算上限 · 独立交易账本",
|
||||
},
|
||||
{
|
||||
icon: Server,
|
||||
title: "为持续运行做好准备",
|
||||
text: "用 OCI 镜像管理多个独立服务,配置资源、环境变量与健康检查,在版本之间从容切换。",
|
||||
detail: "多服务 · 健康发布 · 历史版本",
|
||||
},
|
||||
];
|
||||
const questions = [
|
||||
[
|
||||
"我需要自己准备模型 API Key 吗?",
|
||||
"平台管理员统一配置供应商和开放模型,普通用户从工作台选择可用模型。部署自己的平台时,你可以添加国内供应商、海外供应商或第三方中转站。",
|
||||
],
|
||||
[
|
||||
"支持已有项目持续开发吗?",
|
||||
"可以保存项目需求,并在隔离工作区读取、编辑文件和运行命令。同一项目的后续任务保留已完成任务的上下文,项目文件持久保存。",
|
||||
],
|
||||
[
|
||||
"开发费用和托管费用如何计算?",
|
||||
"AI 开发按任务绑定的模型价格和实际 usage 结算,开始前会预留预算。托管按项目购买套餐,两类费用分开记账。价格以工作台和管理员配置为准。",
|
||||
],
|
||||
[
|
||||
"我可以下载自己的源码吗?",
|
||||
"可以通过项目文件与版本页面下载源码 ZIP,或保存 Git 版本。下载属于当前账号的项目,依赖缓存与 Git 内部数据会从 ZIP 中排除。",
|
||||
],
|
||||
[
|
||||
"现在可以直接体验哪些功能?",
|
||||
"注册登录后可以管理项目、账户、会话和账本。AI 执行与容器发布需要管理员完成模型及运行环境配置。测试预览不会执行真实支付或自动创建云资源。",
|
||||
],
|
||||
];
|
||||
onMounted(async () => {
|
||||
try {
|
||||
plans.value = await api("/public/plans");
|
||||
} catch {
|
||||
pricingError.value = "套餐信息暂时无法读取,请稍后在控制台查看。";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<div class="landing">
|
||||
<div class="landing-notice" v-if="store.settings.announcement">
|
||||
{{ store.settings.announcement }}
|
||||
</div>
|
||||
<div class="landing-nav-wrap">
|
||||
<div class="landing-nav">
|
||||
<RouterLink to="/" class="brand"
|
||||
><img
|
||||
v-if="store.settings.logoUrl"
|
||||
:src="store.settings.logoUrl"
|
||||
alt="平台 Logo"
|
||||
/><span v-else class="brand-mark"><Cloud :size="23" /></span
|
||||
><strong>{{
|
||||
store.settings.siteName || "云端开发平台"
|
||||
}}</strong></RouterLink
|
||||
><button
|
||||
class="icon-button landing-menu"
|
||||
@click="menu = !menu"
|
||||
aria-label="展开导航"
|
||||
>
|
||||
<Layers :size="20" />
|
||||
</button>
|
||||
<nav :class="{ expanded: menu }">
|
||||
<a href="#features" @click="menu = false">平台能力</a
|
||||
><a href="#workflow" @click="menu = false">开发流程</a
|
||||
><a href="#plans" @click="menu = false">托管套餐</a
|
||||
><a href="#questions" @click="menu = false">常见问题</a>
|
||||
</nav>
|
||||
<div class="landing-nav-actions">
|
||||
<RouterLink class="landing-login" to="/login">登录</RouterLink
|
||||
><RouterLink class="primary" to="/console"
|
||||
>进入控制台 <ArrowUpRight :size="15"
|
||||
/></RouterLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="landing-container">
|
||||
<section class="landing-hero">
|
||||
<div class="hero-copy">
|
||||
<div class="hero-kicker">
|
||||
<span></span>{{ store.settings.tagline || "让创意轻松上线" }}
|
||||
<ArrowUpRight :size="13" />
|
||||
</div>
|
||||
<h1>
|
||||
<template
|
||||
v-for="(line, i) in (
|
||||
store.settings.heroHeadline || '让创意\n轻松上线'
|
||||
).split('\n')"
|
||||
:key="i"
|
||||
><br v-if="i" /><span v-if="i">{{ line }}</span
|
||||
><template v-else>{{ line }}</template></template
|
||||
>
|
||||
</h1>
|
||||
<p class="hero-description">
|
||||
用自然语言描述你的需求,让 AI 参与开发。<br />从第一份项目文件到云端运行,<br
|
||||
class="mobile-break"
|
||||
/>在一个工作空间里持续创造。
|
||||
</p>
|
||||
<div class="hero-actions">
|
||||
<RouterLink to="/login?register=1" class="primary"
|
||||
>开始构建你的想法 <ArrowRight :size="17" /></RouterLink
|
||||
><a href="#workflow" class="hero-secondary"
|
||||
>了解如何工作 <ArrowUpRight :size="16"
|
||||
/></a>
|
||||
</div>
|
||||
<div class="hero-points">
|
||||
<span><Check :size="13" />国内外多模型</span
|
||||
><span><Check :size="13" />预算透明可控</span
|
||||
><span><Check :size="13" />项目源码可下载</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hero-product">
|
||||
<div class="product-glow"></div>
|
||||
<div class="product-window">
|
||||
<div class="product-titlebar">
|
||||
<div class="window-dots"><i></i><i></i><i></i></div>
|
||||
<span>你的下一个项目</span><small>工作流示意</small>
|
||||
</div>
|
||||
<div class="product-workspace">
|
||||
<div class="product-filebar">
|
||||
<span class="filebar-label">EXPLORER</span
|
||||
><span>⌄ my-next-idea</span><span class="indent">▸ src</span
|
||||
><span class="indent file-selected">◇ App.vue</span
|
||||
><span class="indent">◇ package.json</span
|
||||
><span class="indent">◇ README.md</span>
|
||||
<div class="filebar-bottom">
|
||||
<ShieldCheck :size="13" />独立工作区
|
||||
</div>
|
||||
</div>
|
||||
<div class="product-code">
|
||||
<div class="code-tab">
|
||||
<Code2 :size="13" />App.vue <span>×</span>
|
||||
</div>
|
||||
<div class="code-lines">
|
||||
<div>
|
||||
<em>1</em><code><b><template></b></code>
|
||||
</div>
|
||||
<div>
|
||||
<em>2</em
|
||||
><code> <main class=<u>"your-next-idea"</u>></code>
|
||||
</div>
|
||||
<div>
|
||||
<em>3</em
|
||||
><code>
|
||||
<h1><strong>Hello, possibility.</strong
|
||||
></h1></code
|
||||
>
|
||||
</div>
|
||||
<div>
|
||||
<em>4</em
|
||||
><code> <p>让你的想法,被世界看见。</p></code>
|
||||
</div>
|
||||
<div><em>5</em><code> </main></code></div>
|
||||
<div>
|
||||
<em>6</em><code><b></template></b></code>
|
||||
</div>
|
||||
<div><em>7</em><code></code></div>
|
||||
<div>
|
||||
<em>8</em
|
||||
><code class="code-comment"
|
||||
>// Build something that matters.</code
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div class="product-terminal">
|
||||
<div><Terminal :size="12" />开发流程</div>
|
||||
<p><span>01</span> 整理需求与技术方案</p>
|
||||
<p><span>02</span> 编写代码,运行构建与检查</p>
|
||||
<p><span>03</span> 保存版本,准备发布 <i></i></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="product-status">
|
||||
<span><span class="status-dot"></span>从第一行代码开始</span
|
||||
><span>Vue · TypeScript · OCI</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="floating-prompt">
|
||||
<span class="prompt-spark"><Sparkles :size="17" /></span>
|
||||
<div>
|
||||
<small>你的下一步</small><b>“帮我把这个想法,做成一个网站。”</b>
|
||||
</div>
|
||||
<ArrowUpRight :size="15" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="landing-values">
|
||||
<span>创造的每一步,都在一个地方。</span>
|
||||
<div><Code2 :size="18" />AI 辅助开发</div>
|
||||
<div><GitBranch :size="18" />文件与版本</div>
|
||||
<div><Server :size="18" />云端运行</div>
|
||||
<div><Wallet :size="18" />透明计费</div>
|
||||
</section>
|
||||
<section id="features" class="landing-section">
|
||||
<div class="landing-section-heading">
|
||||
<span class="eyebrow">ONE WORKSPACE. MORE POSSIBILITIES.</span>
|
||||
<h2>不止生成代码。<br />让开发过程,连成一条路。</h2>
|
||||
<p>
|
||||
把模型、项目、执行过程与运行配置连接起来,<br />让你把注意力留给真正想创造的东西。
|
||||
</p>
|
||||
</div>
|
||||
<div class="landing-feature-grid">
|
||||
<article v-for="f in features" :key="f.title">
|
||||
<div class="landing-feature-icon">
|
||||
<component :is="f.icon" :size="24" />
|
||||
</div>
|
||||
<h3>{{ f.title }}</h3>
|
||||
<p>{{ f.text }}</p>
|
||||
<span>{{ f.detail }} <ArrowUpRight :size="13" /></span>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
<section id="workflow" class="landing-section workflow-section">
|
||||
<div class="workflow-intro">
|
||||
<span class="eyebrow">FROM IDEA TO WORKSPACE</span>
|
||||
<h2>从一句“我想要”,<br />到你的下一个作品。</h2>
|
||||
<p>
|
||||
每一个项目都有自己的上下文、文件和进展。<br />你提出方向,工作空间记录创造的过程。
|
||||
</p>
|
||||
<RouterLink to="/login?register=1" class="text-link"
|
||||
>创建第一个项目 <ArrowRight :size="15"
|
||||
/></RouterLink>
|
||||
</div>
|
||||
<div class="workflow-steps">
|
||||
<article
|
||||
v-for="(step, i) in [
|
||||
[
|
||||
'描述你的想法',
|
||||
'写下目标用户、功能、风格与技术栈,给项目建立清晰的起点。',
|
||||
],
|
||||
[
|
||||
'选择模型与预算',
|
||||
'选择管理员开放的模型,查看价格,为本轮开发设置预算上限。',
|
||||
],
|
||||
[
|
||||
'查看开发过程,持续迭代',
|
||||
'跟踪模型调用与工具结果,查看文件、运行日志和实际费用,继续完善需求。',
|
||||
],
|
||||
[
|
||||
'保存版本,准备云端运行',
|
||||
'下载源码或保存 Git 版本,为 OCI 服务配置资源、环境变量和健康检查。',
|
||||
],
|
||||
]"
|
||||
:key="i"
|
||||
>
|
||||
<span>{{ String(i + 1).padStart(2, "0") }}</span>
|
||||
<div>
|
||||
<h3>{{ step[0] }}</h3>
|
||||
<p>{{ step[1] }}</p>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
<section class="landing-section usecases">
|
||||
<div class="landing-section-heading">
|
||||
<span class="eyebrow">MAKE ROOM FOR YOUR NEXT IDEA</span>
|
||||
<h2>你的下一站,<br />可以有很多种样子。</h2>
|
||||
</div>
|
||||
<div class="usecase-grid">
|
||||
<article>
|
||||
<span>01 / PRESENT</span>
|
||||
<h3>个人品牌与产品展示</h3>
|
||||
<p>让作品集、品牌官网和产品介绍,成为别人了解你的起点。</p>
|
||||
<div class="usecase-visual visual-page">
|
||||
<i></i><b>Ideas, made visible.</b><span></span><span></span>
|
||||
<div><i></i><i></i><i></i></div>
|
||||
</div>
|
||||
</article>
|
||||
<article>
|
||||
<span>02 / CONNECT</span>
|
||||
<h3>社区与业务应用</h3>
|
||||
<p>从用户流程出发,把社区、内部工具和在线业务的需求组织成项目。</p>
|
||||
<div class="usecase-visual visual-app">
|
||||
<div><i></i><span></span><span></span></div>
|
||||
<section>
|
||||
<b>Workspace</b>
|
||||
<div><i></i><i></i><i></i></div>
|
||||
<span></span><span></span>
|
||||
</section>
|
||||
</div>
|
||||
</article>
|
||||
<article>
|
||||
<span>03 / BUILD</span>
|
||||
<h3>服务与 API 项目</h3>
|
||||
<p>面向独立服务设计你的应用,清楚管理启动方式、资源和发布版本。</p>
|
||||
<div class="usecase-visual visual-api">
|
||||
<code>GET /your-next-idea</code>
|
||||
<p>
|
||||
{<br /> "possibility":
|
||||
<span>"unlimited"</span>,<br /> "next_step":
|
||||
<span>"build"</span><br />}
|
||||
</p>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
<section id="plans" class="landing-section landing-pricing">
|
||||
<div class="landing-section-heading">
|
||||
<span class="eyebrow">CLEAR RESOURCES. CLEAR CHOICES.</span>
|
||||
<h2>选择适合项目的运行空间。</h2>
|
||||
<p>
|
||||
AI 开发与网站托管分别计费,<br />托管资源与价格由平台实际开放的套餐决定。
|
||||
</p>
|
||||
</div>
|
||||
<div v-if="plans.length" class="landing-plan-grid">
|
||||
<article v-for="p in plans" :key="p.id">
|
||||
<span class="plan-eyebrow">云托管</span>
|
||||
<h3>{{ p.name }}</h3>
|
||||
<div class="plan-price">
|
||||
¥{{ p.monthly_price }}<span>/ 月</span>
|
||||
</div>
|
||||
<ul>
|
||||
<li>
|
||||
<Check :size="15" />{{ p.cpu_millis / 1000 }} vCPU ·
|
||||
{{ p.memory_mb }} MiB 内存
|
||||
</li>
|
||||
<li><Check :size="15" />{{ p.disk_gb }} GB 存储额度</li>
|
||||
<li><Check :size="15" />{{ p.traffic_gb }} GB 月流量额度</li>
|
||||
<li>
|
||||
<Check :size="15" />{{ p.max_services }} 个服务 · 最多
|
||||
{{ p.max_replicas }} 副本
|
||||
</li>
|
||||
</ul>
|
||||
<RouterLink to="/hosting" class="primary wide"
|
||||
>查看并选择 <ArrowRight :size="15"
|
||||
/></RouterLink>
|
||||
</article>
|
||||
</div>
|
||||
<div v-else class="pricing-empty">
|
||||
<Cloud :size="30" />
|
||||
<h3>
|
||||
{{
|
||||
pricingError
|
||||
? "套餐信息暂时不可用"
|
||||
: "为你的项目,找到合适的空间。"
|
||||
}}
|
||||
</h3>
|
||||
<p>
|
||||
{{
|
||||
pricingError ||
|
||||
"托管套餐将由平台管理员配置并开放。你可以先创建账户,整理你的第一个项目。"
|
||||
}}
|
||||
</p>
|
||||
<RouterLink to="/login?register=1" class="secondary"
|
||||
>先创建我的工作空间 <ArrowUpRight :size="15"
|
||||
/></RouterLink>
|
||||
</div>
|
||||
</section>
|
||||
<section id="questions" class="landing-section landing-faq">
|
||||
<div>
|
||||
<span class="eyebrow">A LITTLE MORE CLARITY</span>
|
||||
<h2>开始之前,<br />你可能想了解。</h2>
|
||||
<p>让每一次选择,都更加清楚。</p>
|
||||
</div>
|
||||
<div class="faq-items">
|
||||
<article v-for="(q, i) in questions" :key="q[0]">
|
||||
<button
|
||||
@click="faq = faq === i ? -1 : i"
|
||||
:aria-expanded="faq === i"
|
||||
>
|
||||
<span>{{ q[0] }}</span
|
||||
><ChevronDown :size="17" :class="{ rotate: faq === i }" />
|
||||
</button>
|
||||
<p v-if="faq === i">{{ q[1] }}</p>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
<section class="landing-cta">
|
||||
<div>
|
||||
<span class="eyebrow">YOUR NEXT CHAPTER STARTS HERE</span>
|
||||
<h2>让下一次灵感,有处生长。</h2>
|
||||
<p>从一个项目开始,把想法一步步带到现实。</p>
|
||||
</div>
|
||||
<RouterLink to="/login?register=1" class="primary"
|
||||
>开始构建 <ArrowUpRight :size="17"
|
||||
/></RouterLink>
|
||||
<div class="cta-orbit"></div>
|
||||
</section>
|
||||
</div>
|
||||
<div class="landing-footer">
|
||||
<div class="landing-footer-inner">
|
||||
<div>
|
||||
<RouterLink to="/" class="brand"
|
||||
><span class="brand-mark"><Cloud :size="21" /></span
|
||||
><strong>{{
|
||||
store.settings.siteName || "云端开发平台"
|
||||
}}</strong></RouterLink
|
||||
>
|
||||
<p>{{ store.settings.siteDescription }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<a href="#features">平台能力</a><a href="#workflow">开发流程</a
|
||||
><a href="#plans">托管套餐</a
|
||||
><RouterLink to="/admin/login">管理后台</RouterLink>
|
||||
</div>
|
||||
</div>
|
||||
<div class="landing-footer-bottom">
|
||||
<span>{{
|
||||
store.settings.footer || "从想法到作品,让创造持续发生。"
|
||||
}}</span
|
||||
><span>{{ store.settings.filing }}</span
|
||||
><small v-if="store.settings.previewMode === 'true'"
|
||||
>本地测试预览</small
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,200 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed } from "vue";
|
||||
import { useRouter, useRoute } from "vue-router";
|
||||
import { useSession } from "../store";
|
||||
import { api, body } from "../api";
|
||||
import {
|
||||
Cloud,
|
||||
ArrowRight,
|
||||
ShieldCheck,
|
||||
Layers,
|
||||
RefreshCw,
|
||||
} from "lucide-vue-next";
|
||||
const route = useRoute();
|
||||
const adminMode = computed(() => route.path === "/admin/login");
|
||||
const store = useSession(),
|
||||
router = useRouter(),
|
||||
register = ref(!adminMode.value && route.query.register === "1"),
|
||||
busy = ref(false),
|
||||
error = ref(""),
|
||||
success = ref("");
|
||||
const email = ref(""),
|
||||
password = ref(""),
|
||||
name = ref(""),
|
||||
code = ref(""),
|
||||
captcha = ref<{ id: string; image: string } | null>(null);
|
||||
async function refresh() {
|
||||
code.value = "";
|
||||
try {
|
||||
captcha.value = await api("/auth/captcha");
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
captcha.value = null;
|
||||
}
|
||||
}
|
||||
async function submit() {
|
||||
if (!captcha.value) return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
success.value = "";
|
||||
try {
|
||||
const v = {
|
||||
email: email.value,
|
||||
password: password.value,
|
||||
captchaId: captcha.value.id,
|
||||
captchaCode: code.value,
|
||||
...(register.value ? { displayName: name.value } : {}),
|
||||
};
|
||||
if (register.value) {
|
||||
await api("/auth/register", { method: "POST", body: body(v) });
|
||||
success.value = "注册成功,请使用新账户登录";
|
||||
register.value = false;
|
||||
password.value = "";
|
||||
await refresh();
|
||||
} else {
|
||||
const result = await api("/auth/login", {
|
||||
method: "POST",
|
||||
body: body(v),
|
||||
});
|
||||
sessionStorage.setItem("session", result.token);
|
||||
await store.load();
|
||||
await store.brand();
|
||||
if (adminMode.value && !store.user?.permissions.length) {
|
||||
await store.logout();
|
||||
throw new Error("此账户没有管理员权限");
|
||||
}
|
||||
router.push(adminMode.value ? { name: "admin-overview" } : "/console");
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
await refresh();
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(refresh);
|
||||
</script>
|
||||
<template>
|
||||
<div class="auth-layout" :class="{ 'admin-auth': adminMode }">
|
||||
<section class="auth-story">
|
||||
<div class="brand">
|
||||
<img
|
||||
v-if="store.settings.logoUrl"
|
||||
:src="store.settings.logoUrl"
|
||||
alt="WebUp Logo"
|
||||
/><span v-else class="brand-mark"><Cloud /></span
|
||||
><strong>{{ store.settings.siteName || "云端开发工作空间" }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span class="eyebrow">IDEAS INTO REALITY</span>
|
||||
<h1 v-if="adminMode">平台管理,<br />从容掌控。</h1>
|
||||
<h1 v-else>每一个想法,<br />都值得被构建。</h1>
|
||||
<p>
|
||||
在一个工作空间中,连接开发、项目与云端。<br />从第一行需求开始,让创造有迹可循。
|
||||
</p>
|
||||
<div class="auth-feature">
|
||||
<Layers /><span>项目持久保存,需求持续迭代</span>
|
||||
</div>
|
||||
<div class="auth-feature">
|
||||
<ShieldCheck /><span>独立账户、权限控制与设备会话</span>
|
||||
</div>
|
||||
</div>
|
||||
<small>AI 与云托管能力正在按阶段建设。</small>
|
||||
</section>
|
||||
<section class="auth-form">
|
||||
<div class="auth-form-inner">
|
||||
<span class="eyebrow">YOUR WORKSPACE AWAITS</span>
|
||||
<h2>
|
||||
{{
|
||||
adminMode ? "管理员登录" : register ? "创建你的账户" : "欢迎回来"
|
||||
}}
|
||||
</h2>
|
||||
<p class="muted">
|
||||
{{
|
||||
register
|
||||
? "从这里开始构建下一个想法"
|
||||
: "登录控制台,继续你的创造之旅"
|
||||
}}
|
||||
</p>
|
||||
<div class="alert error" v-if="error" role="alert">{{ error }}</div>
|
||||
<div class="alert success" v-if="success" role="status">
|
||||
{{ success }}
|
||||
</div>
|
||||
<form @submit.prevent="submit">
|
||||
<label v-if="register"
|
||||
>显示名称<input
|
||||
v-model="name"
|
||||
required
|
||||
maxlength="80"
|
||||
autocomplete="nickname"
|
||||
placeholder="如何称呼你" /></label
|
||||
><label
|
||||
>邮箱地址<input
|
||||
v-model="email"
|
||||
type="email"
|
||||
required
|
||||
maxlength="254"
|
||||
autocomplete="email"
|
||||
placeholder="you@example.com" /></label
|
||||
><label
|
||||
>密码<input
|
||||
v-model="password"
|
||||
type="password"
|
||||
required
|
||||
:minlength="register ? 12 : 1"
|
||||
maxlength="72"
|
||||
:autocomplete="register ? 'new-password' : 'current-password'"
|
||||
placeholder="请输入密码"
|
||||
/><small v-if="register">12–72 字节,包含字母和数字</small></label
|
||||
><label
|
||||
>图片验证码
|
||||
<div class="captcha-row">
|
||||
<input
|
||||
v-model="code"
|
||||
required
|
||||
maxlength="5"
|
||||
autocomplete="off"
|
||||
placeholder="输入图片字符"
|
||||
/><button
|
||||
type="button"
|
||||
class="captcha"
|
||||
@click="refresh"
|
||||
aria-label="刷新验证码"
|
||||
>
|
||||
<img
|
||||
v-if="captcha"
|
||||
:src="captcha.image"
|
||||
alt="图片验证码"
|
||||
/><RefreshCw v-else :size="20" />
|
||||
</button></div></label
|
||||
><button class="primary wide" :disabled="busy || !captcha">
|
||||
{{ busy ? "正在处理…" : register ? "注册账户" : "登录工作空间"
|
||||
}}<ArrowRight :size="17" />
|
||||
</button>
|
||||
</form>
|
||||
<p class="auth-switch" v-if="!adminMode">
|
||||
{{ register ? "已有账户?" : "还没有账户?"
|
||||
}}<button
|
||||
class="link"
|
||||
@click="
|
||||
register = !register;
|
||||
error = '';
|
||||
refresh();
|
||||
"
|
||||
>
|
||||
{{ register ? "立即登录" : "创建账户" }}
|
||||
</button>
|
||||
</p>
|
||||
<p class="auth-switch">
|
||||
<RouterLink to="/" class="link">← 返回网站首页</RouterLink
|
||||
><RouterLink v-if="!adminMode" to="/admin/login" class="link"
|
||||
>管理后台</RouterLink
|
||||
>
|
||||
</p>
|
||||
<p class="security-note">
|
||||
<ShieldCheck :size="14" />会话可随时撤销,安全由你掌控
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,441 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from "vue";
|
||||
import { api, body } from "../api";
|
||||
const providers = ref<any[]>([]),
|
||||
models = ref<any[]>([]),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false),
|
||||
tab = ref("providers"),
|
||||
editing = ref<string | null>(null),
|
||||
show = ref(false);
|
||||
const provider = reactive({
|
||||
authMode: "BEARER",
|
||||
name: "",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
apiType: "OPENAI",
|
||||
apiKey: "",
|
||||
enabled: false,
|
||||
timeoutSeconds: 60,
|
||||
});
|
||||
const model = reactive({
|
||||
providerId: "",
|
||||
name: "",
|
||||
modelId: "",
|
||||
contextLength: 32768,
|
||||
maxOutput: 4096,
|
||||
toolsEnabled: false,
|
||||
visionEnabled: false,
|
||||
enabled: false,
|
||||
inputPrice: "0",
|
||||
outputPrice: "0",
|
||||
cacheReadPrice: "0",
|
||||
cacheWritePrice: "0",
|
||||
});
|
||||
const presets = ref<any[]>([]),
|
||||
selectedPreset = ref("custom");
|
||||
function applyPreset() {
|
||||
const p = presets.value.find((p) => p.id === selectedPreset.value);
|
||||
if (p)
|
||||
Object.assign(provider, {
|
||||
name: p.name,
|
||||
baseUrl: p.baseUrl,
|
||||
apiType: p.apiType,
|
||||
authMode: p.authMode,
|
||||
});
|
||||
}
|
||||
async function load() {
|
||||
try {
|
||||
[providers.value, models.value] = await Promise.all([
|
||||
api("/admin/providers"),
|
||||
api("/admin/models"),
|
||||
]);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
function edit(p?: any) {
|
||||
editing.value = p?.id || null;
|
||||
show.value = true;
|
||||
if (tab.value === "providers")
|
||||
Object.assign(
|
||||
provider,
|
||||
p
|
||||
? {
|
||||
name: p.name,
|
||||
authMode: p.auth_mode || "BEARER",
|
||||
baseUrl: p.base_url,
|
||||
apiType: p.api_type,
|
||||
apiKey: "",
|
||||
enabled: p.enabled,
|
||||
timeoutSeconds: p.timeout_seconds,
|
||||
}
|
||||
: {
|
||||
name: "",
|
||||
authMode: "BEARER",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
apiType: "OPENAI",
|
||||
apiKey: "",
|
||||
enabled: false,
|
||||
timeoutSeconds: 60,
|
||||
},
|
||||
);
|
||||
else
|
||||
Object.assign(
|
||||
model,
|
||||
p
|
||||
? {
|
||||
providerId: p.provider_id,
|
||||
name: p.name,
|
||||
authMode: p.auth_mode || "BEARER",
|
||||
modelId: p.model_id,
|
||||
contextLength: p.context_length,
|
||||
maxOutput: p.max_output,
|
||||
toolsEnabled: p.tools_enabled,
|
||||
visionEnabled: p.vision_enabled,
|
||||
enabled: p.enabled,
|
||||
inputPrice: String(p.input_price),
|
||||
outputPrice: String(p.output_price),
|
||||
cacheReadPrice: String(p.cache_read_price),
|
||||
cacheWritePrice: String(p.cache_write_price),
|
||||
}
|
||||
: {
|
||||
providerId: providers.value[0]?.id || "",
|
||||
name: "",
|
||||
modelId: "",
|
||||
contextLength: 32768,
|
||||
maxOutput: 4096,
|
||||
toolsEnabled: false,
|
||||
visionEnabled: false,
|
||||
enabled: false,
|
||||
inputPrice: "0",
|
||||
outputPrice: "0",
|
||||
cacheReadPrice: "0",
|
||||
cacheWritePrice: "0",
|
||||
},
|
||||
);
|
||||
}
|
||||
async function save() {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
success.value = "";
|
||||
try {
|
||||
await api(
|
||||
"/admin/" + tab.value + (editing.value ? "/" + editing.value : ""),
|
||||
{
|
||||
method: editing.value ? "PUT" : "POST",
|
||||
body: body(tab.value === "providers" ? provider : model),
|
||||
},
|
||||
);
|
||||
provider.apiKey = "";
|
||||
show.value = false;
|
||||
success.value = "配置已保存,操作已记录";
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function test(p: any) {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
success.value = (
|
||||
await api("/admin/providers/" + p.id + "/test", {
|
||||
method: "POST",
|
||||
signal: AbortSignal.timeout(190000),
|
||||
})
|
||||
).message;
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
await load();
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
await load();
|
||||
try {
|
||||
presets.value = await api("/admin/providers/presets");
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">MODEL OPERATIONS</span>
|
||||
<h1>供应商与模型</h1>
|
||||
<p>加密凭证、多协议接入与版本化价格,单位 CNY / 百万 Token。</p>
|
||||
</div>
|
||||
<button class="primary" @click="edit()">
|
||||
添加{{ tab === "providers" ? "供应商" : "模型" }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="alert error" v-if="error">{{ error }}</div>
|
||||
<div class="alert success" v-if="success">{{ success }}</div>
|
||||
<div class="toolbar">
|
||||
<button
|
||||
:class="tab === 'providers' ? 'primary' : 'secondary'"
|
||||
@click="
|
||||
tab = 'providers';
|
||||
show = false;
|
||||
"
|
||||
>
|
||||
供应商</button
|
||||
><button
|
||||
:class="tab === 'models' ? 'primary' : 'secondary'"
|
||||
@click="
|
||||
tab = 'models';
|
||||
show = false;
|
||||
"
|
||||
>
|
||||
模型与计费</button
|
||||
><button class="secondary push" @click="load">刷新</button>
|
||||
</div>
|
||||
<section class="panel table-panel">
|
||||
<div class="table-scroll">
|
||||
<table v-if="tab === 'providers'">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>名称 / 协议</th>
|
||||
<th>API 地址</th>
|
||||
<th>连接状态</th>
|
||||
<th>开放状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="p in providers" :key="p.id">
|
||||
<td>
|
||||
{{ p.name }}<small class="block">{{ p.api_type }}</small>
|
||||
</td>
|
||||
<td>
|
||||
{{ p.base_url
|
||||
}}<small class="block danger" v-if="p.last_error">{{
|
||||
p.last_error
|
||||
}}</small>
|
||||
</td>
|
||||
<td>{{ p.connection_status }}</td>
|
||||
<td>{{ p.enabled ? "启用" : "停用" }}</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button class="link" @click="edit(p)">编辑 / 轮换密钥</button
|
||||
><button class="link" :disabled="busy" @click="test(p)">
|
||||
测试连接
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!providers.length">
|
||||
<td colspan="5" class="empty">
|
||||
尚未配置供应商。先设置服务端加密密钥与允许的主机列表。
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table v-else>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>模型</th>
|
||||
<th>供应商</th>
|
||||
<th>输入 / 输出价格</th>
|
||||
<th>缓存读 / 写</th>
|
||||
<th>上下文 / 输出</th>
|
||||
<th>状态</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="m in models" :key="m.id">
|
||||
<td>
|
||||
{{ m.name }}<small class="block">{{ m.model_id }}</small>
|
||||
</td>
|
||||
<td>{{ m.provider_name }}</td>
|
||||
<td>{{ m.input_price }} / {{ m.output_price }}</td>
|
||||
<td>{{ m.cache_read_price }} / {{ m.cache_write_price }}</td>
|
||||
<td>{{ m.context_length }} / {{ m.max_output }}</td>
|
||||
<td>
|
||||
{{ m.enabled ? "开放" : "停用" }} ·
|
||||
{{ m.tools_enabled ? "工具" : "文本" }}
|
||||
</td>
|
||||
<td><button class="link" @click="edit(m)">编辑</button></td>
|
||||
</tr>
|
||||
<tr v-if="!models.length">
|
||||
<td colspan="7" class="empty">
|
||||
暂无模型,价格由管理员配置,不预置虚假模型。
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<div class="alert info">
|
||||
连接测试会实际请求供应商的模型列表。它不会伪造成功,也不等于已验证所有模型的工具能力。模型必须支持工具调用才能用于开发任务。
|
||||
</div>
|
||||
<div v-if="show" class="modal-backdrop" @click.self="show = false">
|
||||
<section
|
||||
class="modal"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="model-title"
|
||||
>
|
||||
<div class="modal-heading">
|
||||
<h2 id="model-title">
|
||||
{{ editing ? "编辑" : "添加"
|
||||
}}{{ tab === "providers" ? "供应商" : "模型" }}
|
||||
</h2>
|
||||
<button class="secondary" @click="show = false">关闭</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<form @submit.prevent="save">
|
||||
<template v-if="tab === 'providers'"
|
||||
><label v-if="!editing"
|
||||
>供应商模板<select v-model="selectedPreset" @change="applyPreset">
|
||||
<option v-for="p in presets" :key="p.id" :value="p.id">
|
||||
{{ p.region }} · {{ p.name }}
|
||||
</option>
|
||||
</select></label
|
||||
><label
|
||||
>名称<input
|
||||
v-model="provider.name"
|
||||
required
|
||||
maxlength="100" /></label
|
||||
><label
|
||||
>API 类型<select v-model="provider.apiType">
|
||||
<option>OPENAI</option>
|
||||
<option>ANTHROPIC</option>
|
||||
<option>GEMINI</option>
|
||||
</select></label
|
||||
><label
|
||||
>密钥认证方式<select v-model="provider.authMode">
|
||||
<option value="BEARER">Authorization: Bearer(通用)</option>
|
||||
<option value="API_KEY">api-key(MiMo 等)</option>
|
||||
<option value="X_API_KEY">x-api-key</option>
|
||||
</select></label
|
||||
><label
|
||||
>Base URL(包含 API 版本路径)<input
|
||||
v-model="provider.baseUrl"
|
||||
required
|
||||
type="url"
|
||||
maxlength="1000"
|
||||
placeholder="https://api.openai.com/v1" /></label
|
||||
><label
|
||||
>API Key<input
|
||||
v-model="provider.apiKey"
|
||||
type="password"
|
||||
:required="!editing"
|
||||
autocomplete="off"
|
||||
maxlength="2000"
|
||||
/><small
|
||||
>编辑时留空保持原值;完整密钥不会通过 API 返回。</small
|
||||
></label
|
||||
><label
|
||||
>超时(秒)<input
|
||||
v-model.number="provider.timeoutSeconds"
|
||||
type="number"
|
||||
min="5"
|
||||
max="180"
|
||||
required /></label
|
||||
><label
|
||||
>状态<select v-model="provider.enabled">
|
||||
<option :value="false">停用</option>
|
||||
<option :value="true">启用</option>
|
||||
</select></label
|
||||
></template
|
||||
><template v-else
|
||||
><label
|
||||
>供应商<select
|
||||
v-model="model.providerId"
|
||||
required
|
||||
:disabled="!!editing"
|
||||
>
|
||||
<option v-for="p in providers" :key="p.id" :value="p.id">
|
||||
{{ p.name }}
|
||||
</option>
|
||||
</select></label
|
||||
><label
|
||||
>显示名称<input
|
||||
v-model="model.name"
|
||||
required
|
||||
maxlength="100" /></label
|
||||
><label
|
||||
>实际模型 ID<input
|
||||
v-model="model.modelId"
|
||||
:disabled="!!editing"
|
||||
required
|
||||
maxlength="200"
|
||||
/></label>
|
||||
<div class="two-columns">
|
||||
<label
|
||||
>上下文长度<input
|
||||
v-model.number="model.contextLength"
|
||||
type="number"
|
||||
min="256"
|
||||
max="4000000"
|
||||
required /></label
|
||||
><label
|
||||
>最大输出<input
|
||||
v-model.number="model.maxOutput"
|
||||
type="number"
|
||||
min="1"
|
||||
:max="model.contextLength"
|
||||
required
|
||||
/></label>
|
||||
</div>
|
||||
<div class="two-columns">
|
||||
<label
|
||||
>输入单价<input
|
||||
v-model="model.inputPrice"
|
||||
type="number"
|
||||
step="0.00000001"
|
||||
min="0"
|
||||
required /></label
|
||||
><label
|
||||
>输出单价<input
|
||||
v-model="model.outputPrice"
|
||||
type="number"
|
||||
step="0.00000001"
|
||||
min="0"
|
||||
required /></label
|
||||
><label
|
||||
>缓存读取单价<input
|
||||
v-model="model.cacheReadPrice"
|
||||
type="number"
|
||||
step="0.00000001"
|
||||
min="0"
|
||||
required /></label
|
||||
><label
|
||||
>缓存写入单价<input
|
||||
v-model="model.cacheWritePrice"
|
||||
type="number"
|
||||
step="0.00000001"
|
||||
min="0"
|
||||
required
|
||||
/></label>
|
||||
</div>
|
||||
<label
|
||||
>工具调用<select v-model="model.toolsEnabled">
|
||||
<option :value="false">不支持</option>
|
||||
<option :value="true">支持(请先核实模型能力)</option>
|
||||
</select></label
|
||||
><label
|
||||
>视觉输入能力<select v-model="model.visionEnabled">
|
||||
<option :value="false">不支持</option>
|
||||
<option :value="true">支持</option>
|
||||
</select></label
|
||||
><label
|
||||
>用户可选<select v-model="model.enabled">
|
||||
<option :value="false">不开放</option>
|
||||
<option :value="true">开放</option>
|
||||
</select></label
|
||||
></template
|
||||
><button class="primary wide" :disabled="busy">
|
||||
{{ busy ? "处理中…" : "保存配置" }}
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,190 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { api } from "../api";
|
||||
const local = ref<any>(null),
|
||||
nodes = ref<any[]>([]),
|
||||
error = ref(""),
|
||||
busy = ref(false),
|
||||
details = ref("");
|
||||
const workers = ref<any>({ workers: [], execution: null, queuedTasks: 0 });
|
||||
const gb = (n: number) =>
|
||||
n === undefined ? "—" : (n / 1024 ** 3).toFixed(2) + " GB";
|
||||
async function load() {
|
||||
try {
|
||||
[local.value, nodes.value, workers.value] = await Promise.all([
|
||||
api("/admin/nodes/control-plane"),
|
||||
api("/admin/nodes"),
|
||||
api("/admin/workers"),
|
||||
]);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function refresh() {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
nodes.value = (
|
||||
await api("/admin/nodes/refresh", {
|
||||
method: "POST",
|
||||
signal: AbortSignal.timeout(125000),
|
||||
})
|
||||
).items;
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">INFRASTRUCTURE</span>
|
||||
<h1>服务器与节点</h1>
|
||||
<p>控制面真实主机信息与运行集群节点分别显示。</p>
|
||||
</div>
|
||||
<button class="primary" :disabled="busy" @click="refresh">
|
||||
同步集群节点
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error">{{ error }}</div>
|
||||
<section
|
||||
v-if="workers.execution"
|
||||
class="panel form-panel"
|
||||
style="margin-bottom: 24px"
|
||||
>
|
||||
<h3>AI 执行服务 · {{ workers.execution.ready ? "已就绪" : "未就绪" }}</h3>
|
||||
<p style="margin-top: 12px">{{ workers.execution.reason }}</p>
|
||||
<p class="muted">
|
||||
当前排队 {{ workers.queuedTasks }} 项 · 就绪实例
|
||||
{{ workers.execution.readyWorkers }} 个
|
||||
</p>
|
||||
<div
|
||||
v-if="!workers.workers.length"
|
||||
class="alert info"
|
||||
style="margin-top: 14px"
|
||||
>
|
||||
尚未收到执行实例心跳。请在测试集群部署隔离网关,再启用独立 AI
|
||||
Worker;前端和 API 服务正常运行并不代表执行服务已启动。
|
||||
</div>
|
||||
<div v-else class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>实例</th>
|
||||
<th>状态</th>
|
||||
<th>本实例容量 / 执行中</th>
|
||||
<th>健康检查</th>
|
||||
<th>最后心跳</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="w in workers.workers" :key="w.instance_id">
|
||||
<td>
|
||||
<code>{{ w.instance_id.slice(0, 8) }}</code>
|
||||
</td>
|
||||
<td>
|
||||
{{
|
||||
w.status === "STOPPED"
|
||||
? "已停止"
|
||||
: !w.fresh
|
||||
? "心跳超时"
|
||||
: w.status === "READY"
|
||||
? "已就绪"
|
||||
: "环境异常"
|
||||
}}
|
||||
</td>
|
||||
<td>{{ w.capacity }} / {{ w.active_tasks }}</td>
|
||||
<td>{{ w.detail }}</td>
|
||||
<td>{{ new Date(w.updated_at).toLocaleString() }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="local" class="stats">
|
||||
<div class="stat-card">
|
||||
<div>控制面 CPU</div>
|
||||
<strong>{{ local.processors }} 核</strong
|
||||
><small
|
||||
>负载
|
||||
{{
|
||||
local.cpuLoad === null
|
||||
? "未采集"
|
||||
: (local.cpuLoad * 100).toFixed(1) + "%"
|
||||
}}</small
|
||||
>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div>物理内存</div>
|
||||
<strong class="text-stat">{{ gb(local.physicalMemoryTotal) }}</strong
|
||||
><small>可用 {{ gb(local.physicalMemoryFree) }}</small>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div>磁盘</div>
|
||||
<strong class="text-stat">{{ gb(local.diskTotal) }}</strong
|
||||
><small>可用 {{ gb(local.diskUsable) }}</small>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div>JVM 堆内存</div>
|
||||
<strong class="text-stat">{{ gb(local.heapUsed) }}</strong
|
||||
><small>上限 {{ gb(local.heapMax) }}</small>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="local" class="panel form-panel">
|
||||
<h3>控制面运行环境</h3>
|
||||
<p class="muted" style="margin-top: 14px">
|
||||
{{ local.os }} · {{ local.architecture }} · Java {{ local.javaVersion }} ·
|
||||
运行 {{ Math.floor(local.uptimeMillis / 60000) }} 分钟
|
||||
</p>
|
||||
<button class="text-link" style="margin-top: 12px" @click="load">
|
||||
刷新本机信息 →
|
||||
</button>
|
||||
</section>
|
||||
<section class="panel table-panel" style="margin-top: 24px">
|
||||
<div class="panel-heading"><h3>运行集群节点</h3></div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>节点</th>
|
||||
<th>状态</th>
|
||||
<th>CPU / 内存</th>
|
||||
<th>内网地址</th>
|
||||
<th>最近采集</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="n in nodes" :key="n.name">
|
||||
<td>{{ n.name }}</td>
|
||||
<td>{{ n.status }}</td>
|
||||
<td>{{ n.cpu_capacity }} / {{ n.memory_capacity }}</td>
|
||||
<td>{{ n.internal_ip }}</td>
|
||||
<td>{{ new Date(n.last_seen).toLocaleString() }}</td>
|
||||
<td>
|
||||
<button
|
||||
class="link"
|
||||
@click="
|
||||
details = JSON.stringify(JSON.parse(n.node_info), null, 2)
|
||||
"
|
||||
>
|
||||
详细信息
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!nodes.length">
|
||||
<td class="empty" colspan="6">
|
||||
尚未同步运行节点。未配置网关时不展示模拟节点。
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="details" class="panel event-log">
|
||||
<pre style="white-space: pre-wrap">{{ details }}</pre>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,187 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from "vue";
|
||||
import { api, body } from "../api";
|
||||
const plans = ref<any[]>([]),
|
||||
editing = ref(""),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
open = ref(false),
|
||||
busy = ref(false);
|
||||
const form = reactive({
|
||||
name: "",
|
||||
monthlyPrice: "0",
|
||||
cpuMillis: 1000,
|
||||
memoryMb: 1024,
|
||||
diskGb: 5,
|
||||
trafficGb: 5,
|
||||
maxServices: 3,
|
||||
maxReplicas: 1,
|
||||
autoFailover: false,
|
||||
enabled: true,
|
||||
});
|
||||
async function load() {
|
||||
try {
|
||||
plans.value = await api("/admin/plans");
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
function edit(p?: any) {
|
||||
editing.value = p?.id || "";
|
||||
Object.assign(
|
||||
form,
|
||||
p
|
||||
? {
|
||||
name: p.name,
|
||||
monthlyPrice: String(p.monthly_price),
|
||||
cpuMillis: p.cpu_millis,
|
||||
memoryMb: p.memory_mb,
|
||||
diskGb: p.disk_gb,
|
||||
trafficGb: p.traffic_gb,
|
||||
maxServices: p.max_services,
|
||||
maxReplicas: p.max_replicas,
|
||||
autoFailover: p.auto_failover,
|
||||
enabled: p.enabled,
|
||||
}
|
||||
: {
|
||||
name: "",
|
||||
monthlyPrice: "0",
|
||||
cpuMillis: 1000,
|
||||
memoryMb: 1024,
|
||||
diskGb: 5,
|
||||
trafficGb: 5,
|
||||
maxServices: 3,
|
||||
maxReplicas: 1,
|
||||
autoFailover: false,
|
||||
enabled: true,
|
||||
},
|
||||
);
|
||||
open.value = true;
|
||||
}
|
||||
async function save() {
|
||||
busy.value = true;
|
||||
try {
|
||||
await api("/admin/plans" + (editing.value ? "/" + editing.value : ""), {
|
||||
method: editing.value ? "PUT" : "POST",
|
||||
body: body(form),
|
||||
});
|
||||
success.value = "套餐已保存,既有订阅保持购买快照";
|
||||
open.value = false;
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">HOSTING PLANS</span>
|
||||
<h1>托管套餐</h1>
|
||||
<p>动态配置价格、资源与开放状态。</p>
|
||||
</div>
|
||||
<button class="primary" @click="edit()">添加套餐</button>
|
||||
</div>
|
||||
<div class="alert error" v-if="error">{{ error }}</div>
|
||||
<div class="alert success" v-if="success">{{ success }}</div>
|
||||
<section class="panel table-panel">
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>套餐</th>
|
||||
<th>月价</th>
|
||||
<th>CPU / 内存</th>
|
||||
<th>磁盘 / 流量</th>
|
||||
<th>服务 / 副本</th>
|
||||
<th>状态</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="p in plans" :key="p.id">
|
||||
<td>{{ p.name }}</td>
|
||||
<td>¥ {{ p.monthly_price }}</td>
|
||||
<td>{{ p.cpu_millis }}m / {{ p.memory_mb }}MiB</td>
|
||||
<td>{{ p.disk_gb }}GB / {{ p.traffic_gb }}GB</td>
|
||||
<td>{{ p.max_services }} / {{ p.max_replicas }}</td>
|
||||
<td>{{ p.enabled ? "开放" : "停用" }}</td>
|
||||
<td><button class="link" @click="edit(p)">编辑</button></td>
|
||||
</tr>
|
||||
<tr v-if="!plans.length">
|
||||
<td colspan="7" class="empty">暂无套餐</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="open" class="panel form-panel settings-form">
|
||||
<h3>套餐配置</h3>
|
||||
<form @submit.prevent="save" style="margin-top: 20px">
|
||||
<label>名称<input v-model="form.name" required maxlength="100" /></label
|
||||
><label
|
||||
>月价 CNY<input
|
||||
v-model="form.monthlyPrice"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.00000001"
|
||||
required /></label
|
||||
><label
|
||||
>CPU 毫核<input
|
||||
v-model.number="form.cpuMillis"
|
||||
type="number"
|
||||
min="50"
|
||||
max="64000"
|
||||
required /></label
|
||||
><label
|
||||
>内存 MiB<input
|
||||
v-model.number="form.memoryMb"
|
||||
type="number"
|
||||
min="64"
|
||||
max="262144"
|
||||
required /></label
|
||||
><label
|
||||
>磁盘额度 GB<input
|
||||
v-model.number="form.diskGb"
|
||||
type="number"
|
||||
min="1"
|
||||
max="100000"
|
||||
required /></label
|
||||
><label
|
||||
>月流量额度 GB<input
|
||||
v-model.number="form.trafficGb"
|
||||
type="number"
|
||||
min="0"
|
||||
max="10000000"
|
||||
required /></label
|
||||
><label
|
||||
>服务数<input
|
||||
v-model.number="form.maxServices"
|
||||
type="number"
|
||||
min="1"
|
||||
max="100"
|
||||
required /></label
|
||||
><label
|
||||
>副本上限<input
|
||||
v-model.number="form.maxReplicas"
|
||||
type="number"
|
||||
min="1"
|
||||
max="20"
|
||||
required /></label
|
||||
><label
|
||||
>状态<select v-model="form.enabled">
|
||||
<option :value="true">开放</option>
|
||||
<option :value="false">停用</option>
|
||||
</select></label
|
||||
>
|
||||
<div class="modal-footer">
|
||||
<button class="secondary" type="button" @click="open = false">
|
||||
取消</button
|
||||
><button class="primary" :disabled="busy">保存</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,133 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { ArrowLeft, ArrowRight, Puzzle } from "lucide-vue-next";
|
||||
import { api } from "../api";
|
||||
import type { Plugin } from "../extensions";
|
||||
|
||||
const route = useRoute();
|
||||
const tools = ref<Plugin[]>([]),
|
||||
loading = ref(true),
|
||||
error = ref("");
|
||||
const slug = computed(() => route.params.pluginSlug);
|
||||
const selected = computed(() =>
|
||||
tools.value.find((tool) => tool.slug === slug.value),
|
||||
);
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
tools.value = await api("/extensions/plugins");
|
||||
} catch (e) {
|
||||
tools.value = [];
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
watch(slug, load, { immediate: true });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">WORKSPACE TOOLS</span>
|
||||
<h1>{{ selected?.name ?? "扩展工具" }}</h1>
|
||||
<p>{{ selected?.description || "使用站点管理员提供的工具。" }}</p>
|
||||
</div>
|
||||
<RouterLink v-if="slug" class="text-link tool-back" to="/extensions"
|
||||
><ArrowLeft :size="15" />返回工具列表</RouterLink
|
||||
>
|
||||
<button v-else class="secondary" :disabled="loading" @click="load">
|
||||
刷新
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="error" class="alert error" role="alert">{{ error }}</div>
|
||||
<p v-else-if="loading" class="muted" role="status">正在读取扩展工具…</p>
|
||||
<template v-else-if="slug">
|
||||
<section v-if="selected" class="panel tool-frame">
|
||||
<div class="tool-meta">
|
||||
<Puzzle :size="15" />站点扩展 · {{ selected.version }}
|
||||
</div>
|
||||
<iframe
|
||||
:key="selected.id"
|
||||
:title="selected.name"
|
||||
:src="'/api/public/extensions/plugin-frame/' + selected.id"
|
||||
sandbox="allow-scripts"
|
||||
referrerpolicy="no-referrer"
|
||||
></iframe>
|
||||
</section>
|
||||
<div v-else class="alert info">这个工具当前不可用,可能已经停用。</div>
|
||||
</template>
|
||||
<section v-else class="tool-grid">
|
||||
<RouterLink
|
||||
v-for="tool in tools"
|
||||
:key="tool.id"
|
||||
class="panel tool-card"
|
||||
:to="'/extensions/' + tool.slug"
|
||||
>
|
||||
<div class="tool-icon"><Puzzle :size="20" /></div>
|
||||
<strong>{{ tool.name }}</strong>
|
||||
<p>{{ tool.description }}</p>
|
||||
<span>打开工具 <ArrowRight :size="14" /></span>
|
||||
</RouterLink>
|
||||
<div v-if="!tools.length" class="panel form-panel">
|
||||
站点还没有启用扩展工具。
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.tool-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
|
||||
gap: 15px;
|
||||
}
|
||||
.tool-card {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
padding: 18px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.tool-card:hover {
|
||||
border-color: var(--blue);
|
||||
}
|
||||
.tool-card p {
|
||||
font-size: 13px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.tool-card span,
|
||||
.tool-back {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: var(--blue);
|
||||
}
|
||||
.tool-icon {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 10px;
|
||||
color: var(--blue);
|
||||
background: var(--blue-light);
|
||||
}
|
||||
.tool-frame {
|
||||
overflow: hidden;
|
||||
}
|
||||
.tool-meta {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
padding: 12px 16px;
|
||||
color: var(--muted);
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.tool-frame iframe {
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: 65vh;
|
||||
border: 0;
|
||||
background: white;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,221 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { api, body } from "../api";
|
||||
import {
|
||||
Plus,
|
||||
FolderKanban,
|
||||
Search,
|
||||
X,
|
||||
ArrowUpRight,
|
||||
Archive,
|
||||
} from "lucide-vue-next";
|
||||
const route = useRoute(),
|
||||
router = useRouter(),
|
||||
projects = ref<any[]>([]),
|
||||
search = ref(""),
|
||||
loading = ref(true),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
editing = ref<string | null>(null),
|
||||
open = ref(false),
|
||||
busy = ref(false);
|
||||
const form = reactive({
|
||||
name: "",
|
||||
description: "",
|
||||
stack: "Vue 3",
|
||||
requirements: "",
|
||||
});
|
||||
function edit(p?: any) {
|
||||
editing.value = p?.id || null;
|
||||
Object.assign(
|
||||
form,
|
||||
p
|
||||
? {
|
||||
name: p.name,
|
||||
description: p.description,
|
||||
stack: p.stack,
|
||||
requirements: p.requirements,
|
||||
}
|
||||
: { name: "", description: "", stack: "Vue 3", requirements: "" },
|
||||
);
|
||||
open.value = true;
|
||||
}
|
||||
async function load() {
|
||||
try {
|
||||
projects.value = await api("/projects");
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
async function save() {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
await api("/projects" + (editing.value ? "/" + editing.value : ""), {
|
||||
method: editing.value ? "PUT" : "POST",
|
||||
body: body(form),
|
||||
});
|
||||
open.value = false;
|
||||
success.value = "项目已保存,可以进入 AI 开发选择模型并开始任务。";
|
||||
router.replace("/projects");
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function archive(p: any) {
|
||||
if (!confirm("将「" + p.name + "」归档?项目数据会保留。")) return;
|
||||
try {
|
||||
await api("/projects/" + p.id + "/archive", { method: "POST" });
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
await load();
|
||||
if (route.query.new) edit();
|
||||
if (route.query.edit) {
|
||||
const p = projects.value.find((p) => p.id === route.query.edit);
|
||||
if (p) edit(p);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">YOUR NEXT CREATION</span>
|
||||
<h1>我的项目</h1>
|
||||
<p>把每一次灵感,变成有迹可循的计划。</p>
|
||||
</div>
|
||||
<button class="primary" @click="edit()"><Plus :size="17" />创建项目</button>
|
||||
</div>
|
||||
<div class="alert error" v-if="error" role="alert">{{ error }}</div>
|
||||
<div class="alert success" v-if="success" role="status">{{ success }}</div>
|
||||
<div class="toolbar">
|
||||
<div class="search-input">
|
||||
<Search :size="17" /><input
|
||||
v-model="search"
|
||||
placeholder="搜索项目名称或技术栈"
|
||||
aria-label="搜索项目"
|
||||
/>
|
||||
</div>
|
||||
<span class="muted">{{ projects.length }} 个项目</span>
|
||||
</div>
|
||||
<div v-if="loading" class="panel empty">正在加载…</div>
|
||||
<div v-else-if="!projects.length" class="panel empty big-empty">
|
||||
<div class="empty-icon"><FolderKanban :size="32" /></div>
|
||||
<h3>留给下一个好想法</h3>
|
||||
<p>创建项目,填写需求与技术栈,保存你的构建计划。</p>
|
||||
<button class="primary" @click="edit()">
|
||||
<Plus :size="16" />创建第一个项目
|
||||
</button>
|
||||
</div>
|
||||
<div v-else class="project-grid">
|
||||
<article
|
||||
class="panel project-card"
|
||||
v-for="p in projects.filter((p) =>
|
||||
(p.name + p.stack).toLowerCase().includes(search.toLowerCase()),
|
||||
)"
|
||||
:key="p.id"
|
||||
>
|
||||
<div class="project-card-top">
|
||||
<span class="project-icon"><FolderKanban :size="23" /></span
|
||||
><span class="status">{{
|
||||
p.status === "DRAFT" ? "草稿" : "已归档"
|
||||
}}</span>
|
||||
</div>
|
||||
<h3>{{ p.name }}</h3>
|
||||
<p>{{ p.description || "暂无项目简介" }}</p>
|
||||
<div class="project-meta">
|
||||
<span>{{ p.stack }}</span
|
||||
><small>{{ new Date(p.created_at).toLocaleDateString() }}</small>
|
||||
</div>
|
||||
<div class="project-actions">
|
||||
<button class="text-link" @click="edit(p)">
|
||||
项目需求 <ArrowUpRight :size="15" /></button
|
||||
><button
|
||||
v-if="p.status !== 'ARCHIVED'"
|
||||
class="icon-button"
|
||||
@click="archive(p)"
|
||||
aria-label="归档项目"
|
||||
>
|
||||
<Archive :size="17" />
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div v-if="open" class="modal-backdrop" @click.self="open = false">
|
||||
<section
|
||||
class="modal"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="project-title"
|
||||
>
|
||||
<div class="modal-heading">
|
||||
<div>
|
||||
<h2 id="project-title">{{ editing ? "编辑项目" : "创建新项目" }}</h2>
|
||||
<p>先为你的想法,建立一个起点。</p>
|
||||
</div>
|
||||
<button class="icon-button" @click="open = false" aria-label="关闭">
|
||||
<X />
|
||||
</button>
|
||||
</div>
|
||||
<div class="alert error" v-if="error">{{ error }}</div>
|
||||
<form @submit.prevent="save">
|
||||
<label
|
||||
>项目名称<input
|
||||
v-model="form.name"
|
||||
required
|
||||
maxlength="100"
|
||||
placeholder="给你的项目起个名字" /></label
|
||||
><label
|
||||
>项目简介<input
|
||||
v-model="form.description"
|
||||
maxlength="2000"
|
||||
placeholder="用一句话介绍你的项目" /></label
|
||||
><label
|
||||
>技术栈<select v-model="form.stack">
|
||||
<option
|
||||
v-for="s in [
|
||||
'Vue 3',
|
||||
'React',
|
||||
'Next.js',
|
||||
'Nuxt',
|
||||
'HTML',
|
||||
'Node.js',
|
||||
'FastAPI',
|
||||
'Laravel',
|
||||
]"
|
||||
:key="s"
|
||||
>
|
||||
{{ s }}
|
||||
</option>
|
||||
</select></label
|
||||
><label
|
||||
>开发需求<textarea
|
||||
v-model="form.requirements"
|
||||
maxlength="10000"
|
||||
rows="5"
|
||||
placeholder="描述网站的功能、风格、目标用户及其他要求…"
|
||||
/>
|
||||
</label>
|
||||
<div class="alert info">
|
||||
当前支持项目需求持久保存。AI 执行、构建与部署将在后续阶段开放。
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="secondary" @click="open = false">
|
||||
取消</button
|
||||
><button class="primary" :disabled="busy">
|
||||
{{ busy ? "保存中…" : "保存项目" }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,445 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { api } from "../api";
|
||||
import {
|
||||
HardDrive,
|
||||
Upload,
|
||||
Download,
|
||||
Trash2,
|
||||
RotateCcw,
|
||||
RefreshCw,
|
||||
} from "lucide-vue-next";
|
||||
const projects = ref<any[]>([]),
|
||||
project = ref(""),
|
||||
rows = ref<any[]>([]),
|
||||
summary = ref<any>({}),
|
||||
total = ref(0),
|
||||
page = ref(0),
|
||||
trash = ref(false),
|
||||
busy = ref(false),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
loading = ref(false);
|
||||
const selected = ref<File | null>(null),
|
||||
uploadKey = ref("");
|
||||
let request = 0;
|
||||
const percent = computed(() =>
|
||||
summary.value.quotaBytes
|
||||
? Math.min(100, (summary.value.usedBytes / summary.value.quotaBytes) * 100)
|
||||
: 0,
|
||||
);
|
||||
const labels: Record<string, string> = {
|
||||
READY: "可用",
|
||||
UPLOADING: "上传中",
|
||||
FAILED: "待核对",
|
||||
DELETED: "回收站",
|
||||
};
|
||||
function size(n: number) {
|
||||
if (!n) return "0 B";
|
||||
const i = Math.min(3, Math.floor(Math.log(n) / Math.log(1024)));
|
||||
return (
|
||||
(n / 1024 ** i).toFixed(i ? 2 : 0) + " " + ["B", "KiB", "MiB", "GiB"][i]
|
||||
);
|
||||
}
|
||||
async function load() {
|
||||
if (!project.value) return;
|
||||
const id = ++request,
|
||||
target = project.value;
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const data = await api(
|
||||
`/projects/${target}/storage?page=${page.value}&trash=${trash.value}`,
|
||||
);
|
||||
if (id !== request) return;
|
||||
rows.value = data.objects.items;
|
||||
total.value = data.objects.total;
|
||||
summary.value = data.summary;
|
||||
} catch (e) {
|
||||
if (id === request) error.value = (e as Error).message;
|
||||
} finally {
|
||||
if (id === request) loading.value = false;
|
||||
}
|
||||
}
|
||||
function changeProject() {
|
||||
selected.value = null;
|
||||
uploadKey.value = "";
|
||||
page.value = 0;
|
||||
rows.value = [];
|
||||
summary.value = {};
|
||||
success.value = "";
|
||||
load();
|
||||
}
|
||||
function choose(event: Event) {
|
||||
selected.value = (event.target as HTMLInputElement).files?.[0] || null;
|
||||
uploadKey.value = crypto.randomUUID();
|
||||
error.value = "";
|
||||
}
|
||||
async function checkedFetch(path: string, options: RequestInit = {}) {
|
||||
const response = await fetch("/api" + path, {
|
||||
...options,
|
||||
headers: {
|
||||
Authorization: "Bearer " + sessionStorage.getItem("session"),
|
||||
...options.headers,
|
||||
},
|
||||
signal: AbortSignal.timeout(90000),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const data = await response.json().catch(() => ({}));
|
||||
throw new Error(data.message || "文件操作失败,请检查服务状态");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
async function upload() {
|
||||
if (!selected.value) return;
|
||||
if (selected.value.size > 25 * 1024 * 1024) {
|
||||
error.value = "单文件不能超过 25MiB";
|
||||
return;
|
||||
}
|
||||
const form = new FormData();
|
||||
form.append("file", selected.value);
|
||||
form.append("idempotencyKey", uploadKey.value);
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
success.value = "";
|
||||
try {
|
||||
await checkedFetch(`/projects/${project.value}/storage`, {
|
||||
method: "POST",
|
||||
body: form,
|
||||
});
|
||||
selected.value = null;
|
||||
success.value = "文件已上传";
|
||||
page.value = 0;
|
||||
} catch (e) {
|
||||
error.value =
|
||||
(e as Error).message +
|
||||
"。如结果不确定,请在列表核对状态,重试将沿用本次上传标识。";
|
||||
} finally {
|
||||
busy.value = false;
|
||||
const message = error.value;
|
||||
await load();
|
||||
if (message) error.value = message;
|
||||
}
|
||||
}
|
||||
async function action(row: any, kind: string) {
|
||||
if (
|
||||
kind === "trash" &&
|
||||
!confirm(`将「${row.filename}」移入回收站?保留三十天,期间仍占用空间。`)
|
||||
)
|
||||
return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
success.value = "";
|
||||
try {
|
||||
const base = `/projects/${project.value}/storage/${row.id}`;
|
||||
if (kind === "download") {
|
||||
const res = await checkedFetch(base + "/content"),
|
||||
url = URL.createObjectURL(await res.blob()),
|
||||
link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = row.filename;
|
||||
link.click();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
} else {
|
||||
const data = await api(base + (kind === "trash" ? "" : "/" + kind), {
|
||||
method: kind === "trash" ? "DELETE" : "POST",
|
||||
});
|
||||
success.value =
|
||||
data.message ||
|
||||
(data.status === "READY"
|
||||
? "文件已核对,可以下载"
|
||||
: "已核对,文件仍未完整写入,可稍后重查或移入回收站");
|
||||
await load();
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
try {
|
||||
projects.value = await api("/projects");
|
||||
project.value = projects.value[0]?.id || "";
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">PROJECT OBJECT STORAGE</span>
|
||||
<h1>对象存储</h1>
|
||||
<p>集中管理项目文件,用量、上传状态与回收记录清晰可查。</p>
|
||||
</div>
|
||||
<HardDrive :size="30" />
|
||||
</div>
|
||||
<div v-if="success" class="alert success" role="status">{{ success }}</div>
|
||||
<div v-if="error" class="alert error" role="alert">{{ error }}</div>
|
||||
<div class="toolbar">
|
||||
<label
|
||||
>当前项目
|
||||
<select v-model="project" :disabled="busy" @change="changeProject">
|
||||
<option v-for="p in projects" :key="p.id" :value="p.id">
|
||||
{{ p.name }}
|
||||
</option>
|
||||
</select></label
|
||||
><button :disabled="busy || loading || !project" @click="load">
|
||||
<RefreshCw :size="16" />刷新
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="!projects.length" class="panel empty">
|
||||
<HardDrive :size="36" />
|
||||
<h3>先创建一个项目</h3>
|
||||
<p>每个项目拥有独立的文件命名空间和访问权限。</p>
|
||||
<RouterLink to="/projects" class="primary">前往我的项目</RouterLink>
|
||||
</div>
|
||||
<template v-else>
|
||||
<section class="panel storage-usage">
|
||||
<div>
|
||||
<h3>已用 {{ size(summary.usedBytes || 0) }}</h3>
|
||||
<p class="muted">
|
||||
总额度 {{ size(summary.quotaBytes || 0) }} ·
|
||||
回收站与待核对文件计入用量
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
class="storage-meter"
|
||||
role="progressbar"
|
||||
aria-label="存储用量"
|
||||
:aria-valuenow="Math.round(percent)"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100"
|
||||
>
|
||||
<i :style="{ width: percent + '%' }" />
|
||||
</div>
|
||||
</section>
|
||||
<div v-if="summary.configured === false" class="alert info">
|
||||
管理员尚未启用对象存储,请在独立管理后台的「集成配置」中配置 S3
|
||||
兼容存储。已有文件仍按原存储配置读取。
|
||||
</div>
|
||||
<section class="panel storage-upload">
|
||||
<div>
|
||||
<h3>上传文件</h3>
|
||||
<p class="muted">
|
||||
每个文件最大 25MiB。文件私有保存,下载需登录并拥有项目。
|
||||
</p>
|
||||
</div>
|
||||
<input
|
||||
type="file"
|
||||
aria-label="选择上传文件"
|
||||
:disabled="busy || !summary.configured"
|
||||
@change="choose"
|
||||
/><span v-if="selected" class="muted"
|
||||
>{{ selected.name }} · {{ size(selected.size) }}</span
|
||||
><button
|
||||
class="primary"
|
||||
:disabled="busy || !selected || !summary.configured"
|
||||
@click="upload"
|
||||
>
|
||||
<Upload :size="16" />{{ busy ? "处理中…" : "上传文件" }}
|
||||
</button>
|
||||
</section>
|
||||
<section class="panel storage-files">
|
||||
<div class="storage-tabs">
|
||||
<button
|
||||
:class="{ primary: !trash }"
|
||||
:disabled="busy"
|
||||
@click="
|
||||
trash = false;
|
||||
page = 0;
|
||||
load();
|
||||
"
|
||||
>
|
||||
项目文件</button
|
||||
><button
|
||||
:class="{ primary: trash }"
|
||||
:disabled="busy"
|
||||
@click="
|
||||
trash = true;
|
||||
page = 0;
|
||||
load();
|
||||
"
|
||||
>
|
||||
<Trash2 :size="16" />回收站</button
|
||||
><span class="muted">{{ total }} 个文件</span>
|
||||
</div>
|
||||
<p class="muted storage-note" v-if="trash">
|
||||
文件保留三十天,到期由存储清理任务删除。开始物理清理的文件无法恢复。
|
||||
</p>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>文件名称</th>
|
||||
<th>大小</th>
|
||||
<th>状态</th>
|
||||
<th>{{ trash ? "删除时间" : "创建时间" }}</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="loading">
|
||||
<td colspan="5">正在加载…</td>
|
||||
</tr>
|
||||
<tr v-else-if="!rows.length">
|
||||
<td colspan="5" class="empty">
|
||||
{{
|
||||
trash ? "回收站为空" : "还没有文件,上传项目资源即可开始。"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-for="row in loading ? [] : rows" :key="row.id">
|
||||
<td>
|
||||
<strong>{{ row.filename }}</strong
|
||||
><small class="storage-detail">{{ row.content_type }}</small
|
||||
><small v-if="row.error" class="storage-detail">{{
|
||||
row.error
|
||||
}}</small>
|
||||
</td>
|
||||
<td>{{ size(row.size_bytes) }}</td>
|
||||
<td>
|
||||
<span class="status">{{
|
||||
row.purge_started_at
|
||||
? "清理中"
|
||||
: labels[row.status] || row.status
|
||||
}}</span>
|
||||
</td>
|
||||
<td>
|
||||
{{
|
||||
new Date(
|
||||
trash ? row.deleted_at : row.created_at,
|
||||
).toLocaleString()
|
||||
}}
|
||||
</td>
|
||||
<td>
|
||||
<div class="storage-actions">
|
||||
<button
|
||||
v-if="row.status === 'READY'"
|
||||
:disabled="busy"
|
||||
@click="action(row, 'download')"
|
||||
aria-label="下载文件"
|
||||
>
|
||||
<Download :size="16" /></button
|
||||
><button
|
||||
v-if="['UPLOADING', 'FAILED'].includes(row.status)"
|
||||
:disabled="busy"
|
||||
@click="action(row, 'reconcile')"
|
||||
>
|
||||
核对状态</button
|
||||
><button
|
||||
v-if="['READY', 'FAILED'].includes(row.status)"
|
||||
:disabled="busy"
|
||||
@click="action(row, 'trash')"
|
||||
aria-label="移入回收站"
|
||||
>
|
||||
<Trash2 :size="16" /></button
|
||||
><button
|
||||
v-if="row.status === 'DELETED'"
|
||||
:disabled="busy || !!row.purge_started_at"
|
||||
@click="action(row, 'restore')"
|
||||
>
|
||||
<RotateCcw :size="16" />恢复
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="pagination">
|
||||
<button
|
||||
:disabled="busy || loading || page === 0"
|
||||
@click="
|
||||
page--;
|
||||
load();
|
||||
"
|
||||
>
|
||||
上一页</button
|
||||
><span>第 {{ page + 1 }} 页</span
|
||||
><button
|
||||
:disabled="busy || loading || (page + 1) * 50 >= total"
|
||||
@click="
|
||||
page++;
|
||||
load();
|
||||
"
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
</template>
|
||||
<style scoped>
|
||||
.storage-usage,
|
||||
.storage-upload,
|
||||
.storage-files {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.storage-usage,
|
||||
.storage-upload {
|
||||
padding: 24px;
|
||||
}
|
||||
.storage-meter {
|
||||
height: 9px;
|
||||
background: var(--line, #e8edf5);
|
||||
border-radius: 9px;
|
||||
overflow: hidden;
|
||||
margin-top: 18px;
|
||||
}
|
||||
.storage-meter i {
|
||||
display: block;
|
||||
height: 100%;
|
||||
background: #3b6ff5;
|
||||
border-radius: 9px;
|
||||
}
|
||||
.storage-upload {
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.storage-upload > div {
|
||||
flex: 1;
|
||||
min-width: 230px;
|
||||
}
|
||||
.storage-upload input {
|
||||
max-width: 260px;
|
||||
}
|
||||
.storage-tabs {
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
.storage-tabs span {
|
||||
margin-left: auto;
|
||||
}
|
||||
.storage-note {
|
||||
padding: 0 20px;
|
||||
}
|
||||
.storage-detail {
|
||||
display: block;
|
||||
max-width: 330px;
|
||||
overflow-wrap: anywhere;
|
||||
margin-top: 7px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.storage-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-scroll {
|
||||
overflow: auto;
|
||||
}
|
||||
td strong {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.toolbar select {
|
||||
margin-left: 12px;
|
||||
max-width: 280px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,794 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { ArrowLeft, LifeBuoy, Plus, RefreshCw } from "lucide-vue-next";
|
||||
import { api, body } from "../api";
|
||||
|
||||
const statuses = {
|
||||
WAITING_SUPPORT: "待客服处理",
|
||||
WAITING_CUSTOMER: "待用户回复",
|
||||
RESOLVED: "已解决",
|
||||
CLOSED: "已关闭",
|
||||
};
|
||||
const categories = {
|
||||
AI: "AI 开发",
|
||||
HOSTING: "托管与域名",
|
||||
BILLING: "费用与套餐",
|
||||
ACCOUNT: "账户与安全",
|
||||
OTHER: "其他问题",
|
||||
};
|
||||
const priorities = { NORMAL: "普通", HIGH: "较高", URGENT: "紧急" };
|
||||
type State = keyof typeof statuses;
|
||||
type Category = keyof typeof categories;
|
||||
type Priority = keyof typeof priorities;
|
||||
type Ticket = {
|
||||
id: string;
|
||||
ticket_no: number;
|
||||
subject: string;
|
||||
category: Category;
|
||||
status: State;
|
||||
project_name: string | null;
|
||||
updated_at: string;
|
||||
unread?: boolean;
|
||||
reply_revision?: number;
|
||||
owner_name?: string;
|
||||
owner_email?: string;
|
||||
assignee_id?: string | null;
|
||||
assignee_name?: string | null;
|
||||
assignee_status?: string | null;
|
||||
priority?: Priority;
|
||||
};
|
||||
type Message = {
|
||||
id: string;
|
||||
kind: "CUSTOMER" | "STAFF" | "NOTE" | "SYSTEM" | "INTERNAL";
|
||||
content: string;
|
||||
created_at: string;
|
||||
author_name?: string;
|
||||
};
|
||||
type Detail = { ticket: Ticket; messages: Message[]; hasOlder: boolean };
|
||||
type TicketList = {
|
||||
items: Ticket[];
|
||||
counts: { status: State; total: number }[];
|
||||
hasMore: boolean;
|
||||
};
|
||||
type Agent = { id: string; display_name: string; email: string };
|
||||
type Action = {
|
||||
operation:
|
||||
| "REPLY"
|
||||
| "NOTE"
|
||||
| "ASSIGN"
|
||||
| "PRIORITY"
|
||||
| "RESOLVE"
|
||||
| "CLOSE"
|
||||
| "REOPEN";
|
||||
content?: string;
|
||||
assigneeId?: string | null;
|
||||
priority?: Priority;
|
||||
};
|
||||
|
||||
const route = useRoute(),
|
||||
router = useRouter();
|
||||
const staff = computed(() => route.meta.permission === "tickets:manage");
|
||||
const base = computed(() => (staff.value ? "/admin/tickets" : "/tickets"));
|
||||
const ticketId = computed(() =>
|
||||
typeof route.params.ticketId === "string" ? route.params.ticketId : "",
|
||||
);
|
||||
const list = ref<TicketList | null>(null),
|
||||
detail = ref<Detail | null>(null);
|
||||
const agents = ref<Agent[]>([]),
|
||||
projects = ref<{ id: string; name: string }[]>([]);
|
||||
const error = ref(""),
|
||||
loading = ref(false),
|
||||
busy = ref(false);
|
||||
const search = ref(""),
|
||||
status = ref<State | "">(""),
|
||||
category = ref<Category | "">(""),
|
||||
page = ref(0);
|
||||
const createOpen = ref(false);
|
||||
const draft = ref({
|
||||
subject: "",
|
||||
category: "AI" as Category,
|
||||
projectId: "",
|
||||
content: "",
|
||||
});
|
||||
const publicReply = ref(""),
|
||||
internalNote = ref(""),
|
||||
note = ref(false),
|
||||
assignee = ref(""),
|
||||
priority = ref<Priority>("NORMAL");
|
||||
const reply = computed({
|
||||
get: () => (note.value ? internalNote.value : publicReply.value),
|
||||
set: (value: string) => {
|
||||
if (note.value) internalNote.value = value;
|
||||
else publicReply.value = value;
|
||||
},
|
||||
});
|
||||
const waiting = computed(() =>
|
||||
detail.value?.ticket.status.startsWith("WAITING_"),
|
||||
);
|
||||
const requestKeys = new Map<string, string>();
|
||||
let readSequence = 0;
|
||||
|
||||
function number(ticket: Ticket) {
|
||||
return "WU-" + String(ticket.ticket_no).padStart(6, "0");
|
||||
}
|
||||
function time(value: string) {
|
||||
return new Date(value).toLocaleString();
|
||||
}
|
||||
function count(value: State) {
|
||||
return list.value?.counts.find((item) => item.status === value)?.total ?? 0;
|
||||
}
|
||||
function sync(value: Detail) {
|
||||
detail.value = value;
|
||||
assignee.value = value.ticket.assignee_id ?? "";
|
||||
priority.value = value.ticket.priority ?? "NORMAL";
|
||||
}
|
||||
async function load(nextPage = page.value) {
|
||||
const request = ++readSequence;
|
||||
const path = base.value,
|
||||
id = ticketId.value;
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
if (!id) {
|
||||
const params = new URLSearchParams({
|
||||
search: search.value,
|
||||
page: String(nextPage),
|
||||
});
|
||||
if (status.value) params.set("status", status.value);
|
||||
if (category.value) params.set("category", category.value);
|
||||
const result = await api<TicketList>(path + "?" + params);
|
||||
if (request !== readSequence) return;
|
||||
page.value = nextPage;
|
||||
list.value = result;
|
||||
return;
|
||||
}
|
||||
const [result, team] = await Promise.all([
|
||||
api<Detail>(path + "/" + id),
|
||||
staff.value ? api<Agent[]>(path + "/agents") : Promise.resolve([]),
|
||||
]);
|
||||
if (request !== readSequence) return;
|
||||
sync(result);
|
||||
agents.value = team;
|
||||
if (result.ticket.unread) {
|
||||
await api(path + "/" + id + "/read", {
|
||||
method: "POST",
|
||||
body: body({ revision: result.ticket.reply_revision }),
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (request === readSequence) error.value = (e as Error).message;
|
||||
} finally {
|
||||
if (request === readSequence) loading.value = false;
|
||||
}
|
||||
}
|
||||
watch(
|
||||
[base, ticketId],
|
||||
([path], previous) => {
|
||||
if (path !== previous?.[0]) {
|
||||
list.value = null;
|
||||
search.value = "";
|
||||
status.value = "";
|
||||
category.value = "";
|
||||
page.value = 0;
|
||||
}
|
||||
detail.value = null;
|
||||
publicReply.value = "";
|
||||
internalNote.value = "";
|
||||
note.value = false;
|
||||
createOpen.value = false;
|
||||
void load();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
async function openCreate() {
|
||||
createOpen.value = true;
|
||||
try {
|
||||
projects.value = await api("/projects");
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function submit<T>(path: string, payload: object): Promise<T> {
|
||||
const signature = path + body(payload);
|
||||
if (!requestKeys.has(signature))
|
||||
requestKeys.set(signature, crypto.randomUUID());
|
||||
const result = await api<T>(path, {
|
||||
method: "POST",
|
||||
body: body({ ...payload, requestId: requestKeys.get(signature) }),
|
||||
});
|
||||
requestKeys.delete(signature);
|
||||
return result;
|
||||
}
|
||||
async function create() {
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const result = await submit<Detail>("/tickets", {
|
||||
...draft.value,
|
||||
projectId: draft.value.projectId || null,
|
||||
});
|
||||
draft.value = { subject: "", category: "AI", projectId: "", content: "" };
|
||||
if (base.value === "/tickets" && !ticketId.value) {
|
||||
createOpen.value = false;
|
||||
await router.push("/tickets/" + result.ticket.id);
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function action(payload: Action) {
|
||||
const path = base.value + "/" + ticketId.value;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const result = await submit<Detail>(path + "/actions", payload);
|
||||
if (path !== base.value + "/" + ticketId.value) return;
|
||||
sync(result);
|
||||
if (payload.operation === "REPLY") publicReply.value = "";
|
||||
if (payload.operation === "NOTE") internalNote.value = "";
|
||||
} catch (e) {
|
||||
if (path === base.value + "/" + ticketId.value)
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
async function older() {
|
||||
const current = detail.value;
|
||||
const cursor = current?.messages[0]?.id;
|
||||
if (!current || !cursor) return;
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
const result = await api<Detail>(
|
||||
base.value + "/" + ticketId.value + "?before=" + cursor,
|
||||
);
|
||||
if (detail.value !== current) return;
|
||||
current.messages.unshift(...result.messages);
|
||||
current.hasOlder = result.hasOlder;
|
||||
} catch (e) {
|
||||
if (detail.value === current) error.value = (e as Error).message;
|
||||
} finally {
|
||||
if (detail.value === current) loading.value = false;
|
||||
}
|
||||
}
|
||||
function author(message: Message) {
|
||||
if (message.kind === "SYSTEM" || message.kind === "INTERNAL")
|
||||
return "状态记录";
|
||||
if (message.kind === "NOTE")
|
||||
return (message.author_name || "客服") + " · 内部备注";
|
||||
if (message.kind === "STAFF") return message.author_name || "客服";
|
||||
return staff.value ? message.author_name || "用户" : "你";
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">SUPPORT DESK</span>
|
||||
<h1>{{ staff ? "工单管理" : "支持工单" }}</h1>
|
||||
<p>
|
||||
{{
|
||||
staff
|
||||
? "查看服务请求、分派处理人并跟进会话。"
|
||||
: "就 AI 开发、项目托管、费用或账户问题联系平台客服。"
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="ticket-actions">
|
||||
<RouterLink v-if="ticketId" class="ticket-back" :to="base"
|
||||
><ArrowLeft :size="15" />返回列表</RouterLink
|
||||
>
|
||||
<button :disabled="loading || busy" @click="load()">
|
||||
<RefreshCw :size="14" />刷新
|
||||
</button>
|
||||
<button
|
||||
v-if="!staff && !ticketId && !createOpen"
|
||||
class="primary"
|
||||
@click="openCreate"
|
||||
>
|
||||
<Plus :size="16" />提交工单
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="error" class="alert error" role="alert">{{ error }}</div>
|
||||
|
||||
<template v-if="!ticketId">
|
||||
<form
|
||||
v-if="createOpen"
|
||||
class="panel form-panel ticket-create"
|
||||
@submit.prevent="create"
|
||||
>
|
||||
<h3><LifeBuoy :size="17" />新工单</h3>
|
||||
<p class="muted">
|
||||
说明遇到的问题、复现步骤和预期结果。请勿在会话中提交密码、密钥或支付凭证。
|
||||
</p>
|
||||
<label
|
||||
>标题<input
|
||||
v-model.trim="draft.subject"
|
||||
required
|
||||
maxlength="120"
|
||||
placeholder="简述需要处理的问题"
|
||||
/></label>
|
||||
<div class="ticket-fields">
|
||||
<label
|
||||
>问题分类<select v-model="draft.category">
|
||||
<option v-for="(label, key) in categories" :key="key" :value="key">
|
||||
{{ label }}
|
||||
</option>
|
||||
</select></label
|
||||
>
|
||||
<label
|
||||
>关联项目<select v-model="draft.projectId">
|
||||
<option value="">不关联项目</option>
|
||||
<option
|
||||
v-for="project in projects"
|
||||
:key="project.id"
|
||||
:value="project.id"
|
||||
>
|
||||
{{ project.name }}
|
||||
</option>
|
||||
</select></label
|
||||
>
|
||||
</div>
|
||||
<label
|
||||
>问题详情<textarea
|
||||
v-model.trim="draft.content"
|
||||
required
|
||||
maxlength="6000"
|
||||
rows="5"
|
||||
/>
|
||||
</label>
|
||||
<div class="ticket-actions">
|
||||
<button type="button" :disabled="busy" @click="createOpen = false">
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
class="primary"
|
||||
:disabled="busy || !draft.subject || !draft.content"
|
||||
>
|
||||
提交工单
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div v-if="list" class="ticket-stats" aria-label="工单状态统计">
|
||||
<button
|
||||
v-for="(label, key) in statuses"
|
||||
:key="key"
|
||||
class="panel ticket-stat"
|
||||
:aria-pressed="status === key"
|
||||
:disabled="loading"
|
||||
@click="
|
||||
status = status === key ? '' : key;
|
||||
load(0);
|
||||
"
|
||||
>
|
||||
<span>{{ label }}</span
|
||||
><strong>{{ count(key) }}</strong>
|
||||
</button>
|
||||
</div>
|
||||
<form class="toolbar ticket-filters" @submit.prevent="load(0)">
|
||||
<input
|
||||
v-model.trim="search"
|
||||
maxlength="120"
|
||||
:placeholder="staff ? '标题、工单号或邮箱' : '标题或工单号'"
|
||||
aria-label="搜索工单"
|
||||
/>
|
||||
<select v-model="status" aria-label="工单状态">
|
||||
<option value="">全部状态</option>
|
||||
<option v-for="(label, key) in statuses" :key="key" :value="key">
|
||||
{{ label }}
|
||||
</option>
|
||||
</select>
|
||||
<select v-model="category" aria-label="问题分类">
|
||||
<option value="">全部分类</option>
|
||||
<option v-for="(label, key) in categories" :key="key" :value="key">
|
||||
{{ label }}
|
||||
</option>
|
||||
</select>
|
||||
<button class="primary" :disabled="loading">查询</button>
|
||||
</form>
|
||||
<section class="panel table-panel" :aria-busy="loading">
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>工单</th>
|
||||
<th>分类 / 项目</th>
|
||||
<th>状态</th>
|
||||
<th v-if="staff">提交用户</th>
|
||||
<th v-if="staff">优先级 / 处理人</th>
|
||||
<th>最近更新</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in list?.items" :key="item.id">
|
||||
<td>
|
||||
<RouterLink class="ticket-title" :to="base + '/' + item.id">{{
|
||||
item.subject
|
||||
}}</RouterLink>
|
||||
<small class="block muted">{{ number(item) }}</small>
|
||||
</td>
|
||||
<td>
|
||||
{{ categories[item.category]
|
||||
}}<small v-if="item.project_name" class="block muted">{{
|
||||
item.project_name
|
||||
}}</small>
|
||||
</td>
|
||||
<td>
|
||||
<span class="status" :class="item.status.toLowerCase()">{{
|
||||
statuses[item.status]
|
||||
}}</span>
|
||||
<small v-if="item.unread" class="block ticket-unread"
|
||||
>有新回复或状态更新</small
|
||||
>
|
||||
</td>
|
||||
<td v-if="staff">
|
||||
{{ item.owner_name
|
||||
}}<small class="block muted">{{ item.owner_email }}</small>
|
||||
</td>
|
||||
<td v-if="staff">
|
||||
{{ priorities[item.priority ?? "NORMAL"]
|
||||
}}<small class="block muted">{{
|
||||
item.assignee_name || "未分派"
|
||||
}}</small>
|
||||
</td>
|
||||
<td>{{ time(item.updated_at) }}</td>
|
||||
</tr>
|
||||
<tr v-if="!list?.items.length">
|
||||
<td :colspan="staff ? 6 : 4" class="empty">
|
||||
{{
|
||||
loading
|
||||
? "正在读取工单…"
|
||||
: list
|
||||
? "没有匹配的工单"
|
||||
: "暂无工单数据"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div v-if="list?.hasMore || page > 0" class="pagination">
|
||||
<button :disabled="page === 0 || loading" @click="load(page - 1)">
|
||||
上一页
|
||||
</button>
|
||||
<span>第 {{ page + 1 }} 页</span>
|
||||
<button :disabled="!list?.hasMore || loading" @click="load(page + 1)">
|
||||
下一页
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<div v-else-if="detail" class="ticket-detail">
|
||||
<section class="panel form-panel">
|
||||
<div class="ticket-meta">
|
||||
<div>
|
||||
<small class="muted"
|
||||
>{{ number(detail.ticket) }} ·
|
||||
{{ categories[detail.ticket.category] }}</small
|
||||
>
|
||||
<h2>{{ detail.ticket.subject }}</h2>
|
||||
<p v-if="detail.ticket.project_name" class="muted">
|
||||
关联项目 {{ detail.ticket.project_name }}
|
||||
</p>
|
||||
<p v-if="staff" class="muted">
|
||||
{{ detail.ticket.owner_name }} · {{ detail.ticket.owner_email }}
|
||||
</p>
|
||||
</div>
|
||||
<span class="status" :class="detail.ticket.status.toLowerCase()">{{
|
||||
statuses[detail.ticket.status]
|
||||
}}</span>
|
||||
</div>
|
||||
<div class="ticket-thread" aria-label="工单会话">
|
||||
<button
|
||||
v-if="detail.hasOlder"
|
||||
:disabled="busy || loading"
|
||||
@click="older"
|
||||
>
|
||||
加载更早消息
|
||||
</button>
|
||||
<article
|
||||
v-for="message in detail.messages"
|
||||
:key="message.id"
|
||||
class="ticket-message"
|
||||
:class="message.kind.toLowerCase()"
|
||||
>
|
||||
<div>
|
||||
<strong>{{ author(message) }}</strong
|
||||
><time>{{ time(message.created_at) }}</time>
|
||||
</div>
|
||||
<p>{{ message.content }}</p>
|
||||
</article>
|
||||
</div>
|
||||
<form
|
||||
v-if="waiting || staff"
|
||||
class="ticket-reply"
|
||||
@submit.prevent="
|
||||
action({ operation: note ? 'NOTE' : 'REPLY', content: reply })
|
||||
"
|
||||
>
|
||||
<label v-if="staff" class="ticket-inline">
|
||||
<input
|
||||
v-model="note"
|
||||
type="checkbox"
|
||||
:disabled="busy"
|
||||
/>仅工作人员可见的内部备注
|
||||
</label>
|
||||
<label v-if="waiting || note"
|
||||
>{{ note ? "内部备注" : "回复内容" }}
|
||||
<textarea
|
||||
v-model.trim="reply"
|
||||
rows="4"
|
||||
maxlength="6000"
|
||||
required
|
||||
:placeholder="
|
||||
note ? '记录供客服交接的信息' : '输入回复,双方均可查看'
|
||||
"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
v-if="waiting || note"
|
||||
class="primary"
|
||||
:disabled="busy || loading || !reply"
|
||||
>
|
||||
{{ note ? "保存备注" : "发送回复" }}
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
<section class="panel form-panel ticket-controls">
|
||||
<h3>工单操作</h3>
|
||||
<template v-if="staff">
|
||||
<form
|
||||
@submit.prevent="
|
||||
action({ operation: 'ASSIGN', assigneeId: assignee || null })
|
||||
"
|
||||
>
|
||||
<label
|
||||
>处理人<select v-model="assignee">
|
||||
<option value="">未分派</option>
|
||||
<option
|
||||
v-if="
|
||||
detail.ticket.assignee_id &&
|
||||
!agents.some(
|
||||
(agent) => agent.id === detail?.ticket.assignee_id,
|
||||
)
|
||||
"
|
||||
:value="detail.ticket.assignee_id"
|
||||
disabled
|
||||
>
|
||||
{{ detail.ticket.assignee_name }}(不可分派)
|
||||
</option>
|
||||
<option v-for="agent in agents" :key="agent.id" :value="agent.id">
|
||||
{{ agent.display_name }} · {{ agent.email }}
|
||||
</option>
|
||||
</select></label
|
||||
>
|
||||
<button
|
||||
:disabled="
|
||||
busy || loading || assignee === (detail.ticket.assignee_id ?? '')
|
||||
"
|
||||
>
|
||||
保存分派
|
||||
</button>
|
||||
</form>
|
||||
<form @submit.prevent="action({ operation: 'PRIORITY', priority })">
|
||||
<label
|
||||
>优先级<select v-model="priority">
|
||||
<option
|
||||
v-for="(label, key) in priorities"
|
||||
:key="key"
|
||||
:value="key"
|
||||
>
|
||||
{{ label }}
|
||||
</option>
|
||||
</select></label
|
||||
>
|
||||
<button
|
||||
:disabled="busy || loading || priority === detail.ticket.priority"
|
||||
>
|
||||
保存优先级
|
||||
</button>
|
||||
</form>
|
||||
</template>
|
||||
<div class="ticket-actions">
|
||||
<button
|
||||
v-if="staff && waiting"
|
||||
:disabled="busy || loading"
|
||||
@click="action({ operation: 'RESOLVE' })"
|
||||
>
|
||||
标记已解决
|
||||
</button>
|
||||
<button
|
||||
v-if="!waiting"
|
||||
:disabled="busy || loading"
|
||||
@click="action({ operation: 'REOPEN' })"
|
||||
>
|
||||
重开工单
|
||||
</button>
|
||||
<button
|
||||
v-if="detail.ticket.status !== 'CLOSED'"
|
||||
:disabled="busy || loading"
|
||||
@click="action({ operation: 'CLOSE' })"
|
||||
>
|
||||
关闭工单
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="!waiting" class="muted">
|
||||
问题仍未解决时,可以重开工单继续沟通。
|
||||
</p>
|
||||
</section>
|
||||
</div>
|
||||
<p v-else-if="loading" class="muted" role="status">正在读取会话…</p>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ticket-actions {
|
||||
display: flex;
|
||||
gap: 9px;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
.ticket-actions > :is(button, a) {
|
||||
display: inline-flex;
|
||||
gap: 7px;
|
||||
align-items: center;
|
||||
}
|
||||
.ticket-back,
|
||||
.ticket-title,
|
||||
.ticket-unread {
|
||||
color: var(--blue);
|
||||
}
|
||||
.ticket-title {
|
||||
font-weight: 650;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.ticket-title:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.ticket-stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 13px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.ticket-stat {
|
||||
display: grid;
|
||||
justify-content: start;
|
||||
gap: 7px;
|
||||
padding: 14px 17px;
|
||||
text-align: left;
|
||||
color: var(--text);
|
||||
}
|
||||
.ticket-stat strong {
|
||||
font-size: 24px;
|
||||
}
|
||||
.ticket-stat[aria-pressed="true"] {
|
||||
border-color: var(--blue);
|
||||
color: var(--blue);
|
||||
}
|
||||
.ticket-filters {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.ticket-filters :is(input, select) {
|
||||
width: auto;
|
||||
}
|
||||
.ticket-create {
|
||||
max-width: 740px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.ticket-fields {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 12px;
|
||||
}
|
||||
.ticket-detail {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
|
||||
align-items: start;
|
||||
gap: 18px;
|
||||
}
|
||||
.ticket-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: start;
|
||||
gap: 12px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.ticket-meta h2 {
|
||||
margin: 6px 0;
|
||||
}
|
||||
.ticket-thread {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.ticket-message {
|
||||
min-width: 0;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
background: var(--soft);
|
||||
}
|
||||
.ticket-message.staff {
|
||||
border-inline-start: 3px solid var(--blue);
|
||||
}
|
||||
.ticket-message.note,
|
||||
.ticket-message.internal {
|
||||
border-inline-start: 3px solid #a9761d;
|
||||
}
|
||||
.ticket-message.system {
|
||||
background: transparent;
|
||||
}
|
||||
.ticket-message > div {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.ticket-message time {
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.ticket-message p {
|
||||
margin-top: 7px;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.ticket-controls h3 {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.ticket-controls form {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
.ticket-controls form label {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.ticket-inline {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.ticket-inline input {
|
||||
width: auto;
|
||||
margin: 0;
|
||||
}
|
||||
.status.waiting_support {
|
||||
color: #a76a1c;
|
||||
background: #a76a1c14;
|
||||
}
|
||||
.status.waiting_customer {
|
||||
color: var(--blue);
|
||||
background: #4478df14;
|
||||
}
|
||||
.status.resolved {
|
||||
color: #258561;
|
||||
background: #25856114;
|
||||
}
|
||||
@media (max-width: 940px) {
|
||||
.ticket-detail {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
@media (max-width: 560px) {
|
||||
.ticket-stats {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.ticket-fields {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0;
|
||||
}
|
||||
.ticket-meta {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.ticket-filters input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,147 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from "vue";
|
||||
import { api, body } from "../api";
|
||||
import { useSession } from "../store";
|
||||
const store = useSession(),
|
||||
wallet = ref<any>(null),
|
||||
ledger = ref<any[]>([]),
|
||||
error = ref(""),
|
||||
success = ref(""),
|
||||
busy = ref(false);
|
||||
const adjust = reactive({
|
||||
userId: "",
|
||||
amount: "",
|
||||
reason: "",
|
||||
idempotencyKey: crypto.randomUUID(),
|
||||
});
|
||||
async function load() {
|
||||
try {
|
||||
[wallet.value, ledger.value] = await Promise.all([
|
||||
api("/wallet"),
|
||||
api("/wallet/ledger"),
|
||||
]);
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
}
|
||||
}
|
||||
async function save() {
|
||||
if (!confirm("确认对指定用户进行资金调整?此操作将记入账本和审计日志。"))
|
||||
return;
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
await api("/admin/wallets/" + adjust.userId + "/adjust", {
|
||||
method: "POST",
|
||||
body: body(adjust),
|
||||
});
|
||||
success.value = "余额调整已入账";
|
||||
adjust.idempotencyKey = crypto.randomUUID();
|
||||
await load();
|
||||
} catch (e) {
|
||||
error.value = (e as Error).message;
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
onMounted(load);
|
||||
</script>
|
||||
<template>
|
||||
<div class="page-heading">
|
||||
<div>
|
||||
<span class="eyebrow">WALLET & BILLING</span>
|
||||
<h1>钱包与账本</h1>
|
||||
<p>独立账本记录每笔变动,AI 预算预留与实际消费分开。</p>
|
||||
</div>
|
||||
<button class="secondary" @click="load">刷新</button>
|
||||
</div>
|
||||
<div class="alert error" v-if="error">{{ error }}</div>
|
||||
<div class="alert success" v-if="success">{{ success }}</div>
|
||||
<section class="stats" v-if="wallet">
|
||||
<div class="stat-card">
|
||||
<div>账户余额 · CNY</div>
|
||||
<strong>¥ {{ wallet.balance }}</strong
|
||||
><small>包含预留金额</small>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div>可用余额 · CNY</div>
|
||||
<strong>¥ {{ wallet.available }}</strong
|
||||
><small>可用于新任务预算</small>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div>任务预留 · CNY</div>
|
||||
<strong>¥ {{ wallet.reserved }}</strong
|
||||
><small>任务结束后释放未消费部分</small>
|
||||
</div>
|
||||
</section>
|
||||
<div class="alert info">
|
||||
在线支付渠道尚未配置和联调,当前不提供虚假的充值成功流程。管理员可通过有原因、有审计的余额调整入账。
|
||||
</div>
|
||||
<section class="panel table-panel">
|
||||
<div class="panel-heading">
|
||||
<h3>交易账本</h3>
|
||||
<span class="muted">最近 200 条 · CNY</span>
|
||||
</div>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>时间</th>
|
||||
<th>类型</th>
|
||||
<th>变动金额</th>
|
||||
<th>变动后余额</th>
|
||||
<th>关联业务</th>
|
||||
<th>原因</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="l in ledger" :key="l.id">
|
||||
<td>{{ new Date(l.created_at).toLocaleString() }}</td>
|
||||
<td>{{ l.kind }}</td>
|
||||
<td :class="Number(l.amount) >= 0 ? 'good' : 'danger'">
|
||||
{{ l.amount }}
|
||||
</td>
|
||||
<td>{{ l.balance_after }}</td>
|
||||
<td class="truncate" :title="l.business_id">{{ l.business_id }}</td>
|
||||
<td>{{ l.reason }}</td>
|
||||
</tr>
|
||||
<tr v-if="!ledger.length">
|
||||
<td class="empty" colspan="6">
|
||||
暂无交易,所有余额来自实际账本记录。
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<section
|
||||
v-if="store.user?.permissions.includes('finance:write')"
|
||||
class="panel form-panel settings-form"
|
||||
>
|
||||
<h3>管理员资金调整</h3>
|
||||
<p class="muted">正数增加余额,负数扣除可用余额;不能动用已预留资金。</p>
|
||||
<form @submit.prevent="save">
|
||||
<label
|
||||
>用户 UUID<input
|
||||
v-model="adjust.userId"
|
||||
required
|
||||
placeholder="从用户管理获取" /></label
|
||||
><label
|
||||
>金额 · CNY<input
|
||||
v-model="adjust.amount"
|
||||
type="number"
|
||||
step="0.00000001"
|
||||
required /></label
|
||||
><label
|
||||
>调整原因<input
|
||||
v-model="adjust.reason"
|
||||
maxlength="500"
|
||||
required /></label
|
||||
><label
|
||||
>幂等标识<input
|
||||
v-model="adjust.idempotencyKey"
|
||||
maxlength="200"
|
||||
required /></label
|
||||
><button class="primary" :disabled="busy">确认调整</button>
|
||||
</form>
|
||||
</section>
|
||||
</template>
|
||||
Reference in new issue
Block a user