Files
tra-app/src/pages/practice/result.vue
T
2025-11-24 20:45:23 +08:00

278 lines
6.7 KiB
Vue

<template>
<view class="max_page" :class="{ points_bg: showData.num !== 0 }">
<view class="" v-if="showData.num === 0">
<image src="@/static/images/common/wc.png" class="show_img"></image>
<view class="show_msg">练习完成</view>
</view>
<view class="" v-if="showData.num !== 0">
<view class="title_div">
<image class="img" src="@/static/images/pointsAndRank/badge-wheat-left.png"></image>
<view class="">
<view class="title">恭喜你完成练习</view>
<view class="title">并获得积分</view>
</view>
<image class="img" src="@/static/images/pointsAndRank/badge-wheat-right.png"></image>
</view>
<view class="points-div">
<view class="points-img-div">
<image class="img_100" src="@/static/images/pointsAndRank/like.png" mode=""></image>
</view>
<view class="points-num-div">+{{ showData.num }}</view>
<view class="points-msg-div" v-show="showData.message">{{ showData.message }}</view>
</view>
</view>
<view class="fl1"></view>
<view class="show_button">
<uv-button
type="primary"
class="button"
color="#0066FF"
:throttleTime="100"
text="去考试"
:loading="loading === '01'"
loadingText="正在获取考试内容"
:custom-style="customStyle1"
@click="goto_examination"
></uv-button>
<uv-button
type="primary"
class="button"
color="#FFFFFF"
:throttleTime="100"
text="重新练"
:loading="loading === '02'"
loadingText="正在获取练习内容"
@click="goto_practice"
:custom-style="customStyle2"
></uv-button>
<uv-button
type="primary"
class="button"
color="#0066FF"
:throttleTime="100"
text="返回"
@click="back_page"
:custom-style="customStyle3"
></uv-button>
</view>
<badge ref="badgeRef"></badge>
</view>
</template>
<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { onMounted, ref, onUnmounted } from 'vue';
import common from '@/common/common';
import { setPageCache } from '@/common/common';
import { startExamByCrs } from '@/api/examination.js';
import { startPracticeByCrs } from '@/api/practice.js';
import { practiceCommit } from '@/api/practice.js';
import badge from '@/components/points-and-badge/badge';
import { pop_up_time } from '@/enum';
import usePointsAndBadge from '@/components/points-and-badge/usePointsAndBadge';
const { pointAndBadgesRun, badgeRef } = usePointsAndBadge();
const customStyle1 = {
borderRadius: '12rpx',
color: '#FFFFFF',
fontWeight: '600',
fontSize: '28rpx',
border: '1px solid #E0E0E0',
height: '92rpx'
};
const customStyle2 = {
borderRadius: '12rpx',
color: '#333333',
fontWeight: '600',
fontSize: '28rpx',
border: '1px solid #E0E0E0',
height: '92rpx'
};
const customStyle3 = {
color: '#333333',
fontWeight: '600',
fontSize: '28rpx',
border: 'none',
backgroundColor: '#fff',
height: '92rpx'
};
const crsId = ref('');
const name = ref('');
const loading = ref('');
// 用于标记组件是否已卸载
let isUnmounted = false;
// 存储请求取消函数
let abortController = null;
// 返回上一页
const back_page = () => {
if (loading.value !== '') return;
common.navigateBack();
};
// 去考试
const goto_examination = async () => {
// if (examStat.value.examStat === '01') return common.msg('该课程下暂无试题');
if (examStat.value === '02') return common.msg('该课程下的试题未设置考试规则');
if (loading.value !== '') return;
try {
loading.value = '01';
const res = await startExamByCrs({
crsId: crsId.value
});
setPageCache('examination', {
...res.body,
name: name.value,
crsId: crsId.value
});
loading.value = '';
common.redirectTo('/pages/examination/index');
} catch (e) {
loading.value = '';
}
};
// 去练习
const goto_practice = async () => {
if (loading.value !== '') return;
try {
loading.value = '02';
const res = await startPracticeByCrs({
crsId: crsId.value
});
setPageCache('practice', {
...res.body,
name: name.value,
crsId: crsId.value
});
loading.value = '';
common.redirectTo('/pages/practice/index');
} catch (e) {
loading.value = '';
}
};
const exrId = ref('');
const examLenTm = ref('');
const stat = ref('');
const examStat = ref('');
const commit = ref(false);
// const changePoints = ref(0);
const showData = ref({
num: 0,
message: ''
});
onLoad((e) => {
console.log('xx23333');
crsId.value = e.crsId;
name.value = e.name;
exrId.value = e.exrId;
examLenTm.value = e.examLenTm;
stat.value = e.stat;
examStat.value = e.examStat ?? '';
console.log('xxxx111');
practiceCommitFun();
});
const practiceCommitFun = () => {
practiceCommit({ exrId: exrId.value, examLenTm: examLenTm.value, stat: stat.value }).then(() => {
console.log('提交练习状态成功');
commit.value = true;
pointAndBadgesRun('04', crsId.value, (status, msg, { points, pointsBadges, message }) => {
if(!status) return;
if (points?.length > 0) {
showData.value.num = points[0]['changePoints'];
showData.value.message = message;
uni.$emit('update_me_data', true);
}
if (pointsBadges.length > 0) {
nextTick(() => {
setTimeout(() => {
badgeRef.value.open([], pointsBadges);
}, pop_up_time);
});
}
});
});
};
onUnmounted(() => {});
</script>
<style scoped lang="scss">
.points-div {
display: flex;
flex-direction: column;
align-items: center;
padding: 60rpx 0 0 0;
.points-img-div {
width: 320rpx;
height: 278rpx;
}
.points-num-div {
font-family: Arial, Arial;
font-weight: normal;
font-size: 108rpx;
color: #333333;
line-height: 108rpx;
text-align: center;
font-weight: 600;
}
.points-msg-div {
font-family: PingFangSC, PingFang SC;
font-weight: 400;
font-size: 30rpx;
color: #ae723b;
line-height: 40px;
text-align: center;
}
}
.title_div {
display: flex;
align-items: center;
justify-content: center;
margin-top: calc(104rpx + var(--status-bar-height));
height: 68rpx;
.img {
width: 36rpx;
height: 74rpx;
}
.title {
font-family: AlimamaShuHeiTi, AlimamaShuHeiTi;
font-weight: 500;
font-size: 46rpx;
color: #d88f50;
margin: 0rpx 30rpx;
text-align: center;
}
}
.max_page {
display: flex;
align-items: center;
flex-direction: column;
}
.points_bg {
background: linear-gradient(180deg, #fff9eb 0%, #f7f7f7 100%);
}
.show_img {
margin-top: 300rpx;
width: 231rpx;
height: 231rpx;
}
.show_msg {
margin-top: 38rpx;
font-weight: 700;
font-size: 46rpx;
color: #000000;
line-height: 62rpx;
text-align: center;
font-style: normal;
}
.show_button {
width: 80%;
margin-bottom: 90rpx;
.button:nth-child(2) {
margin-top: 38rpx;
margin-bottom: 38rpx;
}
}
</style>