| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- <!-- 考试任务 -->
- <template>
- <view class="examTask-component">
- <view class="card">
- <view class="card-header">
- <view class="header-left">
- <view class="card-title">考试任务</view>
- <view class="header-subtitle">待完成的学习考试任务</view>
- </view>
- <text class="header-link" @click="goToPage('1')">更多 ›</text>
- </view>
- <view class="card-body">
- <view class="for-max-box" @click="goToPage('2',item)"
- v-for="(item,index) in onlineExamList" :key="index">
- <view class="left-box">
- <view>{{item.examName}}</view>
- <view>待完成</view>
- </view>
- <view class="right-box">›</view>
- </view>
- <view v-if="!onlineExamList[0]" class="empty-tip">暂无考试任务</view>
- </view>
- </view>
- <!-- 考试承诺书弹窗 -->
- <uni-popup ref="preExamDialog" type="center" :mask-click="false">
- <view class="pre-exam-dialog">
- <view class="dialog-header">
- <text class="dialog-title">考试承诺书</text>
- </view>
- <view class="dialog-body">
- <scroll-view scroll-y class="content-scroll">
- <richTextPdf ref="richTextPdf" :content="richTextHtml" />
- </scroll-view>
- </view>
- <view class="dialog-footer">
- <view v-if="preButtonType" class="btn btn-border" @click="downloadCommitment">下载</view>
- <view class="btn btn-primary" @click="confirmCommitment">确认</view>
- </view>
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- import {
- examUserExamStudyTaskList,
- examUserExamStart,
- examUserExamCommitmentConfirm,
- } from '@/pages_safetyEducationExamination/api/index.js'
- import richTextPdf from '@/pages_safetyEducationExamination/component/richTextPdf.vue'
- export default {
- components: {
- richTextPdf
- },
- data() {
- return {
- onlineExamList: [],
- // 承诺书相关
- preExamDialogType: false,
- preButtonType: false,
- richTextHtml: '',
- preData: null,
- }
- },
- created() {
- },
- mounted() {
- this.examUserExamStudyTaskList();
- },
- methods: {
- goToPage(type,item){
- if(type == 1){
- //考试列表
- uni.navigateTo({
- url: '/pages_safetyEducationExamination/views/exam/index',
- });
- }else if(type == 2){
- //开始考试相关业务
- if(item.conditionType == 1){
- if(item.examStudy&&item.courseId){
- //学习课程
- let obj = {
- courseId: item.courseId,
- examId: item.examId,
- }
- //等待后续逻辑
- }else{
- //学时要求
- if(item.knowledgePointIds){
- //学时知识点
- uni.navigateTo({
- url: `/pages_safetyEducationExamination/views/studyHourTask/index?knowledgePointId=${item.knowledgePointIds}`,
- });
- }else{
- //无知识点要求
- uni.navigateTo({
- url: '/pages_safetyEducationExamination/views/study/index',
- });
- }
- }
- }else if(item.conditionType == 2){
- //学习课程
- let obj = {
- courseId: item.courseId,
- examId: item.examId,
- }
- //等待后续逻辑
- }else if(item.conditionType == 3){
- //模拟考试
- if(item.mockExamId){
- let obj = {
- examId: item.examId,
- attemptId: item.mockExamId,
- }
- //等待后续逻辑
- }else{
- this.examUserExamStart({examId:item.examId,examScene:2});
- }
- }else if(item.conditionType == 4){
- //开始考试
- }
- }
- },
- //模拟考试获取试卷
- async examUserExamStart(obj) {
- try {
- const { data } = await examUserExamStart(obj);
- if (data.code === 200) {
- let obj = {
- examId: item.examId,
- attemptId: response.data.attemptId,
- }
- //等待后续逻辑
- }
- } catch (e) { console.error('模拟考试获取试卷失败', e); }
- },
- //开始考试判断是否有承诺书
- setRichExamData(item){
- if(item.commitmentEnabled == 1 && !item.commitmentConfirmed){
- //富文本弹窗考试承诺书
- this.preButtonType = item.commitmentPrintEnabled == 1;
- this.richTextHtml = item.commitmentContent;
- this.preData = item;
- this.$refs.preExamDialog.open();
- }else{
- if(item.attemptId){
- //上次考试未完成继续考试
- let obj = {
- attemptId: item.attemptId,
- type: '1',
- examKind:item.examKind,
- }
- //等待后续逻辑
- }else{
- //开始新考试
- this.startNewExam(item);
- }
- }
- },
- // 下载承诺书
- downloadCommitment() {
- uni.showToast({
- title: '正在下载,请耐心等候',
- icon: 'none'
- });
- this.$refs.richTextPdf.downloadPDF();
- },
- // 确认承诺书
- async confirmCommitment() {
- if (this.preData.attemptId) {
- await this.confirmAndStart(this.preData.attemptId);
- } else {
- try {
- const { data } = await examUserExamStart({
- examId: this.preData.examId,
- examScene: 1
- });
- if (data.code === 200 && data.data.attemptId) {
- await this.confirmAndStart(data.data.attemptId);
- } else {
- uni.showToast({
- title: data.message || '开始考试失败',
- icon: 'none'
- });
- }
- } catch (e) {
- console.error('开始考试失败', e);
- uni.showToast({
- title: '开始考试失败',
- icon: 'none'
- });
- }
- }
- },
- // 确认承诺并开始考试
- async confirmAndStart(attemptId) {
- try {
- const { data } = await examUserExamCommitmentConfirm({ attemptId });
- if (data.code === 200) {
- this.$refs.preExamDialog.close();
- // 跳转到考试页面
- let obj = {
- examId: this.preData.examId,
- attemptId: attemptId,
- type: '1',
- examKind: this.preData.examKind,
- };
- // 等待后续逻辑:跳转到答题页面
- uni.showToast({
- title: '已确认承诺书',
- icon: 'success'
- });
- }
- } catch (e) {
- console.error('确认承诺书失败', e);
- uni.showToast({
- title: '确认失败',
- icon: 'none'
- });
- }
- },
- //开始考试
- async examUserExamStart(item) {
- try {
- let obj = {examId:item.examId,examScene:1};
- const { data } = await examUserExamStart(obj);
- if (data.code === 200) {
- let obj = {
- examId: item.examId,
- attemptId: data.data.attemptId,
- type: '1',
- examKind:item.examKind,
- }
- //等待后续逻辑
- }
- } catch (e) { console.error('开始考试失败', e); }
- },
- // 开始新考试
- async startNewExam(item) {
- await this.examUserExamStart(item);
- },
- //获取任务列表
- async examUserExamStudyTaskList() {
- try {
- let obj = { page: 1, pageSize: 1, examStatus: 2, isSpecialExam: false };
- const { data } = await examUserExamStudyTaskList(obj);
- if (data.code === 200) {
- this.$set(this,'onlineExamList',data.data.records);
- }
- } catch (e) { console.error('获取考试任务失败', e); }
- },
- },
- }
- </script>
- <style lang="stylus" scoped>
- .examTask-component {
- margin: 0 32rpx 32rpx;
- .card {
- background: #fff;
- border-radius: 24rpx;
- overflow: hidden;
- margin-bottom: 24rpx;
- box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.03);
- border: 1px solid #dde3ed;
- }
- .card-header {
- padding: 20rpx 28rpx;
- display: flex;
- justify-content: space-between;
- align-items: center;
- .card-title {
- font-size: 28rpx;
- color: #333;
- }
- .header-subtitle{
- margin-top:10rpx;
- font-size:22rpx;
- color:#8896a7;
- }
- .header-link {
- padding:10rpx 20rpx;
- font-size: 24rpx;
- color: #1857d4;
- }
- }
- .card-body {
- padding: 0 28rpx 24rpx;
- .for-max-box:nth-child(1){
- margin-top:0;
- }
- .for-max-box{
- margin-top:20rpx;
- display: flex;
- background-color:#f4f6fa;
- padding: 20rpx 24rpx;
- border-radius: 16rpx;
- .left-box{
- flex:1;
- view:nth-child(1){
- font-size:26rpx;
- margin-bottom:4rpx;
- }
- view:nth-child(2){
- font-size:22rpx;
- color:#8896a7;
- }
- }
- .right-box{
- line-height:60rpx;
- font-size:40rpx;
- color:#8896a7;
- }
- }
- .empty-tip{
- text-align: center;
- line-height:40rpx;
- color:#8896a7;
- font-size:24rpx;
- }
- }
- }
- // 承诺书弹窗样式
- .pre-exam-dialog {
- width: 600rpx;
- max-height: 80vh;
- background: #fff;
- border-radius: 20rpx;
- overflow: hidden;
- }
- .dialog-header {
- padding: 32rpx;
- border-bottom: 1rpx solid #eee;
- .dialog-title {
- font-size: 32rpx;
- font-weight: 600;
- color: #333;
- }
- }
- .dialog-body {
- height: 800rpx;
- overflow: hidden;
- .content-scroll {
- height: 100%;
- }
- }
- .dialog-footer {
- display: flex;
- gap: 20rpx;
- padding: 24rpx 32rpx;
- border-top: 1rpx solid #eee;
- .btn {
- flex: 1;
- height: 72rpx;
- line-height: 72rpx;
- text-align: center;
- font-size: 28rpx;
- border-radius: 12rpx;
- }
- .btn-border {
- background: #fff;
- color: #1857d4;
- border: 1rpx solid #1857d4;
- }
- .btn-primary {
- background: #1857d4;
- color: #fff;
- }
- }
- </style>
|