astrbot_plugin_imagestudio/frontend/plugin-page/src/App.vue

279 行
5.9 KiB
Vue

2026-07-05 09:24:00 +08:00
<script setup lang="ts">
import { computed, onMounted, ref } from "vue"
import { endpoints } from "../../shared/api/endpoints"
import { getJson } from "../../shared/api/client"
import type { UiBootstrap } from "../../shared/types/bootstrap"
import type { DashboardSummary } from "../../shared/types/dashboard"
const bootstrap = ref<UiBootstrap | null>(null)
const dashboard = ref<DashboardSummary | null>(null)
const loading = ref(true)
const error = ref("")
const workbenchUrl = computed(() => `${bootstrap.value?.api_base ?? ""}/web`)
const queueTotal = computed(() => {
const queue = dashboard.value?.queue
return queue ? queue.pending + queue.running + queue.failed + queue.dead_letter : 0
})
onMounted(load)
async function load() {
loading.value = true
error.value = ""
try {
const [bootstrapData, dashboardData] = await Promise.all([
getJson<UiBootstrap>(endpoints.uiBootstrap),
getJson<DashboardSummary>(endpoints.dashboardSummary),
])
bootstrap.value = bootstrapData
dashboard.value = dashboardData
} catch (err) {
error.value = err instanceof Error ? err.message : "加载失败"
} finally {
loading.value = false
}
}
function formatBytes(value = 0) {
if (value < 1024) return `${value} B`
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`
if (value < 1024 * 1024 * 1024) return `${(value / 1024 / 1024).toFixed(1)} MB`
return `${(value / 1024 / 1024 / 1024).toFixed(1)} GB`
}
</script>
2026-07-04 22:51:52 +08:00
<template>
<main class="plugin-page-shell">
2026-07-05 09:24:00 +08:00
<header class="topbar">
<div>
<h1>{{ bootstrap?.display_name ?? "ImageStudio" }}</h1>
<p>{{ bootstrap?.dashboard_user ?? "AstrBot" }}</p>
</div>
<div class="actions">
<span class="status" :data-state="dashboard?.plugin_status ?? 'loading'">
{{ dashboard?.plugin_status ?? "loading" }}
</span>
<button type="button" @click="load">刷新</button>
<a v-if="bootstrap" class="primary" :href="workbenchUrl" target="_blank" rel="noreferrer">工作台</a>
</div>
</header>
<section v-if="error" class="notice">{{ error }}</section>
<section v-else-if="loading" class="notice">加载中</section>
<section v-else class="metrics" aria-label="ImageStudio dashboard">
<article>
<span>角色</span>
<strong>{{ dashboard?.active_profiles ?? 0 }}</strong>
</article>
<article>
<span>队列</span>
<strong>{{ queueTotal }}</strong>
</article>
<article>
<span>运行中</span>
<strong>{{ dashboard?.queue.running ?? 0 }}</strong>
</article>
<article>
<span>失败</span>
<strong>{{ dashboard?.queue.failed ?? 0 }}</strong>
</article>
<article>
<span>存储</span>
<strong>{{ formatBytes(dashboard?.storage.total_bytes) }}</strong>
</article>
</section>
<section class="activity">
<div>
<h2>最近图片</h2>
<ul>
<li v-for="image in dashboard?.recent_images ?? []" :key="String((image as any).image_id)">
<span>{{ (image as any).image_id }}</span>
<small>{{ (image as any).created_at }}</small>
</li>
<li v-if="!dashboard?.recent_images?.length" class="empty">暂无图片</li>
</ul>
</div>
<div>
<h2>任务</h2>
<ul>
<li v-for="job in dashboard?.recent_jobs ?? []" :key="String((job as any).task_id)">
<span>{{ (job as any).task_id }}</span>
<small>{{ (job as any).status }}</small>
</li>
<li v-if="!dashboard?.recent_jobs?.length" class="empty">暂无任务</li>
</ul>
</div>
</section>
2026-07-04 22:51:52 +08:00
</main>
</template>
<style scoped>
.plugin-page-shell {
box-sizing: border-box;
min-height: 100vh;
padding: 24px;
2026-07-05 09:24:00 +08:00
color: #1d2430;
background: #f4f6f8;
2026-07-04 22:51:52 +08:00
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
2026-07-05 09:24:00 +08:00
.topbar,
.activity {
display: grid;
gap: 16px;
grid-template-columns: minmax(0, 1fr) auto;
align-items: start;
}
h1,
h2,
p {
margin: 0;
}
2026-07-04 22:51:52 +08:00
h1 {
font-size: 24px;
font-weight: 700;
}
2026-07-05 09:24:00 +08:00
h2 {
font-size: 14px;
}
p,
small,
.empty {
color: #667085;
}
.actions {
display: flex;
gap: 8px;
align-items: center;
}
button,
a.primary {
min-height: 36px;
padding: 0 14px;
border: 1px solid #c7d0da;
border-radius: 6px;
color: #1d2430;
background: #ffffff;
font: inherit;
text-decoration: none;
cursor: pointer;
}
a.primary {
display: inline-flex;
align-items: center;
border-color: #256f5b;
color: #ffffff;
background: #256f5b;
}
.status {
display: inline-flex;
align-items: center;
min-height: 28px;
padding: 0 10px;
border-radius: 999px;
color: #245347;
background: #dff3eb;
font-size: 13px;
}
.status[data-state="loading"] {
color: #6b4f1d;
background: #f7e7c5;
}
.notice {
margin-top: 18px;
padding: 14px;
border: 1px solid #d6dde6;
border-radius: 8px;
background: #ffffff;
}
.metrics {
display: grid;
grid-template-columns: repeat(5, minmax(120px, 1fr));
gap: 12px;
margin-top: 20px;
}
article,
.activity > div {
border: 1px solid #d6dde6;
border-radius: 8px;
background: #ffffff;
}
article {
display: grid;
gap: 8px;
padding: 16px;
}
article span {
color: #667085;
font-size: 13px;
}
article strong {
font-size: 24px;
}
.activity {
grid-template-columns: repeat(2, minmax(0, 1fr));
margin-top: 16px;
}
.activity > div {
padding: 16px;
}
ul {
display: grid;
gap: 10px;
margin: 12px 0 0;
padding: 0;
list-style: none;
}
li {
display: flex;
justify-content: space-between;
gap: 12px;
min-width: 0;
}
li span,
li small {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
@media (max-width: 820px) {
.topbar,
.activity {
grid-template-columns: 1fr;
}
.actions {
flex-wrap: wrap;
}
.metrics {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
2026-07-04 22:51:52 +08:00
}
</style>