CardDesign.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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="toExit"></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. <el-button
  29. type="primary"
  30. @click="toSave"
  31. :disabled="canSave || !pages.length"
  32. >暂存</el-button
  33. >
  34. <el-button type="primary" @click="toSubmit" :loading="isSubmit"
  35. >提交</el-button
  36. >
  37. </div>
  38. <div class="control-left">
  39. <el-button
  40. v-for="(page, pageNo) in pages"
  41. :key="pageNo"
  42. :class="{ 'btn-white': curPageNo === pageNo }"
  43. @click="swithPage(pageNo)"
  44. >第{{ pageNo + 1 }}页</el-button
  45. >
  46. </div>
  47. </div>
  48. </div>
  49. <!-- actions -->
  50. <div class="design-action">
  51. <div class="action-part">
  52. <div class="action-part-title"><h2>基本设置</h2></div>
  53. <div class="action-part-body">
  54. <page-prop-edit @init-page="initPageData"></page-prop-edit>
  55. </div>
  56. </div>
  57. <div class="action-part">
  58. <div class="action-part-title"><h2>试题配置</h2></div>
  59. <div class="action-part-body">
  60. <div class="type-list">
  61. <div
  62. class="type-item"
  63. v-for="(item, index) in TOPIC_LIST"
  64. :key="index"
  65. >
  66. <el-button @click="addNewTopic(item)"
  67. ><i class="el-icon-plus"></i>{{ item.name }}</el-button
  68. >
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. <div class="action-part">
  74. <div class="action-part-title"><h2>插入元素</h2></div>
  75. <div class="action-part-body">
  76. <div class="type-list">
  77. <div
  78. class="type-item"
  79. v-for="(item, index) in ELEMENT_LIST"
  80. :key="index"
  81. draggable="true"
  82. @dragstart="dragstart(item)"
  83. >
  84. <el-button
  85. ><i class="el-icon-plus"></i>{{ item.name }}</el-button
  86. >
  87. </div>
  88. </div>
  89. <!-- Develop btns -->
  90. <!-- <card-config-prop-edit></card-config-prop-edit> -->
  91. </div>
  92. <!-- <br /><br /> -->
  93. <!-- <el-button @click="initCard">新建页面</el-button> -->
  94. </div>
  95. <!-- <div class="action-part">
  96. <div class="action-part-title"><h2>阅卷参数</h2></div>
  97. <div class="action-part-body">
  98. <el-button type="primary" @click="modifyParams"
  99. >上传阅卷参数<span class="color-danger"
  100. >({{ paperParams["pageSumScore"] || 0 }}分)</span
  101. ></el-button
  102. >
  103. </div>
  104. </div> -->
  105. </div>
  106. <!-- edit body -->
  107. <div class="design-body">
  108. <div
  109. :class="['page-box', `page-box-${curPageNo % 2}`]"
  110. v-if="curPage.locators"
  111. >
  112. <div
  113. :class="[
  114. 'page-locators',
  115. `page-locators-${curPage.locators.length}`
  116. ]"
  117. >
  118. <ul
  119. class="page-locator-group"
  120. v-for="(locator, iind) in curPage.locators"
  121. :key="iind"
  122. >
  123. <li
  124. v-for="(elem, eindex) in locator"
  125. :key="eindex"
  126. :id="elem.id"
  127. ></li>
  128. </ul>
  129. </div>
  130. <!-- inner edit area -->
  131. <div class="page-main-inner">
  132. <div
  133. :class="['page-main', `page-main-${curPage.columns.length}`]"
  134. :style="{ margin: `0 -${curPage.columnGap / 2}px` }"
  135. >
  136. <div
  137. class="page-column"
  138. v-for="(column, columnNo) in curPage.columns"
  139. :key="columnNo"
  140. :style="{ padding: `0 ${curPage.columnGap / 2}px` }"
  141. >
  142. <div
  143. class="page-column-main"
  144. :id="[`column-${curPageNo}-${columnNo}`]"
  145. >
  146. <div class="page-column-body" v-if="column.elements.length">
  147. <topic-element-edit
  148. class="page-column-element"
  149. :data-h="element.h"
  150. v-for="element in column.elements"
  151. :key="element.id"
  152. :data="element"
  153. ></topic-element-edit>
  154. </div>
  155. <div class="page-column-body" v-else>
  156. <div
  157. class="page-column-forbid-area"
  158. v-if="cardConfig.showForbidArea"
  159. >
  160. <p>该区域严禁作答</p>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. </div>
  167. <!-- outer edit area -->
  168. <div class="page-main-outer">
  169. <page-number
  170. type="rect"
  171. :total="pages.length"
  172. :current="curPageNo + 1"
  173. ></page-number>
  174. <page-number
  175. type="text"
  176. :total="pages.length"
  177. :current="curPageNo + 1"
  178. ></page-number>
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. <!-- all topics -->
  184. <div class="topic-list">
  185. <div class="page-box">
  186. <div class="page-main-inner">
  187. <div
  188. :class="['page-main', `page-main-${cardConfig.columnNumber}`]"
  189. :style="{ margin: `0 -${cardConfig.columnGap / 2}px` }"
  190. >
  191. <div
  192. class="page-column"
  193. :style="{ padding: `0 ${cardConfig.columnGap / 2}px` }"
  194. >
  195. <div class="page-column-main" id="topic-column">
  196. <div class="page-column-body">
  197. <!-- card-head-sample -->
  198. <card-head-sample
  199. :data="cardHeadSampleData"
  200. id="simple-card-head"
  201. v-if="topics.length && cardHeadSampleData"
  202. ></card-head-sample>
  203. <!-- topic element -->
  204. <topic-element-preview
  205. class="page-column-element"
  206. v-for="element in topics"
  207. :key="element.id"
  208. :data="element"
  209. ></topic-element-preview>
  210. </div>
  211. </div>
  212. </div>
  213. </div>
  214. </div>
  215. </div>
  216. </div>
  217. <!-- element-prop-edit -->
  218. <element-prop-edit ref="ElementPropEdit"></element-prop-edit>
  219. <!-- right-click-menu -->
  220. <right-click-menu @inset-topic="insetNewTopic"></right-click-menu>
  221. <!-- card-view-frame -->
  222. <div class="design-preview-frame" v-if="cardPreviewUrl">
  223. <iframe :src="cardPreviewUrl" frameborder="0"></iframe>
  224. </div>
  225. <!-- paper-params -->
  226. <paper-params
  227. :pages="pages"
  228. :paper-params="paperParams"
  229. @confirm="paperParamsModified"
  230. ref="PaperParams"
  231. ></paper-params>
  232. <!-- topic select dialog -->
  233. <topic-select-dialog
  234. ref="TopicSelectDialog"
  235. :topics="topicList"
  236. @confirm="addNewTopic"
  237. ></topic-select-dialog>
  238. </div>
  239. </template>
  240. <script>
  241. import { mapState, mapMutations, mapActions } from "vuex";
  242. import {
  243. cardConfigInfos,
  244. cardDetailEdit,
  245. cardTempDetail,
  246. saveCard,
  247. submitCard
  248. } from "../api";
  249. import {
  250. getElementModel,
  251. getCardHeadModel,
  252. ELEMENT_LIST,
  253. TOPIC_LIST
  254. } from "../elementModel";
  255. import { transformField, getAOrBSystem, CARD_VERSION } from "../enumerate";
  256. // import CardConfigPropEdit from "../components/CardConfigPropEdit";
  257. import TopicElementEdit from "../components/TopicElementEdit";
  258. import TopicElementPreview from "../components/TopicElementPreview";
  259. import PagePropEdit from "../components/PagePropEdit";
  260. import ElementPropEdit from "../components/ElementPropEdit";
  261. import RightClickMenu from "../components/RightClickMenu";
  262. import PageNumber from "../components/PageNumber";
  263. import PaperParams from "../components/PaperParams";
  264. import CardHeadSample from "../elements/card-head/CardHead";
  265. import TopicSelectDialog from "../components/TopicSelectDialog";
  266. export default {
  267. name: "card-design",
  268. components: {
  269. // CardConfigPropEdit,
  270. TopicElementEdit,
  271. TopicElementPreview,
  272. PagePropEdit,
  273. ElementPropEdit,
  274. RightClickMenu,
  275. CardHeadSample,
  276. PageNumber,
  277. PaperParams,
  278. TopicSelectDialog
  279. },
  280. data() {
  281. return {
  282. cardId: this.$route.params.cardId || this.$ls.get("cardId"),
  283. cardDetailId: this.$ls.get("cardDetailId"),
  284. prepareTcPCard: this.$ls.get("prepareTcPCard", {}),
  285. ELEMENT_LIST,
  286. TOPIC_LIST,
  287. topicList: [],
  288. steps: ["添加标题", "基本设置", "试题配置", "设置阅卷参数", "预览生成"],
  289. columnWidth: 0,
  290. cardPreviewUrl: "",
  291. isSubmit: false,
  292. canSave: false
  293. };
  294. },
  295. computed: {
  296. ...mapState("card", [
  297. "cardConfig",
  298. "topics",
  299. "pages",
  300. "paperParams",
  301. "curElement",
  302. "curPage",
  303. "curPageNo"
  304. ]),
  305. isEdit() {
  306. return !!this.cardId;
  307. },
  308. cardHeadSampleData() {
  309. if (!this.cardConfig["pageSize"]) return;
  310. const data = getCardHeadModel(this.cardConfig);
  311. data.isSimple = true;
  312. return data;
  313. }
  314. },
  315. mounted() {
  316. this.initCard();
  317. this.registWindowSubmit();
  318. },
  319. methods: {
  320. ...mapMutations("card", [
  321. "addPage",
  322. "setCurPage",
  323. "setCurElement",
  324. "setCardConfig",
  325. "setOpenElementEditDialog",
  326. "setCurDragElement",
  327. "setPages",
  328. "setPaperParams",
  329. "setInsetTarget",
  330. "initState"
  331. ]),
  332. ...mapActions("card", [
  333. "resetTopicSeries",
  334. "removePage",
  335. "addElement",
  336. "modifyCardHead",
  337. "modifyElement",
  338. "rebuildPages",
  339. "initTopicsFromPages"
  340. ]),
  341. async initCard() {
  342. await this.getCardConfig();
  343. if (this.isEdit) {
  344. this.getCardTempDetail();
  345. } else {
  346. this.initPageData();
  347. }
  348. this.addWatch();
  349. },
  350. async getCardTempDetail(content) {
  351. const detData = await cardDetailEdit(this.cardId);
  352. const tempData = await cardTempDetail(this.cardId);
  353. this.canSave = !detData.operateStatus;
  354. this.prepareTcPCard = Object.assign(this.prepareTcPCard, detData);
  355. // 可能存在题卡内容没有记录的情况
  356. if (tempData) {
  357. const cont = JSON.parse(tempData.content);
  358. this.cardDetailId = tempData.id;
  359. this.setPages(cont.pages);
  360. this.setCardConfig(cont.cardConfig);
  361. this.setPaperParams(cont.paperParams);
  362. this.initTopicsFromPages();
  363. this.resetTopicSeries();
  364. this.setCurPage(0);
  365. } else {
  366. // 没有题卡内容时,直接创建新的内容
  367. this.setCardConfig({
  368. cardName: detData.title,
  369. aOrB: detData.enablePaperType.split(",").length > 1
  370. });
  371. this.initPageData();
  372. }
  373. },
  374. initPageData() {
  375. this.modifyCardHead({
  376. ...getCardHeadModel(this.cardConfig)
  377. });
  378. this.$nextTick(() => {
  379. this.rebuildPages();
  380. this.setCurPage(0);
  381. });
  382. },
  383. async getCardConfig() {
  384. const data = await cardConfigInfos();
  385. if (!data) {
  386. this.$message.error("请先配置题卡规则!");
  387. return;
  388. }
  389. const aOrBSystem = getAOrBSystem(this.prepareTcPCard);
  390. let config = {
  391. ...transformField(data),
  392. pageSize: "A3",
  393. columnNumber: 2,
  394. columnGap: 20,
  395. showForbidArea: true,
  396. cardName: ""
  397. };
  398. if (aOrBSystem !== null) config.aOrBSystem = aOrBSystem;
  399. config.aOrB = !!config["aOrBSystem"];
  400. this.setCardConfig(config);
  401. },
  402. addNewTopic(item) {
  403. let element = getElementModel(item.type);
  404. element.w = document.getElementById("topic-column").offsetWidth;
  405. this.setCurElement(element);
  406. this.$refs.ElementPropEdit.open();
  407. // to elementPropEdit/ElementPropEdit open topic edit dialog
  408. },
  409. insetNewTopic({ id, type }) {
  410. console.log(id, type);
  411. this.setInsetTarget({ id, type });
  412. if (type === "FILL_QUESTION") {
  413. this.topicList = this.TOPIC_LIST;
  414. } else {
  415. this.topicList = this.TOPIC_LIST.filter(
  416. item => item.type !== "FILL_QUESTION"
  417. );
  418. }
  419. this.$refs.TopicSelectDialog.open();
  420. },
  421. // 元件编辑
  422. dragstart(element) {
  423. this.setCurDragElement(getElementModel(element.type));
  424. },
  425. addWatch() {
  426. this.$watch("cardConfig", val => {
  427. const element = getCardHeadModel(val);
  428. this.modifyCardHead(element);
  429. this.$nextTick(() => {
  430. this.rebuildPages();
  431. });
  432. });
  433. },
  434. // 操作
  435. async toPreview() {
  436. // this.$ls.set("cardData", {
  437. // cardConfig: this.cardConfig,
  438. // pages: this.pages,
  439. // paperParams: this.paperParams
  440. // });
  441. const result = await this.save();
  442. if (!result) return;
  443. window.open(
  444. this.getRouterPath({
  445. name: "CardPreview",
  446. params: {
  447. cardId: this.cardId,
  448. viewType: "view"
  449. }
  450. })
  451. );
  452. },
  453. swithPage(pindex) {
  454. if (this.curPageNo === pindex) return;
  455. this.setCurPage(pindex);
  456. this.setCurElement({});
  457. },
  458. // paper-params
  459. modifyParams() {
  460. this.$refs.PaperParams.open();
  461. },
  462. paperParamsModified(paperParams) {
  463. this.setPaperParams(paperParams);
  464. },
  465. // save
  466. getCardData(contentTemp = "", model = "") {
  467. const multiEnablePaperType =
  468. this.prepareTcPCard["enablePaperType"] &&
  469. this.prepareTcPCard["enablePaperType"].split(",").length > 1
  470. ? this.prepareTcPCard["enablePaperType"]
  471. : "";
  472. const tcPCard = this.$objAssign(
  473. {
  474. examId: "",
  475. enablePaperType: "A",
  476. courseName: "",
  477. courseCode: "",
  478. cardSource: "",
  479. title: "",
  480. id: this.cardId
  481. },
  482. {
  483. ...this.prepareTcPCard,
  484. title: this.cardConfig.cardName,
  485. enablePaperType: this.cardConfig.aOrB
  486. ? multiEnablePaperType || "A,B"
  487. : "A"
  488. }
  489. );
  490. let data = {
  491. tcPCard,
  492. tcPCardDetail: {
  493. content: model,
  494. subjectiveAttachmentId:
  495. this.paperParams["subjectiveAttachmentId"] || "",
  496. contentTemp
  497. }
  498. };
  499. if (this.cardDetailId) data.tcPCardDetail.id = this.cardDetailId;
  500. if (this.prepareTcPCard.taskId && this.prepareTcPCard.cardSource === "1")
  501. data.tcPExamTaskDetail = {
  502. ...this.prepareTcPCard,
  503. cardId: this.cardId
  504. };
  505. return data;
  506. },
  507. checkElementCovered() {
  508. let elements = [];
  509. this.pages.forEach(page => {
  510. page.columns.forEach(column => {
  511. column.elements.forEach(element => {
  512. if (element.isCovered) {
  513. elements.push(element.id);
  514. }
  515. });
  516. });
  517. });
  518. return elements.length;
  519. },
  520. checkCardValid() {
  521. if (!this.cardConfig.schoolName) {
  522. this.$message.error("主标题不能为空!");
  523. this.setCurPageNo(0);
  524. setTimeout(() => {
  525. document.getElementById("cardTitleInput").focus();
  526. });
  527. return false;
  528. }
  529. if (!this.cardConfig.cardName) {
  530. this.$message.error("题卡标题不能为空!");
  531. this.setCurPage(0);
  532. setTimeout(() => {
  533. document.getElementById("cardNameInput").focus();
  534. });
  535. return false;
  536. }
  537. if (this.checkElementCovered()) {
  538. this.$message.error("题卡中存在被遮挡的元件,请注意调整!");
  539. return false;
  540. }
  541. return true;
  542. },
  543. getModel() {
  544. return JSON.stringify(
  545. {
  546. version: CARD_VERSION,
  547. cardConfig: this.cardConfig,
  548. paperParams: this.paperParams,
  549. pages: this.pages
  550. },
  551. (k, v) => (k.startsWith("_") ? undefined : v)
  552. );
  553. },
  554. async save() {
  555. if (!this.checkCardValid()) return;
  556. const result = await saveCard(this.getCardData("", this.getModel()));
  557. this.cardDetailId = result.cardDetailId;
  558. this.cardId = result.cardId;
  559. this.$ls.set("cardDetailId", this.cardDetailId);
  560. this.$ls.set("cardId", this.cardId);
  561. return true;
  562. },
  563. async toSave() {
  564. const result = await this.save();
  565. if (result) this.$message.success("保存成功!");
  566. },
  567. // toSave() {
  568. // // console.log(this.getCardData());
  569. // this.canSave = true;
  570. // setTimeout(() => {
  571. // this.canSave = false;
  572. // }, 500);
  573. // },
  574. toSubmit() {
  575. if (this.isSubmit) return;
  576. if (!this.checkCardValid()) return;
  577. this.$confirm("确定要提交当前题卡吗?", "提示", {
  578. cancelButtonClass: "el-button--danger is-plain",
  579. confirmButtonClass: "el-button--primary",
  580. type: "warning"
  581. })
  582. .then(() => {
  583. window.cardData = {
  584. cardConfig: this.cardConfig,
  585. pages: this.pages,
  586. paperParams: this.paperParams
  587. };
  588. this.isSubmit = true;
  589. this.cardPreviewUrl = `/#/card/preview/${this.cardId}/frame`;
  590. })
  591. .catch(() => {});
  592. },
  593. registWindowSubmit() {
  594. window.submitCardTemp = async (cardContentTemp, model) => {
  595. const data = this.getCardData(cardContentTemp, model);
  596. const result = await submitCard(data).catch(() => {});
  597. this.cardPreviewUrl = "";
  598. this.isSubmit = false;
  599. window.cardData = null;
  600. if (result) {
  601. this.cardDetailId = result.cardDetailId;
  602. this.cardId = result.cardId;
  603. this.$ls.set("cardDetailId", this.cardDetailId);
  604. this.$ls.set("cardId", this.cardId);
  605. this.canSave = false;
  606. this.$message.success("提交成功!");
  607. // 提交之后退出编辑,v1.1修改
  608. this.goback();
  609. } else {
  610. this.$message.error("提交失败,请重新尝试!");
  611. }
  612. };
  613. },
  614. toExit() {
  615. this.$confirm(
  616. "请确保当前题卡已经正常保存,确定要退出当前题卡编辑吗?",
  617. "提示",
  618. {
  619. cancelButtonClass: "el-button--danger is-plain",
  620. confirmButtonClass: "el-button--primary",
  621. type: "warning"
  622. }
  623. )
  624. .then(() => {
  625. this.goback();
  626. })
  627. .catch(() => {});
  628. }
  629. },
  630. beforeDestroy() {
  631. this.$ls.remove("cardId");
  632. this.$ls.remove("cardDetailId");
  633. this.$ls.remove("prepareTcPCard");
  634. this.initState();
  635. delete window.submitCardTemp;
  636. }
  637. };
  638. </script>