feat(ECR-018): Entitlement 用户权益只读并 Closed

聚合 GET /admin/users/:id/entitlements(Membership∪DeepAccess∪问答额度)与 admin-h5 权益 Tab;无 migration / 无真支付。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jackyu66git
2026-08-07 19:26:15 +08:00
co-authored by Cursor
parent 37b91e51b8
commit c81f57a7d1
28 changed files with 597 additions and 12 deletions
+22
View File
@@ -152,6 +152,28 @@ export const adminApi = {
ask_thread_count: number
}
}>('GET', `/users/${id}/insight`),
userEntitlements: (id: string) =>
request<{
user_id: string
membership: {
plan?: string
status: string
expires_at?: string
ask_quota_left?: number
active: boolean
}
ask_paid_quota_left: number
flags: {
report_detail_via_membership: boolean
deep_access_count: number
}
deep_accesses: Array<{
id: string
report_id: string
report_type?: string
created_at: string
}>
}>('GET', `/users/${id}/entitlements`),
grant: (id: string, plan: string) =>
request<{ ok: boolean }>('POST', `/users/${id}/membership/grant`, { plan }),
grantAskQuota: (id: string, delta: number) =>
@@ -0,0 +1,92 @@
<script setup lang="ts">
import { RouterLink } from 'vue-router'
import { adminApi } from '@/api/client'
export type Entitlement = Awaited<ReturnType<typeof adminApi.userEntitlements>>
defineProps<{
data: Entitlement
}>()
const typeLabel: Record<string, string> = {
portrait: '愈心解码',
star: '星座',
rhythm: '节律',
relation: '关系',
synastry: '合盘',
image_card: '意象卡',
}
function fmtTime(iso?: string | null) {
if (!iso) return '—'
try {
return new Date(iso).toLocaleString('zh-CN')
} catch {
return iso
}
}
</script>
<template>
<div>
<div class="card block">
<h2>权益概览</h2>
<div class="kv">
<div>
<span>报告 detail会员</span>
<strong>{{ data.flags.report_detail_via_membership ? '是' : '否' }}</strong>
</div>
<div>
<span>DeepAccess 份数</span>
<strong>{{ data.flags.deep_access_count }}</strong>
</div>
<div>
<span>已购问答余量</span>
<strong>{{ data.ask_paid_quota_left }}</strong>
</div>
</div>
</div>
<div class="card block">
<h2>成长会员</h2>
<p v-if="data.membership">
{{ data.membership.active ? '有效' : '无效' }} ·
{{ data.membership.plan || '' }} ·
会员问答 {{ data.membership.ask_quota_left ?? 0 }} ·
到期 {{ fmtTime(data.membership.expires_at) }}
</p>
<p v-else class="muted">无会员记录</p>
</div>
<div class="card block">
<h2>深度版DeepAccess</h2>
<p v-if="!data.deep_accesses?.length" class="muted">无单份深度版</p>
<table v-else>
<thead>
<tr><th>类型</th><th>报告</th><th>时间</th></tr>
</thead>
<tbody>
<tr v-for="d in data.deep_accesses" :key="d.id">
<td>{{ typeLabel[d.report_type || ''] || d.report_type || '—' }}</td>
<td><code>{{ d.report_id.slice(0, 8) }}</code></td>
<td>{{ fmtTime(d.created_at) }}</td>
</tr>
</tbody>
</table>
<p class="hint">
<RouterLink :to="`/users/${data.user_id}`">返回基础信息可授予会员 / 问答额度</RouterLink>
</p>
</div>
</div>
</template>
<style scoped>
h2 { margin: 0 0 0.6rem; font-size: 1.05rem; }
.block { margin-bottom: 1rem; }
.kv {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
gap: 0.75rem;
}
.kv span { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.15rem; }
.hint { margin-top: 0.75rem; font-size: 0.85rem; }
.hint a { color: var(--accent); }
</style>
+30 -8
View File
@@ -2,6 +2,7 @@
import { computed, onMounted, ref, watch } from 'vue'
import { RouterLink, useRoute } from 'vue-router'
import { adminApi, type UserDetail } from '@/api/client'
import UserEntitlementPanel, { type Entitlement } from '@/components/UserEntitlementPanel.vue'
import { useAuthStore } from '@/stores/auth'
type Insight = Awaited<ReturnType<typeof adminApi.userInsight>>
@@ -11,10 +12,13 @@ const auth = useAuthStore()
const loading = ref(false)
const error = ref('')
const detail = ref<UserDetail | null>(null)
const tab = ref<'base' | 'insight'>('base')
const tab = ref<'base' | 'insight' | 'entitlement'>('base')
const insight = ref<Insight | null>(null)
const insightErr = ref('')
const insightLoading = ref(false)
const entitlement = ref<Entitlement | null>(null)
const entitlementErr = ref('')
const entitlementLoading = ref(false)
const plan = ref('month')
const askDelta = ref(10)
const grantMsg = ref('')
@@ -45,9 +49,8 @@ async function load() {
} catch {
transitions.value = []
}
if (tab.value === 'insight') {
await loadInsight()
}
if (tab.value === 'insight') await loadInsight()
if (tab.value === 'entitlement') await loadEntitlement()
} catch (e) {
error.value = e instanceof Error ? e.message : '加载失败'
} finally {
@@ -68,10 +71,22 @@ async function loadInsight() {
}
}
watch(tab, (v) => {
if (v === 'insight' && !insight.value && !insightLoading.value) {
void loadInsight()
async function loadEntitlement() {
entitlementLoading.value = true
entitlementErr.value = ''
try {
entitlement.value = await adminApi.userEntitlements(String(route.params.id))
} catch (e) {
entitlementErr.value = e instanceof Error ? e.message : '权益加载失败'
entitlement.value = null
} finally {
entitlementLoading.value = false
}
}
watch(tab, (v) => {
if (v === 'insight' && !insight.value && !insightLoading.value) void loadInsight()
if (v === 'entitlement' && !entitlement.value && !entitlementLoading.value) void loadEntitlement()
})
async function grant() {
@@ -139,6 +154,7 @@ onMounted(load)
<div class="tabs">
<button type="button" :class="{ on: tab === 'base' }" @click="tab = 'base'">基础</button>
<button type="button" :class="{ on: tab === 'insight' }" @click="tab = 'insight'">洞察</button>
<button type="button" :class="{ on: tab === 'entitlement' }" @click="tab = 'entitlement'">权益</button>
</div>
<template v-if="tab === 'base'">
@@ -257,7 +273,7 @@ onMounted(load)
</div>
</template>
<template v-else>
<template v-else-if="tab === 'insight'">
<p v-if="insightLoading" class="muted">加载洞察</p>
<p v-else-if="insightErr" class="err">{{ insightErr }}</p>
<template v-else-if="insight">
@@ -317,6 +333,12 @@ onMounted(load)
</div>
</template>
</template>
<template v-else-if="tab === 'entitlement'">
<p v-if="entitlementLoading" class="muted">加载权益</p>
<p v-else-if="entitlementErr" class="err">{{ entitlementErr }}</p>
<UserEntitlementPanel v-else-if="entitlement" :data="entitlement" />
</template>
</template>
</section>
</template>