paper.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <div class="app-container" >
  3. <div id="paperContainer">
  4. <el-card style="margin-bottom: 10px; text-align: center">
  5. <el-input v-model="papername" style="width: 150px" />
  6. <el-button style="margin-left: 10px" type="text" @click="savePaper" :loading="isLoading">保存试卷</el-button>
  7. <el-button style="margin-left: 10px" type="text" @click="toQuestionList()">返回</el-button>
  8. </el-card>
  9. <el-card style="margin-bottom: 10px" v-for="(questionData, index) in questionList" :key="index">
  10. <div :class="'drag_' + index">
  11. <div slot="header" class="clearfix" @mouseover="showSorce(questionData, index)" @mouseout="hideSorce(questionData, index)" draggable="true" @dragstart="handleDragStart($event, questionData)" @dragover.prevent="handleDragOver($event, questionData)" @drop="handleDragEnter($event, questionData)" @dragend="handleDragEnd($event, questionData)">
  12. <span style="color: #000000; font-size: 14px; font-weight: bold">{{ NumberToChinese(index + 1) }}、{{ questionData.title }}(共{{
  13. questionData.num
  14. }}题;共{{ questionData.score }}分)</span>
  15. <span style="float: right; display: none" :id="'parent_score_' + index">
  16. <el-button type="text" @click="openParentScore = true,currentIndex = index">批量设置得分</el-button>
  17. <el-button type="text" @click="deleteType(index)">删除分类</el-button>
  18. </span>
  19. </div>
  20. <div v-for="(questionInfo, index2) in questionData.list" :key="index2" style="margin-bottom: 10px" @mouseover="showQuestionSorce(index, index2)" @mouseout="hideQuestionSorce(index, index2)" @dragstart="handleQuestionDragStart($event, questionInfo, index2)" @dragover.prevent="handleQuestionDragOver($event, questionInfo)" @drop="handleQuestionDragEnter($event, questionInfo, index, index2)" @dragend="handleQuestionDragEnd($event, questionInfo)" draggable="true">
  21. <div style="display: none" :id="'score_' + index + '_' + index2">
  22. <el-button type="text" @click="
  23. openScore = true;
  24. currentIndex = index;
  25. questionIndex = index2;
  26. ">设置得分</el-button>
  27. <el-button type="text" @click="setCurrentVal(index, index2, questionInfo)">解析</el-button>
  28. <el-button type="text" @click="deleteQuestion(index, index2)">删除题目</el-button>
  29. </div>
  30. <div>
  31. {{ index2 + 1 }}.
  32. <span style="color: #1890ff">题号:{{ questionInfo.id }}({{ questionInfo.score }}分)</span><span v-html="questionInfo.title"></span>
  33. </div>
  34. <div v-for="child in questionInfo.subquestions" v-html="child.title"></div>
  35. </div>
  36. </div>
  37. </el-card>
  38. <!-- 批量设置分数-->
  39. <el-dialog :visible.sync="openParentScore" width="500px" append-to-body>
  40. <el-form label-width="80px">
  41. <el-form-item label="分数" prop="parentScore">
  42. <el-input-number v-model.number="parentScore" :min="1" placeholder="请输入分数" />
  43. </el-form-item>
  44. </el-form>
  45. <div slot="footer" class="dialog-footer">
  46. <el-button type="primary" @click="setParentScore">确 定</el-button>
  47. <el-button @click="openParentScore = false">取 消</el-button>
  48. </div>
  49. </el-dialog>
  50. <!-- 设置题目分数 -->
  51. <el-dialog :visible.sync="openScore" width="500px" append-to-body>
  52. <el-form label-width="80px">
  53. <el-form-item label="分数" prop="parentScore">
  54. <el-input-number v-model.number="questionScore" :min="1" placeholder="请输入分数" />
  55. </el-form-item>
  56. </el-form>
  57. <div slot="footer" class="dialog-footer">
  58. <el-button type="primary" @click="setScore">确 定</el-button>
  59. <el-button @click="openScore = false">取 消</el-button>
  60. </div>
  61. </el-dialog>
  62. </div>
  63. <!-- 试题篮 -->
  64. <el-dialog v-if="openQuestionParseDialog" title="解析" :visible.sync="openQuestionParseDialog" width="70%" append-to-body center>
  65. <el-form label-width="80px" id="paperDialog" >
  66. <el-form-item label="解析">
  67. <div v-html="currentQuestionParse"></div>
  68. <!-- <editor v-model="currentQuestionParse" :min-height="122" />-->
  69. </el-form-item>
  70. <!-- <el-form-item label="答案1">-->
  71. <!-- <div v-html="currentQuestionAnswer1"></div>-->
  72. <!--&lt;!&ndash; <editor v-model="currentQuestionAnswer1" :min-height="122" />&ndash;&gt;-->
  73. <!-- </el-form-item>-->
  74. <el-form-item label="答案2">
  75. <div v-html="currentQuestionAnswer2"></div>
  76. <!-- <editor v-model="currentQuestionAnswer2" :min-height="122" />-->
  77. </el-form-item>
  78. </el-form>
  79. <div slot="footer" class="dialog-footer">
  80. <el-button type="primary" @click="setQuestionParse">确 定</el-button>
  81. <el-button @click="openQuestionParseDialog = false">取 消</el-button>
  82. </div>
  83. </el-dialog>
  84. </div>
  85. </template>
  86. <script>
  87. import { savePaperInfo, deleteQuestionCard } from "@/api/webApi/webQue.js";
  88. import Editor from "@/components/Editor";
  89. import EventBus from '@/components/EventBus'
  90. import consts from '@/common/mx-const'
  91. export default {
  92. name: "Paper",
  93. components: {
  94. Editor,
  95. },
  96. data() {
  97. return {
  98. extraData: {},
  99. isLoading: false,
  100. currentTypeIndex: 0,
  101. currentQuestionIndex: 0,
  102. currentQuestionParse: "",
  103. currentQuestionAnswer1: "",
  104. currentQuestionAnswer2: "",
  105. openQuestionParseDialog: false,
  106. openScore: false,
  107. questionScore: null,
  108. currentIndex: null,
  109. questionIndex: null,
  110. parentScore: "",
  111. openParentScore: false,
  112. papername: "试卷标题",
  113. questionList: [],
  114. chnNumChar: ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"],
  115. chnUnitSection: ["", "万", "亿", "万亿", "亿亿"],
  116. chnUnitChar: ["", "十", "百", "千"],
  117. qtype: [],
  118. jsonData: {},
  119. dragging: null,
  120. questionDragging: null,
  121. questionIndex2: null,
  122. };
  123. },
  124. mounted() {
  125. this.extraData = this.$route.query || {}
  126. this.getQuestionList();
  127. },
  128. deactivated() {
  129. EventBus.instance.$emit(consts.keys.keyGenerationCartChanged)
  130. },
  131. beforeDestroy() {
  132. EventBus.instance.$emit(consts.keys.keyGenerationCartChanged)
  133. },
  134. watch: {
  135. $route() {
  136. this.getQuestionList();
  137. },
  138. },
  139. methods: {
  140. setCurrentVal(index, index2, questionInfo) {
  141. this.openQuestionParseDialog = true;
  142. this.currentTypeIndex = index;
  143. this.currentQuestionIndex = index2;
  144. this.currentQuestionParse = questionInfo.parse;
  145. this.currentQuestionAnswer1 = questionInfo.answer1;
  146. this.currentQuestionAnswer2 = questionInfo.answer2;
  147. setTimeout(_=>{
  148. this.mxGlobal.MathQueue("paperDialog")
  149. }, 500)
  150. },
  151. getQuestionList() {
  152. this.questionList = []
  153. this.jsonData = JSON.parse(localStorage.getItem("paperData"))
  154. this.papername = this.jsonData.paperTitle || this.papername
  155. const source = JSON.parse(localStorage.getItem("questionList"))
  156. const groupedSource = source.groupBy(q => q.qtpye)
  157. this.questionList = groupedSource.map(g => ({
  158. title: g.label,
  159. list: g.options,
  160. num: g.options.length,
  161. score: g.options.sum(q => q.score)
  162. }))
  163. this.$nextTick(_=>this.mxGlobal.MathQueue("paperContainer"))
  164. },
  165. SectionToChinese(section) {
  166. var strIns = "",
  167. chnStr = "";
  168. var unitPos = 0;
  169. var zero = true;
  170. while (section > 0) {
  171. var v = section % 10;
  172. if (v === 0) {
  173. if (!zero) {
  174. zero = true;
  175. chnStr = this.chnNumChar[v] + chnStr;
  176. }
  177. } else {
  178. zero = false;
  179. strIns = this.chnNumChar[v];
  180. strIns += this.chnUnitChar[unitPos];
  181. chnStr = strIns + chnStr;
  182. }
  183. unitPos++;
  184. section = Math.floor(section / 10);
  185. }
  186. return chnStr;
  187. },
  188. NumberToChinese(num) {
  189. var unitPos = 0;
  190. var strIns = "",
  191. chnStr = "";
  192. var needZero = false;
  193. if (num === 0) {
  194. return this.chnNumChar[0];
  195. }
  196. while (num > 0) {
  197. var section = num % 10000;
  198. if (needZero) {
  199. chnStr = this.chnNumChar[0] + chnStr;
  200. }
  201. strIns = this.SectionToChinese(section);
  202. strIns +=
  203. section !== 0 ? this.chnUnitSection[unitPos] : this.chnUnitSection[0];
  204. chnStr = strIns + chnStr;
  205. needZero = section < 1000 && section > 0;
  206. num = Math.floor(num / 10000);
  207. unitPos++;
  208. }
  209. return chnStr;
  210. },
  211. showSorce(data, index) {
  212. let doc = document.getElementById("parent_score_" + index);
  213. doc.style.display = "block";
  214. },
  215. hideSorce(data, index) {
  216. let doc = document.getElementById("parent_score_" + index);
  217. doc.style.display = "none";
  218. },
  219. setParentScore() {
  220. let data = this.questionList[this.currentIndex];
  221. let len = data.list.length;
  222. data.score = len * this.parentScore;
  223. for (let q of data.list) {
  224. q.score = this.parentScore;
  225. }
  226. this.openParentScore = false;
  227. },
  228. setScore() {
  229. this.questionList[this.currentIndex].list[this.questionIndex].score =
  230. this.questionScore;
  231. let list = this.questionList[this.currentIndex].list;
  232. let score = 0;
  233. for (let q of list) {
  234. score = q.score + score;
  235. }
  236. this.questionList[this.currentIndex].score = score;
  237. this.openScore = false;
  238. },
  239. showQuestionSorce(pIndex, qIndex) {
  240. let doc = document.getElementById("score_" + pIndex + "_" + qIndex);
  241. doc.style.display = "block";
  242. },
  243. hideQuestionSorce(pIndex, qIndex) {
  244. let doc = document.getElementById("score_" + pIndex + "_" + qIndex);
  245. doc.style.display = "none";
  246. },
  247. deleteType(index) {
  248. this.questionList.splice(index, 1);
  249. },
  250. deleteQuestion(pIndex, qIndex) {
  251. let data = this.questionList[pIndex].list[qIndex];
  252. this.questionList[pIndex].list.splice(qIndex, 1);
  253. this.questionList[pIndex].num--;
  254. this.questionList[pIndex].score =
  255. this.questionList[pIndex].score - data.score;
  256. },
  257. toQuestionList() {
  258. this.$router.back()
  259. },
  260. savePaper() {
  261. let list = [];
  262. let index = 1;
  263. let remark = ''
  264. for (let item of this.questionList) {
  265. remark += item.title + "(" + item.score + ")分;"
  266. for (let item1 of item.list) {
  267. let data = {
  268. questionId: item1.id,
  269. seq: index,
  270. score: item1.score,
  271. knowledgeId: item1.knowledgeId,
  272. knowledgeName: item1.knowledgeName,
  273. answer1: item1.answer1,
  274. answer2: item1.answer2,
  275. parse: item1.parse,
  276. };
  277. index++;
  278. list.push(data);
  279. }
  280. }
  281. let param = {
  282. ...this.extraData,
  283. subjectid: this.jsonData.subjectId ? this.jsonData.subjectId : 0,
  284. subjectName: this.jsonData.subjectName || '',
  285. gradeId: this.jsonData.gradeId,
  286. buildType: this.jsonData.buildType,
  287. name: this.papername,
  288. remark: remark,
  289. paperId: this.jsonData.paperId,
  290. paperQuestions: list,
  291. };
  292. this.isLoading = true;
  293. savePaperInfo(param)
  294. .then((response) => {
  295. this.msgSuccess("保存成功");
  296. this.isLoading = false;
  297. localStorage.setItem("paperData", JSON.stringify({}));
  298. localStorage.setItem("questionList", JSON.stringify([]));
  299. deleteQuestionCard(this.extraData).then(res => this.$router.back())
  300. })
  301. .catch((err) => {
  302. this.isLoading = false;
  303. console.log(err);
  304. });
  305. },
  306. setQuestionParse() {
  307. this.questionList[this.currentTypeIndex].list[
  308. this.currentQuestionIndex
  309. ].parse = this.currentQuestionParse;
  310. this.questionList[this.currentTypeIndex].list[
  311. this.currentQuestionIndex
  312. ].answer1 = this.currentQuestionAnswer1;
  313. this.questionList[this.currentTypeIndex].list[
  314. this.currentQuestionIndex
  315. ].answer2 = this.currentQuestionAnswer2;
  316. this.openQuestionParseDialog = false;
  317. },
  318. // 拖动
  319. handleDragStart(e, item) {
  320. console.log(item);
  321. this.dragging = item;
  322. },
  323. handleDragEnd(e, item) {
  324. this.dragging = null;
  325. },
  326. handleDragOver(e) {
  327. e.dataTransfer.dropEffect = "move"; // e.dataTransfer.dropEffect="move";//在dragenter中针对放置目标来设置!
  328. },
  329. handleDragEnter(e, item) {
  330. e.dataTransfer.effectAllowed = "move"; //为需要移动的元素设置dragstart事件
  331. if (item === this.dragging) {
  332. return;
  333. }
  334. const newItems = this.questionList;
  335. const src = newItems.indexOf(this.dragging);
  336. const dst = newItems.indexOf(item);
  337. newItems.splice(dst, 0, ...newItems.splice(src, 1));
  338. this.questionList = newItems;
  339. },
  340. // 拖动
  341. handleQuestionDragStart(e, item, index2) {
  342. this.questionDragging = item;
  343. this.questionIndex2 = index2;
  344. },
  345. handleQuestionDragEnd(e, item) {
  346. this.questionDragging = null;
  347. this.questionIndex2 = null;
  348. },
  349. handleQuestionDragOver(e) {
  350. e.dataTransfer.dropEffect = "move"; // e.dataTransfer.dropEffect="move";//在dragenter中针对放置目标来设置!
  351. },
  352. handleQuestionDragEnter(e, item, index, index2) {
  353. e.dataTransfer.effectAllowed = "move"; //为需要移动的元素设置dragstart事件
  354. if (item === this.questionDragging && this.questionIndex2 == index2) {
  355. return;
  356. }
  357. const newItems = this.questionList[index].list;
  358. const src = this.questionIndex2;
  359. const dst = index2;
  360. newItems.splice(dst, 0, ...newItems.splice(src, 1));
  361. this.questionList[index].list = newItems;
  362. },
  363. },
  364. };
  365. </script>