index.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  1. <template>
  2. <view>
  3. <!-- 自定义导航栏 -->
  4. <view class="nav-bar-box">
  5. <!-- 状态栏占位 -->
  6. <view class="status-bar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
  7. <!-- 真正的导航栏内容 -->
  8. <view class="nav-bar">
  9. <view class="nav-bar-left">
  10. <view class="left-bg" @click="onBack">
  11. <uni-icons type="back" size="16" color="#34343A" />
  12. </view>
  13. </view>
  14. <view class="nav-bar-right">
  15. <view class="nav-bar-number" @click="showQuestionTypeArea = !showQuestionTypeArea"
  16. :style="{ backgroundColor: showQuestionTypeArea ? '#E9E8EA' : ''}"
  17. v-if="showQuestionNumber||isAnswerReport">
  18. <SvgIcon icon-class="menu" :size="13" />
  19. <text>{{cur_number}} / {{total_number}}</text>
  20. <text class="type_name">{{cur_type_name}}</text>
  21. <view class="question-type-area" v-if="showQuestionTypeArea">
  22. <view :class="['question-type-name',cur_number==index+1?'active':'']"
  23. v-for="(item,index) in questionIndexList" :key="index" @click="switchQuestionIndex(index)">
  24. <text>
  25. {{index+1}}.{{item.type==='select'?item.additional_type==='single' ? '单选题' : '多选题':item.type_name}}
  26. </text>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="nav-bar-countdown" v-if="!is_remarked&&!isAnswerReport&&share_record.answer_time_limit_minute>0">
  31. <SvgIcon icon-class="hourglass" :size="13" />
  32. <uni-countdown color="#175DFF" splitorColor="#175DFF" :showDay="false" :start="startCountdown"
  33. :minute="share_record.answer_time_limit_minute" @timeup="submitTopic(false)" />
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 题目 -->
  39. <view class="topic-area" id="topic-area" :style="`height: ${contentRealHeight}px`" @scroll="handlePageScroll">
  40. <view class="start-answer-box" v-if="questionType===''&&!is_remarked&&!isAnswerReport">
  41. <view class="start-answer-title">{{share_record.name}}</view>
  42. <text class="start-answer-content">{{share_record.memo}}</text>
  43. <hr />
  44. <text
  45. class="start-answer-tip">本练习共{{share_record.question_count?share_record.question_count:0}}题,限时{{share_record.answer_time_limit_minute?share_record.answer_time_limit_minute:0}}分钟。点击“开始答题”按钮进行作答,
  46. <text v-if="isExamMode">答题中途不可退出否则视为交卷。</text>作答完毕后请点击“提交”按钮。
  47. </text>
  48. </view>
  49. <!-- 选择题 -->
  50. <select-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  51. v-if="questionType==='select'" ref="exercise"></select-question>
  52. <!-- 判断题 -->
  53. <judge-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  54. v-if="questionType==='judge'" ref="exercise"></judge-question>
  55. <!-- 连线题 -->
  56. <matching-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  57. v-if="questionType==='matching'" ref="exercise"></matching-question>
  58. <!-- 填空题 -->
  59. <fill-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  60. v-if="questionType==='fill'" ref="exercise"></fill-question>
  61. <!-- 基础写作题 -->
  62. <write-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  63. v-if="questionType==='write'" ref="exercise"></write-question>
  64. <!-- 对话 -->
  65. <dialogue-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  66. v-if="questionType==='dialogue'" ref="exercise"></dialogue-question>
  67. <!-- 看图说话 -->
  68. <talk-picture-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  69. v-if="questionType==='talk_picture'" ref="exercise"></talk-picture-question>
  70. <!-- 听说训练 -->
  71. <repeat-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  72. v-if="questionType==='repeat'" ref="exercise"></repeat-question>
  73. <!-- 朗读 -->
  74. <read-aloud-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  75. v-if="questionType==='read_aloud'" ref="exercise"></read-aloud-question>
  76. <!-- 听后辨调题 -->
  77. <choose-tone-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  78. v-if="questionType==='choose_tone'" ref="exercise"></choose-tone-question>
  79. <!-- 阅读 -->
  80. <read-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  81. v-if="questionType==='read'" ref="exercise"></read-question>
  82. <!-- 汉字书写题 -->
  83. <chinese-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  84. v-if="questionType==='chinese'" ref="exercise"></chinese-question>
  85. <!-- 字词卡片-->
  86. <word-card-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  87. v-if="questionType==='word_card'" ref="exercise"></word-card-question>
  88. <!-- 问答题 -->
  89. <essay-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  90. v-if="questionType==='essay_question'" ref="exercise"></essay-question>
  91. <!-- 排序题 -->
  92. <sort-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  93. v-if="questionType==='sort'" ref="exercise"></sort-question>
  94. <!-- 替换练习 -->
  95. <replace-answer-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  96. v-if="questionType==='replace_answer'" ref="exercise"></replace-answer-question>
  97. <!-- 填表题-->
  98. <table-fill-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  99. v-if="questionType==='table_fill'" ref="exercise"></table-fill-question>
  100. <!-- 看图写作 -->
  101. <write-picture-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  102. v-if="questionType==='write_picture'" ref="exercise"></write-picture-question>
  103. <!-- 口语表达 -->
  104. <answer-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  105. v-if="questionType==='answer_question'" ref="exercise"></answer-question>
  106. <!-- 听后选择题 -->
  107. <listen-select-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  108. v-if="questionType==='listen_select'" ref="exercise"></listen-select-question>
  109. <!-- 听后判断题 -->
  110. <listen-judge-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  111. v-if="questionType==='listen_judge'" ref="exercise"></listen-judge-question>
  112. <!-- 听后填空题 -->
  113. <listen-fill-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  114. v-if="questionType==='listen_fill'" ref="exercise"></listen-fill-question>
  115. <!-- 字词听写-->
  116. <word-dictation-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  117. v-if="questionType==='word_dictation'" ref="exercise"></word-dictation-question>
  118. <!-- 活动题-->
  119. <activity-question :questionData="questionData" @getUserAnswer="getQuestionInfo_AnswerRecord"
  120. v-if="questionType==='activity'" ref="exercise"></activity-question>
  121. </view>
  122. <!-- 查看教师批改 -->
  123. <view class="remark-area" v-if="isEnable(questionData.remark.is_remarked)">
  124. <uni-title type="h1" title="教师批改"></uni-title>
  125. <view class="remark-box">
  126. <text class="uni-text">{{questionData.remark.remark}}</text>
  127. </view>
  128. <view class="img-box">
  129. <image v-for="(file,i) in questionData.remark.file_list" :key="i" :src="file.file_url" mode="aspectFit">
  130. </image>
  131. </view>
  132. <view class="reviewer-area">
  133. <view class="head-img">
  134. <text class="head-img-box">
  135. <image :src="questionData.remark.remark_person_image_url" mode="aspectFit" />
  136. </text>
  137. <text class="reviewer-name">{{questionData.remark.remark_person_name}}</text>
  138. </view>
  139. <text class="date-box">{{questionData.remark.remark_time}}</text>
  140. </view>
  141. </view>
  142. <!-- 按钮 -->
  143. <view class="foot-btn">
  144. <template v-if="cur_number === 0">
  145. <button class="next-btn start-answer-btn"
  146. @click="startAnswer(share_record_id,share_record.exercise_id)">开始答题</button>
  147. </template>
  148. <template v-if="cur_number > 1">
  149. <button class="pre-btn" v-if="isExerciseMode" @click="switchQuestionIndex(cur_number-2)">上一题</button>
  150. <button class="pre-btn" v-else @click="preTopic()">上一题</button>
  151. </template>
  152. <template v-if="cur_number > 0&&cur_number < total_number">
  153. <template v-if="isExerciseMode&&!isAnswerReport">
  154. <button class="next-btn" @click="nextTopic()"
  155. :style="{backgroundColor:isSwitchQuestionIndex[questionIndexList[cur_number-1].id]?'#306EFF':'#00C72C'}">
  156. {{isSwitchQuestionIndex[questionIndexList[cur_number-1].id]?'下一题':'提交'}}
  157. </button>
  158. </template>
  159. <template v-else>
  160. <button class="next-btn" @click="nextTopic()">下一题</button>
  161. </template>
  162. </template>
  163. <template v-if="total_number!=0&&cur_number === total_number&&!is_remarked&&!isAnswerReport">
  164. <template v-if="isExerciseMode">
  165. <button class="next-btn submit-btn" @click="submitTopic(true)"
  166. v-if="isSwitchQuestionIndex[questionIndexList[cur_number-1].id]">完成答题</button>
  167. <button class="next-btn submit-btn" @click="nextTopic()" v-else>提交</button>
  168. </template>
  169. <template v-else>
  170. <button class="next-btn submit-btn" @click="submitTopic(true)">完成答题</button>
  171. </template>
  172. </template>
  173. </view>
  174. <!-- <view class="message-box"
  175. v-if="false&&questionData.objective_user_answer&&isEnable(questionData.objective_user_answer.is_objective)&&isEnable(questionData.objective_user_answer.is_fill_answer)">
  176. <view class="checkmarkempty"
  177. v-if="questionData.objective_user_answer.answer_status===answer_status_list[1].value">
  178. <uni-icons type="checkmarkempty" size="16" color="#ffffff"></uni-icons>
  179. <text>回答正确</text>
  180. </view>
  181. <view class="closeempty" v-if="questionData.objective_user_answer.answer_status===answer_status_list[2].value">
  182. <uni-icons type="closeempty" size="16" color="#ffffff"></uni-icons>
  183. <text>回答错误</text>
  184. </view>
  185. </view> -->
  186. <view class="scroll-tip" v-show="showScrollTip&&questionType!==''">
  187. <img src="static/arrow_down.png" />
  188. </view>
  189. </view>
  190. </template>
  191. <script setup>
  192. import {
  193. GetShareRecordInfo,
  194. GetExerciseQuestionIndexList,
  195. GetQuestionInfo,
  196. StartAnswer,
  197. GetQuestionInfo_AnswerRecord,
  198. FillQuestionAnswer,
  199. SubmitAnswer,
  200. EndAnswer,
  201. } from '@/api/exercise.js';
  202. import {
  203. optionTypeList,
  204. scoreTypeList,
  205. stemTypeList,
  206. selectTypeList,
  207. questionNumberTypeList,
  208. questionData,
  209. answer_mode_list,
  210. questionInfoData,
  211. isEnable,
  212. answer_status_list,
  213. isSwitchQuestionIndex,
  214. answer_control,
  215. } from '@/pages/answer_question/common/data/common.js';
  216. export default {
  217. data() {
  218. return {
  219. // 状态栏高度
  220. statusBarHeight: 0,
  221. // 导航栏高度
  222. navBarHeight: 82 + 11,
  223. isEnable,
  224. answer_mode_list,
  225. answer_status_list,
  226. questionType: '',
  227. share_record_id: '',
  228. share_record: {},
  229. answer_record_id: '',
  230. cur_number: 0,
  231. total_number: 0,
  232. showQuestionNumber: false, //是否显示题目索引块
  233. cur_type_name: '', //当前题型名称
  234. showQuestionTypeArea: false, //快捷切换题目
  235. startCountdown: false,
  236. //题目索引列表
  237. questionIndexList: [{
  238. id: '',
  239. type: '',
  240. type_name: '',
  241. additional_type: '',
  242. }],
  243. questionData: questionData,
  244. isScanCode: false, //是否扫码进入
  245. is_remarked: false, //整个练习是否批注完成
  246. isTask: false, //是否由任务进入(用于返回)
  247. isAnswerReport: false, //是否答题报告进入
  248. //isSwitchQuestionIndex: {}, //是否直接切换题目索引
  249. isSwitchQuestionIndex,
  250. answer_control,
  251. isQH: false, //答题控制切换题目开关
  252. showScrollTip: true, // 是否显示向下滑动提示
  253. questionClientHeight: 0,
  254. taskSelectedDate: '',
  255. contentRealHeight: 0, //答题内容区域高度
  256. }
  257. },
  258. //第一次加载时调用
  259. created() {
  260. //获取手机状态栏高度
  261. this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
  262. uni.getSystemInfo({
  263. success: (res) => {
  264. this.contentRealHeight = res.windowHeight - 160;
  265. }
  266. });
  267. },
  268. onLoad(options) {
  269. this.isTask = options.isTask;
  270. this.taskSelectedDate = options.date;
  271. //二维码或者链接进入
  272. this.isScanCode = options.isScanCode;
  273. this.share_record_id = options.share_record_id;
  274. this.questionData.share_record_id = options.share_record_id;
  275. this.getShareRecordInfo();
  276. if (options && options.exercise_id) {
  277. // 任务或者练习列表测试报告进入
  278. this.cur_number = Number(options.cur_number);
  279. this.answer_record_id = options.answer_record_id;
  280. this.is_remarked = isEnable(options.is_remarked);
  281. this.isAnswerReport = true;
  282. this.getExerciseQuestionIndexList(options.exercise_id, options.question_id);
  283. this.$refs.exercise?.initAnswerControl();
  284. }
  285. var storageKey = this.answer_record_id + '_' + this.share_record_id;
  286. //清空本地缓存
  287. uni.removeStorage({
  288. key: storageKey
  289. });
  290. },
  291. computed: {
  292. // 是否练习模式
  293. isExerciseMode() {
  294. return this.share_record.answer_mode === this.answer_mode_list[0].value;
  295. },
  296. // 是否考试模式
  297. isExamMode() {
  298. return this.share_record.answer_mode === this.answer_mode_list[1].value;
  299. },
  300. },
  301. mounted() {
  302. uni.$on('receiveClientHeight', this.receiveClientHeight);
  303. },
  304. onUnload() {
  305. uni.$off('receiveClientHeight', this.receiveClientHeight);
  306. },
  307. methods: {
  308. //获取题目高度
  309. receiveClientHeight(questionClientHeight) {
  310. this.questionClientHeight = questionClientHeight;
  311. },
  312. //得到分享记录信息
  313. getShareRecordInfo() {
  314. GetShareRecordInfo({
  315. 'share_record_id': this.share_record_id
  316. }).then((res) => {
  317. if (res.status) {
  318. // console.log('得到分享记录', res);
  319. this.share_record = res.share_record;
  320. this.total_number = res.share_record.question_count;
  321. // 扫码或输入链接,得到分享记录信息时,发现存在答题记录。如果是考试模式。
  322. // 跳转到答题报告显示。如果是练习模式,可以进行继续作答。
  323. if (isEnable(res.user_answer_record_info.is_exist_answer_record)) {
  324. //扫码进入且考试模式
  325. if (this.isScanCode && this.isExamMode) {
  326. uni.reLaunch({
  327. url: '/pages/common/AnswerReport?answer_record_id=' + res.user_answer_record_info
  328. .answer_record_id
  329. })
  330. }
  331. }
  332. }
  333. })
  334. },
  335. //开始答题
  336. startAnswer(share_record_id, exercise_id) {
  337. StartAnswer({
  338. 'share_record_id': share_record_id,
  339. 'exercise_id': exercise_id
  340. }).then((res) => {
  341. if (res.status) {
  342. this.answer_record_id = res.answer_record_id;
  343. this.showQuestionNumber = true;
  344. this.cur_number = 1;
  345. this.isSwitchQuestionIndex = {};
  346. this.getExerciseQuestionIndexList(this.share_record.exercise_id, '');
  347. }
  348. })
  349. },
  350. //获取题目索引
  351. getExerciseQuestionIndexList(exercise_id, question_id) {
  352. GetExerciseQuestionIndexList({
  353. 'exercise_id': exercise_id
  354. }).then((res) => {
  355. if (res.status) {
  356. this.questionIndexList = res.index_list;
  357. this.startCountdown = true;
  358. this.total_number = res.index_list.length;
  359. this.getQuestionInfo({
  360. "question_id": question_id ? question_id : this.questionIndexList[0].id
  361. });
  362. }
  363. })
  364. },
  365. //获取题目详情
  366. async getQuestionInfo(data) {
  367. GetQuestionInfo(data).then((res) => {
  368. if (res.status && res.question && res.question.content) {
  369. var _questionData = JSON.parse(res.question.content);
  370. var cur_question = this.questionIndexList[this.cur_number - 1];
  371. this.cur_type_name = cur_question.type == 'select' ? cur_question.additional_type === 'single' ?
  372. '单选题' : '多选题' : cur_question.type_name; //当前题型名称
  373. if (Array.isArray(_questionData.option_list)) {
  374. _questionData.option_list.forEach(p => {
  375. p.answer = '',
  376. p.checked = false
  377. })
  378. }
  379. _questionData.file_list = res.file_list;
  380. _questionData.question_id = data.question_id;
  381. if (_questionData.file_list && _questionData.file_list.length > 0) {
  382. this.questionData.audio.src = _questionData.file_list[0].file_url;
  383. var that = this;
  384. this.questionData.audio.addEventListener('ended', function() {
  385. that.questionData.playing = false;
  386. })
  387. }
  388. this.questionData.user_answer = {};
  389. this.questionData.user_answer[data.question_id] = {
  390. is_fill_answer: false, // 用户是否填写答案,
  391. content: '', // 答案内容(JSON 格式文本),
  392. answer_list: [],
  393. isEdit: false,
  394. };
  395. //写作题,问答题,活动题答案格式
  396. var needUploadFilesQuestionTypeList = ['write', 'essay_question', 'activity'];
  397. if (needUploadFilesQuestionTypeList.includes(_questionData.type)) {
  398. this.questionData.user_answer[data.question_id].answer_list.push({
  399. text: '', // 用户文章
  400. audio_file_id: '', // 录音id
  401. accessory_file_id_list: [], // 上传文件列表
  402. });
  403. }
  404. //朗读题或简答答案格式'short_answer'
  405. var needSoundRecordQuestionTypeList = ['read_aloud'];
  406. if (needSoundRecordQuestionTypeList.includes(_questionData.type)) {
  407. this.questionData.user_answer[data.question_id].answer_list.push({
  408. text: '', // 用户文章
  409. voice_file_id: '', // 录音id
  410. });
  411. }
  412. //口语表达答案格式
  413. if (_questionData.type === 'answer_question') {
  414. this.questionData.user_answer[data.question_id].answer_list.push({
  415. audio_file_id: '', // 录音id
  416. });
  417. }
  418. //替换练习答案格式
  419. if (_questionData.type === 'replace_answer') {
  420. this.questionData.user_answer[data.question_id].answer_list.push({
  421. mark_list: [],
  422. audio_file_id: '', // 录音id
  423. });
  424. }
  425. //this.questionData, _questionData合并为新对象{},属性值重复的后者覆盖前者
  426. this.questionData = Object.assign({}, this.questionData, _questionData);
  427. this.questionData.answer_record_id = this.answer_record_id;
  428. this.questionData.isLoaded = false;
  429. this.questionType = this.questionData.type;
  430. this.questionData.isReadQuestionWatch = false;
  431. // console.log("index题目:", this.questionData);
  432. }
  433. })
  434. },
  435. //获取用户答案
  436. getQuestionInfo_AnswerRecord(question_id, callback) {
  437. GetQuestionInfo_AnswerRecord({
  438. answer_record_id: this.answer_record_id,
  439. question_id: question_id
  440. }).then((res) => {
  441. if (!res.status) return;
  442. this.questionData.remark = res.remark;
  443. this.questionData.objective_user_answer = res.user_answer;
  444. //从答题报告中进入答题控制需要判断
  445. if (this.isAnswerReport) {
  446. this.answerControl(res.user_answer, question_id);
  447. //如果是阅读题需提前获取阅读题附加题的答题控制
  448. if (res.question.type == 'read') {
  449. var obj = JSON.parse(res.question.content);
  450. if (!obj) return;
  451. obj.question_list?.map(item => {
  452. if (!item) return;
  453. this.answerControl(res.user_answer, item.id);
  454. });
  455. }
  456. }
  457. // console.log('批注', this.questionData.remark);
  458. let lst = [];
  459. if (res.user_answer.content) {
  460. var obj = JSON.parse(res.user_answer.content);
  461. if (obj)
  462. lst = obj.answer_list;
  463. }
  464. //写作题或者问答题答案格式
  465. var needUploadFilesQuestionTypeList = ['write', 'essay_question', 'activity'];
  466. if (needUploadFilesQuestionTypeList.includes(this.questionData.type) && lst.length ===
  467. 0) {
  468. lst.push({
  469. text: '', // 用户文章
  470. audio_file_id: '', // 录音id
  471. accessory_file_id_list: [], // 上传文件列表
  472. });
  473. }
  474. //朗读题或简答答案格式'short_answer'
  475. var needSoundRecordQuestionTypeList = ['read_aloud'];
  476. if (needSoundRecordQuestionTypeList.includes(this.questionData.type) && lst
  477. .length === 0) {
  478. lst.push({
  479. text: '', // 用户文章
  480. voice_file_id: '', // 录音id
  481. });
  482. }
  483. //写作题或者问答题答案格式
  484. if ((this.questionData.type === 'answer_question') && lst.length === 0) {
  485. lst.push({
  486. audio_file_id: '', // 录音id
  487. });
  488. }
  489. //替换练习答案格式
  490. if (this.questionData.type === 'replace_answer' && lst.length === 0) {
  491. lst.push({
  492. mark_list: [],
  493. audio_file_id: '', // 录音id
  494. });
  495. }
  496. this.questionData.user_answer[question_id].answer_list = lst;
  497. this.questionData.user_answer[question_id].isEdit = false;
  498. // console.log('获取用户答案', this.questionData.user_answer);
  499. if (callback && typeof callback === 'function') {
  500. callback();
  501. };
  502. //获取元素高度,判断是否有滚动条
  503. this.$nextTick(() => {
  504. const element = document.getElementById('topic-area');
  505. let clientHeight = element.children[0].clientHeight + 34;
  506. if (this.questionClientHeight > 0) {
  507. clientHeight = this.questionClientHeight + clientHeight;
  508. }
  509. //此处的34是elementde的padding需计入
  510. if (clientHeight - element.clientHeight > 0) {
  511. this.showScrollTip = true;
  512. } else {
  513. this.showScrollTip = false;
  514. }
  515. this.questionClientHeight = 0;
  516. })
  517. })
  518. },
  519. //上一题
  520. preTopic() {
  521. this.$nextTick().then(() => {
  522. this.getOtherQuesion(-1);
  523. });
  524. },
  525. //下一题
  526. nextTopic() {
  527. this.$nextTick().then(() => {
  528. this.getOtherQuesion(1);
  529. });
  530. },
  531. async getOtherQuesion(otherIndex) {
  532. var cur_qid = this.questionIndexList[this.cur_number - 1].id;
  533. //不是答题卡进入;初次进入题目(不直接切换题目)
  534. var isChange = !this.isAnswerReport &&
  535. !this.isSwitchQuestionIndex[cur_qid];
  536. /**
  537. * 是否即刻执行切换题目
  538. */
  539. // var isImmediate = false;
  540. if (isChange) {
  541. var userAnswer = this.questionData.user_answer[this.questionData.question_id];
  542. if (!userAnswer) return;
  543. // if (userAnswer.isEdit) {
  544. if (true) {
  545. // 保存数据
  546. var answer_data = {
  547. "answer_record_id": this.answer_record_id,
  548. "question_id": this.questionData.question_id,
  549. "answer": {
  550. answer_list: userAnswer.answer_list
  551. },
  552. };
  553. var _ans = [];
  554. if (this.questionData.type == "read") {
  555. this.questionData.question_list.forEach(p => {
  556. var subAnswerList = this.questionData.user_answer[p.question_id];
  557. _ans.push({
  558. id: p.question_id,
  559. type: p.type,
  560. answer_list: subAnswerList ? subAnswerList.answer_list : []
  561. })
  562. })
  563. answer_data.answer.question_list = _ans;
  564. }
  565. if (!this.isAnswerReport) {
  566. await FillQuestionAnswer(answer_data).then((res) => {
  567. if (res.status) {
  568. if (isEnable(res.user_answer.is_fill_answer) && !this.isExamMode) {
  569. // 如果已经填写过答案,直接显示答案
  570. // console.log(res.user_answer.is_objective);
  571. // isImmediate = !isEnable(res.user_answer.is_objective);
  572. this.answerControl(res.user_answer, cur_qid);
  573. this.$set(this.isSwitchQuestionIndex, cur_qid, true);
  574. }
  575. }
  576. })
  577. }
  578. }
  579. } else {
  580. // console.log('已经判断答案跳过');
  581. this.switchQuestion(otherIndex);
  582. this.isQH = true;
  583. }
  584. //isQH是为了防止符合上面条件进行了题目切换,同时又符合下边的条件再次进行题目切换,(解决连跳两题的问题)
  585. var is_objective = !this.answer_control[cur_qid] ? true : this.answer_control[cur_qid].is_objective;
  586. //考试模式或者主观题(非客观题)直接切换题
  587. if (((this.isExamMode) && !this.isQH)) {
  588. // console.log('无需判断答案');
  589. this.switchQuestion(otherIndex);
  590. }
  591. setTimeout(() => {
  592. this.isQH = false
  593. }, 100)
  594. },
  595. switchQuestion(otherIndex) {
  596. if (otherIndex === 0) return;
  597. this.cur_number = this.cur_number + otherIndex;
  598. const data = {
  599. "question_id": this.questionIndexList[this.cur_number - 1].id,
  600. "answer_record_id": this.answer_record_id
  601. };
  602. this.getQuestionInfo(data);
  603. },
  604. switchQuestionIndex(index) {
  605. this.cur_number = index + 1;
  606. const data = {
  607. "question_id": this.questionIndexList[index].id,
  608. "answer_record_id": this.answer_record_id
  609. };
  610. this.getQuestionInfo(data);
  611. },
  612. async submitTopic(isSubmit) {
  613. await this.getOtherQuesion(0);
  614. var that = this;
  615. if (isSubmit) {
  616. uni.showModal({
  617. title: '提示',
  618. content: '是否提交答题?',
  619. success: function(res) {
  620. that.$refs.exercise?.initAnswerControl();
  621. if (res.confirm) {
  622. SubmitAnswer({
  623. answer_record_id: that.answer_record_id
  624. }).then((_res) => {
  625. if (_res.status) {
  626. uni.reLaunch({
  627. url: '/pages/common/AnswerReport?answer_record_id=' + that.answer_record_id +
  628. '&isTask=' + that.isTask + '&date=' + that.taskSelectedDate
  629. })
  630. }
  631. })
  632. }
  633. }
  634. });
  635. } else {
  636. //倒计时结束调用结束答题后直接到答题报告
  637. EndAnswer({
  638. answer_record_id: that.answer_record_id
  639. }).then((_res) => {
  640. that.$refs.exercise?.initAnswerControl();
  641. if (_res.status) {
  642. uni.reLaunch({
  643. url: '/pages/common/AnswerReport?answer_record_id=' + that.answer_record_id +
  644. '&isTask=' + that.isTask + '&date=' + that.taskSelectedDate
  645. })
  646. }
  647. })
  648. }
  649. },
  650. onBack() {
  651. let routes = getCurrentPages();
  652. //获取当前页路径
  653. let curPage = routes[routes.length - 1].route;
  654. //扫码进入答题直接返回到练习
  655. if (curPage.indexOf('answer_question') != -1 && this.isScanCode) {
  656. uni.reLaunch({
  657. url: '/pages/tabbar/exercise/index'
  658. })
  659. } else {
  660. uni.navigateBack({
  661. delta: 1
  662. })
  663. }
  664. this.$refs.exercise?.initAnswerControl();
  665. },
  666. //答题控制
  667. answerControl(user_answer, question_id) {
  668. this.$nextTick().then(() => {
  669. /**
  670. * 是否判断对错
  671. * 1. 答题模式为练习模式:1【练习模式】,2【考试模式】
  672. * 2. 答题模式为考试模式,且已经批改过
  673. * 3. 从答题报告跳转到题目
  674. */
  675. let isJudgeAnswer =
  676. this.isExerciseMode ||
  677. (this.isExamMode && this.is_remarked) ||
  678. this.isAnswerReport;
  679. /**
  680. * 是否显示正确答案
  681. * 1. 答题模式为练习模式,且正确答案显示模式为答题后显示
  682. * correct_answer_show_mode: 1、答题后显示2、提交后显示'
  683. * 3. 从答题报告跳转到题目
  684. */
  685. let isViewRightAnswer =
  686. (this.isExerciseMode && this.share_record.correct_answer_show_mode === 1) ||
  687. this.isAnswerReport;
  688. /**
  689. * 是否禁用答题
  690. * 1. 答题模式为练习模式,且正确答案显示模式为答题后显示
  691. * 2. 教师已经批改过
  692. * 3. 从答题报告跳转到题目
  693. */
  694. let isReadOnly =
  695. (this.isExerciseMode && this.share_record.correct_answer_show_mode === 1) ||
  696. this.is_remarked ||
  697. this.isAnswerReport;
  698. this.$refs.exercise?.showAnswer(
  699. isJudgeAnswer,
  700. isViewRightAnswer,
  701. isReadOnly,
  702. question_id,
  703. user_answer.content.length > 0 ? JSON.parse(user_answer.content) : null,
  704. isEnable(user_answer.is_objective)
  705. );
  706. this.questionData.isReadQuestionWatch = true;
  707. });
  708. },
  709. //滚动事件
  710. handlePageScroll() {
  711. if (this.questionType === '') return;
  712. const element = document.getElementById('topic-area');
  713. const scrollTop = element.scrollTop;
  714. //此处的34是elementde的padding需计入
  715. if ((element.children[0].clientHeight + 34) - element.clientHeight > 0) {
  716. this.showScrollTip = true;
  717. if (scrollTop > 0)
  718. this.showScrollTip = false;
  719. } else {
  720. this.showScrollTip = false;
  721. }
  722. },
  723. }
  724. }
  725. </script>
  726. <style lang="scss" scoped>
  727. // @import url("../../../static/style/exercise.scss");
  728. .nav-bar-box {
  729. .nav-bar {
  730. background-color: #ffffff;
  731. display: flex;
  732. align-items: center;
  733. height: 92rpx;
  734. .nav-bar-left {
  735. flex: 1;
  736. padding: 0 16rpx;
  737. .left-bg {
  738. display: flex;
  739. justify-content: center;
  740. align-items: center;
  741. width: 60rpx;
  742. height: 60rpx;
  743. border-radius: 80rpx;
  744. background-color: $uni-bg-color-grey;
  745. }
  746. }
  747. .nav-bar-right {
  748. flex: 2;
  749. padding: 0 16rpx;
  750. display: flex;
  751. justify-content: right;
  752. column-gap: 24rpx;
  753. .nav-bar-number,
  754. .nav-bar-countdown {
  755. padding: 12rpx 32rpx;
  756. border-radius: 40rpx;
  757. display: flex;
  758. align-items: center;
  759. justify-content: center;
  760. text {
  761. white-space: nowrap;
  762. }
  763. }
  764. .nav-bar-number {
  765. background-color: $uni-bg-color-grey;
  766. color: #34343A;
  767. column-gap: 8rpx;
  768. }
  769. .nav-bar-countdown {
  770. background-color: #E7EEFF;
  771. color: #175DFF;
  772. flex-direction: row;
  773. svg {
  774. margin-top: -1px;
  775. }
  776. }
  777. .question-type-area {
  778. position: absolute;
  779. top: 96rpx;
  780. padding: 10rpx;
  781. background-color: #ffffff;
  782. width: 250rpx;
  783. height: 400rpx;
  784. border-radius: 8px;
  785. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.25);
  786. overflow-y: auto;
  787. z-index: 99;
  788. .question-type-name {
  789. padding: 16rpx;
  790. &.active {
  791. background-color: #F4F8FF;
  792. color: $uni-color-main;
  793. }
  794. }
  795. }
  796. }
  797. }
  798. }
  799. .topic-area {
  800. display: flex;
  801. flex-direction: column;
  802. width: 88%;
  803. margin: 16rpx auto 32rpx auto;
  804. background-color: #fff;
  805. border-radius: 16rpx;
  806. padding: 32rpx;
  807. overflow: scroll;
  808. box-shadow: 0px 10px 24px 0px rgba(0, 0, 0, 0.2);
  809. .start-answer-box {
  810. height: 80%;
  811. display: flex;
  812. flex-direction: column;
  813. row-gap: 32rpx;
  814. align-items: center;
  815. justify-content: center;
  816. text-align: center;
  817. .start-answer-title {
  818. font-size: 32px;
  819. font-weight: 500;
  820. color: #306EFF;
  821. }
  822. .start-answer-content {
  823. font-size: 36rpx;
  824. line-height: 64rpx;
  825. font-weight: 400;
  826. }
  827. .start-answer-tip {
  828. font-size: 32rpx;
  829. line-height: 48rpx;
  830. font-weight: 500;
  831. color: #306EFF;
  832. }
  833. hr {
  834. width: 100%;
  835. border: none;
  836. border-top: 1px solid #efefef;
  837. }
  838. }
  839. }
  840. .remark-area {
  841. display: flex;
  842. flex-direction: column;
  843. height: auto;
  844. width: 88%;
  845. margin: -12rpx auto 32rpx auto;
  846. background-color: #fff;
  847. border-radius: 16rpx;
  848. padding: 32rpx;
  849. overflow: scroll;
  850. box-shadow: 0px 10px 24px 0px rgba(0, 0, 0, 0.2);
  851. .img-box {
  852. margin: 32rpx 0;
  853. width: 100%;
  854. display: flex;
  855. flex-direction: row;
  856. flex-wrap: wrap;
  857. row-gap: 16rpx;
  858. column-gap: 16rpx;
  859. image {
  860. width: 160rpx;
  861. height: 160rpx;
  862. background-color: #D9D9D9;
  863. }
  864. }
  865. .reviewer-area {
  866. display: flex;
  867. justify-content: space-between;
  868. align-items: center;
  869. .head-img {
  870. width: 50%;
  871. display: flex;
  872. align-items: center;
  873. column-gap: 16rpx;
  874. .head-img-box {
  875. image {
  876. width: 64rpx;
  877. height: 64rpx;
  878. border-radius: 50%;
  879. background-color: #ECB8B8;
  880. }
  881. }
  882. .reviewer-name {
  883. font-size: 32rpx;
  884. }
  885. }
  886. .date-box {
  887. font-size: 24rpx;
  888. opacity: 0.4;
  889. }
  890. }
  891. }
  892. .foot-btn {
  893. display: flex;
  894. flex-direction: row;
  895. justify-content: space-around;
  896. width: 94%;
  897. margin: 0 auto;
  898. .pre-btn,
  899. .next-btn {
  900. border-radius: 220rpx;
  901. font-size: 28rpx;
  902. font-weight: 400;
  903. padding: 8rpx 124rpx;
  904. border: none;
  905. color: #fff;
  906. background-color: #306EFF;
  907. }
  908. .submit-btn {
  909. background-color: #00C72C;
  910. }
  911. .start-answer-btn {
  912. width: 100%;
  913. }
  914. // .pre-btn {
  915. // background-color: #E9E8EA;
  916. // color: #34343A;
  917. // }
  918. // .next-btn {
  919. // background-color: #306EFF;
  920. // color: #fff;
  921. // }
  922. }
  923. .message-box {
  924. position: absolute;
  925. bottom: 160rpx;
  926. margin: 0 auto;
  927. width: 100%;
  928. display: flex;
  929. flex-direction: column;
  930. align-items: center;
  931. uni-view {
  932. padding: 20rpx 36rpx;
  933. border-radius: 80rpx;
  934. font-size: 28rpx;
  935. font-weight: 500;
  936. color: #ffffff;
  937. display: flex;
  938. align-items: center;
  939. column-gap: 8rpx;
  940. }
  941. .checkmarkempty {
  942. background-color: #3ACB85;
  943. }
  944. .closeempty {
  945. background-color: #E65656;
  946. }
  947. }
  948. .scroll-tip {
  949. position: fixed;
  950. bottom: 150rpx;
  951. left: 50%;
  952. transform: translateX(-50%);
  953. padding: 8rpx 16rpx;
  954. background-color: #E7E7E7;
  955. color: #626262;
  956. border-radius: 8rpx;
  957. font-size: 26rpx;
  958. img {
  959. width: 40rpx;
  960. }
  961. }
  962. </style>