feat(ECR-046): ScaleDefinition 元数据写面闭环并 Closed
explore.write POST/PUT · create→draft · status 仍 ECR-008 · migration 000055 · Loop STOP Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -726,9 +726,42 @@ export const adminApi = {
|
||||
funnelDefinition: (id: string) =>
|
||||
request<Record<string, unknown>>('GET', `/analytics/funnel-definitions/${id}`),
|
||||
exploreScales: () =>
|
||||
request<{ items: Array<Record<string, unknown>> }>('GET', '/explore/scales'),
|
||||
request<{
|
||||
items: Array<{
|
||||
id: string
|
||||
slug: string
|
||||
title: string
|
||||
description: string
|
||||
status: string
|
||||
}>
|
||||
}>('GET', '/explore/scales'),
|
||||
exploreScale: (id: string) =>
|
||||
request<Record<string, unknown>>('GET', `/explore/scales/${id}`),
|
||||
request<{
|
||||
id: string
|
||||
slug: string
|
||||
title: string
|
||||
description: string
|
||||
status: string
|
||||
}>('GET', `/explore/scales/${id}`),
|
||||
createExploreScale: (body: { slug: string; title: string; description: string }) =>
|
||||
request<{
|
||||
id: string
|
||||
slug: string
|
||||
title: string
|
||||
description: string
|
||||
status: string
|
||||
}>('POST', '/explore/scales', body),
|
||||
updateExploreScale: (
|
||||
id: string,
|
||||
body: { slug: string; title: string; description: string },
|
||||
) =>
|
||||
request<{
|
||||
id: string
|
||||
slug: string
|
||||
title: string
|
||||
description: string
|
||||
status: string
|
||||
}>('PUT', `/explore/scales/${id}`, body),
|
||||
orders: (params?: {
|
||||
status?: string
|
||||
kind?: string
|
||||
|
||||
@@ -38,6 +38,7 @@ async function onLogout() {
|
||||
<RouterLink to="/star-configs">星座配置</RouterLink>
|
||||
<RouterLink to="/rhythm-configs">节律配置</RouterLink>
|
||||
<RouterLink to="/image-card-decks">意象牌组</RouterLink>
|
||||
<RouterLink to="/scale-definitions">量表元数据</RouterLink>
|
||||
<RouterLink to="/catalogs">目录仓</RouterLink>
|
||||
<RouterLink to="/orders">订单</RouterLink>
|
||||
<RouterLink v-if="auth.can('admin.membership.plans.read')" to="/pricing">定价</RouterLink>
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { adminApi } from '@/api/client'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
type Row = Awaited<ReturnType<typeof adminApi.exploreScales>>['items'][number]
|
||||
|
||||
const auth = useAuthStore()
|
||||
const canWrite = () => auth.can('admin.explore.write')
|
||||
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const items = ref<Row[]>([])
|
||||
const selected = ref<Row | null>(null)
|
||||
const saving = ref(false)
|
||||
const formErr = ref('')
|
||||
const form = reactive({
|
||||
slug: '',
|
||||
title: '',
|
||||
description: '',
|
||||
})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const res = await adminApi.exploreScales()
|
||||
items.value = res.items || []
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : '加载失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
form.slug = ''
|
||||
form.title = ''
|
||||
form.description = ''
|
||||
selected.value = null
|
||||
formErr.value = ''
|
||||
}
|
||||
|
||||
async function openRow(id: string) {
|
||||
formErr.value = ''
|
||||
try {
|
||||
const row = await adminApi.exploreScale(id)
|
||||
selected.value = row
|
||||
form.slug = row.slug
|
||||
form.title = row.title
|
||||
form.description = row.description || ''
|
||||
} catch {
|
||||
selected.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function payload() {
|
||||
return {
|
||||
slug: form.slug.trim(),
|
||||
title: form.title.trim(),
|
||||
description: form.description.trim(),
|
||||
}
|
||||
}
|
||||
|
||||
async function createRow() {
|
||||
if (!canWrite()) return
|
||||
saving.value = true
|
||||
formErr.value = ''
|
||||
try {
|
||||
const row = await adminApi.createExploreScale(payload())
|
||||
await load()
|
||||
await openRow(row.id)
|
||||
} catch (e) {
|
||||
formErr.value = e instanceof Error ? e.message : '创建失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function saveRow() {
|
||||
if (!selected.value || !canWrite()) return
|
||||
saving.value = true
|
||||
formErr.value = ''
|
||||
try {
|
||||
const row = await adminApi.updateExploreScale(selected.value.id, payload())
|
||||
selected.value = row
|
||||
await load()
|
||||
} catch (e) {
|
||||
formErr.value = e instanceof Error ? e.message : '保存失败'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void load()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<h1>量表元数据</h1>
|
||||
<p class="muted">
|
||||
ScaleDefinition 写面 · 仅 slug/title/description · 创建为 draft · 上下架请用「内容」页(ECR-008)· ECR-046
|
||||
</p>
|
||||
<p v-if="!canWrite()" class="err">需要 admin.explore.write 才可写</p>
|
||||
<p v-if="loading" class="muted">加载中…</p>
|
||||
<p v-else-if="error" class="err">{{ error }}</p>
|
||||
<div v-else class="layout">
|
||||
<div class="card">
|
||||
<h2>列表</h2>
|
||||
<button v-if="canWrite()" class="btn" type="button" @click="resetForm">新建</button>
|
||||
<p v-if="!items.length" class="muted">暂无</p>
|
||||
<table v-else>
|
||||
<thead>
|
||||
<tr><th>slug</th><th>标题</th><th>状态</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="b in items" :key="b.id">
|
||||
<td><code>{{ b.slug }}</code></td>
|
||||
<td>{{ b.title }}</td>
|
||||
<td>{{ b.status }}</td>
|
||||
<td><button class="btn" type="button" @click="openRow(b.id)">编辑</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>{{ selected ? '编辑元数据' : '新建(draft)' }}</h2>
|
||||
<label>slug <input v-model="form.slug" :disabled="!canWrite()" /></label>
|
||||
<label>标题 <input v-model="form.title" :disabled="!canWrite()" /></label>
|
||||
<label>简介 <textarea v-model="form.description" rows="3" :disabled="!canWrite()" /></label>
|
||||
<p v-if="selected" class="muted">当前 status={{ selected.status }}(本页不可改)</p>
|
||||
<p v-if="formErr" class="err">{{ formErr }}</p>
|
||||
<div v-if="canWrite()" class="actions">
|
||||
<button v-if="!selected" class="btn primary" type="button" :disabled="saving" @click="createRow">
|
||||
创建
|
||||
</button>
|
||||
<button v-else class="btn primary" type="button" :disabled="saving" @click="saveRow">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin: 0 0 0.35rem; font-size: 1.35rem; }
|
||||
h2 { margin: 0 0 0.6rem; font-size: 1.05rem; }
|
||||
.layout { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1rem; margin-top: 1rem; }
|
||||
code { font-size: 0.8rem; }
|
||||
.card label { display: block; margin: 0.4rem 0; font-size: 0.9rem; }
|
||||
.card input, .card textarea { width: 100%; margin-top: 0.2rem; }
|
||||
.actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
|
||||
.btn.primary { font-weight: 600; }
|
||||
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
@@ -42,6 +42,12 @@ const router = createRouter({
|
||||
component: () => import('@/pages/ImageCardDeckPage.vue'),
|
||||
meta: { permission: 'admin.explore.read' },
|
||||
},
|
||||
{
|
||||
path: 'scale-definitions',
|
||||
name: 'scale-definitions',
|
||||
component: () => import('@/pages/ScaleDefinitionPage.vue'),
|
||||
meta: { permission: 'admin.explore.read' },
|
||||
},
|
||||
{ path: 'catalogs', name: 'catalogs', component: () => import('@/pages/CatalogHubPage.vue') },
|
||||
{ path: 'push', name: 'push', component: () => import('@/pages/PushJobsPage.vue') },
|
||||
{ path: 'admins', name: 'admins', component: () => import('@/pages/AdminsPage.vue'), meta: { superOnly: true } },
|
||||
|
||||
Reference in New Issue
Block a user