practiceAnswer.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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" @click="OpenAi(item)">
  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.studentAnswer"
  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.studentAnswer"
  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.studentAnswer"
  108. :key="index"
  109. @click="HandlePictureCardPreview(url)"
  110. >
  111. <img :src="url" />
  112. <i
  113. @click.stop="HandleRemove(item.studentAnswer,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","subjectName"]),
  176. },
  177. inject: ['openAiRobot'],//注入Ai机器人组件调用方法
  178. data() {
  179. return {
  180. waitList: [], //待练习知识点
  181. exerciseId: "", // 练习id
  182. knowledgeName: "", //知识点名称
  183. questionList: [],
  184. optionsData: [
  185. "A",
  186. "B",
  187. "C",
  188. "D",
  189. "E",
  190. "F",
  191. "G",
  192. "H",
  193. "I",
  194. "J",
  195. "K",
  196. "L",
  197. "M",
  198. "N",
  199. "O",
  200. "P",
  201. "Q",
  202. "R",
  203. "S",
  204. "T",
  205. "U",
  206. "V",
  207. "W",
  208. "X",
  209. "Y",
  210. "Z",
  211. ],
  212. getToken: getToken(),
  213. uploadUrl: '',//上传图片地址
  214. dialogImageUrl: "", //图片预览
  215. dialogVisible: false, //图片预览
  216. dialogPaperVisible: false, //下载试卷
  217. radio: 3, //下载试卷
  218. };
  219. },
  220. watch: {},
  221. mounted() {
  222. this.GetUploadUrl();
  223. this.GetStudentTargeWaitExercise();
  224. },
  225. methods: {
  226. //获取上传图片地址
  227. GetUploadUrl(){
  228. this.uploadUrl = `${base.prefix}/api/v1/student_upload/oss/upload_filesSele`;
  229. },
  230. //打开AI解读
  231. OpenAi(item)
  232. {
  233. console.log("打开AI解读",item);
  234. console.log("this.subjectName",this.subjectName);
  235. let content = "科目:"+this.subjectName+",知识点:"+item.knowledgeName;
  236. this.openAiRobot(content);
  237. },
  238. //待练习知识点
  239. GetStudentTargeWaitExercise() {
  240. this.$api.target
  241. .studentTargeWaitExercise({
  242. levelCode: this.levelCode, // 学段code
  243. subjectCode: this.subjectCode, //学科code
  244. })
  245. .then((res) => {
  246. if (res.code == 200) {
  247. this.waitList = res?.data || [];
  248. if (this.waitList.length > 0) {
  249. this.exerciseId = this.waitList?.[0]?.exerciseId || "";
  250. this.knowledgeName = this.waitList?.[0]?.knowledgeName || "";
  251. this.GetStudentTargeExerciseQuestion();
  252. }else{
  253. this.exerciseId = "";
  254. this.knowledgeName = "";
  255. this.questionList = [];
  256. }
  257. }
  258. });
  259. },
  260. // 查询试题列表(type 1待练习的列表 2已练习的列表)
  261. GetStudentTargeExerciseQuestion() {
  262. this.$api.target
  263. .studentTargeExerciseQuestion({
  264. exerciseId: this.exerciseId, // 练习id
  265. type: 1, // 1待练习的列表 2已练习的列表
  266. })
  267. .then((res) => {
  268. if (res.code == 200) {
  269. // 客观题->选择、判断。主观题->上传图片
  270. // isObjective 是否客观题 1是 0否 isJudge 是否判断题 1是 0否
  271. const questionList = res?.data || [];
  272. questionList.forEach((item) => {
  273. if (Number(item.isObjective) === 1) {
  274. //客观题
  275. let studentAnswer = "";
  276. if (Number(item.isJudge) === 1) {
  277. //判断题
  278. studentAnswer = item.studentAnswer || "";
  279. } else {
  280. //选择题
  281. studentAnswer = item.studentAnswer ? (item?.studentAnswer?.split('') || []) : [];
  282. }
  283. item.studentAnswer = studentAnswer;
  284. } else {
  285. item.studentAnswer = item.studentAnswer ? (item?.studentAnswer?.split(',') || []) : [];
  286. }
  287. });
  288. this.questionList = questionList;
  289. } else {
  290. this.questionList = [];
  291. }
  292. });
  293. },
  294. //切换知识点
  295. ChangeKnowledge(item) {
  296. if (this.exerciseId == item.exerciseId) {
  297. return;
  298. }
  299. this.exerciseId = item.exerciseId || "";
  300. this.knowledgeName = item.knowledgeName || "";
  301. this.GetStudentTargeExerciseQuestion();
  302. },
  303. //判断题改变
  304. HandleJudgeChange(item) {
  305. item.studentAnswer = item.studentAnswer || "";
  306. this.SubmitQuestionAnswering(item.exerciseQueId,item.studentAnswer);
  307. },
  308. //选择题改变
  309. HandleCheckChange(item) {
  310. item.studentAnswer = item.studentAnswer || [];
  311. const studentAnswer = item?.studentAnswer?.join('') || '';
  312. this.SubmitQuestionAnswering(item.exerciseQueId,studentAnswer);
  313. },
  314. // 超出最大数量触发
  315. HandleExceed(files, fileList) {
  316. this.$message.warning(`最多只能上传10张图片`)
  317. },
  318. //上传图片成功
  319. HandleUploadSuccess(res, file, fileList,item){
  320. if(res.code == 200){
  321. const url = res?.data?.url || '';
  322. item.studentAnswer.push(url);
  323. const studentAnswer = item?.studentAnswer?.join(',') || '';
  324. this.SubmitQuestionAnswering(item.exerciseQueId,studentAnswer);
  325. }
  326. },
  327. //删除图片
  328. HandleRemove(studentAnswer,index) {
  329. studentAnswer.splice(index, 1);
  330. },
  331. //提交答案
  332. SubmitQuestionAnswering(exerciseQueId,stuAnswer) {
  333. this.$api.target.studentTargeQuestionAnswering({
  334. exerciseQueId: exerciseQueId, // 练习试题id
  335. stuAnswer: stuAnswer, // 学生答案
  336. }).then((res) => {
  337. if (res.code == 200) {
  338. // this.$message.success('提交成功');
  339. }
  340. });
  341. },
  342. //提交作答
  343. SubmitAnswer(){
  344. console.log(this.questionList)
  345. const studentAnswers = this.questionList.map(item=>item.studentAnswer);
  346. const hasInvalid = studentAnswers.some(item => {
  347. // 判断 null 或 undefined
  348. if (item == null) return true;
  349. // 判断空字符串
  350. if (item === '') return true;
  351. // 判断空数组
  352. if (Array.isArray(item) && item.length === 0) return true;
  353. return false;
  354. });
  355. if (hasInvalid) {
  356. this.$message.warning('不能提交空答案');
  357. return;
  358. }
  359. this.$api.target.studentTargeSubmitExercise({
  360. exerciseId: this.exerciseId, // 练习id
  361. }).then((res) => {
  362. if (res.code == 200) {
  363. this.$message.success('提交成功');
  364. this.GetStudentTargeWaitExercise();//获取待练习知识点
  365. }
  366. });
  367. },
  368. //图片预览
  369. HandlePictureCardPreview(url) {
  370. this.dialogImageUrl = url;
  371. this.dialogVisible = true;
  372. },
  373. //下载试卷
  374. downloadPaper() {
  375. this.dialogPaperVisible = true;
  376. },
  377. //确定下载
  378. ConfirmDownloadPaper() {
  379. this.dialogPaperVisible = false;
  380. },
  381. },
  382. };
  383. </script>
  384. <style scoped lang="scss">
  385. .practice_answer {
  386. flex: 1;
  387. width: 100%;
  388. overflow: hidden;
  389. .side_list {
  390. width: 100%;
  391. display: flex;
  392. flex-direction: column;
  393. background-color: #ffffff;
  394. border-radius: 10px;
  395. padding: 16px 10px 14px;
  396. box-sizing: border-box;
  397. .side_title {
  398. font-weight: 550;
  399. font-size: 16px;
  400. color: #333333;
  401. }
  402. .side_item {
  403. margin-top: 16px;
  404. background-color: #ffffff;
  405. border-radius: 4px;
  406. border: 1px solid #dcdfe6;
  407. width: 100%;
  408. padding: 10px;
  409. box-sizing: border-box;
  410. cursor: pointer;
  411. &.active {
  412. background: rgba(46, 100, 250, 0.1);
  413. border: 1px solid #2e64fa;
  414. }
  415. .item_name {
  416. width: 100%;
  417. font-weight: 500;
  418. font-size: 14px;
  419. color: #333333;
  420. white-space: nowrap;
  421. overflow: hidden;
  422. text-overflow: ellipsis;
  423. }
  424. .item_content {
  425. width: 100%;
  426. display: flex;
  427. justify-content: space-between;
  428. margin-top: 10px;
  429. .content_left {
  430. flex: 1;
  431. display: flex;
  432. font-weight: 400;
  433. font-size: 12px;
  434. color: #999999;
  435. .content_type {
  436. flex-shrink: 0;
  437. margin-right: 10px;
  438. }
  439. .content_num {
  440. flex-shrink: 0;
  441. }
  442. }
  443. .ai_explain {
  444. flex-shrink: 0;
  445. display: flex;
  446. align-items: center;
  447. .ai_icon {
  448. width: 14px;
  449. height: 14px;
  450. margin-right: 4px;
  451. }
  452. span {
  453. font-weight: 400;
  454. font-size: 14px;
  455. color: #4f3eff;
  456. }
  457. }
  458. }
  459. }
  460. }
  461. .main_body {
  462. padding: 0 0 0 10px;
  463. overflow: hidden;
  464. .content_main {
  465. width: 100%;
  466. height: 100%;
  467. padding: 20px 0;
  468. display: flex;
  469. flex-direction: column;
  470. box-sizing: border-box;
  471. background-color: #ffffff;
  472. border-radius: 10px;
  473. .content_title {
  474. display: flex;
  475. width: 100%;
  476. padding: 0 20px 20px;
  477. box-sizing: border-box;
  478. justify-content: space-between;
  479. align-items: center;
  480. .title_name {
  481. font-weight: 500;
  482. font-size: 16px;
  483. color: #333333;
  484. flex: 1;
  485. white-space: nowrap;
  486. overflow: hidden;
  487. text-overflow: ellipsis;
  488. margin-right: 10px;
  489. }
  490. .button {
  491. display: flex;
  492. :deep(.el-button) {
  493. padding: 10px 20px;
  494. }
  495. .download_btn {
  496. color: #666666;
  497. &:hover {
  498. border-color: #dcdfe6;
  499. }
  500. &:focus {
  501. border-color: #dcdfe6;
  502. }
  503. }
  504. }
  505. }
  506. .question_list {
  507. display: flex;
  508. flex-direction: column;
  509. width: 100%;
  510. padding: 0 20px;
  511. overflow: auto;
  512. box-sizing: border-box;
  513. flex: 1;
  514. .question_item {
  515. background: #ffffff;
  516. border-radius: 10px 10px 10px 10px;
  517. border: 1px solid #dcdfe6;
  518. :deep(.question_preview) {
  519. padding: 16px;
  520. box-sizing: border-box;
  521. }
  522. &:first-child {
  523. margin-top: 0;
  524. }
  525. margin-top: 20px;
  526. .question_footer {
  527. padding: 20px 16px;
  528. background-color: #f8f8f9;
  529. border-top: 1px solid #dcdfe6;
  530. display: flex;
  531. // align-items: center;
  532. &.img_list {
  533. padding: 16px;
  534. .footer_title {
  535. line-height: 48px;
  536. }
  537. }
  538. .footer_title {
  539. font-weight: 500;
  540. font-size: 14px;
  541. color: #333333;
  542. line-height: 24px;
  543. }
  544. .upload_answer {
  545. flex: 1;
  546. display: flex;
  547. flex-wrap: wrap;
  548. .img_uploader {
  549. // display: flex;
  550. // flex-direction: row-reverse;
  551. // justify-content: flex-end;
  552. // align-items: center;
  553. :deep(.el-upload-list--picture-card) {
  554. .el-upload-list__item {
  555. width: 64px;
  556. height: 48px;
  557. margin: 0 20px 8px 0;
  558. background-color: #f0f4f8;
  559. border-radius: 2px 2px 2px 2px;
  560. border: 1px solid #ebeef5;
  561. }
  562. }
  563. :deep(.el-upload--picture-card) {
  564. background-color: transparent;
  565. border: 0;
  566. height: 48px;
  567. width: auto;
  568. line-height: 48px;
  569. border-radius: 0;
  570. margin-right: 22px;
  571. }
  572. .upload_btn {
  573. border: 1px solid #2e64fa;
  574. font-weight: 400;
  575. font-size: 14px;
  576. color: #2e64fa;
  577. padding: 9px 15px;
  578. }
  579. }
  580. .upload_list_item {
  581. width: 64px;
  582. height: 48px;
  583. margin: 0 20px 8px 0;
  584. background-color: #f0f4f8;
  585. border-radius: 2px 2px 2px 2px;
  586. border: 1px solid #ebeef5;
  587. box-sizing: border-box;
  588. overflow: hidden;
  589. position: relative;
  590. cursor: pointer;
  591. img {
  592. width: 100%;
  593. height: 100%;
  594. object-fit: cover;
  595. }
  596. .upload_list_item_delete {
  597. position: absolute;
  598. top: 3px;
  599. right: 3px;
  600. font-size: 16px;
  601. cursor: pointer;
  602. color: rgba(0, 0, 0, 0.5);
  603. }
  604. }
  605. }
  606. .radio_group {
  607. :deep(.el-radio) {
  608. line-height: 24px;
  609. font-weight: 400;
  610. font-size: 14px;
  611. color: #333333;
  612. margin-right: 20px;
  613. .el-radio__input {
  614. &.is-checked + .el-radio__label {
  615. color: #333333;
  616. }
  617. &.is-checked .el-radio__inner {
  618. border-color: #2e64fa;
  619. background-color: #ffff;
  620. }
  621. .el-radio__inner {
  622. width: 16px;
  623. height: 16px;
  624. border-color: rgba(0, 0, 0, 0.2);
  625. &::after {
  626. width: 10px;
  627. height: 10px;
  628. background-color: #2e64fa;
  629. }
  630. }
  631. }
  632. .el-radio__label {
  633. padding-left: 4px;
  634. }
  635. }
  636. }
  637. .checkbox_group {
  638. //多选
  639. :deep(.el-checkbox) {
  640. line-height: 24px;
  641. font-weight: 400;
  642. font-size: 14px;
  643. color: #333333;
  644. margin-right: 20px;
  645. .is-checked + .el-checkbox__label {
  646. color: #333333;
  647. }
  648. .is-checked .el-checkbox__inner {
  649. border-color: #2e64fa;
  650. }
  651. .el-checkbox__input {
  652. .el-checkbox__inner {
  653. width: 16px;
  654. height: 16px;
  655. border-color: rgba(0, 0, 0, 0.2);
  656. &::after {
  657. left: 5px;
  658. }
  659. }
  660. }
  661. .el-checkbox__label {
  662. padding-left: 4px;
  663. line-height: 24px;
  664. }
  665. }
  666. }
  667. }
  668. }
  669. }
  670. }
  671. }
  672. }
  673. .dialog_img {
  674. height: 70vh;
  675. text-align: center;
  676. overflow: auto;
  677. }
  678. .dialog_paper {
  679. padding: 8px 4px;
  680. display: flex;
  681. flex-direction: column;
  682. gap: 20px;
  683. .dialog_paper_item {
  684. height: 36px;
  685. display: flex;
  686. align-items: center;
  687. .dialog_paper_title {
  688. font-weight: 400;
  689. font-size: 14px;
  690. color: #303133;
  691. margin-right: 10px;
  692. }
  693. .radio_group {
  694. :deep(.el-radio) {
  695. line-height: 24px;
  696. font-weight: 400;
  697. font-size: 14px;
  698. color: #333333;
  699. margin-right: 40px;
  700. .el-radio__input {
  701. &.is-checked + .el-radio__label {
  702. color: #333333;
  703. }
  704. &.is-checked .el-radio__inner {
  705. border-color: #2e64fa;
  706. background-color: #ffff;
  707. }
  708. .el-radio__inner {
  709. width: 16px;
  710. height: 16px;
  711. border-color: rgba(0, 0, 0, 0.2);
  712. &::after {
  713. width: 10px;
  714. height: 10px;
  715. background-color: #2e64fa;
  716. }
  717. }
  718. }
  719. .el-radio__label {
  720. padding-left: 4px;
  721. }
  722. }
  723. }
  724. }
  725. }
  726. </style>