CardFreeDesign.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <div class="card-design card-free-design">
  3. <div class="design-header">
  4. <div class="design-header-cont box-justify">
  5. <el-button
  6. class="btn-help"
  7. icon="el-icon-question"
  8. type="text"
  9. @click="showHelp"
  10. ></el-button>
  11. <div class="design-back" @click="toExit">
  12. <i class="el-icon-d-arrow-left" title="退出"></i>
  13. 返回
  14. </div>
  15. </div>
  16. </div>
  17. <!-- actions -->
  18. <div class="design-action">
  19. <div class="design-logo">
  20. <h1>
  21. <i class="el-icon-d-arrow-left" @click="toExit" title="退出"></i>
  22. 答题卡制作
  23. </h1>
  24. </div>
  25. <div class="action-part">
  26. <div class="action-part-title"><h2>基本设置</h2></div>
  27. <div class="action-part-body">
  28. <page-prop-edit></page-prop-edit>
  29. </div>
  30. </div>
  31. <div class="action-part">
  32. <div class="action-part-title"><h2>当前页面设置</h2></div>
  33. <div class="action-part-body">
  34. <edit-page></edit-page>
  35. </div>
  36. </div>
  37. <div class="action-part">
  38. <div class="action-part-title"><h2>复杂元素</h2></div>
  39. <div class="action-part-body">
  40. <div class="type-list">
  41. <div
  42. class="type-item"
  43. v-for="(item, index) in TOPIC_LIST"
  44. :key="index"
  45. draggable="true"
  46. @dragstart="dragstart(item)"
  47. >
  48. <el-button><i class="el-icon-plus"></i>{{ item.name }}</el-button>
  49. </div>
  50. </div>
  51. <p class="tips-info">提示:拖动插入元素</p>
  52. </div>
  53. </div>
  54. <div class="action-part">
  55. <div class="action-part-title"><h2>简单元素</h2></div>
  56. <div class="action-part-body">
  57. <div class="type-list">
  58. <div
  59. class="type-item"
  60. v-for="(item, index) in ELEMENT_LIST"
  61. :key="index"
  62. draggable="true"
  63. @dragstart="dragstart(item)"
  64. >
  65. <el-button><i class="el-icon-plus"></i>{{ item.name }}</el-button>
  66. </div>
  67. <p class="tips-info">提示:拖动插入元素</p>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="action-part">
  72. <div class="action-part-title"><h2>元素面板</h2></div>
  73. <div class="action-part-body">
  74. <!-- element-tier-edit -->
  75. <element-tier-edit ref="ElementTierEdit"></element-tier-edit>
  76. </div>
  77. </div>
  78. </div>
  79. <div class="design-main">
  80. <!-- menus -->
  81. <div class="design-control">
  82. <div class="control-left tab-btns">
  83. <el-button
  84. v-for="(page, pageNo) in pages"
  85. :key="pageNo"
  86. :type="curPageNo === pageNo ? 'primary' : 'default'"
  87. @click="swithPage(pageNo)"
  88. >
  89. <span>第{{ pageNo + 1 }}页</span>
  90. <span class="page-delete" @click.stop="toDeletePage(page)"
  91. ><i class="el-icon-error"></i
  92. ></span>
  93. </el-button>
  94. <el-button icon="el-icon-plus" @click="toAddPage"></el-button>
  95. </div>
  96. <div class="control-right">
  97. <div v-if="hasUnsubmitCont" class="tips-info tips-error">
  98. <i class="el-icon-warning"></i>有未提交数据
  99. </div>
  100. <el-button
  101. type="success"
  102. :loading="isSubmit"
  103. :disabled="!pages.length"
  104. @click="toPreview"
  105. >预览</el-button
  106. >
  107. <!-- <el-button
  108. v-if="showSaveBtn"
  109. type="primary"
  110. :loading="isSubmit"
  111. :disabled="canSave || !pages.length"
  112. @click="toSave"
  113. >暂存</el-button
  114. > -->
  115. <el-button type="primary" :loading="isSubmit" @click="toSubmit"
  116. >提交</el-button
  117. >
  118. </div>
  119. </div>
  120. <!-- edit body -->
  121. <div class="design-body">
  122. <div
  123. :class="[
  124. 'page-box',
  125. `page-box-${curPage.pageSize}`,
  126. `page-box-${curPageNo % 2}`,
  127. { 'page-box-less': pages.length <= 2 },
  128. ]"
  129. v-if="curPage.id"
  130. >
  131. <!-- locator -->
  132. <div class="page-locator page-locator-top">
  133. <div
  134. v-for="elem in curPage.locators.top"
  135. :key="elem.id"
  136. :id="elem.id"
  137. class="page-locator-item"
  138. ></div>
  139. </div>
  140. <div class="page-locator page-locator-bottom">
  141. <div
  142. v-for="elem in curPage.locators.bottom"
  143. :key="elem.id"
  144. :id="elem.id"
  145. class="page-locator-item"
  146. ></div>
  147. </div>
  148. <!-- inner edit area -->
  149. <div class="page-main-inner">
  150. <div
  151. :class="['page-main', `page-main-${curPage.columns.length}`]"
  152. :style="{ margin: `0 -${curPage.columnGap / 2}px` }"
  153. >
  154. <div
  155. class="page-column"
  156. v-for="(column, columnNo) in curPage.columns"
  157. :key="columnNo"
  158. :style="{ padding: `0 ${curPage.columnGap / 2}px` }"
  159. >
  160. <topic-column-edit
  161. class="page-column-main"
  162. :data="column"
  163. ></topic-column-edit>
  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. <course-barcode
  180. v-if="curPageNo % 2 === 0"
  181. :data="cardConfig"
  182. ></course-barcode>
  183. </div>
  184. </div>
  185. </div>
  186. </div>
  187. <!-- element-prop-edit -->
  188. <element-prop-edit ref="ElementPropEdit"></element-prop-edit>
  189. <!-- right-click-menu -->
  190. <right-click-menu></right-click-menu>
  191. <!-- shortcut-key -->
  192. <shortcut-key
  193. ref="ShortcutKey"
  194. @sk-save="skSave"
  195. @sk-submit="skSubmit"
  196. @sk-preview="skPreview"
  197. ></shortcut-key>
  198. <!-- help-dialog -->
  199. <help-dialog
  200. ref="HelpDialog"
  201. @on-enable="shortcutEnableChange"
  202. ></help-dialog>
  203. </div>
  204. </template>
  205. <script>
  206. import { mapState, mapMutations, mapActions } from "vuex";
  207. import { getElementModel, ELEMENT_LIST, TOPIC_LIST } from "../elements/model";
  208. import { getModel as getPageModel } from "../../../elements/page/model";
  209. import { CARD_VERSION } from "../../../enumerate";
  210. import TopicColumnEdit from "../components/TopicColumnEdit";
  211. import ElementPropEdit from "../components/ElementPropEdit";
  212. import ElementTierEdit from "../components/ElementTierEdit";
  213. import PagePropEdit from "../components/PagePropEdit";
  214. import RightClickMenu from "../components/RightClickMenu";
  215. import ShortcutKey from "../components/ShortcutKey";
  216. import HelpDialog from "../components/HelpDialog";
  217. import EditPage from "../../../elements/page/EditPage";
  218. import PageNumber from "../../../components/PageNumber";
  219. import CourseBarcode from "../../../components/CourseBarcode.vue";
  220. export default {
  221. name: "card-free-design",
  222. props: {
  223. content: {
  224. type: Object,
  225. default() {
  226. return {
  227. pages: [],
  228. cardConfig: {},
  229. };
  230. },
  231. },
  232. showSaveBtn: {
  233. type: Boolean,
  234. default: true,
  235. },
  236. },
  237. components: {
  238. TopicColumnEdit,
  239. PagePropEdit,
  240. EditPage,
  241. ElementPropEdit,
  242. ElementTierEdit,
  243. RightClickMenu,
  244. ShortcutKey,
  245. HelpDialog,
  246. PageNumber,
  247. CourseBarcode,
  248. },
  249. data() {
  250. return {
  251. ELEMENT_LIST,
  252. TOPIC_LIST,
  253. topicList: [],
  254. columnWidth: 0,
  255. isSubmit: false,
  256. canSave: false,
  257. hasUnsubmitCont: false,
  258. };
  259. },
  260. computed: {
  261. ...mapState("free", [
  262. "cardConfig",
  263. "pages",
  264. "curElement",
  265. "curPage",
  266. "curPageNo",
  267. "curDragElement",
  268. "curColumnId",
  269. ]),
  270. },
  271. mounted() {
  272. this.initCard();
  273. },
  274. beforeDestroy() {
  275. this.initState();
  276. },
  277. methods: {
  278. ...mapMutations("free", [
  279. "setCurPageNo",
  280. "setCurElement",
  281. "setCardConfig",
  282. "setOpenElementEditDialog",
  283. "setCurDragElement",
  284. "setPages",
  285. "initState",
  286. ]),
  287. ...mapActions("free", [
  288. "addPage",
  289. "removePage",
  290. "addElement",
  291. "modifyElement",
  292. ]),
  293. async initCard() {
  294. const { cardConfig, pages } = this.content;
  295. this.setCardConfig(cardConfig);
  296. if (pages && pages.length) {
  297. this.setPages(pages);
  298. this.setCurPageNo(0);
  299. } else {
  300. this.initPageData();
  301. }
  302. },
  303. initPageData() {
  304. const page = getPageModel(this.cardConfig);
  305. this.addPage(page);
  306. this.setCurPageNo(0);
  307. },
  308. toAddPage() {
  309. const page = getPageModel(this.cardConfig);
  310. this.addPage(page);
  311. },
  312. addNewTopic(item) {
  313. let element = getElementModel(item.type);
  314. this.setCurElement(element);
  315. this.$refs.ElementPropEdit.open();
  316. // to elementPropEdit/ElementPropEdit open topic edit dialog
  317. },
  318. // 元件编辑
  319. dragstart(element) {
  320. this.setCurDragElement(getElementModel(element.type));
  321. },
  322. // 操作
  323. swithPage(pindex) {
  324. if (this.curPageNo === pindex) return;
  325. this.setCurPageNo(pindex);
  326. this.setCurElement({});
  327. },
  328. toDeletePage(page) {
  329. if (this.pages.length === 1) {
  330. this.$message.error("只剩最后一页,不能再删除了");
  331. return;
  332. }
  333. this.removePage(page);
  334. },
  335. // save
  336. getCardData(htmlContent = "", model = "") {
  337. let data = {
  338. title: this.cardConfig.cardTitle,
  339. content: model,
  340. htmlContent,
  341. };
  342. return data;
  343. },
  344. getCardJson() {
  345. // 防止页面未渲染完成,各试题高度未及时更新,保存数据有误的问题
  346. return new Promise((resolve) => {
  347. setTimeout(() => {
  348. const data = JSON.stringify(
  349. {
  350. version: CARD_VERSION,
  351. cardType: "FREE",
  352. cardConfig: this.cardConfig,
  353. pages: this.pages,
  354. },
  355. (k, v) => (k.startsWith("_") ? undefined : v)
  356. );
  357. resolve(data);
  358. }, 100);
  359. });
  360. },
  361. skSave() {
  362. this.toSave();
  363. },
  364. skSubmit() {
  365. this.toSubmit();
  366. },
  367. skPreview() {
  368. this.toPreview();
  369. },
  370. shortcutEnableChange(enable) {
  371. if (enable) {
  372. this.$refs.ShortcutKey.registShortcutKey();
  373. } else {
  374. this.$refs.ShortcutKey.removeShortcutKey();
  375. }
  376. },
  377. toPreview() {
  378. this.$emit("on-preview", {
  379. cardConfig: this.cardConfig,
  380. pages: this.pages,
  381. });
  382. },
  383. async toSave() {
  384. const model = await this.getCardJson();
  385. const datas = this.getCardData("", model);
  386. this.$emit("on-save", datas);
  387. },
  388. toSubmit() {
  389. if (this.isSubmit) return;
  390. if (this.pages.length % 2) {
  391. this.$message.error("请确保题卡页数是偶数");
  392. return;
  393. }
  394. this.$emit("on-submit", {
  395. cardConfig: {
  396. ...this.cardConfig,
  397. courseCodeBarcodeSrc: "",
  398. courseCodeBarcodeName: "",
  399. },
  400. pages: this.pages,
  401. });
  402. },
  403. toExit() {
  404. this.$emit("on-exit");
  405. },
  406. showHelp() {
  407. this.$refs.HelpDialog.open();
  408. },
  409. loading() {
  410. this.isSubmit = true;
  411. },
  412. unloading() {
  413. this.isSubmit = false;
  414. },
  415. updateUnsubmitStatus(status) {
  416. this.hasUnsubmitCont = status;
  417. },
  418. },
  419. };
  420. </script>