SelectTikuPaperDialog.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <el-dialog
  3. class="select-tiku-paper-dialog page-dialog"
  4. :visible.sync="modalIsShow"
  5. title="试卷选择"
  6. top="10vh"
  7. width="900px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. destroy-on-close
  12. @open="visibleChange"
  13. >
  14. <div class="part-box part-box-pad">
  15. <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
  16. <el-form-item label="试卷名称:">
  17. <el-input
  18. v-model.trim="filter.paperName"
  19. placeholder="请输入试卷名称"
  20. clearable
  21. ></el-input>
  22. </el-form-item>
  23. <el-form-item label-width="0px">
  24. <el-checkbox v-model="youSelf">仅显示本人试卷</el-checkbox>
  25. </el-form-item>
  26. <el-form-item label-width="0px">
  27. <el-button type="primary" @click="getList">查询</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </div>
  31. <div class="part-box part-box-pad">
  32. <el-table ref="TableList" :data="dataList">
  33. <el-table-column
  34. type="index"
  35. label="序号"
  36. :index="indexMethod"
  37. ></el-table-column>
  38. <el-table-column prop="name" label="试卷名称"></el-table-column>
  39. <el-table-column prop="createByAccount" label="命题人">
  40. </el-table-column>
  41. <el-table-column prop="paperDetailCount" label="大题数" width="65">
  42. </el-table-column>
  43. <el-table-column prop="unitCount" label="小题数" width="65">
  44. </el-table-column>
  45. <el-table-column prop="totalScore" label="试卷总分" width="80">
  46. </el-table-column>
  47. <el-table-column prop="creationTime" label="创建时间" width="160">
  48. </el-table-column>
  49. <el-table-column class-name="action-column" label="操作" width="60">
  50. <template slot-scope="scope">
  51. <el-button
  52. :class="
  53. scope.row.id === row.paperId ? 'btn-success' : 'btn-primary'
  54. "
  55. type="text"
  56. @click="toSelect(scope.row)"
  57. >选择</el-button
  58. >
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. <div class="part-page">
  63. <el-pagination
  64. background
  65. layout="total, sizes, prev, pager, next, jumper"
  66. :pager-count="5"
  67. :current-page="current"
  68. :total="total"
  69. :page-size="size"
  70. @current-change="toPage"
  71. @size-change="pageSizeChange"
  72. >
  73. </el-pagination>
  74. </div>
  75. </div>
  76. <div v-if="showTkTips" class="tips-markedness">
  77. <p class="tips-info">
  78. 请在题库-试卷列表点击生成试卷,检查试卷,确定试卷无误后点击顶部确定按钮
  79. <el-button
  80. v-if="tkAuth.hasAuth"
  81. type="text"
  82. class="btn-primary btn-link ml-2"
  83. @click="toTk"
  84. >点击跳转题库</el-button
  85. >
  86. </p>
  87. </div>
  88. <div slot="footer">
  89. <el-button @click="cancel">关闭</el-button>
  90. </div>
  91. </el-dialog>
  92. </template>
  93. <script>
  94. import json5 from "json5";
  95. import { tikuPaperListQuery, tikuPaperDetail } from "../../api";
  96. import { tikuAuth } from "../../../stmms/api";
  97. export default {
  98. name: "select-tiku-paper-dialog",
  99. props: {
  100. row: {
  101. type: Object,
  102. default() {
  103. return {};
  104. },
  105. },
  106. },
  107. data() {
  108. return {
  109. modalIsShow: false,
  110. filter: {
  111. paperName: "",
  112. account: "",
  113. },
  114. youSelf: true,
  115. dataList: [],
  116. current: 1,
  117. size: this.GLOBAL.pageSize,
  118. total: 0,
  119. loading: false,
  120. // tiku
  121. showTkTips: false,
  122. tkAuth: {
  123. hasAuth: false,
  124. role: null,
  125. },
  126. };
  127. },
  128. mounted() {
  129. this.checkTkAuth();
  130. },
  131. methods: {
  132. visibleChange() {
  133. this.filter = {
  134. paperName: "",
  135. account: "",
  136. };
  137. this.youSelf = true;
  138. this.toPage(1);
  139. },
  140. cancel() {
  141. this.modalIsShow = false;
  142. },
  143. open() {
  144. this.modalIsShow = true;
  145. },
  146. async getList() {
  147. const datas = {
  148. courseId: this.row.courseId,
  149. ...this.filter,
  150. pageNumber: this.current,
  151. pageSize: this.size,
  152. };
  153. if (this.youSelf)
  154. datas.account = this.$ls.get("user", { loginName: "" }).loginName;
  155. const res = await tikuPaperListQuery(datas);
  156. this.dataList = res.records;
  157. this.total = res.total;
  158. if (this.dataList.length) {
  159. this.showTkTips = true;
  160. }
  161. },
  162. toPage(page) {
  163. this.current = page;
  164. this.getList();
  165. },
  166. getPaperStruct(paperJson) {
  167. const structs = [];
  168. paperJson.details.forEach((detail) => {
  169. detail.questions.forEach((question) => {
  170. if (question.subQuestions && question.subQuestions.length) {
  171. question.subQuestions.forEach((subq) => {
  172. structs.push(
  173. `${detail.number}_${question.number}_${question.structType}_${subq.number}_${subq.structType}`
  174. );
  175. });
  176. } else {
  177. structs.push(
  178. `${detail.number}_${question.number}_${question.structType}`
  179. );
  180. }
  181. });
  182. });
  183. return structs.join();
  184. },
  185. async comparePaperStruct(paperIds) {
  186. const allFunc = paperIds.map((paperId) =>
  187. tikuPaperDetail({
  188. paperId,
  189. examId: this.row.examId,
  190. uuid: this.row.uuid,
  191. })
  192. );
  193. const result = await Promise.all(allFunc).catch(() => {});
  194. if (!result) return;
  195. const paperStructs = result.map((item) => {
  196. const paperJson = item.paperJson
  197. ? json5.parse(item.paperJson)
  198. : { details: [] };
  199. return this.getPaperStruct(paperJson);
  200. });
  201. const compareStruct = paperStructs[0];
  202. const valid = !paperStructs.some((item) => item !== compareStruct);
  203. return { valid };
  204. },
  205. async toSelect(row) {
  206. if (this.row.comparePaperId && this.row.comparePaperId !== row.id) {
  207. const res = await this.comparePaperStruct([
  208. row.id,
  209. this.row.comparePaperId,
  210. ]).catch(() => {});
  211. if (!res) return;
  212. if (!res.valid) {
  213. this.$message.error("试卷结构不一致,请重新选择!");
  214. return;
  215. }
  216. }
  217. this.$emit("confirm", row);
  218. this.cancel();
  219. },
  220. checkTkAuth() {
  221. const user = this.$ls.get("user");
  222. const userRoles = user.roleSource.filter(
  223. (item) => item.roleSource === "QUESTION_LIBRARY"
  224. );
  225. if (!userRoles.length) {
  226. this.tkAuth.hasAuth = false;
  227. return;
  228. }
  229. this.tkAuth.hasAuth = true;
  230. const stRole = userRoles.find(
  231. (item) => item.roleCode === "SUBJECT_TEACHER"
  232. );
  233. this.tkAuth.role = {
  234. ...(stRole ? stRole : userRoles[0]),
  235. loginName: user.loginName,
  236. realName: user.realName,
  237. };
  238. },
  239. async toTk() {
  240. if (this.loading) return;
  241. this.loading = true;
  242. const data = await tikuAuth({
  243. loginName: this.tkAuth.role.loginName,
  244. realName: this.tkAuth.role.realName,
  245. role: this.tkAuth.role.roleCode,
  246. returnUrl: encodeURIComponent(window.location.href),
  247. }).catch(() => {});
  248. this.loading = false;
  249. if (!data) return;
  250. window.open(data.redirectUrl);
  251. },
  252. },
  253. };
  254. </script>