CardDesign.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <div class="card-design">
  3. <div class="design-top">
  4. <div class="design-top-logo">
  5. <h1><i class="icon icon-back" @click="goback"></i>答题卡制作</h1>
  6. </div>
  7. <div class="design-top-info">
  8. <div class="info-help"><i class="icon icon-help"></i>帮助</div>
  9. </div>
  10. </div>
  11. <div class="design-main">
  12. <!-- menus -->
  13. <div class="design-head">
  14. <div class="design-steps">
  15. <div class="step-item" v-for="(step, index) in steps" :key="index">
  16. <i>{{ index + 1 }}</i>
  17. <span>{{ step }}</span>
  18. </div>
  19. </div>
  20. <div class="design-control">
  21. <div class="control-right">
  22. <el-button
  23. class="btn-white"
  24. @click="toPreview"
  25. :disabled="!pages.length"
  26. >预览</el-button
  27. >
  28. <save-page @confirm="toSave" ref="SavePage"></save-page>
  29. <el-button type="primary" @click="toSubmit">提交</el-button>
  30. </div>
  31. <div class="control-left">
  32. <el-button
  33. v-for="(page, pageNo) in pages"
  34. :key="pageNo"
  35. :class="{ 'btn-white': curPageNo === pageNo }"
  36. @click="swithPage(pageNo)"
  37. >第{{ pageNo + 1 }}页</el-button
  38. >
  39. </div>
  40. </div>
  41. </div>
  42. <!-- actions -->
  43. <div class="design-action">
  44. <div class="action-part">
  45. <div class="action-part-title"><h2>基本设置</h2></div>
  46. <div class="action-part-body">
  47. <page-prop-edit @init-page="initPageData"></page-prop-edit>
  48. </div>
  49. </div>
  50. <div class="action-part">
  51. <div class="action-part-title"><h2>试题配置</h2></div>
  52. <div class="action-part-body">
  53. <div class="type-list">
  54. <div
  55. class="type-item"
  56. v-for="(item, index) in TOPIC_LIST"
  57. :key="index"
  58. >
  59. <el-button @click="addNewTopic(item)"
  60. ><i class="el-icon-plus"></i>{{ item.name }}</el-button
  61. >
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="action-part">
  67. <div class="action-part-title"><h2>插入元素</h2></div>
  68. <div class="action-part-body">
  69. <div class="type-list">
  70. <div
  71. class="type-item"
  72. v-for="(item, index) in ELEMENT_LIST"
  73. :key="index"
  74. draggable="true"
  75. @dragstart="dragstart(item)"
  76. >
  77. <el-button
  78. ><i class="el-icon-plus"></i>{{ item.name }}</el-button
  79. >
  80. </div>
  81. </div>
  82. </div>
  83. <!-- Develop btns -->
  84. <!-- <card-config-prop-edit></card-config-prop-edit> -->
  85. <!-- <br /><br /> -->
  86. <!-- <el-button @click="initCard">新建页面</el-button> -->
  87. </div>
  88. <div class="action-part">
  89. <div class="action-part-title"><h2>阅卷参数</h2></div>
  90. <div class="action-part-body">
  91. <el-button type="primary">上传阅卷参数(0)</el-button>
  92. </div>
  93. </div>
  94. </div>
  95. <!-- edit body -->
  96. <div class="design-body">
  97. <template v-for="(page, pageNo) in pages">
  98. <div
  99. :class="['page-box', `page-box-${pageNo % 2}`]"
  100. v-if="curPageNo === pageNo"
  101. :key="pageNo"
  102. >
  103. <div
  104. :class="[
  105. 'page-locators',
  106. `page-locators-${page.locators.length}`
  107. ]"
  108. >
  109. <ul
  110. class="page-locator-group"
  111. v-for="(locator, iind) in page.locators"
  112. :key="iind"
  113. >
  114. <li
  115. v-for="(elem, eindex) in locator"
  116. :key="eindex"
  117. :id="elem.id"
  118. ></li>
  119. </ul>
  120. </div>
  121. <!-- inner edit area -->
  122. <div class="page-main-inner">
  123. <div
  124. :class="['page-main', `page-main-${page.columns.length}`]"
  125. :style="{ margin: `0 -${page.columnGap / 2}px` }"
  126. >
  127. <div
  128. class="page-column"
  129. v-for="(column, columnNo) in page.columns"
  130. :key="columnNo"
  131. :style="{ padding: `0 ${page.columnGap / 2}px` }"
  132. >
  133. <div
  134. class="page-column-main"
  135. :id="[`column-${pageNo}-${columnNo}`]"
  136. >
  137. <div class="page-column-body" v-if="column.elements.length">
  138. <topic-element-edit
  139. class="page-column-element"
  140. :data-h="element.h"
  141. v-for="element in column.elements"
  142. :key="element.id"
  143. :data="element"
  144. ></topic-element-edit>
  145. </div>
  146. <div class="page-column-body" v-else>
  147. <div
  148. class="page-column-forbid-area"
  149. v-if="cardConfig.showForbidArea"
  150. >
  151. <p>该区域严禁作答</p>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <!-- outer edit area -->
  159. <div class="page-main-outer">
  160. <page-number
  161. type="rect"
  162. :total="pages.length"
  163. :current="pageNo + 1"
  164. ></page-number>
  165. <page-number
  166. type="text"
  167. :total="pages.length"
  168. :current="pageNo + 1"
  169. ></page-number>
  170. </div>
  171. </div>
  172. </template>
  173. </div>
  174. <!-- design other pages -->
  175. <div class="design-other-pages">
  176. <template v-for="(page, pageNo) in pages">
  177. <div
  178. :class="['page-box', `page-box-${pageNo % 2}`]"
  179. v-if="curPageNo !== pageNo"
  180. :key="pageNo"
  181. >
  182. <div
  183. :class="[
  184. 'page-locators',
  185. `page-locators-${page.locators.length}`
  186. ]"
  187. >
  188. <ul
  189. class="page-locator-group"
  190. v-for="(locator, iind) in page.locators"
  191. :key="iind"
  192. >
  193. <li
  194. v-for="(elem, eindex) in locator"
  195. :key="eindex"
  196. :id="elem.id"
  197. ></li>
  198. </ul>
  199. </div>
  200. <!-- inner edit area -->
  201. <div class="page-main-inner">
  202. <div
  203. :class="['page-main', `page-main-${page.columns.length}`]"
  204. :style="{ margin: `0 -${page.columnGap / 2}px` }"
  205. >
  206. <div
  207. class="page-column"
  208. v-for="(column, columnNo) in page.columns"
  209. :key="columnNo"
  210. :style="{ padding: `0 ${page.columnGap / 2}px` }"
  211. >
  212. <div
  213. class="page-column-main"
  214. :id="[`column-${pageNo}-${columnNo}`]"
  215. >
  216. <div class="page-column-body">
  217. <topic-element-edit
  218. class="page-column-element"
  219. v-for="(element, eindex) in column.elements"
  220. :key="eindex"
  221. :data="element"
  222. ></topic-element-edit>
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. </template>
  230. </div>
  231. </div>
  232. <!-- element-prop-edit -->
  233. <element-prop-edit></element-prop-edit>
  234. <!-- right-click-menu -->
  235. <right-click-menu></right-click-menu>
  236. <!-- card-head-sample -->
  237. <card-head-sample v-if="pages.length"></card-head-sample>
  238. <!-- card-view-frame -->
  239. <div class="design-preview-frame" v-if="cardPreviewUrl">
  240. <iframe :src="cardPreviewUrl" frameborder="0"></iframe>
  241. </div>
  242. </div>
  243. </template>
  244. <script>
  245. import { mapState, mapMutations, mapActions } from "vuex";
  246. import {
  247. cardConfigInfos,
  248. cardDetailEdit,
  249. cardTempDetail,
  250. saveCard,
  251. submitCard
  252. } from "../api";
  253. import {
  254. getElementModel,
  255. getCardHeadModel,
  256. getNewPage,
  257. getTopicModel,
  258. ELEMENT_LIST,
  259. TOPIC_LIST
  260. } from "../elementModel";
  261. import { transformField, getAOrBSystem } from "../enumerate";
  262. // import CardConfigPropEdit from "../components/CardConfigPropEdit";
  263. import TopicElementEdit from "../components/TopicElementEdit";
  264. import PagePropEdit from "../components/PagePropEdit";
  265. import ElementPropEdit from "../components/elementPropEdit/ElementPropEdit";
  266. import RightClickMenu from "../components/RightClickMenu";
  267. import CardHeadSample from "../components/elementEdit/CardHeadSample";
  268. import SavePage from "../components/SavePage";
  269. import PageNumber from "../components/pageInfo/PageNumber";
  270. export default {
  271. name: "card-design",
  272. components: {
  273. // CardConfigPropEdit,
  274. TopicElementEdit,
  275. PagePropEdit,
  276. ElementPropEdit,
  277. RightClickMenu,
  278. CardHeadSample,
  279. SavePage,
  280. PageNumber
  281. },
  282. data() {
  283. return {
  284. cardId: this.$route.params.cardId || this.$ls.get("cardId"),
  285. cardDetailId: this.$ls.get("cardDetailId"),
  286. prepareTcPCard: this.$ls.get("prepareTcPCard", {}),
  287. ELEMENT_LIST,
  288. TOPIC_LIST,
  289. steps: ["添加标题", "基本设置", "试题配置", "设置阅卷参数", "预览生成"],
  290. columnWidth: 0,
  291. cardPreviewUrl: ""
  292. };
  293. },
  294. computed: {
  295. ...mapState("card", ["cardConfig", "pages", "curElement", "curPageNo"]),
  296. isEdit() {
  297. return !!this.cardId;
  298. }
  299. },
  300. mounted() {
  301. this.initCard();
  302. this.registWindowSubmit();
  303. },
  304. methods: {
  305. ...mapMutations("card", [
  306. "addPage",
  307. "setCurPageNo",
  308. "setCurElement",
  309. "setCardConfig",
  310. "setOpenElementEditDialog",
  311. "setCurDragElement",
  312. "setPages",
  313. "initTopicNos",
  314. "initState"
  315. ]),
  316. ...mapActions("card", [
  317. "removePage",
  318. "addElement",
  319. "modifyCardHead",
  320. "modifyElement",
  321. "rebuildPages"
  322. ]),
  323. async initCard() {
  324. await this.getCardConfig();
  325. if (this.isEdit) {
  326. this.getCardTempDetail();
  327. } else {
  328. this.initPageData();
  329. }
  330. this.addWatch();
  331. },
  332. async getCardTempDetail() {
  333. const detData = await cardDetailEdit(this.cardId);
  334. const tempData = await cardTempDetail(this.cardId);
  335. this.prepareTcPCard = Object.assign(this.prepareTcPCard, detData);
  336. // 可能存在题卡内容没有记录的情况
  337. if (tempData) {
  338. const cont = JSON.parse(tempData.content);
  339. this.cardDetailId = tempData.id;
  340. this.setPages(cont.pages);
  341. this.setCardConfig(cont.cardConfig);
  342. this.initTopicNos();
  343. } else {
  344. // 没有题卡内容时,直接创建新的内容
  345. this.setCardConfig({ cardName: detData.title });
  346. this.initPageData();
  347. }
  348. },
  349. initPageData() {
  350. this.addNewPage();
  351. this.addNewPage();
  352. this.$nextTick(() => {
  353. this.modifyCardHead({
  354. ...getCardHeadModel(this.cardConfig)
  355. });
  356. });
  357. },
  358. async getCardConfig() {
  359. const data = await cardConfigInfos();
  360. const aOrBSystem = getAOrBSystem(this.prepareTcPCard);
  361. let config = {
  362. ...transformField(data),
  363. pageSize: "A3",
  364. columnNumber: 2,
  365. columnGap: 20,
  366. showForbidArea: true,
  367. cardName: ""
  368. };
  369. if (aOrBSystem !== null) config.aOrBSystem = aOrBSystem;
  370. config.aOrB = !!config["aOrBSystem"];
  371. this.setCardConfig(config);
  372. },
  373. addNewTopic(item) {
  374. let element = getTopicModel(item.type);
  375. element.w = document.getElementById("column-0-0").offsetWidth;
  376. this.setCurElement(element);
  377. this.setOpenElementEditDialog(true);
  378. // to elementPropEdit/ElementPropEdit open topic edit dialog
  379. },
  380. addNewPage() {
  381. const page = getNewPage(this.pages.length, this.cardConfig.columnNumber);
  382. this.addPage(page);
  383. },
  384. // 元件编辑
  385. dragstart(element) {
  386. this.setCurDragElement(getElementModel(element.type));
  387. },
  388. addWatch() {
  389. this.$watch("cardConfig", val => {
  390. const element = getCardHeadModel(val);
  391. this.modifyCardHead(element);
  392. this.$nextTick(() => {
  393. this.rebuildPages();
  394. });
  395. });
  396. },
  397. // 操作
  398. async toPreview() {
  399. const result = await this.save();
  400. if (!result) return;
  401. window.open(
  402. this.getRouterPath({
  403. name: "CardPreview",
  404. params: {
  405. cardId: this.cardId,
  406. viewType: "view"
  407. }
  408. })
  409. );
  410. },
  411. swithPage(pindex) {
  412. if (this.curPageNo === pindex) return;
  413. this.setCurPageNo(pindex);
  414. this.setCurElement({});
  415. },
  416. // save
  417. getCardData(contentTemp = "") {
  418. const tcPCard = this.$objAssign(
  419. {
  420. examId: "",
  421. enablePaperType: "A",
  422. // paperAttachmentId: "",
  423. courseName: "",
  424. courseCode: "",
  425. cardSource: "",
  426. title: "",
  427. id: this.cardId
  428. },
  429. {
  430. ...this.prepareTcPCard,
  431. title: this.cardConfig.cardName,
  432. // todo:A,B最好前端配置一下,以便支持扩展
  433. enablePaperType: this.cardConfig.aOrB ? "A,B" : "A"
  434. }
  435. );
  436. let data = {
  437. tcPCard,
  438. tcPCardDetail: {
  439. content: this.$refs.SavePage.getPageModel()
  440. }
  441. };
  442. if (this.cardDetailId) data.tcPCardDetail.id = this.cardDetailId;
  443. if (contentTemp) data.tcPCardDetail.contentTemp = contentTemp;
  444. if (this.prepareTcPCard.taskId && this.prepareTcPCard.cardSource === "1")
  445. data.tcPExamTaskDetail = {
  446. ...this.prepareTcPCard,
  447. cardId: this.cardId
  448. };
  449. return data;
  450. },
  451. async save() {
  452. if (!this.cardConfig.cardName) {
  453. this.$message.error("题卡标题不能为空!");
  454. this.setCurPageNo(0);
  455. setTimeout(() => {
  456. document.getElementById("cardNameInput").focus();
  457. });
  458. return false;
  459. }
  460. const result = await saveCard(this.getCardData());
  461. this.cardDetailId = result.cardDetailId;
  462. this.cardId = result.cardId;
  463. this.$ls.set("cardDetailId", this.cardDetailId);
  464. this.$ls.set("cardId", this.cardId);
  465. return true;
  466. },
  467. async toSave() {
  468. const result = await this.save();
  469. if (result) this.$message.success("保存成功!");
  470. },
  471. toSubmit() {
  472. this.$confirm("确定要提交当前题卡吗?", "提示", {
  473. confirmButtonText: "确定",
  474. cancelButtonText: "取消",
  475. type: "warning"
  476. })
  477. .then(async () => {
  478. const result = await this.save();
  479. if (result)
  480. this.cardPreviewUrl = `/#/card/preview/${this.cardId}/frame`;
  481. })
  482. .catch(() => {});
  483. },
  484. registWindowSubmit() {
  485. window.submitCardTemp = async cardContentTemp => {
  486. const result = await submitCard(
  487. this.getCardData(cardContentTemp)
  488. ).catch(() => {});
  489. this.cardPreviewUrl = "";
  490. if (result) {
  491. this.$message.success("提交成功!");
  492. } else {
  493. this.$message.error("提交失败,请重新尝试!");
  494. }
  495. };
  496. }
  497. },
  498. beforeDestroy() {
  499. this.$ls.remove("cardId");
  500. this.$ls.remove("cardDetailId");
  501. this.$ls.remove("prepareTcPCard");
  502. this.initState();
  503. }
  504. };
  505. </script>