Compare commits

4 Commits

3 changed files with 50 additions and 304 deletions

View File

@@ -2,170 +2,70 @@
<view class="page" :style="{ paddingTop: navBarHeight }"> <view class="page" :style="{ paddingTop: navBarHeight }">
<CustomNavBar title="管理中心" show-back /> <CustomNavBar title="管理中心" show-back />
<!-- Stats summary card --> <!-- Section: 课务运营 -->
<view class="stats-card-wrap"> <view class="section-header">
<view class="stats-card"> <text class="section-title">课务运营</text>
<view v-if="statsLoading" class="stats-loading">
<view v-for="i in 3" :key="i" class="stat-skeleton" />
</view> </view>
<template v-else> <view class="list">
<view class="stat-block"> <view class="list-item" @tap="navigate('/pages/admin/schedule')">
<text class="stat-num">{{ stats.todayBookings }}</text> <text class="item-title">排课管理</text>
<text class="stat-sub">今日预约</text> <text class="arrow-text"></text>
</view> </view>
<view class="stat-sep" /> <view class="list-item" @tap="navigate('/pages/admin/bookings')">
<view class="stat-block"> <text class="item-title">预约管理</text>
<text class="stat-num">{{ stats.totalOrders }}</text> <text class="arrow-text"></text>
<text class="stat-sub">总订单</text>
</view>
<view class="stat-sep" />
<view class="stat-block">
<text class="stat-num">{{ stats.totalBookings }}</text>
<text class="stat-sub">总预约</text>
</view>
</template>
</view> </view>
</view> </view>
<view class="section-header"><text class="section-title">教学报告</text></view> <!-- Section: 教学复盘 -->
<view class="section-header">
<text class="section-title">教学复盘</text>
</view>
<view class="list"> <view class="list">
<view class="list-item" @tap="navigate('/pages/admin/analytics')"> <view class="list-item" @tap="navigate('/pages/admin/analytics')">
<view class="item-left"> <text class="item-title">统计分析</text>
<view class="item-icon-wrap icon--subscribe"><text class="item-icon-text"></text></view> <text class="arrow-text"></text>
<view class="item-text-group"><text class="item-title">统计分析</text><text class="item-desc">月度课次 · 学员出勤 · 上课明细</text></view>
</view> </view>
<view class="item-arrow"><text class="arrow-text"></text></view> <view class="list-item" @tap="navigate('/pages/admin/reviews')">
</view> <text class="item-title">课后评价</text>
</view>
<view class="list"><view class="list-item" @tap="navigate('/pages/admin/reviews')"><view class="item-left"><view class="item-icon-wrap icon--subscribe"><text class="item-icon-text"></text></view><view class="item-text-group"><text class="item-title">课后评价</text><text class="item-desc">学员反馈 · 星级均分 · 推荐意愿趋势</text></view></view><view class="item-arrow"><text class="arrow-text"></text></view></view></view>
<!-- Section header: 课程管理 -->
<view class="section-header">
<text class="section-title">课程管理</text>
</view>
<!-- List: schedule -->
<view class="list">
<view class="list-item" @tap="navigate('/pages/admin/bookings')">
<view class="item-left">
<view class="item-icon-wrap icon--bookings">
<text class="item-icon-text"></text>
</view>
<view class="item-text-group">
<text class="item-title">预约管理</text>
<text class="item-desc">查看/确认/核销学员预约</text>
</view>
</view>
<view class="item-arrow">
<text class="arrow-text"></text> <text class="arrow-text"></text>
</view> </view>
</view> </view>
<view class="list-item" @tap="navigate('/pages/admin/schedule')"> <!-- Section: 会员与订单 -->
<view class="item-left">
<view class="item-icon-wrap icon--schedule">
<text class="item-icon-text"></text>
</view>
<view class="item-text-group">
<text class="item-title">排课管理</text>
<text class="item-desc">管理每周课程时段</text>
</view>
</view>
<view class="item-arrow">
<text class="arrow-text"></text>
</view>
</view>
</view>
<!-- Section header: 会员与订单 -->
<view class="section-header"> <view class="section-header">
<text class="section-title">会员与订单</text> <text class="section-title">会员与订单</text>
</view> </view>
<!-- List: members & orders -->
<view class="list"> <view class="list">
<view class="list-item" @tap="navigate('/pages/admin/members')"> <view class="list-item" @tap="navigate('/pages/admin/members')">
<view class="item-left">
<view class="item-icon-wrap icon--members">
<text class="item-icon-text"></text>
</view>
<view class="item-text-group">
<text class="item-title">会员管理</text> <text class="item-title">会员管理</text>
<text class="item-desc">查看所有会员信息</text>
</view>
</view>
<view class="item-arrow">
<text class="arrow-text"></text> <text class="arrow-text"></text>
</view> </view>
</view>
<view class="list-item" @tap="navigate('/pages/admin/orders')"> <view class="list-item" @tap="navigate('/pages/admin/orders')">
<view class="item-left">
<view class="item-icon-wrap icon--orders">
<text class="item-icon-text"></text>
</view>
<view class="item-text-group">
<text class="item-title">订单管理</text> <text class="item-title">订单管理</text>
<text class="item-desc">查看所有订单记录</text>
</view>
</view>
<view class="item-arrow">
<text class="arrow-text"></text> <text class="arrow-text"></text>
</view> </view>
</view> </view>
<view class="list-item" @tap="navigate('/pages/admin/card-types')"> <!-- Section: 系统设置 -->
<view class="item-left">
<view class="item-icon-wrap icon--card">
<text class="item-icon-text"></text>
</view>
<view class="item-text-group">
<text class="item-title">卡种管理</text>
<text class="item-desc">设置会员卡类型</text>
</view>
</view>
<view class="item-arrow">
<text class="arrow-text"></text>
</view>
</view>
</view>
<!-- Section header: 系统 -->
<view class="section-header"> <view class="section-header">
<text class="section-title">系统</text> <text class="section-title">系统设置</text>
</view> </view>
<!-- List: settings -->
<view class="list"> <view class="list">
<view class="list-item" @tap="navigate('/pages/admin/studio')"> <view class="list-item" @tap="navigate('/pages/admin/card-types')">
<view class="item-left"> <text class="item-title">卡种管理</text>
<view class="item-icon-wrap icon--studio">
<text class="item-icon-text"></text>
</view>
<view class="item-text-group">
<text class="item-title">工作室设置</text>
<text class="item-desc">工作室信息与配置</text>
</view>
</view>
<view class="item-arrow">
<text class="arrow-text"></text> <text class="arrow-text"></text>
</view> </view>
<view class="list-item" @tap="navigate('/pages/admin/studio')">
<text class="item-title">工作室设置</text>
<text class="arrow-text"></text>
</view> </view>
<view class="list-item" @tap="handleIncreaseSubscriptionCount"> <view class="list-item" @tap="handleIncreaseSubscriptionCount">
<view class="item-left">
<view class="item-icon-wrap icon--subscribe">
<text class="item-icon-text"></text>
</view>
<view class="item-text-group">
<text class="item-title">增加订阅次数</text> <text class="item-title">增加订阅次数</text>
<text class="item-desc">当前剩余 {{ user?.adminBookingSubscriptionCount ?? 0 }} </text> <text class="item-extra">剩余 {{ user?.adminBookingSubscriptionCount ?? 0 }} </text>
</view>
</view>
<view class="item-arrow">
<text class="arrow-text">{{ adminSubscribeLoading ? '...' : '' }}</text> <text class="arrow-text">{{ adminSubscribeLoading ? '...' : '' }}</text>
</view> </view>
</view> </view>
</view>
<view style="height: 40rpx" /> <view style="height: 40rpx" />
</view> </view>
@@ -176,37 +76,21 @@ import { ref, onMounted } from 'vue'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import CustomNavBar from '../../components/CustomNavBar.vue' import CustomNavBar from '../../components/CustomNavBar.vue'
import { getSystemLayout } from '../../utils/system' import { getSystemLayout } from '../../utils/system'
import { useAdminStore } from './stores/admin'
import { useUserStore } from '../../stores/user' import { useUserStore } from '../../stores/user'
import type { AdminStats } from './stores/admin'
import { requestAdminBookingSubscriptionCount } from '../../utils/wechat-subscription' import { requestAdminBookingSubscriptionCount } from '../../utils/wechat-subscription'
import { getErrorMessage } from '../../utils/auth' import { getErrorMessage } from '../../utils/auth'
const navBarHeight = ref('64px') const navBarHeight = ref('64px')
const adminStore = useAdminStore()
const userStore = useUserStore() const userStore = useUserStore()
const { user } = storeToRefs(userStore) const { user } = storeToRefs(userStore)
const statsLoading = ref(false)
const stats = ref<AdminStats>({ todayBookings: 0, totalOrders: 0, totalBookings: 0 })
const adminSubscribeLoading = ref(false) const adminSubscribeLoading = ref(false)
function navigate(path: string) { function navigate(path: string) {
uni.navigateTo({ url: path }) uni.navigateTo({ url: path })
} }
async function loadStats() {
statsLoading.value = true
try {
stats.value = await adminStore.fetchDashboardStats()
} catch {
// fail silently — stats are non-critical
} finally {
statsLoading.value = false
}
}
async function handleIncreaseSubscriptionCount() { async function handleIncreaseSubscriptionCount() {
if (adminSubscribeLoading.value) { if (adminSubscribeLoading.value) {
return return
@@ -231,78 +115,18 @@ async function handleIncreaseSubscriptionCount() {
onMounted(() => { onMounted(() => {
navBarHeight.value = `${getSystemLayout().navBarHeight}px` navBarHeight.value = `${getSystemLayout().navBarHeight}px`
loadStats()
userStore.fetchProfile() userStore.fetchProfile()
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
/* ── Page ───────────────────────────────────── */ /* ── Page ───────────────────────── */
.page { .page {
min-height: 100vh; min-height: 100vh;
padding-bottom: 40rpx; padding-bottom: 40rpx;
} }
/* ── Stats card ─────────────────────────────── */ /* ── Section header ───────────────── */
.stats-card-wrap {
padding: 24rpx 24rpx 8rpx;
}
.stats-card {
background: #FFFFFF;
border-radius: 20rpx;
padding: 32rpx 24rpx;
display: flex;
align-items: center;
box-shadow: 0 4rpx 20rpx rgba(180, 160, 130, 0.10);
border: 1rpx solid rgba(180, 160, 130, 0.12);
}
.stats-loading {
width: 100%;
display: flex;
align-items: center;
justify-content: space-around;
}
.stat-skeleton {
width: 100rpx;
height: 64rpx;
border-radius: 12rpx;
background: linear-gradient(90deg, $primary-border 25%, $primary-light 50%, $primary-border 75%);
background-size: 400% 100%;
animation: shimmer 1.6s ease infinite;
}
.stat-block {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 8rpx;
}
.stat-num {
font-size: 44rpx;
font-weight: 700;
color: #4A4035;
line-height: 1;
font-family: 'DIN Alternate', 'Helvetica Neue', Arial, sans-serif;
}
.stat-sub {
font-size: 22rpx;
color: #A09080;
letter-spacing: 0.5rpx;
}
.stat-sep {
width: 1rpx;
height: 56rpx;
background: rgba(180, 160, 130, 0.2);
}
/* ── Section header ─────────────────────────── */
.section-header { .section-header {
padding: 32rpx 24rpx 12rpx; padding: 32rpx 24rpx 12rpx;
} }
@@ -315,7 +139,7 @@ onMounted(() => {
text-transform: uppercase; text-transform: uppercase;
} }
/* ── List ───────────────────────────────────── */ /* ── List ───────────────────────── */
.list { .list {
background: #FFFFFF; background: #FFFFFF;
margin: 0 24rpx; margin: 0 24rpx;
@@ -328,8 +152,8 @@ onMounted(() => {
.list-item { .list-item {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; gap: 16rpx;
padding: 28rpx 24rpx; padding: 32rpx 28rpx;
border-bottom: 1rpx solid rgba(180, 160, 130, 0.1); border-bottom: 1rpx solid rgba(180, 160, 130, 0.1);
transition: background 0.15s ease; transition: background 0.15s ease;
@@ -342,63 +166,23 @@ onMounted(() => {
} }
} }
.item-left {
display: flex;
align-items: center;
gap: 20rpx;
}
.item-icon-wrap {
width: 72rpx;
height: 72rpx;
border-radius: 18rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.item-icon-text {
font-size: 32rpx;
color: #FFFFFF;
line-height: 1;
}
/* Icon variants — warm muted tones */
.icon--bookings { background: linear-gradient(135deg, #C4A87E, #B49868); }
.icon--schedule { background: linear-gradient(135deg, #8B9E7E, #7A8E6E); }
.icon--template { background: linear-gradient(135deg, #A090C0, #9080B0); }
.icon--members { background: linear-gradient(135deg, $primary-color, $primary-dark); }
.icon--orders { background: linear-gradient(135deg, #7E9EC4, #6E8EB4); }
.icon--card { background: linear-gradient(135deg, #C48E7E, #B47E6E); }
.icon--studio { background: linear-gradient(135deg, #9E9E7E, #8E8E6E); }
.icon--subscribe { background: linear-gradient(135deg, #5D8C8A, #476D72); }
.item-text-group {
display: flex;
flex-direction: column;
gap: 4rpx;
}
.item-title { .item-title {
flex: 1;
font-size: 30rpx; font-size: 30rpx;
font-weight: 600; font-weight: 500;
color: #4A4035; color: #4A4035;
letter-spacing: 0.5rpx; letter-spacing: 0.5rpx;
} }
.item-desc { .item-extra {
font-size: 24rpx; font-size: 24rpx;
color: #A09080; color: #A09080;
}
.item-arrow {
flex-shrink: 0; flex-shrink: 0;
padding-left: 16rpx;
} }
.arrow-text { .arrow-text {
font-size: 40rpx; flex-shrink: 0;
font-size: 36rpx;
color: rgba(180, 160, 130, 0.5); color: rgba(180, 160, 130, 0.5);
font-weight: 300; font-weight: 300;
line-height: 1; line-height: 1;

View File

@@ -54,12 +54,6 @@ function normalizePaginatedData<T>(
} }
} }
export interface AdminStats {
todayBookings: number
totalOrders: number
totalBookings: number
}
export type MemberSummary = AdminMemberSummary export type MemberSummary = AdminMemberSummary
export interface UserMembership { export interface UserMembership {
@@ -264,12 +258,7 @@ export const useAdminStore = defineStore('admin', () => {
await fetchSchedulePreview(dto.date) await fetchSchedulePreview(dto.date)
} }
// ── Dashboard stats ────────────────────────────────────────────── // ── Teaching analytics ─────────────────────────────────────────
async function fetchDashboardStats(): Promise<AdminStats> {
return get<AdminStats>('/admin/stats')
}
// ── Teaching analytics ─────────────────────────────────────────
async function fetchTeachingAnalytics(month: string): Promise<TeachingAnalytics> { async function fetchTeachingAnalytics(month: string): Promise<TeachingAnalytics> {
return get<TeachingAnalytics>('/admin/teaching-analytics', { month }) return get<TeachingAnalytics>('/admin/teaching-analytics', { month })
} }
@@ -315,7 +304,5 @@ export const useAdminStore = defineStore('admin', () => {
fetchSchedulePreview, fetchSchedulePreview,
previewScheduleByDate, previewScheduleByDate,
publishDaySlots, publishDaySlots,
// Stats
fetchDashboardStats,
} }
}) })

View File

@@ -4,40 +4,15 @@ import { JwtAuthGuard } from '../auth/jwt-auth.guard'
import { Roles } from '../auth/roles.decorator' import { Roles } from '../auth/roles.decorator'
import { RolesGuard } from '../auth/roles.guard' import { RolesGuard } from '../auth/roles.guard'
import { UserRole } from '@mp-pilates/shared' import { UserRole } from '@mp-pilates/shared'
import { PrismaService } from '../prisma/prisma.service'
interface AdminStats {
todayBookings: number
totalOrders: number
totalBookings: number
}
@Controller('admin') @Controller('admin')
@UseGuards(JwtAuthGuard, RolesGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN) @Roles(UserRole.ADMIN)
export class AdminController { export class AdminController {
constructor(private readonly prisma: PrismaService, private readonly analytics: TeachingAnalyticsService) {} constructor(private readonly analytics: TeachingAnalyticsService) {}
@Get('teaching-analytics') @Get('teaching-analytics')
getTeachingAnalytics(@Query('month') month: string) { getTeachingAnalytics(@Query('month') month: string) {
return this.analytics.getMonthly(month) return this.analytics.getMonthly(month)
} }
@Get('stats')
async getStats(): Promise<AdminStats> {
const today = new Date()
today.setUTCHours(0, 0, 0, 0)
const [todayBookings, totalOrders, totalBookings] = await Promise.all([
this.prisma.booking.count({
where: {
timeSlot: { date: today },
},
}),
this.prisma.order.count(),
this.prisma.booking.count(),
])
return { todayBookings, totalOrders, totalBookings }
}
} }