新增教练端,实现业务闭环:会员登录注册→查询团课→预约团课→扫码签到→教练端开课→记录实际开课时间→教练端结课→记录实际结课时间→后台查询数据

This commit is contained in:
2026-07-20 17:21:28 +08:00
parent df0e68469b
commit 4a4697c816
84 changed files with 6914 additions and 258 deletions
@@ -0,0 +1,428 @@
<template>
<view class="detail-page">
<view class="header-wrap" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="nav-bar" :style="{ height: navBarHeight + 'px' }">
<text class="back-btn" @click="goBack">&#8592;</text>
<text class="nav-title">课程详情</text>
</view>
</view>
<!-- 封面区 -->
<view class="cover-area">
<image v-if="course.coverImage && !loading" class="cover-img" :src="course.coverImage" mode="aspectFill"
@error="course.coverError = true" />
<view v-if="!course.coverImage || course.coverError || loading" class="cover-bg">
<text class="cover-text">{{ (course.typeName ? course.typeName.slice(0, 2) : '团课') }}</text>
</view>
<view class="cover-status" :class="courseStatusClass" v-if="!loading">
<text>{{ courseStatusText }}</text>
</view>
</view>
<scroll-view class="content" scroll-y :style="{ height: 'calc(100vh - ' + totalHeaderHeight + 'px - 200px)' }">
<view class="content-inner" v-if="!loading">
<!-- 课程名称 -->
<view class="title-row">
<text class="detail-title">{{ course.courseName }}</text>
</view>
<!-- 信息卡片 -->
<view class="info-card">
<view class="info-item">
<text class="info-label">时间</text>
<text class="info-value">{{ formatDate(course.startTime) }} {{ formatTime(course.startTime) }} - {{ formatTime(course.endTime) }}</text>
</view>
<view class="info-item">
<text class="info-label">时长</text>
<text class="info-value">{{ duration }}</text>
</view>
<view class="info-item">
<text class="info-label">地点</text>
<text class="info-value">{{ course.location || '未设置' }}</text>
</view>
<view class="info-item">
<text class="info-label">人数</text>
<text class="info-value">{{ course.currentMembers || 0 }} / {{ course.maxMembers || 0 }}</text>
</view>
<view class="info-item" v-if="course.storedValueAmount">
<text class="info-label">消耗</text>
<text class="info-value price-text">¥{{ course.storedValueAmount }}</text>
</view>
</view>
<!-- 课程介绍 -->
<view class="desc-card" v-if="course.description">
<text class="desc-title">课程介绍</text>
<text class="desc-content">{{ course.description }}</text>
</view>
<!-- 操作区 -->
<view class="action-area">
<button
v-if="course.status == 0"
class="action-btn start-btn"
:class="{ disabled: !canStartCourse }"
:loading="actionLoading"
:disabled="actionLoading || !canStartCourse"
@click="handleStartCourse"
>
{{ actionLoading ? '开课中...' : (canStartCourse ? '开 课' : '尚未到开课时间') }}
</button>
<button
v-if="course.status == 3 || course.status == 7"
class="action-btn end-btn"
:class="{ disabled: !canEndCourse }"
:loading="actionLoading"
:disabled="actionLoading || !canEndCourse"
@click="handleEndCourse"
>
{{ actionLoading ? '结课中...' : (canEndCourse ? '结 课' : '尚未到结课时间') }}
</button>
<button
v-if="course.status != 0 && course.status != 3 && course.status != 7"
class="action-btn disabled-btn"
disabled
>
不可操作
</button>
</view>
<view class="bottom-safe"></view>
</view>
<view v-else class="loading-wrap">
<text class="loading-text">加载中...</text>
</view>
</scroll-view>
</view>
</template>
<script>
const coachApi = require('../../api/coach')
const store = require('../../store/index')
const { resolveCoverUrl } = require('../../utils/request')
export default {
data() {
return {
statusBarHeight: 0,
navBarHeight: 44,
totalHeaderHeight: 44,
courseId: '',
loading: true,
actionLoading: false,
course: {},
now: Date.now()
}
},
computed: {
duration() {
if (!this.course.startTime || !this.course.endTime) return '--'
const start = new Date(this.course.startTime).getTime()
const end = new Date(this.course.endTime).getTime()
const mins = Math.round((end - start) / 60000)
if (mins < 60) return mins + '分钟'
return Math.floor(mins / 60) + '小时' + (mins % 60 > 0 ? mins % 60 + '分钟' : '')
},
canStartCourse() {
return (this.course.status == 0) && this.now >= new Date(this.course.startTime || 0).getTime()
},
canEndCourse() {
return (this.course.status == 3 || this.course.status == 7) && this.now >= new Date(this.course.endTime || 0).getTime()
},
courseStatusClass() {
const map = { 0: 'normal', 1: 'cancelled', 2: 'ended', 3: 'in-progress', 4: 'timeout', 5: 'absent', 6: 'auto-ended', 7: 'late' }
return map[this.course.status] || ''
},
courseStatusText() {
const labels = { 0: '正常', 1: '已取消', 2: '已结束', 3: '进行中', 4: '超时', 5: '教练缺席', 6: '自动结束', 7: '教练迟到' }
return labels[this.course.status] || '未知'
}
},
onLoad(options) {
const systemInfo = uni.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 20
let navBarHeight = 44
// #ifdef MP-WEIXIN
const menuButton = uni.getMenuButtonBoundingClientRect()
if (menuButton) {
navBarHeight = (menuButton.top - statusBarHeight) * 2 + menuButton.height
}
// #endif
this.statusBarHeight = statusBarHeight
this.navBarHeight = navBarHeight
this.totalHeaderHeight = statusBarHeight + navBarHeight
if (options && options.id) {
this.courseId = options.id
this.loadDetail()
}
},
onShow() {
if (!store.isLoggedIn) {
uni.reLaunch({ url: '/pages/login/login' })
}
},
methods: {
goBack() { uni.navigateBack() },
async loadDetail() {
this.loading = true
try {
const data = await coachApi.getCourseDetail(this.courseId)
this.course = {
...(data || {}),
coverImage: resolveCoverUrl((data || {}).coverImage),
coverError: false
}
this.now = Date.now()
} catch (e) {
console.error('加载课程详情失败:', e)
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
this.loading = false
}
},
async handleStartCourse() {
if (this.actionLoading) return
this.now = Date.now()
if (!this.canStartCourse) {
uni.showToast({ title: '尚未到课程预计开始时间,无法开课', icon: 'none', duration: 3000 })
return
}
this.actionLoading = true
try {
await coachApi.startCourse(this.courseId)
uni.showToast({ title: '开课成功', icon: 'success' })
// 刷新课程详情
await this.loadDetail()
} catch (err) {
console.error('开课失败:', err)
let msg = '开课失败'
if (err && err.data && err.data.message) {
msg = err.data.message
} else if (err && err.message) {
msg = err.message
}
uni.showToast({ title: msg, icon: 'none', duration: 3000 })
} finally {
this.actionLoading = false
}
},
async handleEndCourse() {
if (this.actionLoading) return
this.now = Date.now()
if (!this.canEndCourse) {
uni.showToast({ title: '尚未到课程预计结束时间,无法结课', icon: 'none', duration: 3000 })
return
}
this.actionLoading = true
try {
await coachApi.endCourse(this.courseId)
uni.showToast({ title: '结课成功', icon: 'success' })
await this.loadDetail()
} catch (err) {
console.error('结课失败:', err)
let msg = '结课失败'
if (err && err.data && err.data.message) {
msg = err.data.message
} else if (err && err.message) {
msg = err.message
}
uni.showToast({ title: msg, icon: 'none', duration: 3000 })
} finally {
this.actionLoading = false
}
},
formatDate(timeStr) {
if (!timeStr) return '--'
return timeStr.substring(0, 10)
},
formatTime(timeStr) {
if (!timeStr) return '--'
return timeStr.substring(11, 16)
}
}
}
</script>
<style scoped>
.detail-page {
min-height: 100vh;
background: #F5F7FA;
overflow-x: hidden;
}
.header-wrap {
background: #1A1A1A;
}
.nav-bar {
padding: 0 16px;
display: flex;
align-items: center;
}
.back-btn {
font-size: 20px;
color: #FFFFFF;
margin-right: 12px;
}
.nav-title {
font-size: 18px;
font-weight: 700;
color: #FFFFFF;
}
.content-inner {
padding: 0 14px;
}
.loading-wrap {
display: flex;
justify-content: center;
padding: 60px 0;
}
.loading-text {
font-size: 14px;
color: #7A7E84;
}
/* 封面区 */
.cover-area { height: 200px; position: relative; overflow: hidden; }
.cover-img { width: 100%; height: 100%; }
.cover-bg { width: 100%; height: 100%; background: linear-gradient(135deg, #00C853, #00BFA5); display: flex; align-items: center; justify-content: center; }
.cover-text { font-size: 56px; font-weight: 700; color: rgba(255,255,255,0.9); }
.cover-status {
position: absolute;
top: 14px;
right: 14px;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: 600;
}
.cover-status.normal, .cover-status.in-progress, .cover-status.late {
background: rgba(255,255,255,0.25);
color: #FFFFFF;
}
.cover-status.ended, .cover-status.auto-ended {
background: rgba(255,255,255,0.2);
color: rgba(255,255,255,0.8);
}
.cover-status.cancelled, .cover-status.timeout, .cover-status.absent {
background: rgba(244,67,54,0.2);
color: #FFCDD2;
}
/* 课程名称 */
.title-row {
padding: 0 4px;
margin-bottom: 12px;
}
.detail-title {
font-size: 20px;
font-weight: 700;
color: #1E1E1E;
}
/* 信息卡片 */
.info-card {
background: #FFFFFF;
border-radius: 16px;
padding: 16px;
margin-bottom: 14px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.info-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0;
border-bottom: 1px solid #F0F0F0;
}
.info-item:last-child {
border-bottom: none;
}
.info-label {
font-size: 14px;
color: #7A7E84;
}
.info-value {
font-size: 14px;
color: #1E1E1E;
font-weight: 500;
text-align: right;
flex: 1;
margin-left: 12px;
}
.price-text {
color: #00C853;
font-weight: 700;
font-size: 16px;
}
/* 课程介绍 */
.desc-card {
background: #FFFFFF;
border-radius: 16px;
padding: 16px;
margin-bottom: 14px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.desc-title {
font-size: 16px;
font-weight: 700;
color: #1E1E1E;
display: block;
margin-bottom: 8px;
}
.desc-content {
font-size: 14px;
color: #7A7E84;
line-height: 1.6;
}
/* 操作区 */
.action-area {
padding: 10px 0 20px;
}
.action-btn {
width: 100%;
height: 50px;
border-radius: 40px;
font-size: 17px;
font-weight: 700;
display: flex;
align-items: center;
justify-content: center;
border: none;
}
.action-btn::after { border: none; }
.start-btn {
background: #00E676;
color: #1A1A1A;
box-shadow: 0 4px 16px rgba(0,230,118,0.35);
}
.start-btn.disabled {
background: #E0E0E0;
color: #9E9E9E;
box-shadow: none;
}
.end-btn {
background: #FF9800;
color: #FFFFFF;
box-shadow: 0 4px 16px rgba(255,152,0,0.35);
}
.end-btn.disabled {
background: #E0E0E0;
color: #9E9E9E;
box-shadow: none;
}
.disabled-btn {
background: #E0E0E0;
color: #9E9E9E;
}
.bottom-safe {
height: 30px;
}
</style>
@@ -0,0 +1,292 @@
<template>
<view class="course-list-page">
<view class="header-wrap" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="nav-bar" :style="{ height: navBarHeight + 'px' }">
<text class="back-btn" @click="goBack">&#8592;</text>
<text class="nav-title">我的团课</text>
</view>
<!-- 状态筛选 Tab -->
<view class="tab-row">
<view
v-for="(tab, idx) in tabs"
:key="idx"
class="tab-item"
:class="{ active: currentTab === tab.value }"
@click="switchTab(tab.value)"
>
<text>{{ tab.label }}</text>
</view>
</view>
</view>
<scroll-view class="content" scroll-y :style="{ height: 'calc(100vh - ' + totalHeaderHeight + 'px)' }">
<view class="content-inner">
<view v-if="loading" class="loading-wrap">
<text class="loading-text">加载中...</text>
</view>
<view v-else-if="filteredCourses.length === 0" class="empty-wrap">
<text class="empty-text">暂无课程</text>
</view>
<view v-else class="course-list">
<view v-for="course in filteredCourses" :key="course.id" class="course-card" :class="{ grayed: !course._isToday }" @click="goToDetail(course.id)">
<view class="card-header">
<text class="course-name">{{ course.courseName }}</text>
<view class="status-tag" :class="course._statusClass">
<text>{{ course._statusLabel }}</text>
</view>
</view>
<view class="card-info">
<view class="info-row">
<text class="info-label">时间</text>
<text class="info-value">{{ formatDate(course.startTime) }} {{ formatTime(course.startTime) }} - {{ formatTime(course.endTime) }}</text>
</view>
<view class="info-row">
<text class="info-label">地点</text>
<text class="info-value">{{ course.location || '未设置' }}</text>
</view>
<view class="info-row">
<text class="info-label">人数</text>
<text class="info-value">{{ course.currentMembers || 0 }} / {{ course.maxMembers || 0 }}</text>
</view>
</view>
</view>
</view>
<view class="bottom-safe"></view>
</view>
</scroll-view>
</view>
</template>
<script>
const coachApi = require('../../api/coach')
const store = require('../../store/index')
export default {
data() {
return {
statusBarHeight: 0,
navBarHeight: 44,
totalHeaderHeight: 0,
loading: true,
courses: [],
currentTab: 'all',
tabs: [
{ label: '全部', value: 'all' },
{ label: '待开课', value: 'pending' },
{ label: '进行中', value: 'in_progress' },
{ label: '已结束', value: 'ended' }
]
}
},
computed: {
filteredCourses() {
switch (this.currentTab) {
case 'pending':
return this.courses.filter(c => c.status == 0)
case 'in_progress':
return this.courses.filter(c => c.status == 3 || c.status == 7)
case 'ended':
return this.courses.filter(c => c.status == 2 || c.status == 6 || c.status == 1 || c.status == 4 || c.status == 5)
default:
return this.courses
}
}
},
onLoad() {
const systemInfo = uni.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 20
let navBarHeight = 44
// #ifdef MP-WEIXIN
const menuButton = uni.getMenuButtonBoundingClientRect()
if (menuButton) {
navBarHeight = (menuButton.top - statusBarHeight) * 2 + menuButton.height
}
// #endif
this.statusBarHeight = statusBarHeight
this.navBarHeight = navBarHeight
// 状态栏 + 导航栏 + tab行高度
this.totalHeaderHeight = statusBarHeight + navBarHeight + 44
},
onShow() {
if (!store.isLoggedIn) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
this.loadCourses()
},
methods: {
goBack() { uni.navigateBack() },
goToDetail(id) {
uni.navigateTo({ url: '/pages/course-detail/course-detail?id=' + id })
},
switchTab(value) { this.currentTab = value },
async loadCourses() {
this.loading = true
try {
const coachId = store.getCoachId()
if (!coachId) return
const result = await coachApi.getCoachCourses(coachId)
const list = Array.isArray(result) ? result : (result && result.content ? result.content : [])
// 预计算状态 class 和 labeluni-app 模板不支持 :class 中调用方法
const classMap = { 0: 'normal', 1: 'cancelled', 2: 'ended', 3: 'in-progress', 4: 'timeout', 5: 'absent', 6: 'auto-ended', 7: 'late' }
const labelMap = { 0: '正常', 1: '已取消', 2: '已结束', 3: '进行中', 4: '超时', 5: '教练缺席', 6: '自动结束', 7: '教练迟到' }
const todayStr = new Date().toISOString().substring(0, 10)
this.courses = list
.map(c => ({
...c,
_statusClass: classMap[c.status] || '',
_statusLabel: labelMap[c.status] || '未知',
_isToday: (c.startTime || '').substring(0, 10) === todayStr
}))
.sort((a, b) => {
if (a._isToday && !b._isToday) return -1
if (!a._isToday && b._isToday) return 1
return 0
})
} catch (e) {
console.error('加载课程失败:', e)
uni.showToast({ title: '加载课程失败', icon: 'none' })
} finally {
this.loading = false
}
},
formatDate(timeStr) {
if (!timeStr) return '--'
return timeStr.substring(0, 10)
},
formatTime(timeStr) {
if (!timeStr) return '--'
return timeStr.substring(11, 16)
},
}
}
</script>
<style scoped>
.course-list-page {
min-height: 100vh;
background: #F5F7FA;
overflow-x: hidden;
}
.header-wrap {
background: #1A1A1A;
}
.nav-bar {
padding: 0 16px;
display: flex;
align-items: center;
}
.back-btn {
font-size: 20px;
color: #FFFFFF;
margin-right: 12px;
}
.nav-title {
font-size: 18px;
font-weight: 700;
color: #FFFFFF;
}
/* Tab 筛选 */
.tab-row {
display: flex;
padding: 8px 16px 10px;
}
.tab-item {
padding: 6px 16px;
border-radius: 20px;
margin-right: 8px;
font-size: 13px;
color: rgba(255,255,255,0.6);
background: rgba(255,255,255,0.1);
}
.tab-item.active {
color: #1A1A1A;
background: #00E676;
font-weight: 600;
}
/* 内容区 */
.content-inner {
padding: 14px 14px 0;
}
.loading-wrap, .empty-wrap {
display: flex;
justify-content: center;
padding: 60px 0;
}
.loading-text, .empty-text {
font-size: 14px;
color: #7A7E84;
}
/* 课程卡片 */
.course-card {
background: #FFFFFF;
border-radius: 16px;
padding: 16px;
margin-bottom: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.course-name {
font-size: 16px;
font-weight: 700;
color: #1E1E1E;
flex: 1;
}
.status-tag {
padding: 3px 10px;
border-radius: 12px;
font-size: 11px;
font-weight: 600;
}
.status-tag.normal { background: rgba(0,230,118,0.15); color: #00C853; }
.status-tag.in-progress, .status-tag.late { background: rgba(33,150,243,0.15); color: #2196F3; }
.status-tag.ended, .status-tag.auto-ended { background: rgba(158,158,158,0.15); color: #9E9E9E; }
.status-tag.cancelled { background: rgba(255,152,0,0.15); color: #FF9800; }
.status-tag.timeout { background: rgba(244,67,54,0.15); color: #F44336; }
.status-tag.absent { background: rgba(244,67,54,0.15); color: #F44336; }
.card-info {
background: #F5F7FA;
border-radius: 10px;
padding: 10px 12px;
}
.info-row {
display: flex;
justify-content: space-between;
margin-bottom: 4px;
}
.info-row:last-child {
margin-bottom: 0;
}
.info-label {
font-size: 12px;
color: #7A7E84;
}
.info-value {
font-size: 13px;
color: #1E1E1E;
font-weight: 500;
}
/* 操作按钮 - 已移除,仅保留按钮样式供可能复用 */
.course-card.grayed {
opacity: 0.5;
pointer-events: auto;
}
.bottom-safe {
height: 20px;
}
</style>
@@ -0,0 +1,282 @@
<template>
<view class="home-page">
<view class="header-wrap" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="nav-bar" :style="{ height: navBarHeight + 'px' }">
<text class="nav-title"> Novalon 教练端</text>
</view>
</view>
<scroll-view class="content" scroll-y :style="{ height: 'calc(100vh - ' + totalHeaderHeight + 'px)' }">
<view class="content-inner">
<!-- 教练欢迎卡片 -->
<view class="greeting-card">
<view class="greeting-text">
<text class="greeting-label">{{ greetingLabel }}</text>
<text class="coach-name">{{ coachName }} 教练</text>
</view>
<view class="greeting-desc">
<text>祝您今日授课顺利</text>
</view>
</view>
<!-- 今日统计 -->
<view class="stats-card">
<view class="stat-item">
<text class="stat-number">{{ todayStats.pending }}</text>
<text class="stat-label">待开课</text>
</view>
<view class="stat-divider"></view>
<view class="stat-item">
<text class="stat-number">{{ todayStats.inProgress }}</text>
<text class="stat-label">进行中</text>
</view>
<view class="stat-divider"></view>
<view class="stat-item">
<text class="stat-number">{{ todayStats.ended }}</text>
<text class="stat-label">已结束</text>
</view>
</view>
<!-- 功能入口 -->
<view class="section-header">
<text class="section-title">快捷功能</text>
</view>
<view class="entry-grid">
<view class="entry-card" @click="goToCourseList">
<view class="entry-icon-wrap green-bg">
<text class="entry-icon">&#9776;</text>
</view>
<text class="entry-name">我的团课</text>
<text class="entry-desc">查看和管理课程</text>
</view>
<view class="entry-card" @click="goToProfile">
<view class="entry-icon-wrap dark-bg">
<text class="entry-icon">&#9786;</text>
</view>
<text class="entry-name">个人中心</text>
<text class="entry-desc">信息与违规记录</text>
</view>
</view>
<view class="bottom-safe"></view>
</view>
</scroll-view>
</view>
</template>
<script>
const store = require('../../store/index')
const coachApi = require('../../api/coach')
export default {
data() {
return {
statusBarHeight: 0,
navBarHeight: 44,
totalHeaderHeight: 44,
coachName: '加载中...',
todayStats: {
pending: 0,
inProgress: 0,
ended: 0
}
}
},
computed: {
greetingLabel() {
const hour = new Date().getHours()
if (hour < 6) return '夜深了,'
if (hour < 12) return '早上好,'
if (hour < 18) return '下午好,'
return '晚上好,'
}
},
onLoad() {
const systemInfo = uni.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 20
let navBarHeight = 44
// #ifdef MP-WEIXIN
const menuButton = uni.getMenuButtonBoundingClientRect()
if (menuButton) {
navBarHeight = (menuButton.top - statusBarHeight) * 2 + menuButton.height
}
// #endif
this.statusBarHeight = statusBarHeight
this.navBarHeight = navBarHeight
this.totalHeaderHeight = statusBarHeight + navBarHeight
},
onShow() {
if (!store.isLoggedIn) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
this.coachName = store.getUsername() || '教练'
this.loadStats()
},
onPullDownRefresh() {
this.loadStats().finally(() => { uni.stopPullDownRefresh() })
},
methods: {
goToCourseList() {
uni.navigateTo({ url: '/pages/course-list/course-list' })
},
goToProfile() {
uni.navigateTo({ url: '/pages/profile/profile' })
},
async loadStats() {
try {
const coachId = store.getCoachId()
if (!coachId) return
const courses = await coachApi.getCoachCourses(coachId)
const list = Array.isArray(courses) ? courses : (courses && courses.content ? courses.content : [])
this.todayStats = {
pending: list.filter(c => c.status == 0).length,
inProgress: list.filter(c => c.status == 3 || c.status == 7).length,
ended: list.filter(c => c.status == 2 || c.status == 6).length
}
} catch (e) {
console.error('加载统计失败:', e)
}
}
}
}
</script>
<style scoped>
.home-page {
min-height: 100vh;
background: #F5F7FA;
overflow-x: hidden;
}
.header-wrap {
background: #1A1A1A;
}
.nav-bar {
background: #1A1A1A;
padding: 0 20px;
display: flex;
align-items: center;
}
.nav-title {
font-size: 18px;
font-weight: 700;
color: #FFFFFF;
}
.content-inner {
padding: 16px;
}
/* 欢迎卡片 */
.greeting-card {
background: #1A1A1A;
border-radius: 20px;
padding: 20px;
color: #FFFFFF;
margin-bottom: 16px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.greeting-text {
display: flex;
align-items: baseline;
}
.greeting-label {
font-size: 16px;
color: rgba(255,255,255,0.7);
}
.coach-name {
font-size: 22px;
font-weight: 700;
color: #00E676;
}
.greeting-desc {
margin-top: 6px;
font-size: 13px;
color: rgba(255,255,255,0.5);
}
/* 统计卡片 */
.stats-card {
background: #FFFFFF;
border-radius: 20px;
padding: 18px 20px;
display: flex;
justify-content: space-around;
margin-bottom: 20px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
}
.stat-number {
font-size: 28px;
font-weight: 700;
color: #00C853;
}
.stat-label {
font-size: 12px;
color: #7A7E84;
margin-top: 4px;
}
.stat-divider {
width: 1px;
background: #EEEEEE;
}
/* 功能入口 */
.section-header {
margin-bottom: 14px;
}
.section-title {
font-size: 18px;
font-weight: 700;
color: #1E1E1E;
}
.entry-grid {
display: flex;
justify-content: space-between;
}
.entry-card {
width: calc(50% - 6px);
background: #FFFFFF;
border-radius: 20px;
padding: 20px 16px;
display: flex;
flex-direction: column;
align-items: center;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.entry-icon-wrap {
width: 56px;
height: 56px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 10px;
}
.entry-icon-wrap.green-bg {
background: rgba(0,230,118,0.15);
}
.entry-icon-wrap.dark-bg {
background: rgba(26,26,26,0.1);
}
.entry-icon {
font-size: 24px;
color: #00C853;
}
.entry-name {
font-size: 16px;
font-weight: 600;
color: #1E1E1E;
margin-bottom: 4px;
}
.entry-desc {
font-size: 12px;
color: #7A7E84;
}
.bottom-safe {
height: 20px;
}
</style>
@@ -0,0 +1,217 @@
<template>
<view class="login-page" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="brand-area">
<view class="logo-icon">
<text class="logo-symbol"></text>
</view>
<text class="app-name">Novalon 教练端</text>
<text class="app-slogan">高效管理 · 轻松授课</text>
</view>
<view class="login-form">
<view class="input-group">
<text class="input-icon">&#128100;</text>
<input
class="login-input"
type="text"
v-model="username"
placeholder="请输入教练账号"
placeholder-style="color: #BDBDBD"
/>
</view>
<view class="input-group">
<text class="input-icon">&#128274;</text>
<input
class="login-input"
:type="showPassword ? 'text' : 'password'"
v-model="password"
placeholder="请输入密码"
placeholder-style="color: #BDBDBD"
/>
<text class="toggle-pwd" @click="showPassword = !showPassword">
{{ showPassword ? '&#128065;' : '&#128064;' }}
</text>
</view>
<button class="login-btn" :loading="loading" :disabled="loading || !username || !password" @click="handleLogin">
{{ loading ? '登录中...' : ' ' }}
</button>
</view>
<view class="footer-tip">
<text>Novalon 健身房管理系统</text>
</view>
</view>
</template>
<script>
const coachApi = require('../../api/coach')
const store = require('../../store/index')
export default {
data() {
return {
statusBarHeight: 0,
username: '',
password: '',
showPassword: false,
loading: false
}
},
onLoad() {
const systemInfo = uni.getSystemInfoSync()
this.statusBarHeight = systemInfo.statusBarHeight || 20
if (store.isLoggedIn) {
uni.reLaunch({ url: '/pages/index/index' })
}
},
methods: {
async handleLogin() {
if (!this.username.trim()) {
uni.showToast({ title: '请输入教练账号', icon: 'none' })
return
}
if (!this.password) {
uni.showToast({ title: '请输入密码', icon: 'none' })
return
}
if (this.loading) return
this.loading = true
try {
const res = await coachApi.login(this.username.trim(), this.password)
if (res && res.token) {
store.setLogin(res.token, {
coachId: res.userId,
username: res.username
})
uni.showToast({ title: '登录成功', icon: 'success' })
setTimeout(() => {
uni.reLaunch({ url: '/pages/index/index' })
}, 500)
} else {
uni.showToast({ title: '登录失败:账号或密码错误', icon: 'none' })
}
} catch (err) {
console.error('登录失败:', err)
let msg = '登录失败,请重试'
if (err && err.data && err.data.message) {
msg = err.data.message
} else if (err && err.message) {
msg = err.message
}
uni.showToast({ title: msg, icon: 'none' })
} finally {
this.loading = false
}
}
}
}
</script>
<style scoped>
.login-page {
min-height: 100vh;
background: #F5F7FA;
display: flex;
flex-direction: column;
align-items: center;
padding: 0 32px;
overflow-x: hidden;
}
.brand-area {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 80px;
margin-bottom: 60px;
}
.logo-icon {
width: 80px;
height: 80px;
background: rgba(0,230,118,0.15);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 20px;
}
.logo-symbol {
font-size: 36px;
color: #00C853;
}
.app-name {
font-size: 28px;
font-weight: 700;
color: #1E1E1E;
letter-spacing: 1px;
}
.app-slogan {
font-size: 14px;
color: #7A7E84;
margin-top: 8px;
letter-spacing: 2px;
}
.login-form {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.input-group {
width: 100%;
height: 52px;
background: #FFFFFF;
border-radius: 40px;
display: flex;
align-items: center;
padding: 0 18px;
margin-bottom: 14px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.input-icon {
font-size: 18px;
margin-right: 10px;
color: #7A7E84;
}
.login-input {
flex: 1;
height: 100%;
font-size: 15px;
color: #1E1E1E;
}
.toggle-pwd {
font-size: 18px;
color: #7A7E84;
padding-left: 8px;
}
.login-btn {
width: 100%;
height: 52px;
background: #00E676;
border-radius: 40px;
display: flex;
align-items: center;
justify-content: center;
border: none;
padding: 0;
margin-top: 10px;
font-size: 17px;
font-weight: 700;
color: #1A1A1A;
box-shadow: 0 4px 16px rgba(0,230,118,0.35);
}
.login-btn::after { border: none; }
.login-btn[disabled] { opacity: 0.5; }
.footer-tip {
position: absolute;
bottom: 60px;
font-size: 12px;
color: #BDBDBD;
}
</style>
@@ -0,0 +1,347 @@
<template>
<view class="profile-page">
<view class="header-wrap" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="nav-bar" :style="{ height: navBarHeight + 'px' }">
<text class="back-btn" @click="goBack">&#8592;</text>
<text class="nav-title">个人中心</text>
</view>
</view>
<scroll-view class="content" scroll-y :style="{ height: 'calc(100vh - ' + totalHeaderHeight + 'px)' }">
<view class="content-inner">
<!-- 教练信息卡片 -->
<view class="user-card">
<view class="user-header">
<view class="avatar">
<text class="avatar-text">CC</text>
</view>
<view class="user-info">
<text class="user-name">{{ coachInfo.username }}</text>
<view class="user-tag">
<text>教练</text>
</view>
</view>
</view>
<view class="user-details">
<view class="detail-row">
<text class="detail-label">教练 ID</text>
<text class="detail-value">{{ coachInfo.coachId }}</text>
</view>
</view>
</view>
<!-- 违规统计 -->
<view class="stats-card">
<view class="stat-item">
<text class="stat-number">{{ violations.length }}</text>
<text class="stat-label">违规次数</text>
</view>
</view>
<!-- 违规记录列表 -->
<view class="section-header">
<text class="section-title">违规记录</text>
</view>
<view v-if="violations.length === 0 && !loadingViolations" class="empty-wrap">
<text class="empty-text">暂无违规记录</text>
</view>
<view v-else class="violation-list">
<view v-for="(v, idx) in violations" :key="idx" class="violation-card">
<view class="violation-header">
<text class="violation-course">{{ v.course_name || '未知课程' }}</text>
<view class="violation-tag" :class="v._violationClass">
<text>{{ v._violationLabel }}</text>
</view>
</view>
<text class="violation-time">{{ formatViolationTime(v.violation_time) }}</text>
</view>
</view>
<!-- 退出登录 -->
<view class="logout-area">
<button class="logout-btn" @click="handleLogout">退出登录</button>
</view>
<view class="bottom-safe"></view>
</view>
</scroll-view>
</view>
</template>
<script>
const store = require('../../store/index')
const coachApi = require('../../api/coach')
export default {
data() {
return {
statusBarHeight: 0,
navBarHeight: 44,
totalHeaderHeight: 44,
coachInfo: {
username: '加载中...',
coachId: ''
},
violations: [],
loadingViolations: true
}
},
onLoad() {
const systemInfo = uni.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 20
let navBarHeight = 44
// #ifdef MP-WEIXIN
const menuButton = uni.getMenuButtonBoundingClientRect()
if (menuButton) {
navBarHeight = (menuButton.top - statusBarHeight) * 2 + menuButton.height
}
// #endif
this.statusBarHeight = statusBarHeight
this.navBarHeight = navBarHeight
this.totalHeaderHeight = statusBarHeight + navBarHeight
},
onShow() {
if (!store.isLoggedIn) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
this.coachInfo = store.getCoachInfo() || { username: '教练', coachId: '' }
this.loadViolations()
},
methods: {
goBack() { uni.navigateBack() },
async loadViolations() {
this.loadingViolations = true
try {
const coachId = store.getCoachId()
if (!coachId) return
const result = await coachApi.getCoachViolations(coachId)
const list = Array.isArray(result) ? result : (result && result.content ? result.content : [])
// 预计算违规 class 和 labeluni-app 模板不支持 :class 中调用方法
const classMap = { COACH_LATE: 'late', COACH_ABSENT: 'absent', NOT_MANUAL_END: 'no-manual-end' }
const labelMap = { COACH_LATE: '迟到', COACH_ABSENT: '缺席', NOT_MANUAL_END: '未手动结课' }
this.violations = list.map(v => ({
...v,
_violationClass: classMap[v.violation_reason] || '',
_violationLabel: labelMap[v.violation_reason] || v.violation_reason || '违规'
}))
} catch (e) {
console.error('加载违规记录失败:', e)
} finally {
this.loadingViolations = false
}
},
handleLogout() {
uni.showModal({
title: '提示',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
store.clearLogin()
uni.reLaunch({ url: '/pages/login/login' })
}
}
})
},
formatViolationTime(timeStr) {
if (!timeStr) return ''
return timeStr.replace('T', ' ').substring(0, 19)
}
}
}
</script>
<style scoped>
.profile-page {
min-height: 100vh;
background: #F5F7FA;
overflow-x: hidden;
}
.header-wrap {
background: #1A1A1A;
}
.nav-bar {
padding: 0 16px;
display: flex;
align-items: center;
}
.back-btn {
font-size: 20px;
color: #FFFFFF;
margin-right: 12px;
}
.nav-title {
font-size: 18px;
font-weight: 700;
color: #FFFFFF;
}
.content-inner {
padding: 16px 14px 0;
}
/* 用户卡片 */
.user-card {
background: #FFFFFF;
border-radius: 20px;
padding: 20px;
margin-bottom: 16px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.user-header {
display: flex;
align-items: center;
margin-bottom: 16px;
}
.avatar {
width: 56px;
height: 56px;
border-radius: 50%;
background: rgba(0,230,118,0.15);
display: flex;
align-items: center;
justify-content: center;
margin-right: 14px;
}
.avatar-text {
font-size: 20px;
font-weight: 700;
color: #00C853;
}
.user-info {
flex: 1;
}
.user-name {
font-size: 18px;
font-weight: 700;
color: #1E1E1E;
}
.user-tag {
font-size: 13px;
color: #00C853;
font-weight: 500;
}
.user-details {
background: #F5F7FA;
border-radius: 12px;
padding: 14px 16px;
}
.detail-row {
display: flex;
justify-content: space-between;
}
.detail-label {
font-size: 13px;
color: #7A7E84;
}
.detail-value {
font-size: 14px;
font-weight: 600;
color: #1E1E1E;
}
/* 违规统计 */
.stats-card {
background: #1A1A1A;
border-radius: 20px;
padding: 18px 20px;
margin-bottom: 16px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
}
.stat-number {
font-size: 28px;
font-weight: 700;
color: #F44336;
}
.stat-label {
font-size: 12px;
color: rgba(255,255,255,0.6);
margin-top: 4px;
}
/* 违规记录 */
.section-header {
margin-bottom: 12px;
}
.section-title {
font-size: 16px;
font-weight: 700;
color: #1E1E1E;
}
.empty-wrap {
display: flex;
justify-content: center;
padding: 30px 0;
}
.empty-text {
font-size: 14px;
color: #7A7E84;
}
.violation-list {
margin-bottom: 16px;
}
.violation-card {
background: #FFFFFF;
border-radius: 12px;
padding: 12px 16px;
margin-bottom: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}
.violation-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 4px;
}
.violation-course {
font-size: 14px;
font-weight: 600;
color: #1E1E1E;
}
.violation-tag {
padding: 3px 10px;
border-radius: 12px;
font-size: 11px;
font-weight: 600;
}
.violation-tag.late { background: rgba(255,152,0,0.15); color: #FF9800; }
.violation-tag.absent { background: rgba(244,67,54,0.15); color: #F44336; }
.violation-tag.no-manual-end { background: rgba(33,150,243,0.15); color: #2196F3; }
.violation-time {
font-size: 12px;
color: #7A7E84;
}
/* 退出登录 */
.logout-area {
padding: 20px 0;
}
.logout-btn {
width: 100%;
height: 50px;
background: #FFFFFF;
color: #F44336;
border-radius: 40px;
font-size: 16px;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
border: 2px solid #F44336;
}
.logout-btn::after { border: none; }
.bottom-safe {
height: 30px;
}
</style>