first commit

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kunkunxiaomaoandClaude committed 2026-11-16 20:45:22 +08:00
commit 9c5fef1a4d
412 files changed
+94582

No files matched your search

@@ -0,0 +1,74 @@
<template>
<main class="content">
<header class="page-head">
<div>
<p class="eyebrow">管理</p>
<h1>{{ resourceTitle }}</h1>
</div>
<div class="toolbar">
<input v-if="canSearch" v-model.trim="q" placeholder="搜索" @keyup.enter="load" />
<button class="primary" @click="load">刷新</button>
</div>
</header>
<section class="panel">
<p v-if="loading" class="muted">加载中...</p>
<pre v-else-if="resource === 'system/health'">{{ single }}</pre>
<table v-else>
<thead>
<tr>
<th v-for="key in columns" :key="key">{{ key }}</th>
<th v-if="resource === 'users'">操作</th>
</tr>
</thead>
<tbody>
<tr v-for="row in rows" :key="row.id">
<td v-for="key in columns" :key="key">{{ row[key] }}</td>
<td v-if="resource === 'users'" class="actions">
<RouterLink class="small-link" :to="`/admin/users/${row.id}`">详情</RouterLink>
<button class="danger" @click="toggleUser(row)">{{ row.is_active ? "禁用" : "启用" }}</button>
</td>
</tr>
</tbody>
</table>
<p v-if="!loading && rows.length === 0 && resource !== 'system/health'" class="muted">暂无数据。</p>
</section>
</main>
</template>
<script setup lang="ts">
import { computed, onMounted, ref, watch } from "vue";
import { apiData, http } from "../../api/http";
const props = defineProps<{ resource: string }>();
const loading = ref(false);
const q = ref("");
const rows = ref<Array<Record<string, any>>>([]);
const single = ref("");
const resourceTitle = computed(() => props.resource.replace("/", " / "));
const canSearch = computed(() => ["users", "gallery", "novels"].includes(props.resource));
const columns = computed(() => Object.keys(rows.value[0] || {}).filter((key) => !["password_hash", "fcm_token"].includes(key)).slice(0, 8));
async function load() {
loading.value = true;
try {
const response = await http.get(`/admin/${props.resource}`, { params: q.value ? { q: q.value } : {} });
const data = apiData<any>(response);
if (props.resource === "system/health") {
single.value = JSON.stringify(data, null, 2);
rows.value = [];
} else {
rows.value = Array.isArray(data) ? data : data.items || [];
}
} finally {
loading.value = false;
}
}
async function toggleUser(row: Record<string, any>) {
await http.patch(`/admin/users/${row.id}/status`, { is_active: !row.is_active, reason: row.is_active ? "Disabled from web admin" : null });
await load();
}
watch(() => props.resource, load);
onMounted(load);
</script>