Files

192 lines
3.9 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="content">
<view class="page-body">
<view class="loading-box" v-if="records.length === 0 && !loadError">
<u-loading mode="circle" size="40"></u-loading>
<text class="loading-text">加载中...</text>
</view>
<view class="loading-box" v-if="loadError">
<text class="error-text">{{ loadError }}</text>
<button class="retry-btn" @tap="fetchRecords">重新加载</button>
</view>
<template v-if="records.length > 0">
<view class="record-item" v-for="(item, i) in records" :key="item.id" @click="goDetail(item)">
<view class="record-index">
<text class="record-index-text">{{ i + 1 }}</text>
</view>
<view class="record-body">
<view class="record-row">
<text class="record-label">答题时间:</text>
<text class="record-value">{{ item.create_time }}</text>
</view>
<view class="record-row">
<text class="record-label">答对题数:</text>
<text class="record-value">{{ item.correct_question_num }} / {{ item.total_question_num }} 题</text>
</view>
<view class="record-row">
<text class="record-label">答题用时:</text>
<text class="record-value">{{ formatTime(item.use_time) }}</text>
</view>
</view>
</view>
</template>
</view>
</view>
</template>
<script>
export default {
data() {
return {
records: [],
loadError: ''
}
},
onLoad() {
this.fetchRecords()
},
methods: {
fetchRecords() {
this.loadError = ''
const userId = uni.getStorageSync('userId')
if (!userId) {
this.loadError = '暂未登录'
return
}
this.$u.api.getUserHisResultList({
wenjuanId: 1001,
userId: userId
}).then(res => {
if (res.code === 0 && res.Data?.result_list) {
this.records = res.Data.result_list
} else {
this.loadError = res.msg || '数据异常'
}
}).catch(err => {
console.error('获取答题记录失败', err)
this.loadError = '网络请求失败'
})
},
formatTime(sec) {
const m = Math.floor(sec / 60)
const s = sec % 60
return (m < 10 ? '0' : '') + m + ':' + (s < 10 ? '0' : '') + s
},
goDetail(item) {
uni.navigateTo({
url: '/pages/record-detail/record-detail?resultId=' + item.id
})
}
}
}
</script>
<style lang="scss">
page {
background-color: #7CC6EB;
}
.content {
position: relative;
height: 100vh;
height: 100dvh;
}
.page-body {
position: relative;
z-index: 1;
height: 100%;
padding: 40rpx 30rpx;
box-sizing: border-box;
overflow-y: auto;
}
.record-item {
background: rgba(255,255,255,0.95);
border-radius: 20rpx;
padding: 28rpx;
margin-bottom: 20rpx;
display: flex;
box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04);
}
.record-index {
width: 44rpx;
height: 44rpx;
border-radius: 50%;
background: linear-gradient(135deg, #FD5401, #FF7A3D);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
margin-right: 16rpx;
margin-top: 2rpx;
box-shadow: 0 2rpx 8rpx rgba(253,84,1,0.3);
}
.record-index-text {
font-size: 20rpx;
font-weight: 700;
color: #fff;
}
.record-body {
flex: 1;
min-width: 0;
}
.record-row {
display: flex;
align-items: baseline;
margin-top: 6rpx;
}
.record-row:first-child {
margin-top: 0;
}
.record-label {
font-size: 24rpx;
color: #999;
flex-shrink: 0;
}
.record-value {
font-size: 26rpx;
color: #333;
font-weight: 500;
}
.loading-box {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.loading-text {
font-size: 28rpx;
color: #fff;
margin-top: 20rpx;
}
.error-text {
font-size: 28rpx;
color: #fff;
text-align: center;
display: block;
}
.retry-btn {
margin-top: 30rpx;
width: 240rpx;
height: 72rpx;
line-height: 72rpx;
background: rgba(255, 255, 255, 0.9);
color: #FD5401;
border: none;
border-radius: 36rpx;
font-size: 28rpx;
}
</style>