123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653 |
- <template>
- <div class="card-design">
- <div class="design-header">
- <div class="design-steps">
- <div class="step-item" v-for="(step, index) in steps" :key="index">
- <i>{{ index + 1 }}</i>
- <span>{{ step }}</span>
- </div>
- </div>
- </div>
- <!-- actions -->
- <div class="design-action">
- <div class="design-logo">
- <h1>
- <i class="el-icon-d-arrow-left" @click="toExit" title="退出"></i>
- 答题卡制作
- </h1>
- </div>
- <div class="action-part">
- <div class="action-part-title"><h2>基本设置</h2></div>
- <div class="action-part-body">
- <page-prop-edit @init-page="initPageData"></page-prop-edit>
- </div>
- </div>
- <div class="action-part">
- <div class="action-part-title"><h2>试题配置</h2></div>
- <div class="action-part-body">
- <div class="type-list">
- <div
- class="type-item"
- v-for="(item, index) in TOPIC_LIST"
- :key="index"
- >
- <el-button @click="addNewTopic(item)"
- ><i class="el-icon-plus"></i>{{ item.name }}</el-button
- >
- </div>
- </div>
- <p class="tips-info">提示:点击创建试题</p>
- </div>
- </div>
- <div class="action-part">
- <div class="action-part-title"><h2>插入元素</h2></div>
- <div class="action-part-body">
- <div class="type-list">
- <div
- class="type-item"
- v-for="(item, index) in ELEMENT_LIST"
- :key="index"
- draggable="true"
- @dragstart="dragstart(item)"
- >
- <el-button><i class="el-icon-plus"></i>{{ item.name }}</el-button>
- </div>
- <p class="tips-info">提示:拖动插入元素</p>
- </div>
- <!-- Develop btns -->
- <!-- <card-config-prop-edit></card-config-prop-edit> -->
- </div>
- <!-- <br /><br /> -->
- <!-- <el-button @click="initCard">新建页面</el-button> -->
- </div>
- <!-- <div class="action-part">
- <div class="action-part-title"><h2>阅卷参数</h2></div>
- <div class="action-part-body">
- <el-button type="primary" @click="modifyParams"
- >上传阅卷参数<span class="color-danger"
- >({{ paperParams["pageSumScore"] || 0 }}分)</span
- ></el-button
- >
- </div>
- </div> -->
- </div>
- <div class="design-main">
- <!-- menus -->
- <div class="design-control">
- <div class="control-left tab-btns">
- <el-button
- v-for="(page, pageNo) in pages"
- :key="pageNo"
- :type="curPageNo === pageNo ? 'primary' : 'default'"
- @click="swithPage(pageNo)"
- >第{{ pageNo + 1 }}页</el-button
- >
- </div>
- <div class="control-right">
- <el-button
- type="success"
- :loading="isSubmit"
- :disabled="!pages.length"
- @click="toPreview"
- >预览</el-button
- >
- <el-button
- type="primary"
- :loading="isSubmit"
- :disabled="canSave || !pages.length"
- @click="toSave"
- >暂存</el-button
- >
- <el-button type="primary" :loading="isSubmit" @click="toSubmit"
- >提交</el-button
- >
- </div>
- </div>
- <!-- edit body -->
- <div class="design-body">
- <div
- :class="[
- 'page-box',
- `page-box-${cardConfig.pageSize}`,
- `page-box-${curPageNo % 2}`
- ]"
- v-if="curPage.locators"
- >
- <div
- :class="[
- 'page-locators',
- `page-locators-${curPage.locators.length}`
- ]"
- >
- <ul
- class="page-locator-group"
- v-for="(locator, iind) in curPage.locators"
- :key="iind"
- >
- <li
- v-for="(elem, eindex) in locator"
- :key="eindex"
- :id="elem.id"
- ></li>
- </ul>
- </div>
- <!-- inner edit area -->
- <div class="page-main-inner">
- <div
- :class="['page-main', `page-main-${curPage.columns.length}`]"
- :style="{ margin: `0 -${curPage.columnGap / 2}px` }"
- >
- <div
- class="page-column"
- v-for="(column, columnNo) in curPage.columns"
- :key="columnNo"
- :style="{ padding: `0 ${curPage.columnGap / 2}px` }"
- >
- <div
- class="page-column-main"
- :id="[`column-${curPageNo}-${columnNo}`]"
- >
- <div class="page-column-body" v-if="column.elements.length">
- <topic-element-edit
- class="page-column-element"
- :data-h="element.h"
- v-for="element in column.elements"
- :key="element.id"
- :data="element"
- ></topic-element-edit>
- </div>
- <div class="page-column-body" v-else>
- <div
- class="page-column-forbid-area"
- v-if="cardConfig.showForbidArea"
- >
- <p>该区域严禁作答</p>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- outer edit area -->
- <div class="page-main-outer">
- <page-number
- type="rect"
- :total="pages.length"
- :current="curPageNo + 1"
- ></page-number>
- <page-number
- type="text"
- :total="pages.length"
- :current="curPageNo + 1"
- ></page-number>
- </div>
- </div>
- </div>
- </div>
- <!-- all topics -->
- <div class="topic-list">
- <div :class="['page-box', `page-box-${cardConfig.pageSize}`]">
- <div class="page-main-inner">
- <div
- :class="['page-main', `page-main-${cardConfig.columnNumber}`]"
- :style="{ margin: `0 -${cardConfig.columnGap / 2}px` }"
- >
- <div
- class="page-column"
- :style="{ padding: `0 ${cardConfig.columnGap / 2}px` }"
- >
- <div class="page-column-main" id="topic-column">
- <div class="page-column-body">
- <!-- card-head-sample -->
- <card-head-sample
- :data="cardHeadSampleData"
- id="simple-card-head"
- v-if="topics.length && cardHeadSampleData"
- ></card-head-sample>
- <!-- topic element -->
- <topic-element-preview
- class="page-column-element"
- v-for="element in topics"
- :key="element.id"
- :data="element"
- ></topic-element-preview>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- element-prop-edit -->
- <element-prop-edit ref="ElementPropEdit"></element-prop-edit>
- <!-- right-click-menu -->
- <right-click-menu @inset-topic="insetNewTopic"></right-click-menu>
- <!-- card-view-frame -->
- <div class="design-preview-frame" v-if="cardPreviewUrl">
- <iframe :src="cardPreviewUrl" frameborder="0"></iframe>
- </div>
- <!-- paper-params -->
- <paper-params
- :pages="pages"
- :paper-params="paperParams"
- @confirm="paperParamsModified"
- ref="PaperParams"
- ></paper-params>
- <!-- topic select dialog -->
- <topic-select-dialog
- ref="TopicSelectDialog"
- :topics="topicList"
- @confirm="addNewTopic"
- ></topic-select-dialog>
- </div>
- </template>
- <script>
- import { mapState, mapMutations, mapActions } from "vuex";
- import { cardConfigInfos, cardDetail, saveCard } from "../api";
- import {
- getElementModel,
- getCardHeadModel,
- ELEMENT_LIST,
- TOPIC_LIST
- } from "../elementModel";
- import { CARD_VERSION } from "../enumerate";
- // import CardConfigPropEdit from "../components/CardConfigPropEdit";
- import TopicElementEdit from "../components/TopicElementEdit";
- import TopicElementPreview from "../components/TopicElementPreview";
- import PagePropEdit from "../components/PagePropEdit";
- import ElementPropEdit from "../components/ElementPropEdit";
- import RightClickMenu from "../components/RightClickMenu";
- import PageNumber from "../components/PageNumber";
- import PaperParams from "../components/PaperParams";
- import CardHeadSample from "../elements/card-head/CardHead";
- import TopicSelectDialog from "../components/TopicSelectDialog";
- export default {
- name: "card-design",
- components: {
- // CardConfigPropEdit,
- TopicElementEdit,
- TopicElementPreview,
- PagePropEdit,
- ElementPropEdit,
- RightClickMenu,
- CardHeadSample,
- PageNumber,
- PaperParams,
- TopicSelectDialog
- },
- data() {
- return {
- cardId: this.$route.params.cardId || this.$ls.get("cardId"),
- prepareTcPCard: this.$ls.get("prepareTcPCard", {
- examTaskId: "",
- courseCode: "",
- courseName: "",
- makeMethod: "SELF",
- cardRuleId: ""
- }),
- ELEMENT_LIST,
- TOPIC_LIST,
- topicList: [],
- steps: ["添加标题", "基本设置", "试题配置", "预览生成"],
- columnWidth: 0,
- cardPreviewUrl: "",
- isSubmit: false,
- canSave: false
- };
- },
- computed: {
- ...mapState("card", [
- "cardConfig",
- "topics",
- "pages",
- "paperParams",
- "curElement",
- "curPage",
- "curPageNo"
- ]),
- isEdit() {
- return !!this.cardId;
- },
- cardHeadSampleData() {
- if (!this.cardConfig["pageSize"]) return;
- const data = getCardHeadModel(this.cardConfig);
- data.isSimple = true;
- return data;
- }
- },
- mounted() {
- if (!this.prepareTcPCard.examTaskId && !this.isEdit) {
- this.$message.error("找不到命题任务,请退出题卡制作!");
- return;
- }
- this.initCard();
- this.registWindowSubmit();
- },
- methods: {
- ...mapMutations("card", [
- "addPage",
- "setCurPage",
- "setCurElement",
- "setCardConfig",
- "setOpenElementEditDialog",
- "setCurDragElement",
- "setPages",
- "setPaperParams",
- "setInsetTarget",
- "initState"
- ]),
- ...mapActions("card", [
- "resetTopicSeries",
- "removePage",
- "addElement",
- "modifyCardHead",
- "modifyElement",
- "rebuildPages",
- "initTopicsFromPages"
- ]),
- async initCard() {
- if (this.isEdit) {
- await this.getCardTempDetail();
- } else {
- await this.getCardConfig();
- this.initPageData();
- }
- this.addWatch();
- },
- getCardTitle(titleRule) {
- const fieldMap = {
- courseCode: this.prepareTcPCard.courseCode,
- courseName: this.prepareTcPCard.courseName,
- schoolName: this.prepareTcPCard.schoolName
- };
- Object.entries(fieldMap).forEach(([key, val]) => {
- titleRule = titleRule.replace("${" + key + "}", val);
- });
- return titleRule;
- },
- async getCardTempDetail() {
- const detData = await cardDetail(this.cardId);
- // this.canSave = !detData.operateStatus;
- // 可能存在题卡内容没有记录的情况
- if (detData.content) {
- const cont = JSON.parse(detData.content);
- this.setPages(cont.pages);
- this.setCardConfig(cont.cardConfig);
- this.setPaperParams(cont.paperParams);
- this.initTopicsFromPages();
- this.resetTopicSeries();
- this.setCurPage(0);
- } else {
- await this.getCardConfig();
- // 没有题卡内容时,直接创建新的内容
- if (detData.makeMethod === "CUST") {
- this.setCardConfig({ cardTitle: detData.title });
- }
- this.initPageData();
- }
- },
- initPageData() {
- this.modifyCardHead({
- ...getCardHeadModel(this.cardConfig)
- });
- this.$nextTick(() => {
- this.rebuildPages();
- this.setCurPage(0);
- });
- },
- async getCardConfig() {
- const data = await cardConfigInfos(this.prepareTcPCard.cardRuleId);
- if (!data) {
- this.$message.error("找不到题卡规则!");
- return;
- }
- let config = {
- ...data,
- ...{
- pageSize: "A3",
- columnNumber: 2,
- columnGap: 20,
- showForbidArea: true,
- cardDesc: "",
- makeMethod: this.prepareTcPCard.makeMethod
- }
- };
- config.aOrB = true; // 默认开启A/B卷型
- config.requiredFields = JSON.parse(config.requiredFields);
- config.extendFields = JSON.parse(config.extendFields);
- config.cardTitle = this.getCardTitle(config.titleRule);
- this.setCardConfig(config);
- },
- addNewTopic(item) {
- let element = getElementModel(item.type);
- element.w = document.getElementById("topic-column").offsetWidth;
- this.setCurElement(element);
- this.$refs.ElementPropEdit.open();
- // to elementPropEdit/ElementPropEdit open topic edit dialog
- },
- insetNewTopic({ id, type }) {
- console.log(id, type);
- this.setInsetTarget({ id, type });
- if (type === "FILL_QUESTION") {
- this.topicList = this.TOPIC_LIST;
- } else {
- this.topicList = this.TOPIC_LIST.filter(
- item => item.type !== "FILL_QUESTION"
- );
- }
- this.$refs.TopicSelectDialog.open();
- },
- // 元件编辑
- dragstart(element) {
- this.setCurDragElement(getElementModel(element.type));
- },
- addWatch() {
- this.$watch("cardConfig", val => {
- const element = getCardHeadModel(val);
- this.modifyCardHead(element);
- this.$nextTick(() => {
- this.rebuildPages();
- });
- });
- },
- // 操作
- async toPreview() {
- if (this.isSubmit) return;
- this.isSubmit = true;
- const result = await this.save().catch(() => {});
- this.isSubmit = false;
- if (!result) return;
- const { href } = this.$router.resolve({
- name: "CardPreview",
- params: {
- cardId: this.cardId,
- viewType: "view"
- }
- });
- window.open(href);
- },
- swithPage(pindex) {
- if (this.curPageNo === pindex) return;
- this.setCurPage(pindex);
- this.setCurElement({});
- },
- // paper-params
- modifyParams() {
- this.$refs.PaperParams.open();
- },
- paperParamsModified(paperParams) {
- this.setPaperParams(paperParams);
- },
- // save
- getCardData(htmlContent = "", model = "") {
- let data = {
- title: this.cardConfig.cardTitle,
- content: model,
- htmlContent,
- type: "CUSTOM",
- ...this.prepareTcPCard
- };
- if (this.cardId) data.id = this.cardId;
- return data;
- },
- getRequestConfig() {
- return this.prepareTcPCard.makeMethod === "CUST"
- ? {
- headers: {
- schoolId: this.prepareTcPCard.schoolId
- }
- }
- : {};
- },
- checkElementCovered() {
- let elements = [];
- this.pages.forEach(page => {
- page.columns.forEach(column => {
- column.elements.forEach(element => {
- if (element.isCovered) {
- elements.push(element.id);
- }
- });
- });
- });
- return elements.length;
- },
- checkCardValid() {
- if (!this.cardConfig.cardTitle) {
- this.$message.error("题卡标题不能为空!");
- this.setCurPageNo(0);
- setTimeout(() => {
- document.getElementById("cardTitleInput").focus();
- });
- return false;
- }
- // if (!this.cardConfig.cardDesc) {
- // this.$message.error("题卡描述信息不能为空!");
- // this.setCurPage(0);
- // setTimeout(() => {
- // document.getElementById("cardDescInput").focus();
- // });
- // return false;
- // }
- if (this.checkElementCovered()) {
- this.$message.error("题卡中存在被遮挡的元件,请注意调整!");
- return false;
- }
- return true;
- },
- getModel() {
- // 防止页面未渲染完成,各试题高度未及时更新,保存数据有误的问题
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- const data = JSON.stringify(
- {
- version: CARD_VERSION,
- cardConfig: this.cardConfig,
- paperParams: this.paperParams,
- pages: this.pages
- },
- (k, v) => (k.startsWith("_") ? undefined : v)
- );
- resolve(data);
- }, 100);
- });
- },
- async save() {
- if (!this.checkCardValid()) return;
- const model = await this.getModel();
- let datas = this.getCardData("", model);
- datas.status = "STAGE";
- const result = await saveCard(datas, this.getRequestConfig());
- this.cardId = result;
- this.$ls.set("cardId", this.cardId);
- return true;
- },
- async toSave() {
- if (this.isSubmit) return;
- this.isSubmit = true;
- const result = await this.save().catch(() => {});
- this.isSubmit = false;
- if (result) this.$message.success("保存成功!");
- },
- toSubmit() {
- if (this.isSubmit) return;
- if (!this.checkCardValid()) return;
- this.$confirm("确定要提交当前题卡吗?", "提示", {
- type: "warning"
- })
- .then(() => {
- window.cardData = {
- cardConfig: this.cardConfig,
- pages: this.pages,
- paperParams: this.paperParams
- };
- this.isSubmit = true;
- const { href } = this.$router.resolve({
- name: "CardPreview",
- params: {
- cardId: 1,
- viewType: "frame"
- }
- });
- this.cardPreviewUrl = href;
- })
- .catch(() => {});
- },
- registWindowSubmit() {
- window.submitCardTemp = async (htmlContent, model) => {
- const datas = this.getCardData(htmlContent, model);
- datas.status = "SUBMIT";
- const result = await saveCard(
- datas,
- this.getRequestConfig()
- ).catch(() => {});
- this.cardPreviewUrl = "";
- this.isSubmit = false;
- window.cardData = null;
- if (result) {
- this.cardId = result;
- this.$ls.set("cardId", this.cardId);
- this.canSave = false;
- this.$message.success("提交成功!");
- this.goback();
- } else {
- this.$message.error("提交失败,请重新尝试!");
- }
- };
- },
- toExit() {
- this.$confirm(
- "请确保当前题卡已经正常保存,确定要退出当前题卡编辑吗?",
- "提示",
- {
- type: "warning"
- }
- )
- .then(() => {
- this.goback();
- })
- .catch(() => {});
- }
- },
- beforeDestroy() {
- this.$ls.remove("cardId");
- this.$ls.remove("prepareTcPCard");
- this.initState();
- delete window.submitCardTemp;
- }
- };
- </script>
|