answerTheResult.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <template>
  2. <div class="answerTheResult">
  3. <div class="atr_detail">
  4. <div class="atr_d_btn" @click="lookDetail()">{{ isShowDialog ? lang.ssViewQ : lang.ssViewRes }}</div>
  5. <div class="atr_d_msg">
  6. <div>{{ lang.ssParticipants }}</div>
  7. <span
  8. >{{ workArrayLength }}/{{
  9. workArrayLength + unsubmittedStudentsLength
  10. }}</span
  11. >
  12. </div>
  13. <div class="atr_d_msg" v-if="workDetail && workDetail.type === '45'">
  14. <div>{{ lang.ssAccuracy }}</div>
  15. <span v-if="choiceQuestionListData[workIndex]">{{choiceQuestionListData[workIndex].accuracyRate}}%({{choiceQuestionListData[workIndex].yes}}/{{choiceQuestionListData[workIndex].all}})</span>
  16. </div>
  17. <div class="atr_d_msg" v-if="workDetail && workDetail.type === '78'">
  18. <div>{{ lang.ssAccuracy }}</div>
  19. <span v-if="choiceQuestionListData[workIndex]">{{choiceQuestionListData[workIndex].accuracyRate}}%({{choiceQuestionListData[workIndex].yes}}/{{choiceQuestionListData[workIndex].all}})</span>
  20. </div>
  21. <div class="atr_d_msg" v-if="choiceQuestionAnswer">
  22. <div>{{ lang.ssCorrectAns }}</div>
  23. <span style="color: #03ae2b">{{ choiceQuestionAnswer }}</span>
  24. </div>
  25. <span class="atr_d_line" v-if="props.unsubmittedStudents && props.unsubmittedStudents?.length > 0"></span>
  26. <div class="no_submit" v-if="props.unsubmittedStudents && props.unsubmittedStudents?.length > 0">
  27. <div>{{ lang.ssUnsubStu }}</div>
  28. <img
  29. @click="showNoSubmitDetail = !showNoSubmitDetail"
  30. :class="{ no_submit_active: !showNoSubmitDetail }"
  31. src="../../../assets/img/arrow_up.png"
  32. />
  33. </div>
  34. <div
  35. class="no_submitList"
  36. v-if="props.unsubmittedStudents && props.unsubmittedStudents?.length > 0"
  37. :class="{ no_submitList_active: showNoSubmitDetail }"
  38. >
  39. <div
  40. v-for="(student, idx) in props.unsubmittedStudents"
  41. :key="student.id ?? idx"
  42. >
  43. {{ student.name ?? "" }}
  44. </div>
  45. </div>
  46. <span class="atr_d_line" v-if="props.workArray && props.workArray?.length > 0"></span>
  47. <div class="is_submit" v-if="props.workArray && props.workArray?.length > 0">
  48. <div>{{ lang.ssSubStu }}</div>
  49. <img
  50. @click="showIsSubmitDetail = !showIsSubmitDetail"
  51. :class="{ is_submit_active: !showIsSubmitDetail }"
  52. src="../../../assets/img/arrow_up.png"
  53. />
  54. </div>
  55. <div
  56. class="is_submitList"
  57. v-if="props.workArray && props.workArray?.length > 0"
  58. :class="{ is_submitList_active: showIsSubmitDetail }"
  59. >
  60. <div
  61. v-for="(student, idx) in props.workArray"
  62. :key="student.id ?? idx"
  63. @click="emit('openWorkModal', student)"
  64. >
  65. {{ student.name ?? "" }}
  66. </div>
  67. </div>
  68. </div>
  69. <div
  70. class="atr_type45Area"
  71. v-if="
  72. workDetail &&
  73. (workDetail.type === '45' || workDetail.type === '78') &&
  74. choiceQuestionListData[workIndex] &&
  75. choiceQuestionListData[workIndex].choiceUser
  76. "
  77. >
  78. <!-- <div class="atr_t45a_title" >
  79. <span>{{ workIndex+1 }}、{{ choiceQuestionListData[workIndex].type=='1'?'单选题':'多选题' }}:</span>
  80. <span>{{ choiceQuestionListData[workIndex].teststitle }}</span>
  81. <img @click="previewImage(choiceQuestionListData[workIndex].timuList[0].src)" :src="choiceQuestionListData[workIndex].timuList[0].src" v-if="choiceQuestionListData[workIndex].timuList.length>0">
  82. </div> -->
  83. <template
  84. v-for="(op, idx) in choiceQuestionListData[workIndex].choiceUser"
  85. :key="`${workIndex}_${idx}`"
  86. >
  87. <div class="atr_t45a_item">
  88. <div class="atr_t45a_i_top">
  89. <div class="atr_t45a_i_left">
  90. <span>{{ serialNumber[idx] }}</span>
  91. <div>
  92. <img
  93. v-if="op.option.imgType"
  94. :src="op.option.src"
  95. @click="previewImage(op.option.src)"
  96. />
  97. <span v-else>{{ op.option }}</span>
  98. </div>
  99. <span v-if="op.isAnswer">{{ lang.ssCorrectTag }}</span>
  100. </div>
  101. <img
  102. @click="changeShow(op, idx)"
  103. v-if="op.user.length > 0"
  104. :class="{ show_active: !op.show }"
  105. src="../../../assets/img/arrow_up.png"
  106. />
  107. </div>
  108. <div
  109. class="atr_t45a_i_bottom"
  110. v-if="op.user.length > 0 && op.show"
  111. :class="{ atr_t45a_i_b_active: op.show }"
  112. >
  113. <div
  114. v-for="(name, uIdx) in op.user"
  115. :key="`${workIndex}_${idx}_${uIdx}`"
  116. >
  117. {{ name }}
  118. </div>
  119. </div>
  120. </div>
  121. </template>
  122. <div class="nextAndUpBtn" v-if="choiceQuestionListData.length>1">
  123. <span :class="{no_active:workIndex==0}" @click="changeWorkIndex(0)">{{ lang.ssPrevQ }}</span>
  124. <span :class="{no_active:choiceQuestionListData.length-1<=workIndex}" @click="changeWorkIndex(1)">{{ lang.ssNextQ }}</span>
  125. </div>
  126. </div>
  127. </div>
  128. <!-- 预览放大(带缩放/拖拽/旋转/工具栏) -->
  129. <previewImageTool ref="previewImageToolRef"/>
  130. </template>
  131. <script lang="ts" setup>
  132. import { ref, computed, watch, inject, type Ref } from 'vue'
  133. import previewImageTool from '../../components/tool/previewImageTool.vue'
  134. import api from '../../../services/course'
  135. import { lang } from '@/main'
  136. interface Props {
  137. workArray?: object[] | null;
  138. unsubmittedStudents?: object[] | null;
  139. workId?: string | null;
  140. slideIndex?:number
  141. toolType?:number
  142. }
  143. const props = withDefaults(defineProps<Props>(), {
  144. workArray: () => [],
  145. unsubmittedStudents: () => [],
  146. workId: '',
  147. toolType: 0,
  148. slideIndex: 0
  149. })
  150. const emit = defineEmits<{
  151. (e: 'openChoiceQuestionDetail', v: number): void,
  152. (e: 'openWorkModal', v:any):void
  153. }>()
  154. const choiceQuestionDetailDialogOpenList = inject<Ref<number[]>>('choiceQuestionDetailDialogOpenList', ref<number[]>([]))
  155. const isShowDialog = computed(() => {
  156. return choiceQuestionDetailDialogOpenList.value.includes(props.slideIndex)
  157. })
  158. // 已提交的作业数量
  159. const workArrayLength = computed(() => {
  160. let _result = 0
  161. if (props.workArray) {
  162. _result = props.workArray.length
  163. }
  164. return _result
  165. })
  166. // 未提交的作业数量
  167. const unsubmittedStudentsLength = computed(() => {
  168. let _result = 0
  169. if (props.unsubmittedStudents) {
  170. _result = props.unsubmittedStudents.length
  171. }
  172. return _result
  173. })
  174. // 选项序号
  175. const serialNumber = ref<string[]>([
  176. 'A',
  177. 'B',
  178. 'C',
  179. 'D',
  180. 'E',
  181. 'F',
  182. 'G',
  183. 'H',
  184. 'I',
  185. 'J',
  186. 'K',
  187. 'L',
  188. 'M',
  189. 'N',
  190. 'O',
  191. 'P',
  192. 'Q',
  193. 'R',
  194. 'S',
  195. 'T',
  196. 'U',
  197. 'V',
  198. 'W',
  199. 'X',
  200. 'Y',
  201. 'Z',
  202. ])
  203. // 第几题
  204. const workIndex = ref<number>(0)
  205. // 是否显示未提交人员
  206. const showNoSubmitDetail = ref<boolean>(false)
  207. const showIsSubmitDetail = ref<boolean>(false)
  208. // 作业详细
  209. const workDetail = ref<any>({})
  210. // 获取作业详细
  211. const getWorkDetail = async () => {
  212. if (props.workId) {
  213. const _res = await api.getWorkDetail({ id: props.workId })
  214. const _data = _res[0][0]
  215. if (_data) {
  216. _data.json = JSON.parse(_data.json)
  217. workDetail.value = _data
  218. choiceQuestionListData.value = choiceQuestionList()
  219. }
  220. }
  221. }
  222. // 选择题题目数组
  223. const choiceQuestionList = () => {
  224. let _result: any[] = []
  225. if (workDetail.value && (workDetail.value.type === '45' || workDetail.value.type === '78')) {
  226. const _workData = workDetail.value.json.testJson
  227. _workData.forEach((item: any, index: number) => {
  228. // 修复 props.workArray 可能为 null 的问题
  229. item.choiceUser = []
  230. item.yes = 0
  231. item.no = 0
  232. item.checkList.forEach((op: any, oidx: number) =>
  233. item.choiceUser.push({
  234. index: serialNumber.value[oidx],
  235. option: op,
  236. user: [],
  237. show: false,
  238. isAnswer: Array.isArray(item.answer)
  239. ? item.answer.includes(oidx)
  240. : item.answer === oidx,
  241. })
  242. )
  243. });
  244. (props.workArray ?? []).forEach(
  245. (studentWork: any, studentIndex: number) => {
  246. let _studentContent: any = []
  247. try {
  248. _studentContent = JSON.parse(
  249. decodeURIComponent(studentWork.content)
  250. ).testJson
  251. }
  252. catch (error) {
  253. console.log(error)
  254. }
  255. // let _studentContentCorrection = []
  256. // console.log(_workData)
  257. // console.log(_studentContent)
  258. // _studentContentCorrection = _workData.map((i:any) => {
  259. // return _studentContent.find((i2:any) => {
  260. // return (JSON.stringify({testtitle: i2.testtitle, checkList: i2.checkList, timuList: i2.timuList}) === JSON.stringify({testtitle: i.testtitle, checkList: i.checkList, timuList: i.timuList}))
  261. // })
  262. // })
  263. // console.log(_studentContentCorrection)
  264. _studentContent.forEach((test: any, testIndex: number) => {
  265. if (_workData[testIndex] && JSON.stringify({testtitle: test.testtitle, checkList: test.checkList, timuList: test.timuList}) === JSON.stringify({testtitle: _workData[testIndex].testtitle, checkList: _workData[testIndex].checkList, timuList: _workData[testIndex].timuList}) && (test.userAnswer || test.userAnswer === 0)) {
  266. if (Array.isArray(test.userAnswer)) {
  267. test.userAnswer.forEach((ch: number) => {
  268. _workData[testIndex].choiceUser[ch].user.push(studentWork.name)
  269. })
  270. if (
  271. JSON.stringify(
  272. test.userAnswer.sort((a: number, b: number) => a - b)
  273. ) === JSON.stringify(_workData[testIndex].answer.sort((a: number, b: number) => a - b))
  274. ) {
  275. _workData[testIndex].yes += 1
  276. }
  277. else {
  278. _workData[testIndex].no += 1
  279. }
  280. }
  281. else {
  282. _workData[testIndex].choiceUser[test.userAnswer].user.push(
  283. studentWork.name
  284. )
  285. if (test.userAnswer === _workData[testIndex].answer) {
  286. _workData[testIndex].yes += 1
  287. }
  288. else {
  289. _workData[testIndex].no += 1
  290. }
  291. }
  292. }
  293. })
  294. }
  295. )
  296. _workData.forEach((item:any) => {
  297. item.all = item.yes + item.no
  298. if (item.all === 0) {
  299. item.accuracyRate = 0
  300. }
  301. else {
  302. const rate = (item.yes / item.all) * 100
  303. item.accuracyRate = Number.isInteger(rate) ? rate : Number(rate.toFixed(2))
  304. }
  305. })
  306. _result = _workData
  307. }
  308. return _result
  309. }
  310. const choiceQuestionListData = ref<any[]>([])
  311. // 选择题题目正确答案
  312. const choiceQuestionAnswer = computed(() => {
  313. let _result = ''
  314. if (
  315. workDetail.value &&
  316. workDetail.value.type === '45' &&
  317. workDetail.value.json.testJson[workIndex.value]
  318. ) {
  319. const _answer = workDetail.value.json.testJson[workIndex.value].answer
  320. if (Array.isArray(_answer)) {
  321. _result = _answer.map((i: any) => serialNumber.value[i]).join('、')
  322. }
  323. else {
  324. _result = [serialNumber.value[_answer]].join('、')
  325. }
  326. }
  327. return _result
  328. })
  329. // //当前题目正确率
  330. // const choiceQuestionAccuracyRate = computed
  331. // 监听作业Id
  332. watch(
  333. () => props.workId,
  334. (newVal, oldVal) => {
  335. console.log('props.workId变化', { newVal, oldVal })
  336. if (newVal && newVal !== oldVal) {
  337. getWorkDetail()
  338. }
  339. },
  340. { immediate: true }
  341. )
  342. // 监听已提交的作业
  343. watch(() => props.workArray, (newVal, oldVal) => {
  344. if (newVal && newVal !== oldVal) {
  345. choiceQuestionListData.value = choiceQuestionList()
  346. // choiceQuestionAnswerData.value = choiceQuestionAnswer()
  347. }
  348. }, { immediate: true })
  349. // 切换题目
  350. const changeWorkIndex = (type:number) => {
  351. if (type === 0) {
  352. if (workIndex.value === 0) return
  353. workIndex.value -= 1
  354. }
  355. else if (type === 1) {
  356. if (choiceQuestionListData.value.length - 1 <= workIndex.value) return
  357. workIndex.value += 1
  358. }
  359. }
  360. // 切换题目展示所有人选项
  361. const changeShow = (op: any, idx: number) => {
  362. choiceQuestionListData.value[workIndex.value].choiceUser[idx].show = !choiceQuestionListData.value[workIndex.value].choiceUser[idx].show
  363. }
  364. const lookDetail = () => {
  365. console.log(props.toolType)
  366. if ([45, 15, 72, 73, 78, 79].includes(props.toolType)) {
  367. emit('openChoiceQuestionDetail', props.slideIndex)
  368. }
  369. }
  370. const previewImageToolRef = ref<any>(null)
  371. const previewImage = (url:string) => {
  372. previewImageToolRef.value.previewImage(url)
  373. }
  374. defineExpose({
  375. workDetail,
  376. choiceQuestionListData,
  377. workIndex,
  378. workArray: props.workArray,
  379. unsubmittedStudents: props.unsubmittedStudents,
  380. toolType: props.toolType,
  381. changeWorkIndex
  382. })
  383. </script>
  384. <style lang="scss" scoped>
  385. .answerTheResult {
  386. width: 100%;
  387. height: auto;
  388. max-height: 100%;
  389. overflow: auto;
  390. box-sizing: border-box;
  391. padding: 12px;
  392. .atr_detail {
  393. width: 100%;
  394. height: auto;
  395. border-radius: 4px;
  396. padding: 10px 15px 10px 15px;
  397. box-sizing: border-box;
  398. border: solid 1px rgba(0, 0, 0, 0.1);
  399. .atr_d_btn {
  400. width: 100%;
  401. height: 40px;
  402. display: flex;
  403. align-items: center;
  404. justify-content: center;
  405. background: rgba(0, 0, 0, 0.9);
  406. color: #fff;
  407. font-weight: 500;
  408. font-size: 14px;
  409. border-radius: 4px;
  410. cursor: pointer;
  411. }
  412. .atr_d_msg {
  413. width: 100%;
  414. display: flex;
  415. align-items: center;
  416. margin-top: 15px;
  417. font-size: 14px;
  418. color: rgba(0, 0, 0, 0.9);
  419. & > div {
  420. width: 4em;
  421. margin-right: 35px;
  422. font-weight: 500;
  423. }
  424. }
  425. .atr_d_line {
  426. width: 100%;
  427. height: 2px;
  428. display: block;
  429. background: rgba(242, 243, 245, 1);
  430. margin: 20px 0;
  431. border-radius: 2px;
  432. }
  433. .no_submit {
  434. width: 100%;
  435. display: flex;
  436. align-items: center;
  437. justify-content: space-between;
  438. font-size: 14px;
  439. font-weight: 500;
  440. margin-bottom: 20px;
  441. .no_submit_active {
  442. transform: rotate(180deg);
  443. }
  444. & > img {
  445. cursor: pointer;
  446. }
  447. }
  448. .no_submitList {
  449. width: 100%;
  450. display: flex;
  451. align-items: center;
  452. flex-wrap: nowrap;
  453. overflow: hidden;
  454. gap: 10px;
  455. & > div {
  456. padding: 5px 10px;
  457. background: rgba(255, 236, 232, 1);
  458. color: rgba(245, 63, 63, 1);
  459. font-size: 14px;
  460. font-weight: 500;
  461. border-radius: 10px;
  462. white-space: nowrap;
  463. }
  464. }
  465. .no_submitList_active {
  466. flex-wrap: wrap;
  467. }
  468. .is_submit {
  469. width: 100%;
  470. display: flex;
  471. align-items: center;
  472. justify-content: space-between;
  473. font-size: 14px;
  474. font-weight: 500;
  475. margin-bottom: 20px;
  476. .is_submit_active {
  477. transform: rotate(180deg);
  478. }
  479. & > img {
  480. cursor: pointer;
  481. }
  482. }
  483. .is_submitList {
  484. width: 100%;
  485. display: flex;
  486. align-items: center;
  487. flex-wrap: nowrap;
  488. overflow: hidden;
  489. gap: 10px;
  490. & > div {
  491. padding: 5px 10px;
  492. background: #fff;
  493. color: #2F80ED;
  494. font-size: 14px;
  495. font-weight: 500;
  496. border-radius: 10px;
  497. white-space: nowrap;
  498. box-sizing: border-box;
  499. border: solid 1px #2F80ED;
  500. cursor: pointer;
  501. }
  502. }
  503. .is_submitList_active {
  504. flex-wrap: wrap;
  505. }
  506. }
  507. .atr_type45Area {
  508. width: 100%;
  509. height: auto;
  510. .atr_t45a_title{
  511. width: 100%;
  512. height: auto;
  513. box-sizing: border-box;
  514. padding: 10px 15px 10px 15px;
  515. border: solid 1px #0000001a;
  516. border-radius: 4px;
  517. margin-top: 20px;
  518. font-size: 14px;
  519. font-weight: 600;
  520. img{
  521. width: auto;
  522. max-width: 100%;
  523. height: auto;
  524. object-fit: cover;
  525. cursor: pointer;
  526. display: block;
  527. }
  528. }
  529. .atr_t45a_item {
  530. width: 100%;
  531. height: auto;
  532. box-sizing: border-box;
  533. padding: 10px 15px 10px 15px;
  534. border: solid 1px #0000001a;
  535. border-radius: 4px;
  536. margin-top: 20px;
  537. .atr_t45a_i_top {
  538. width: 100%;
  539. height: auto;
  540. display: flex;
  541. align-items: center;
  542. justify-content: space-between;
  543. .atr_t45a_i_left {
  544. width: calc(100% - 50px);
  545. height: auto;
  546. display: flex;
  547. align-items: center;
  548. & > span:nth-child(1) {
  549. display: block;
  550. width: 20px;
  551. height: 20px;
  552. background: #fccf00;
  553. border-radius: 50%;
  554. padding: auto;
  555. box-sizing: border-box;
  556. display: flex;
  557. align-items: center;
  558. justify-content: center;
  559. font-size: 14px;
  560. font-weight: 500;
  561. color: #fff;
  562. margin-right: 10px;
  563. }
  564. & > div {
  565. font-size: 14px;
  566. font-weight: bold;
  567. max-width: calc(100% - 20px - 10px - 45px);
  568. overflow: hidden;
  569. text-overflow: ellipsis;
  570. white-space: nowrap;
  571. display: block;
  572. position: relative;
  573. &>img{
  574. width: 20px;
  575. height: 20px;
  576. object-fit: cover;
  577. cursor: pointer;
  578. }
  579. }
  580. & > span:nth-of-type(2) {
  581. display: block;
  582. padding: 2px 4px;
  583. border-radius: 2px;
  584. background: #aff0b580;
  585. color: #03ae2b;
  586. font-size: 12px;
  587. font-weight: 400;
  588. margin-left: 10px;
  589. }
  590. }
  591. & > img {
  592. width: 16px;
  593. height: 16px;
  594. margin-left: 20px;
  595. cursor: pointer;
  596. }
  597. .show_active {
  598. transform: rotate(180deg);
  599. }
  600. }
  601. .atr_t45a_i_bottom {
  602. width: 100%;
  603. display: flex;
  604. align-items: center;
  605. flex-wrap: nowrap;
  606. overflow: hidden;
  607. gap: 10px;
  608. margin-top: 10px;
  609. & > div {
  610. padding: 5px 10px;
  611. background: #0000000f;
  612. color: #222222;
  613. font-size: 14px;
  614. font-weight: 500;
  615. border-radius: 10px;
  616. }
  617. }
  618. .atr_t45a_i_b_active {
  619. flex-wrap: wrap !important;
  620. }
  621. }
  622. .nextAndUpBtn{
  623. width: 100%;
  624. height: auto;
  625. display: grid;
  626. grid-template-columns: 1fr 1fr;
  627. margin-top: 20px;
  628. gap: 15px;
  629. &>span{
  630. display: flex;
  631. justify-content: center;
  632. align-items: center;
  633. width: 100%;
  634. height: 40px;
  635. border-radius: 5px;
  636. font-size: 14px;
  637. font-weight: 500;
  638. color: #fff;
  639. background: #3681FC;
  640. cursor: pointer;
  641. }
  642. &>.no_active{
  643. background: #cccccc !important;
  644. color: #999999 !important;
  645. cursor: not-allowed !important;
  646. pointer-events: none !important;
  647. }
  648. }
  649. }
  650. }
  651. </style>