practiceAnswer.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. <template>
  2. <div class="practice_answer">
  3. <el-container style="height: 100%">
  4. <el-aside width="260px" class="hide_scrollbar">
  5. <div class="side_list">
  6. <div class="side_title">待练习知识点</div>
  7. <div
  8. :class="['side_item', { active: item.exerciseId == exerciseId }]"
  9. v-for="item in waitList"
  10. :key="item.exerciseId"
  11. @click="ChangeKnowledge(item)"
  12. >
  13. <div class="item_name">
  14. {{ item.knowledgeName }}
  15. </div>
  16. <div class="item_content">
  17. <div class="content_left">
  18. <div class="content_type">
  19. {{ item.exerciseType == 1 ? "自主练习" : "指定练习" }}
  20. </div>
  21. <div class="content_num">
  22. 题量:{{ item?.questionNum || "0" }}
  23. </div>
  24. </div>
  25. <div class="ai_explain">
  26. <img class="ai_icon" src="@/assets/icon_ai.png" />
  27. <span>AI讲解</span>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </el-aside>
  33. <el-main class="main_body">
  34. <div class="content_main">
  35. <div class="content_title">
  36. <div class="title_name">{{ knowledgeName }}</div>
  37. <div class="button">
  38. <el-button plain class="download_btn" @click="downloadPaper"
  39. >下载试卷</el-button
  40. >
  41. <el-button type="primary" @click="SubmitAnswer">提交作答</el-button>
  42. </div>
  43. </div>
  44. <div class="question_list">
  45. <div
  46. class="question_item"
  47. v-for="(item, index) in questionList"
  48. :key="item.questionId"
  49. >
  50. <QuestionItem :index="index + 1" :question="item"></QuestionItem>
  51. <!-- 客观题->选择、判断。主观题->上传图片 -->
  52. <!-- isObjective 是否客观题 1是 0否 isJudge 是否判断题 1是 0否 -->
  53. <div
  54. :class="[
  55. 'question_footer',
  56. { img_list: Number(item.isObjective) === 0 },
  57. ]"
  58. >
  59. <span class="footer_title">我的作答:</span>
  60. <div
  61. v-if="Number(item.isObjective) === 1"
  62. class="upload_answer"
  63. >
  64. <!-- 判断题 -->
  65. <el-radio-group
  66. class="radio_group"
  67. v-if="Number(item.isJudge) === 1"
  68. v-model="item.answer"
  69. @input="HandleJudgeChange(item)"
  70. >
  71. <el-radio label="√">√</el-radio>
  72. <el-radio label="×">×</el-radio>
  73. </el-radio-group>
  74. <!-- 选择题 -->
  75. <el-checkbox-group
  76. class="checkbox_group"
  77. v-else
  78. v-model="item.answer"
  79. @change="HandleCheckChange(item)"
  80. >
  81. <el-checkbox
  82. v-for="num in item.optionsNum"
  83. :key="num"
  84. :label="optionsData[num - 1]"
  85. ></el-checkbox>
  86. </el-checkbox-group>
  87. </div>
  88. <div v-else class="upload_answer">
  89. <el-upload
  90. class="img_uploader"
  91. list-type="picture-card"
  92. :show-file-list="false"
  93. :headers="{'Authorization': getToken}"
  94. :action="uploadUrl"
  95. accept="image/*"
  96. multiple
  97. :limit="10"
  98. :on-exceed="HandleExceed"
  99. :on-success="(response, file, fileList)=>HandleUploadSuccess(response, file, fileList,item)"
  100. >
  101. <el-button slot="default" class="upload_btn" plain
  102. >拍照/上传答案</el-button
  103. >
  104. </el-upload>
  105. <div
  106. class="upload_list_item"
  107. v-for="(url, index) in item.answer"
  108. :key="index"
  109. @click="HandlePictureCardPreview(url)"
  110. >
  111. <img :src="url" />
  112. <i
  113. @click.stop="HandleRemove(item.answer,index)"
  114. class="el-icon-error upload_list_item_delete"
  115. ></i>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </el-main>
  123. </el-container>
  124. <div class="page_dialog">
  125. <el-dialog :visible.sync="dialogVisible">
  126. <div class="dialog_center padding_20">
  127. <div class="dialog_img">
  128. <img style="max-width: 100%" :src="dialogImageUrl" />
  129. </div>
  130. </div>
  131. </el-dialog>
  132. <el-dialog
  133. title="下载试卷"
  134. width="360px"
  135. :visible.sync="dialogPaperVisible"
  136. >
  137. <div class="dialog_center padding_20">
  138. <div class="dialog_paper">
  139. <div class="dialog_paper_item">
  140. <span class="dialog_paper_title">试卷名称:</span>
  141. <el-radio-group class="radio_group" v-model="radio">
  142. <el-radio :label="3">A4</el-radio>
  143. <el-radio :label="6">A3</el-radio>
  144. </el-radio-group>
  145. </div>
  146. <div class="dialog_paper_item">
  147. <span class="dialog_paper_title">下载格式:</span>
  148. <el-radio-group class="radio_group" v-model="radio">
  149. <el-radio :label="3">PDF</el-radio>
  150. <el-radio :label="6">Word</el-radio>
  151. </el-radio-group>
  152. </div>
  153. </div>
  154. </div>
  155. <div slot="footer" class="dialog-footer">
  156. <el-button @click="dialogPaperVisible = false">取 消</el-button>
  157. <el-button type="primary" @click="ConfirmDownloadPaper"
  158. >确 定</el-button
  159. >
  160. </div>
  161. </el-dialog>
  162. </div>
  163. </div>
  164. </template>
  165. <script>
  166. import QuestionItem from "@/views/targetImprove/components/QuestionItem.vue"; //题目公共组件
  167. import { getToken } from "@/utils/auth";
  168. import base from '@/http/common/base.js';
  169. import { mapState } from "vuex";
  170. export default {
  171. components: {
  172. QuestionItem,
  173. },
  174. computed: {
  175. ...mapState("target", ["subjectCode", "levelCode"]),
  176. },
  177. data() {
  178. return {
  179. waitList: [], //待练习知识点
  180. exerciseId: "", // 练习id
  181. knowledgeName: "", //知识点名称
  182. questionList: [],
  183. optionsData: [
  184. "A",
  185. "B",
  186. "C",
  187. "D",
  188. "E",
  189. "F",
  190. "G",
  191. "H",
  192. "I",
  193. "J",
  194. "K",
  195. "L",
  196. "M",
  197. "N",
  198. "O",
  199. "P",
  200. "Q",
  201. "R",
  202. "S",
  203. "T",
  204. "U",
  205. "V",
  206. "W",
  207. "X",
  208. "Y",
  209. "Z",
  210. ],
  211. getToken: getToken(),
  212. uploadUrl: '',//上传图片地址
  213. dialogImageUrl: "", //图片预览
  214. dialogVisible: false, //图片预览
  215. dialogPaperVisible: false, //下载试卷
  216. radio: 3, //下载试卷
  217. };
  218. },
  219. watch: {},
  220. mounted() {
  221. this.GetUploadUrl();
  222. this.GetStudentTargeWaitExercise();
  223. },
  224. methods: {
  225. //获取上传图片地址
  226. GetUploadUrl(){
  227. this.uploadUrl = `${base.prefix}/api/v1/student_upload/oss/upload_filesSele`;
  228. },
  229. //待练习知识点
  230. GetStudentTargeWaitExercise() {
  231. this.$api.target
  232. .studentTargeWaitExercise({
  233. levelCode: this.levelCode, // 学段code
  234. subjectCode: this.subjectCode, //学科code
  235. })
  236. .then((res) => {
  237. if (res.code == 200) {
  238. this.waitList = res?.data || [];
  239. if (this.waitList.length > 0) {
  240. this.exerciseId = this.waitList?.[0]?.exerciseId || "";
  241. this.knowledgeName = this.waitList?.[0]?.knowledgeName || "";
  242. this.GetStudentTargeExerciseQuestion();
  243. }
  244. }
  245. });
  246. },
  247. // 查询试题列表(type 1待练习的列表 2已练习的列表)
  248. GetStudentTargeExerciseQuestion() {
  249. this.$api.target
  250. .studentTargeExerciseQuestion({
  251. exerciseId: this.exerciseId, // 练习id
  252. type: 1, // 1待练习的列表 2已练习的列表
  253. })
  254. .then((res) => {
  255. if (res.code == 200) {
  256. // 客观题->选择、判断。主观题->上传图片
  257. // isObjective 是否客观题 1是 0否 isJudge 是否判断题 1是 0否
  258. const questionList = res?.data || [];
  259. questionList.forEach((item) => {
  260. if (Number(item.isObjective) === 1) {
  261. //客观题
  262. let answer = "";
  263. if (Number(item.isJudge) === 1) {
  264. //判断题
  265. answer = item.answer || "";
  266. } else {
  267. //选择题
  268. answer = Array.isArray(item.answer) ? item.answer : [];
  269. }
  270. item.answer = answer;
  271. } else {
  272. item.answer = Array.isArray(item.answer) ? item.answer : [];
  273. }
  274. });
  275. this.questionList = questionList;
  276. } else {
  277. this.questionList = [];
  278. }
  279. });
  280. },
  281. //切换知识点
  282. ChangeKnowledge(item) {
  283. if (this.exerciseId == item.exerciseId) {
  284. return;
  285. }
  286. this.exerciseId = item.exerciseId || "";
  287. this.knowledgeName = item.knowledgeName || "";
  288. this.GetStudentTargeExerciseQuestion();
  289. },
  290. //判断题改变
  291. HandleJudgeChange(item) {
  292. item.answer = item.answer || "";
  293. this.SubmitQuestionAnswering(item.exerciseQueId,item.answer);
  294. },
  295. //选择题改变
  296. HandleCheckChange(item) {
  297. item.answer = item.answer || [];
  298. const answer = item?.answer?.join('') || '';
  299. this.SubmitQuestionAnswering(item.exerciseQueId,answer);
  300. },
  301. // 超出最大数量触发
  302. HandleExceed(files, fileList) {
  303. this.$message.warning(`最多只能上传10张图片`)
  304. },
  305. //上传图片成功
  306. HandleUploadSuccess(res, file, fileList,item){
  307. if(res.code == 200){
  308. const url = res?.data?.url || '';
  309. item.answer.push(url);
  310. const answer = item?.answer?.join(',') || '';
  311. this.SubmitQuestionAnswering(item.exerciseQueId,answer);
  312. }
  313. },
  314. //删除图片
  315. HandleRemove(answer,index) {
  316. answer.splice(index, 1);
  317. },
  318. //提交答案
  319. SubmitQuestionAnswering(exerciseQueId,stuAnswer) {
  320. this.$api.target.studentTargeQuestionAnswering({
  321. exerciseQueId: exerciseQueId, // 练习试题id
  322. stuAnswer: stuAnswer, // 学生答案
  323. }).then((res) => {
  324. if (res.code == 200) {
  325. // this.$message.success('提交成功');
  326. }
  327. });
  328. },
  329. //提交作答
  330. SubmitAnswer(){
  331. this.$api.target.studentTargeSubmitExercise({
  332. exerciseId: this.exerciseId, // 练习id
  333. }).then((res) => {
  334. if (res.code == 200) {
  335. this.$message.success('提交成功');
  336. this.GetStudentTargeWaitExercise();//获取待练习知识点
  337. }
  338. });
  339. },
  340. //图片预览
  341. HandlePictureCardPreview(url) {
  342. this.dialogImageUrl = url;
  343. this.dialogVisible = true;
  344. },
  345. //下载试卷
  346. downloadPaper() {
  347. this.dialogPaperVisible = true;
  348. },
  349. //确定下载
  350. ConfirmDownloadPaper() {
  351. this.dialogPaperVisible = false;
  352. },
  353. },
  354. };
  355. </script>
  356. <style scoped lang="scss">
  357. .practice_answer {
  358. flex: 1;
  359. width: 100%;
  360. overflow: hidden;
  361. .side_list {
  362. width: 100%;
  363. display: flex;
  364. flex-direction: column;
  365. background-color: #ffffff;
  366. border-radius: 10px;
  367. padding: 16px 10px 14px;
  368. box-sizing: border-box;
  369. .side_title {
  370. font-weight: 500;
  371. font-size: 16px;
  372. color: #333333;
  373. }
  374. .side_item {
  375. margin-top: 16px;
  376. background-color: #ffffff;
  377. border-radius: 4px;
  378. border: 1px solid #dcdfe6;
  379. width: 100%;
  380. padding: 10px;
  381. box-sizing: border-box;
  382. cursor: pointer;
  383. &.active {
  384. background: rgba(46, 100, 250, 0.1);
  385. border: 1px solid #2e64fa;
  386. }
  387. .item_name {
  388. width: 100%;
  389. font-weight: 500;
  390. font-size: 14px;
  391. color: #333333;
  392. white-space: nowrap;
  393. overflow: hidden;
  394. text-overflow: ellipsis;
  395. }
  396. .item_content {
  397. width: 100%;
  398. display: flex;
  399. justify-content: space-between;
  400. margin-top: 10px;
  401. .content_left {
  402. flex: 1;
  403. display: flex;
  404. font-weight: 400;
  405. font-size: 12px;
  406. color: #999999;
  407. .content_type {
  408. flex-shrink: 0;
  409. margin-right: 10px;
  410. }
  411. .content_num {
  412. flex-shrink: 0;
  413. }
  414. }
  415. .ai_explain {
  416. flex-shrink: 0;
  417. display: flex;
  418. align-items: center;
  419. .ai_icon {
  420. width: 14px;
  421. height: 14px;
  422. margin-right: 4px;
  423. }
  424. span {
  425. font-weight: 400;
  426. font-size: 14px;
  427. color: #4f3eff;
  428. }
  429. }
  430. }
  431. }
  432. }
  433. .main_body {
  434. padding: 0 0 0 10px;
  435. overflow: hidden;
  436. .content_main {
  437. width: 100%;
  438. height: 100%;
  439. padding: 20px 0;
  440. display: flex;
  441. flex-direction: column;
  442. box-sizing: border-box;
  443. background-color: #ffffff;
  444. border-radius: 10px;
  445. .content_title {
  446. display: flex;
  447. width: 100%;
  448. padding: 0 20px 20px;
  449. box-sizing: border-box;
  450. justify-content: space-between;
  451. align-items: center;
  452. .title_name {
  453. font-weight: 500;
  454. font-size: 16px;
  455. color: #333333;
  456. flex: 1;
  457. white-space: nowrap;
  458. overflow: hidden;
  459. text-overflow: ellipsis;
  460. margin-right: 10px;
  461. }
  462. .button {
  463. display: flex;
  464. :deep(.el-button) {
  465. padding: 10px 20px;
  466. }
  467. .download_btn {
  468. color: #666666;
  469. &:hover {
  470. border-color: #dcdfe6;
  471. }
  472. &:focus {
  473. border-color: #dcdfe6;
  474. }
  475. }
  476. }
  477. }
  478. .question_list {
  479. display: flex;
  480. flex-direction: column;
  481. width: 100%;
  482. padding: 0 20px;
  483. overflow: auto;
  484. box-sizing: border-box;
  485. flex: 1;
  486. .question_item {
  487. background: #ffffff;
  488. border-radius: 10px 10px 10px 10px;
  489. border: 1px solid #dcdfe6;
  490. :deep(.question_preview) {
  491. padding: 16px;
  492. box-sizing: border-box;
  493. }
  494. &:first-child {
  495. margin-top: 0;
  496. }
  497. margin-top: 20px;
  498. .question_footer {
  499. padding: 20px 16px;
  500. background-color: #f8f8f9;
  501. border-top: 1px solid #dcdfe6;
  502. display: flex;
  503. // align-items: center;
  504. &.img_list {
  505. padding: 16px;
  506. .footer_title {
  507. line-height: 48px;
  508. }
  509. }
  510. .footer_title {
  511. font-weight: 500;
  512. font-size: 14px;
  513. color: #333333;
  514. line-height: 24px;
  515. }
  516. .upload_answer {
  517. flex: 1;
  518. display: flex;
  519. flex-wrap: wrap;
  520. .img_uploader {
  521. // display: flex;
  522. // flex-direction: row-reverse;
  523. // justify-content: flex-end;
  524. // align-items: center;
  525. :deep(.el-upload-list--picture-card) {
  526. .el-upload-list__item {
  527. width: 64px;
  528. height: 48px;
  529. margin: 0 20px 8px 0;
  530. background-color: #f0f4f8;
  531. border-radius: 2px 2px 2px 2px;
  532. border: 1px solid #ebeef5;
  533. }
  534. }
  535. :deep(.el-upload--picture-card) {
  536. background-color: transparent;
  537. border: 0;
  538. height: 48px;
  539. width: auto;
  540. line-height: 48px;
  541. border-radius: 0;
  542. margin-right: 22px;
  543. }
  544. .upload_btn {
  545. border: 1px solid #2e64fa;
  546. font-weight: 400;
  547. font-size: 14px;
  548. color: #2e64fa;
  549. padding: 9px 15px;
  550. }
  551. }
  552. .upload_list_item {
  553. width: 64px;
  554. height: 48px;
  555. margin: 0 20px 8px 0;
  556. background-color: #f0f4f8;
  557. border-radius: 2px 2px 2px 2px;
  558. border: 1px solid #ebeef5;
  559. box-sizing: border-box;
  560. overflow: hidden;
  561. position: relative;
  562. cursor: pointer;
  563. img {
  564. width: 100%;
  565. height: 100%;
  566. object-fit: cover;
  567. }
  568. .upload_list_item_delete {
  569. position: absolute;
  570. top: 3px;
  571. right: 3px;
  572. font-size: 16px;
  573. cursor: pointer;
  574. color: rgba(0, 0, 0, 0.5);
  575. }
  576. }
  577. }
  578. .radio_group {
  579. :deep(.el-radio) {
  580. line-height: 24px;
  581. font-weight: 400;
  582. font-size: 14px;
  583. color: #333333;
  584. margin-right: 20px;
  585. .el-radio__input {
  586. &.is-checked + .el-radio__label {
  587. color: #333333;
  588. }
  589. &.is-checked .el-radio__inner {
  590. border-color: #2e64fa;
  591. background-color: #ffff;
  592. }
  593. .el-radio__inner {
  594. width: 16px;
  595. height: 16px;
  596. border-color: rgba(0, 0, 0, 0.2);
  597. &::after {
  598. width: 10px;
  599. height: 10px;
  600. background-color: #2e64fa;
  601. }
  602. }
  603. }
  604. .el-radio__label {
  605. padding-left: 4px;
  606. }
  607. }
  608. }
  609. .checkbox_group {
  610. //多选
  611. :deep(.el-checkbox) {
  612. line-height: 24px;
  613. font-weight: 400;
  614. font-size: 14px;
  615. color: #333333;
  616. margin-right: 20px;
  617. .is-checked + .el-checkbox__label {
  618. color: #333333;
  619. }
  620. .is-checked .el-checkbox__inner {
  621. border-color: #2e64fa;
  622. }
  623. .el-checkbox__input {
  624. .el-checkbox__inner {
  625. width: 16px;
  626. height: 16px;
  627. border-color: rgba(0, 0, 0, 0.2);
  628. &::after {
  629. left: 5px;
  630. }
  631. }
  632. }
  633. .el-checkbox__label {
  634. padding-left: 4px;
  635. line-height: 24px;
  636. }
  637. }
  638. }
  639. }
  640. }
  641. }
  642. }
  643. }
  644. }
  645. .dialog_img {
  646. height: 70vh;
  647. text-align: center;
  648. overflow: auto;
  649. }
  650. .dialog_paper {
  651. padding: 8px 4px;
  652. display: flex;
  653. flex-direction: column;
  654. gap: 20px;
  655. .dialog_paper_item {
  656. height: 36px;
  657. display: flex;
  658. align-items: center;
  659. .dialog_paper_title {
  660. font-weight: 400;
  661. font-size: 14px;
  662. color: #303133;
  663. margin-right: 10px;
  664. }
  665. .radio_group {
  666. :deep(.el-radio) {
  667. line-height: 24px;
  668. font-weight: 400;
  669. font-size: 14px;
  670. color: #333333;
  671. margin-right: 40px;
  672. .el-radio__input {
  673. &.is-checked + .el-radio__label {
  674. color: #333333;
  675. }
  676. &.is-checked .el-radio__inner {
  677. border-color: #2e64fa;
  678. background-color: #ffff;
  679. }
  680. .el-radio__inner {
  681. width: 16px;
  682. height: 16px;
  683. border-color: rgba(0, 0, 0, 0.2);
  684. &::after {
  685. width: 10px;
  686. height: 10px;
  687. background-color: #2e64fa;
  688. }
  689. }
  690. }
  691. .el-radio__label {
  692. padding-left: 4px;
  693. }
  694. }
  695. }
  696. }
  697. }
  698. </style>