123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <template>
- <el-dialog
- class="element-prop-edit edit-dialog"
- :visible.sync="openElementEditDialog"
- :title="title"
- top="10vh"
- width="640px"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- :before-close="cancel"
- append-to-body
- >
- <component
- v-if="openElementEditDialog"
- ref="ElementPropEditComp"
- :is="curEditComponent"
- :instance="curElement"
- :key="curElement.id"
- @modified="modified"
- ></component>
- <div slot="footer">
- <el-button type="primary" :disabled="loading" @click="submit"
- >确认</el-button
- >
- <el-button @click="cancel">取消</el-button>
- </div>
- </el-dialog>
- </template>
- <script>
- import { mapState, mapMutations, mapActions } from "vuex";
- import { getElementName } from "../elementModel";
- import EditComposition from "../elements/composition/EditComposition";
- import EditExplain from "../elements/explain/EditExplain";
- import EditFillLine from "../elements/fill-line/EditFillLine";
- import EditFillQuestion from "../elements/fill-question/EditFillQuestion";
- import EditText from "../elements/text/EditText";
- import EditImage from "../elements/image/EditImage";
- import EditLine from "../elements/line/EditLine";
- import EditLines from "../elements/lines/EditLines";
- import EditGrids from "../elements/grids/EditGrids";
- export default {
- name: "element-prop-edit",
- components: {
- EditComposition,
- EditExplain,
- EditFillLine,
- EditFillQuestion,
- EditText,
- EditImage,
- EditLine,
- EditLines,
- EditGrids,
- },
- data() {
- return { loading: false };
- },
- computed: {
- ...mapState("card", ["curElement", "topics", "openElementEditDialog"]),
- title() {
- return this.curElement.type
- ? getElementName(this.curElement.type)
- : "属性编辑";
- },
- curEditComponent() {
- if (!this.curElement.type) return;
- let type = this.curElement.type.toLowerCase().replace("_", "-");
- if (type.indexOf("line-") === 0) type = "line";
- return `edit-${type}`;
- },
- },
- methods: {
- ...mapMutations("card", ["setOpenElementEditDialog"]),
- ...mapActions("card", [
- "addElement",
- "modifyElement",
- "modifyElementChild",
- "rebuildPages",
- "scrollToElementPage",
- ]),
- cancel() {
- this.setOpenElementEditDialog(false);
- },
- open() {
- this.setOpenElementEditDialog(true);
- },
- submit() {
- if (this.loading) return;
- this.loading = true;
- setTimeout(() => {
- this.loading = false;
- }, 500);
- this.$refs.ElementPropEditComp.submit();
- },
- equalTopicType(topic1, topic2) {
- if (topic1.type === topic2.type) {
- if (topic1.type !== "FILL_QUESTION") {
- return true;
- }
- return (
- topic1.isBoolean === topic2.isBoolean &&
- topic1.isMultiply === topic2.isMultiply
- );
- }
- return false;
- },
- checkTopicType(element) {
- const relateTopics = this.topics.filter(
- (item) =>
- item.topicNo === element.topicNo &&
- item.parent &&
- item.parent.id !== element.id
- );
- if (!relateTopics.length) return true;
- return !relateTopics.some((topic) => this.equalTopicType(element, topic));
- },
- checkTopicNo(element) {
- if (element.type === "COMPOSITION") return true;
- const relateTopics = this.topics.filter(
- (item) =>
- item.topicNo === element.topicNo &&
- item.parent &&
- item.parent.id !== element.id
- );
- if (!relateTopics.length) return true;
- let er = [
- element.startNumber,
- element.startNumber + element.questionsCount - 1,
- ];
- const unvalid = relateTopics.some((item) => {
- const topic = item.type === "EXPLAIN" ? item.parent : item;
- const tr = [
- topic.startNumber,
- topic.startNumber + topic.questionsCount - 1,
- ];
- return (
- (er[0] <= tr[0] && er[1] >= tr[0]) ||
- (er[0] <= tr[1] && er[1] >= tr[1]) ||
- (er[0] >= tr[0] && er[1] <= tr[1])
- );
- });
- return !unvalid;
- },
- modified(element) {
- if (!element["container"]) {
- if (!this.checkTopicType(element)) {
- this.$message.error("同一大题号的所有试题题型必须相同");
- return;
- }
- // 在不校验大题号重复的情况下,需要校验小题号重复
- if (!this.checkTopicNo(element)) {
- this.$message.error("小题号重复,请重新设置小题号");
- return;
- }
- }
- // 编辑试题
- // 属性存在的条件:parent:大题的小题,container:题目内的子元素
- if (this.curElement["_edit"]) {
- if (element["container"]) {
- this.modifyElementChild(element);
- } else {
- this.modifyElement(element);
- }
- } else {
- this.addElement(element);
- }
- this.cancel();
- this.$nextTick(() => {
- this.rebuildPages();
- this.$nextTick(() => {
- this.scrollToElementPage(element);
- });
- });
- },
- },
- };
- </script>
|