保存数据

This commit is contained in:
Ls
2026-04-11 17:47:28 +08:00
parent f682c0316b
commit c9aeba0949
35 changed files with 5658 additions and 3544 deletions

View File

@@ -1,20 +1,24 @@
<template>
<view class="segmentation-container">
<!-- 配置区域 -->
<view class="config-section">
<view class="config-header">
<text class="config-title">分段设置</text>
<u-icon @click="Service.GoPage('/pages/userFunc/setCourse?id='+planId+'&type=2')" name="setting" size="24"
color="#1890ff"></u-icon>
</view>
<view class="config-info">
<text class="info-text">总距离: {{ totalDistance }} ({{ segmentCount }} × {{ segmentDistance }})</text>
</view>
</view>
<!-- 总计时器区域 -->
<view class="total-time-section">
<view class="timer-circle">
<view class="circle-content">
<view class="timer-sound">
<text class="sound-text">计时器</text>
</view>
<view class="timer-time">{{ formatTime(currentTime) }}</view>
<view class="timer-duration">{{ formatDuration(currentTime) }}</view>
</view>
<view class="timer-controls">
<u-icon name="reload" size="32" color="#22a6f2" @click="resetAll"></u-icon>
<u-icon :name="isRunning ? 'pause-circle' : 'play-circle'" size="32" color="#22a6f2"
@click="toggleTimer"></u-icon>
</view>
<view class="timer-bar">
<view class="timer-time">{{ formatTime(currentTime) }}</view>
</view>
</view>
@@ -26,96 +30,180 @@
</view>
<view class="students-list">
<view v-for="(student, index) in students" :key="student.id" class="student-item">
<view v-for="(student, index) in students" :key="student.id" class="student-item"
:class="{ 'not-started': !student.hasStarted }">
<view class="student-header">
<view class="student-number">{{ student.number }}</view>
<view class="student-number" :class="{ 'started': student.hasStarted }">{{ student.number }}
</view>
<view class="student-info">
<text class="student-name">{{ student.name }}</text>
<text class="student-lane">{{ student.lane }}</text>
<!-- <view class="start-status" v-if="startMode === 1 && !student.hasStarted">
<text class="status-text">等待</text>
</view> -->
<text class="total-time-text"
v-if="student.segments.length > 0">{{ formatSimpleTime(getLastSegmentTime(student)) }}</text>
<view class="record-badge"
:class="{ 'completed': student.segments.length >= Number(segmentCount) }">
<text class="badge-text">{{ student.segments.length }}/{{ segmentCount }}</text>
</view>
</view>
<view class="student-buttons">
<button class="record-btn" @click="recordStudentSegment(student)">
<u-icon name="checkmark" size="18" color="#fff"></u-icon>
<button class="record-btn" :disabled="!student.hasStarted"
@click="recordStudentSegment(student)">
<text class="btn-text">记录</text>
</button>
<button class="view-btn" @click="showStudentRecords(student)">
<text class="btn-text">详情</text>
</button>
<button class="reset-btn" @click="resetStudent(student)">
<u-icon name="reload" size="18" color="#fff"></u-icon>
<text class="btn-text">重置</text>
</button>
</view>
</view>
<!-- 分段时间块 -->
<view class="segments-list">
<view v-for="(segment, segIndex) in student.segments" :key="segIndex" class="segment-item">
<text class="segment-label">{{ segIndex + 1 }}</text>
<text class="segment-time">{{ segment.time ? formatTime(segment.time) : '--:--.--' }}</text>
</view>
<view v-if="student.segments.length<4" class="segment-item empty">
<text class="segment-label">{{ student.segments.length + 1 }}</text>
<text class="segment-time">--:--.--</text>
</view>
</view>
</view>
</view>
</view>
<!-- 保存按钮 -->
<view class="save-btn-wrapper">
<button class="save-btn" @click="saveData">
<text class="btn-text">保存</text>
</button>
<!-- 底部操作栏 -->
<view class="bottom-actions">
<view class="action-btn reset-action" @click="resetAll">
<u-icon name="reload" size="24" color="#fff"></u-icon>
<text class="action-text">重置</text>
</view>
<view class="action-btn timer-action" :class="{ 'running': isRunning }" @click="toggleTimer">
<u-icon :name="isRunning ? 'pause-circle' : 'play-circle'" size="28" color="#fff"></u-icon>
<text class="action-text">{{ isRunning ? '暂停' : '开始' }}</text>
</view>
<view class="action-btn save-action" @click="saveData">
<u-icon name="checkmark" size="24" color="#fff"></u-icon>
<text class="action-text">保存</text>
</view>
</view>
<!-- 记录弹窗 -->
<u-popup :show="showRecordPopup" mode="bottom" :round="20" @close="closeRecordPopup">
<view class="record-popup">
<view class="popup-header">
<text class="popup-title">{{ currentStudent?.name }} - 分段记录</text>
<view class="close-btn" @click="closeRecordPopup">
<u-icon name="close" size="24" color="#999"></u-icon>
</view>
</view>
<view class="popup-summary">
<view class="summary-item">
<text class="summary-label">总距离</text>
<text class="summary-value">{{ totalDistance }}</text>
</view>
<view class="summary-item">
<text class="summary-label">已记录</text>
<text
class="summary-value">{{ currentStudent?.segments?.length || 0 }}/{{ segmentCount }}</text>
</view>
</view>
<view class="record-list"
v-if="currentStudent && currentStudent.segments && currentStudent.segments.length > 0">
<view class="record-header">
<text class="record-cell header-cell">分段</text>
<text class="record-cell header-cell">距离</text>
<text class="record-cell header-cell">累计时间</text>
<text class="record-cell header-cell">分段用时</text>
</view>
<view v-for="(segment, index) in currentStudent.segments" :key="index" class="record-item">
<text class="record-cell">{{ index + 1 }}</text>
<text class="record-cell">{{ segmentDistance }}</text>
<text class="record-cell time-cell">{{ formatTime(segment.time) }}</text>
<text class="record-cell time-cell">{{ formatTimeDiff(index, segment.time) }}</text>
</view>
</view>
<view class="empty-record" v-else>
<u-icon name="info-circle" size="48" color="#ccc"></u-icon>
<text class="empty-text">暂无记录数据</text>
</view>
<view class="popup-footer">
<button class="popup-btn close-popup" @click="closeRecordPopup">关闭</button>
</view>
</view>
</u-popup>
</view>
</template>
<script setup lang="ts">
import { ref, onUnmounted } from 'vue'
import { ref, onUnmounted, computed } from 'vue'
import { Service } from '@/Service/Service'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { PlanService } from '@/Service/swimming/PlanService'
// 分段配置
const segmentDistance = ref(50)
const segmentCount = ref(4)
// 出发模式: 0-一起出发, 1-间隔出发
const startMode = ref(0)
// 间隔时间(秒)
const intervalTime = ref(10)
// 最大分段数
const maxSegments = 4
// 计算总距离
const totalDistance = computed(() => {
return Number(segmentDistance.value) * Number(segmentCount.value)
})
// 学生列表
const students = ref<Array<any>>([
{
id: '1',
number: '01',
name: '张三',
lane: '第一泳道',
segments: []
},
{
id: '2',
number: '02',
name: '李四',
lane: '第二泳道',
segments: []
},
{
id: '3',
number: '03',
name: '王五',
lane: '第三泳道',
segments: []
},
{
id: '4',
number: '04',
name: '赵六',
lane: '第四泳道',
segments: []
}
])
const students = ref<Array<any>>([])
// 弹窗状态
const showRecordPopup = ref(false)
const currentStudent = ref<any>(null)
// 计时器状态
const isRunning = ref(false)
const currentTime = ref(0)
let timerInterval : number | null = null
let startTime : number = 0
let intervalStartTimer : number | null = null
let planId = ref('')
onLoad((data : any) => {
planId.value = data.id
})
onShow(()=>{
getPlanInfo()
})
// 获取计划详情
const getPlanInfo = () => {
PlanService.GetPlanInfo(planId.value).then(res => {
if (res.code == 0) {
// planName.value = res.data.plan.name
segmentDistance.value=res.data.plan.subsectionDistance/res.data.plan.subsectionInt
segmentCount.value=res.data.plan.subsectionInt
// 将计划数据转换为选手数据
// athletes.value = res.data.plan.users.
students.value=res.data.plan.users.map((item:any,index:any)=>{
return {
id: item.studentId,
number: index+1,
name: item.name,
segments: [],
hasStarted: res.data.plan.departType == '间隔出发'?false:true,
startTime: 0
}
})
startMode.value = res.data.plan.departType == '间隔出发' ? 1 : 0
intervalTime.value = res.data.plan.interval
} else {
Service.Msg(res.msg)
}
})
}
// 格式化时间显示
const formatTime = (seconds : number) : string => {
@@ -142,6 +230,34 @@
return result
}
// 格式化时间差
const formatTimeDiff = (index : number, currentTime : number) : string => {
if (index === 0) {
return '00:00:00'
}
if (!currentStudent.value || !currentStudent.value.segments[index - 1]) {
return '00:00:00'
}
const prevTime = currentStudent.value.segments[index - 1].time
const diff = currentTime - prevTime
return formatTime(diff)
}
// 获取学生最后一次记录的累计时间
const getLastSegmentTime = (student : any) : number => {
if (!student.segments || student.segments.length === 0) {
return 0
}
return student.segments[student.segments.length - 1].time
}
// 简化时间格式化(分:秒)
const formatSimpleTime = (seconds : number) : string => {
const mins = Math.floor(seconds / 60)
const secs = Math.floor(seconds % 60)
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
}
// 开始计时
const startTimer = () => {
if (isRunning.value) return
@@ -153,6 +269,32 @@
const elapsed = (Date.now() - startTime) / 1000
currentTime.value = elapsed
}, 10)
// 间隔出发模式
if (startMode.value === 1) {
// 第一个学生立即出发
if (students.value.length > 0) {
students.value[0].hasStarted = true
students.value[0].startTime = 0
}
// 设置间隔出发定时器
const interval = intervalTime.value * 1000
let startedCount = 1
intervalStartTimer = setInterval(() => {
if (startedCount < students.value.length) {
const student = students.value[startedCount]
student.hasStarted = true
student.startTime = (Date.now() - startTime) / 1000
startedCount++
Service.Msg(`${student.name} 已出发`)
} else {
clearInterval(intervalStartTimer as number)
intervalStartTimer = null
}
}, interval)
}
}
// 停止计时
@@ -164,6 +306,10 @@
clearInterval(timerInterval)
timerInterval = null
}
if (intervalStartTimer) {
clearInterval(intervalStartTimer)
intervalStartTimer = null
}
}
// 切换计时器状态
@@ -176,27 +322,42 @@
}
// 记录学生分段
const recordStudentSegment = (student : Student) => {
const recordStudentSegment = (student : any) => {
console.log(22222);
if (!isRunning.value) {
Service.Msg('请先开始计时')
return
}
if (student.segments.length >= maxSegments) {
Service.Msg('已达到最大分段数')
if (!student.hasStarted) {
Service.Msg('该学生尚未出发')
return
}
const maxSeg = Number(segmentCount.value)
if (student.segments.length >= maxSeg) {
Service.Msg(`已达到最大分段数(${maxSeg}段)`)
return
}
let recordTime = currentTime.value
// 间隔出发模式下,使用学生自己的开始时间
if (startMode.value === 1) {
recordTime = currentTime.value - student.startTime
}
student.segments.push({
time: currentTime.value
time: recordTime
})
Service.Msg(`${student.name}${student.segments.length}段已记录`)
}
// 重置学生
const resetStudent = (student : Student) => {
const resetStudent = (student : any) => {
student.segments = []
student.hasStarted = false
student.startTime = 0
Service.Msg(`${student.name} 已重置`)
}
@@ -206,6 +367,8 @@
currentTime.value = 0
students.value.forEach(student => {
student.segments = []
student.hasStarted = startMode.value == 1?false:true,
student.startTime = 0
})
Service.Msg('已全部重置')
}
@@ -228,11 +391,26 @@
}, 1000)
}
// 显示学生记录弹窗
const showStudentRecords = (student : any) => {
currentStudent.value = student
showRecordPopup.value = true
}
// 关闭记录弹窗
const closeRecordPopup = () => {
showRecordPopup.value = false
currentStudent.value = null
}
// 页面卸载时清理计时器
onUnmounted(() => {
if (timerInterval) {
clearInterval(timerInterval)
}
if (intervalStartTimer) {
clearInterval(intervalStartTimer)
}
})
</script>
@@ -241,83 +419,65 @@
min-height: 100vh;
background-color: #f6f6f6;
padding: 20rpx 20rpx;
padding-bottom: 200rpx;
padding-bottom: 180rpx;
}
/* 配置区域 */
.config-section {
background-color: #fff;
border-radius: 20rpx;
padding: 30rpx;
margin-bottom: 30rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
.config-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24rpx;
.config-title {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
}
.config-info {
background-color: #e6f7ff;
border-radius: 8rpx;
padding: 16rpx 20rpx;
.info-text {
font-size: 26rpx;
color: #1890ff;
font-weight: 500;
}
}
}
/* 总计时器区域 */
.total-time-section {
margin-top: 20rpx;
margin-bottom: 40rpx;
display: flex;
justify-content: center;
margin-bottom: 30rpx;
}
.timer-circle {
width: 350rpx;
height: 360rpx;
border-radius: 20rpx;
.timer-bar {
background-color: #fff;
border-radius: 20rpx;
padding: 30rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
display: flex;
padding: 20rpx;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0 4rpx 16rpx rgba(250, 140, 22, 0.3);
.circle-content {
// background-color: #faad14;
padding: 30rpx;
border-radius: 50%;
border: 16rpx solid #faad14;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 16rpx;
}
.timer-sound {
display: flex;
align-items: center;
gap: 8rpx;
padding: 8rpx 16rpx;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 20rpx;
.sound-text {
font-size: 24rpx;
font-weight: 500;
}
}
.timer-time {
font-size: 48rpx;
font-size: 80rpx;
font-weight: bold;
}
.timer-duration {
font-size: 24rpx;
opacity: 0.9;
background-color: #f6f6f6;
padding: 4rpx 12rpx;
border-radius: 4rpx;
}
.timer-controls {
display: flex;
justify-content: space-between;
align-items: center;
width: 280rpx;
u-icon {
cursor: pointer;
transition: all 0.2s ease;
&:hover {
transform: scale(1.1);
}
}
color: #ff4d4f;
font-family: 'DIN Alternate', monospace;
}
}
@@ -354,10 +514,13 @@
margin-bottom: 20rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
&.not-started {
opacity: 0.6;
}
.student-header {
display: flex;
align-items: center;
margin-bottom: 24rpx;
.student-number {
width: 56rpx;
@@ -371,22 +534,62 @@
align-items: center;
justify-content: center;
margin-right: 20rpx;
&.started {
background-color: #52c41a;
color: #fff;
}
}
.student-info {
flex: 1;
display: flex;
align-items: center;
gap: 12rpx;
.student-name {
font-size: 30rpx;
font-weight: 500;
color: #333;
margin-bottom: 4rpx;
display: block;
}
.student-lane {
.start-status {
background-color: #faad14;
border-radius: 8rpx;
padding: 4rpx 12rpx;
.status-text {
font-size: 22rpx;
color: #fff;
font-weight: 500;
}
}
.total-time-text {
font-size: 24rpx;
color: #999;
font-family: 'DIN Alternate', monospace;
font-weight: 500;
}
.record-badge {
background-color: #f0f0f0;
border-radius: 12rpx;
padding: 4rpx 12rpx;
.badge-text {
font-size: 22rpx;
color: #999;
font-weight: 500;
}
&.completed {
background-color: #52c41a;
.badge-text {
color: #fff;
}
}
}
}
@@ -395,6 +598,7 @@
gap: 12rpx;
.record-btn,
.view-btn,
.reset-btn {
height: 56rpx;
padding: 0 20rpx;
@@ -415,6 +619,15 @@
.record-btn {
background-color: #52c41a;
&:disabled {
background-color: #d9d9d9;
opacity: 0.6;
}
}
.view-btn {
background-color: #1890ff;
}
.reset-btn {
@@ -422,91 +635,201 @@
}
}
}
}
}
}
/* 分段时间列表 */
.segments-list {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
/* 记录弹窗 */
.record-popup {
background-color: #fff;
border-radius: 20rpx 20rpx 0 0;
max-height: 80vh;
overflow: hidden;
display: flex;
flex-direction: column;
.segment-item {
flex: 1;
min-width: 140rpx;
background-color: #f5f5f5;
border-radius: 12rpx;
padding: 20rpx 16rpx;
text-align: center;
.popup-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 30rpx;
border-bottom: 1rpx solid #f0f0f0;
&.empty {
opacity: 0.5;
}
.popup-title {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
.segment-label {
font-size: 22rpx;
color: #666;
display: block;
margin-bottom: 8rpx;
}
.close-btn {
padding: 10rpx;
cursor: pointer;
}
}
.segment-time {
font-size: 26rpx;
font-weight: 600;
color: #333;
font-family: 'DIN Alternate', monospace;
}
.popup-summary {
display: flex;
gap: 20rpx;
padding: 20rpx 30rpx;
background-color: #f6f6f6;
.summary-item {
flex: 1;
background-color: #fff;
border-radius: 12rpx;
padding: 20rpx;
text-align: center;
.summary-label {
font-size: 24rpx;
color: #999;
display: block;
margin-bottom: 8rpx;
}
.summary-value {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
}
}
.record-list {
flex: 1;
overflow-y: auto;
padding: 0 30rpx 20rpx;
.record-header {
display: flex;
background-color: #f5f5f5;
border-radius: 8rpx;
margin-bottom: 16rpx;
margin-top: 20rpx;
.record-cell {
flex: 1;
text-align: center;
font-size: 26rpx;
padding: 16rpx 8rpx;
color: #666;
}
.header-cell {
font-weight: 600;
color: #333;
}
}
.record-item {
display: flex;
background-color: #fff;
border-radius: 8rpx;
margin-bottom: 12rpx;
border: 1rpx solid #f0f0f0;
.record-cell {
flex: 1;
text-align: center;
font-size: 26rpx;
padding: 20rpx 8rpx;
color: #333;
&.time-cell {
font-family: 'DIN Alternate', monospace;
font-weight: 600;
color: #1890ff;
}
}
}
}
}
/* 保存按钮 */
.save-btn-wrapper {
position: fixed;
bottom: 40rpx;
right: 30rpx;
z-index: 100;
.save-btn {
width: 140rpx;
height: 140rpx;
background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
border-radius: 50%;
border: none;
.empty-record {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8rpx;
box-shadow: 0 8rpx 24rpx rgba(24, 144, 255, 0.5),
0 4rpx 12rpx rgba(24, 144, 255, 0.3);
transition: all 0.3s ease;
position: relative;
overflow: hidden;
padding: 80rpx 0;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
pointer-events: none;
.empty-text {
font-size: 28rpx;
color: #999;
margin-top: 20rpx;
}
}
.popup-footer {
padding: 20rpx 30rpx 40rpx;
border-top: 1rpx solid #f0f0f0;
.popup-btn {
height: 80rpx;
border-radius: 12rpx;
border: none;
font-size: 30rpx;
font-weight: 500;
display: flex;
align-items: center;
justify-content: center;
}
&:active {
transform: scale(0.95);
box-shadow: 0 4rpx 12rpx rgba(24, 144, 255, 0.4),
0 2rpx 6rpx rgba(24, 144, 255, 0.2);
}
.btn-text {
font-size: 26rpx;
color: #fff;
font-weight: 600;
letter-spacing: 1rpx;
.close-popup {
background-color: #f5f5f5;
color: #666;
}
}
}
/* 底部操作栏 */
.bottom-actions {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background-color: #fff;
padding: 20rpx 30rpx 40rpx;
display: flex;
gap: 20rpx;
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.08);
z-index: 100;
.action-btn {
flex: 1;
height: 80rpx;
border-radius: 12rpx;
display: flex;
align-items: center;
justify-content: center;
gap: 10rpx;
cursor: pointer;
transition: all 0.2s ease;
.action-text {
font-size: 28rpx;
color: #fff;
font-weight: 500;
}
&:active {
transform: scale(0.98);
}
}
.reset-action {
background-color: #faad14;
}
.timer-action {
background-color: #52c41a;
flex: 1.5;
&.running {
background-color: #ff4d4f;
}
}
.save-action {
background-color: #1890ff;
}
}
</style>