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
+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>