feat(app): implement home, booking, and profile pages

Home: brand banner, studio info swiper, smart quick entries based on
membership status, upcoming bookings, card shop horizontal scroll
Booking: 7-day date selector, time period filter, slot cards with
status, booking confirm popup with membership picker
Profile: user card with login, training stats, menu with admin entry
8 reusable components: BrandBanner, StudioInfo, QuickEntry,
UpcomingBooking, CardShop, DateSelector, SlotCard, BookingConfirmPopup,
TimePeriodFilter, UserCard, TrainingStats, ProfileMenu
This commit is contained in:
richarjiang
2026-04-02 14:35:17 +08:00
parent 554fc30954
commit 3a29aca0db
26 changed files with 7766 additions and 74 deletions

View File

@@ -1,15 +1,624 @@
<template>
<view class="page">
<view class="placeholder">
<text>排课设置 - 待实现</text>
<!-- Top toolbar -->
<view class="toolbar">
<text class="toolbar-hint"> {{ templates.length }} 条模板</text>
<view class="add-btn" @tap="openAdd">
<text class="add-btn-text"> 新增</text>
</view>
</view>
<!-- Loading skeleton -->
<view v-if="loading" class="skeleton-list">
<view v-for="i in 4" :key="i" class="skeleton-item" />
</view>
<!-- Empty -->
<view v-else-if="!templates.length" class="empty-state">
<text class="empty-icon">📅</text>
<text class="empty-text">暂无排课模板点击右上角新增</text>
</view>
<!-- Template list grouped by weekday -->
<template v-else>
<view v-for="day in weekDays" :key="day.value" class="day-group">
<view class="day-header">
<text class="day-label">{{ day.label }}</text>
<text class="day-count">{{ dayTemplates(day.value).length }} </text>
</view>
<view v-if="!dayTemplates(day.value).length" class="day-empty">
<text class="day-empty-text">该天无课</text>
</view>
<view
v-for="tpl in dayTemplates(day.value)"
:key="tpl.id"
class="tpl-card"
:class="{ 'tpl-card--inactive': !tpl.isActive }"
>
<view class="tpl-main">
<view class="tpl-time-block">
<text class="tpl-time">{{ tpl.startTime.slice(0, 5) }}{{ tpl.endTime.slice(0, 5) }}</text>
<view class="tpl-status-dot" :class="tpl.isActive ? 'dot--active' : 'dot--inactive'" />
</view>
<view class="tpl-meta">
<text class="tpl-capacity">容量 {{ tpl.capacity }} </text>
<text class="tpl-active-label">{{ tpl.isActive ? '启用中' : '已停用' }}</text>
</view>
</view>
<view class="tpl-actions">
<view class="action-btn edit-btn" @tap="openEdit(tpl)">
<text class="action-btn-text">编辑</text>
</view>
<view
class="action-btn toggle-btn"
:class="tpl.isActive ? 'toggle-btn--off' : 'toggle-btn--on'"
@tap="toggleActive(tpl)"
>
<text class="action-btn-text">{{ tpl.isActive ? '停用' : '启用' }}</text>
</view>
<view class="action-btn delete-btn" @tap="confirmDelete(tpl)">
<text class="action-btn-text">删除</text>
</view>
</view>
</view>
</view>
</template>
<!-- Save all button -->
<view v-if="dirty" class="save-bar">
<view class="save-bar-btn" :class="{ 'save-bar-btn--loading': saving }" @tap="saveAll">
<text class="save-bar-text">{{ saving ? '保存中...' : '保存全部更改' }}</text>
</view>
</view>
<!-- Add / Edit modal -->
<view v-if="showModal" class="modal-mask" @tap.self="closeModal">
<view class="modal">
<text class="modal-title">{{ editTarget ? '编辑模板' : '新增模板' }}</text>
<view class="modal-field">
<text class="modal-label">星期</text>
<picker mode="selector" :range="weekDays" range-key="label" :value="form.dayOfWeek" @change="onDayChange">
<view class="picker-display">
<text class="picker-text">{{ weekDays[form.dayOfWeek].label }}</text>
<text class="picker-arrow"></text>
</view>
</picker>
</view>
<view class="modal-field">
<text class="modal-label">开始时间</text>
<picker mode="time" :value="form.startTime" @change="(e: any) => form.startTime = e.detail.value">
<view class="picker-display">
<text class="picker-text">{{ form.startTime }}</text>
<text class="picker-arrow"></text>
</view>
</picker>
</view>
<view class="modal-field">
<text class="modal-label">结束时间</text>
<picker mode="time" :value="form.endTime" @change="(e: any) => form.endTime = e.detail.value">
<view class="picker-display">
<text class="picker-text">{{ form.endTime }}</text>
<text class="picker-arrow"></text>
</view>
</picker>
</view>
<view class="modal-field">
<text class="modal-label">容量</text>
<input
class="modal-input"
type="number"
v-model="form.capacityStr"
placeholder="如10"
placeholder-style="color:#bbb"
/>
</view>
<view class="modal-actions">
<view class="modal-cancel" @tap="closeModal">
<text class="modal-cancel-text">取消</text>
</view>
<view class="modal-confirm" :class="{ 'modal-confirm--loading': submitting }" @tap="submitForm">
<text class="modal-confirm-text">{{ submitting ? '保存中...' : '确认' }}</text>
</view>
</view>
</view>
</view>
</view>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { get, put } from '../../utils/request'
import type { WeekTemplate, WeekTemplateInput } from '@mp-pilates/shared'
const templates = ref<WeekTemplate[]>([])
const loading = ref(false)
const saving = ref(false)
const dirty = ref(false)
const showModal = ref(false)
const submitting = ref(false)
const editTarget = ref<WeekTemplate | null>(null)
const weekDays = [
{ label: '周一', value: 1 },
{ label: '周二', value: 2 },
{ label: '周三', value: 3 },
{ label: '周四', value: 4 },
{ label: '周五', value: 5 },
{ label: '周六', value: 6 },
{ label: '周日', value: 0 },
]
const form = ref({
dayOfWeek: 0,
startTime: '09:00',
endTime: '10:00',
capacityStr: '10',
})
function dayTemplates(dayVal: number) {
return templates.value.filter((t) => t.dayOfWeek === dayVal)
}
async function fetchTemplates() {
loading.value = true
try {
const data = await get<WeekTemplate[]>('/admin/week-template')
templates.value = data
} catch {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function openAdd() {
editTarget.value = null
form.value = { dayOfWeek: 0, startTime: '09:00', endTime: '10:00', capacityStr: '10' }
showModal.value = true
}
function openEdit(tpl: WeekTemplate) {
editTarget.value = tpl
form.value = {
dayOfWeek: weekDays.findIndex((d) => d.value === tpl.dayOfWeek),
startTime: tpl.startTime.slice(0, 5),
endTime: tpl.endTime.slice(0, 5),
capacityStr: String(tpl.capacity),
}
showModal.value = true
}
function closeModal() {
showModal.value = false
editTarget.value = null
}
function onDayChange(e: any) {
form.value.dayOfWeek = Number(e.detail.value)
}
async function submitForm() {
const capacity = parseInt(form.value.capacityStr, 10)
if (isNaN(capacity) || capacity < 1) {
uni.showToast({ title: '请输入有效容量', icon: 'none' })
return
}
const dayVal = weekDays[form.value.dayOfWeek].value
if (editTarget.value) {
// Update in local list
const idx = templates.value.findIndex((t) => t.id === editTarget.value!.id)
if (idx !== -1) {
templates.value[idx] = {
...templates.value[idx],
dayOfWeek: dayVal,
startTime: form.value.startTime,
endTime: form.value.endTime,
capacity,
}
}
} else {
// Add locally with a temp id
templates.value.push({
id: `tmp_${Date.now()}`,
dayOfWeek: dayVal,
startTime: form.value.startTime,
endTime: form.value.endTime,
capacity,
isActive: true,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
} as unknown as WeekTemplate)
}
dirty.value = true
closeModal()
}
function toggleActive(tpl: WeekTemplate) {
const idx = templates.value.findIndex((t) => t.id === tpl.id)
if (idx !== -1) {
templates.value[idx] = { ...templates.value[idx], isActive: !templates.value[idx].isActive }
dirty.value = true
}
}
function confirmDelete(tpl: WeekTemplate) {
uni.showModal({
title: '确认删除',
content: `删除 ${weekDays.find((d) => d.value === tpl.dayOfWeek)?.label} ${tpl.startTime.slice(0, 5)} 的模板?`,
success: (res) => {
if (res.confirm) {
templates.value = templates.value.filter((t) => t.id !== tpl.id)
dirty.value = true
}
},
})
}
async function saveAll() {
if (saving.value) return
saving.value = true
try {
const payload: WeekTemplateInput[] = templates.value.map((t) => ({
dayOfWeek: t.dayOfWeek,
startTime: t.startTime,
endTime: t.endTime,
capacity: t.capacity,
isActive: t.isActive,
}))
await put('/admin/week-template', { templates: payload })
dirty.value = false
uni.showToast({ title: '保存成功', icon: 'success' })
await fetchTemplates()
} catch {
uni.showToast({ title: '保存失败,请重试', icon: 'none' })
} finally {
saving.value = false
}
}
onMounted(fetchTemplates)
</script>
<style lang="scss" scoped>
.page { min-height: 100vh; background: #f5f5f5; }
.placeholder { display: flex; align-items: center; justify-content: center; height: 400rpx; color: #999; }
.page {
min-height: 100vh;
background: #f5f3f0;
padding-bottom: 160rpx;
}
/* ── Toolbar ────────────────────────────── */
.toolbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 24rpx 16rpx;
}
.toolbar-hint {
font-size: 24rpx;
color: #999;
}
.add-btn {
background: #1a1a2e;
border-radius: 32rpx;
padding: 12rpx 32rpx;
}
.add-btn-text {
font-size: 26rpx;
font-weight: 600;
color: #c9a87c;
}
/* ── Skeleton ───────────────────────────── */
.skeleton-list {
padding: 0 24rpx;
}
.skeleton-item {
height: 120rpx;
border-radius: 12rpx;
margin-bottom: 16rpx;
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
background-size: 400% 100%;
animation: shimmer 1.4s infinite;
}
@keyframes shimmer {
0% { background-position: 100% 0; }
100% { background-position: -100% 0; }
}
/* ── Empty ──────────────────────────────── */
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
padding: 120rpx 0;
gap: 20rpx;
}
.empty-icon {
font-size: 80rpx;
}
.empty-text {
font-size: 28rpx;
color: #bbb;
}
/* ── Day group ──────────────────────────── */
.day-group {
margin: 0 24rpx 24rpx;
}
.day-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16rpx 0 12rpx;
}
.day-label {
font-size: 28rpx;
font-weight: 700;
color: #1a1a2e;
}
.day-count {
font-size: 22rpx;
color: #c9a87c;
}
.day-empty {
padding: 20rpx 0;
}
.day-empty-text {
font-size: 24rpx;
color: #ccc;
}
/* ── Template card ──────────────────────── */
.tpl-card {
background: #ffffff;
border-radius: 12rpx;
padding: 24rpx;
margin-bottom: 12rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.06);
&--inactive {
opacity: 0.55;
}
}
.tpl-main {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16rpx;
}
.tpl-time-block {
display: flex;
align-items: center;
gap: 12rpx;
}
.tpl-time {
font-size: 32rpx;
font-weight: 700;
color: #1a1a2e;
}
.tpl-status-dot {
width: 14rpx;
height: 14rpx;
border-radius: 50%;
}
.dot--active { background: #27ae60; }
.dot--inactive { background: #ccc; }
.tpl-meta {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 4rpx;
}
.tpl-capacity {
font-size: 24rpx;
color: #555;
}
.tpl-active-label {
font-size: 22rpx;
color: #999;
}
.tpl-actions {
display: flex;
gap: 12rpx;
}
.action-btn {
flex: 1;
padding: 12rpx 0;
border-radius: 8rpx;
display: flex;
align-items: center;
justify-content: center;
}
.action-btn-text {
font-size: 24rpx;
font-weight: 600;
}
.edit-btn {
background: #f0f0f0;
.action-btn-text { color: #1a1a2e; }
}
.toggle-btn--off {
background: #fff3cd;
.action-btn-text { color: #a07000; }
}
.toggle-btn--on {
background: #d4edda;
.action-btn-text { color: #155724; }
}
.delete-btn {
background: #fde8e8;
.action-btn-text { color: #c0392b; }
}
/* ── Save bar ───────────────────────────── */
.save-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 24rpx;
background: #ffffff;
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.08);
}
.save-bar-btn {
width: 100%;
height: 88rpx;
background: linear-gradient(90deg, #1a1a2e, #2d2d5e);
border-radius: 44rpx;
display: flex;
align-items: center;
justify-content: center;
&--loading {
opacity: 0.6;
}
}
.save-bar-text {
font-size: 30rpx;
font-weight: 700;
color: #c9a87c;
}
/* ── Modal ──────────────────────────────── */
.modal-mask {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: flex-end;
z-index: 100;
}
.modal {
width: 100%;
background: #ffffff;
border-radius: 24rpx 24rpx 0 0;
padding: 40rpx 32rpx 60rpx;
}
.modal-title {
font-size: 32rpx;
font-weight: 700;
color: #1a1a2e;
display: block;
margin-bottom: 32rpx;
}
.modal-field {
display: flex;
align-items: center;
justify-content: space-between;
padding: 28rpx 0;
border-bottom: 1rpx solid #f5f5f5;
}
.modal-label {
font-size: 28rpx;
color: #555;
width: 160rpx;
flex-shrink: 0;
}
.picker-display {
flex: 1;
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8rpx;
}
.picker-text {
font-size: 28rpx;
color: #222;
}
.picker-arrow {
font-size: 28rpx;
color: #bbb;
}
.modal-input {
flex: 1;
text-align: right;
font-size: 28rpx;
color: #222;
}
.modal-actions {
display: flex;
gap: 16rpx;
margin-top: 40rpx;
}
.modal-cancel {
flex: 1;
height: 88rpx;
background: #f0f0f0;
border-radius: 44rpx;
display: flex;
align-items: center;
justify-content: center;
}
.modal-cancel-text {
font-size: 28rpx;
color: #555;
}
.modal-confirm {
flex: 2;
height: 88rpx;
background: linear-gradient(90deg, #1a1a2e, #2d2d5e);
border-radius: 44rpx;
display: flex;
align-items: center;
justify-content: center;
&--loading {
opacity: 0.6;
}
}
.modal-confirm-text {
font-size: 28rpx;
font-weight: 700;
color: #c9a87c;
}
</style>