ElementPropEdit.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <el-dialog
  3. class="element-prop-edit edit-dialog"
  4. :visible.sync="openElementEditDialog"
  5. :title="title"
  6. top="10vh"
  7. width="640px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. :before-close="cancel"
  11. append-to-body
  12. >
  13. <component
  14. v-if="openElementEditDialog"
  15. ref="ElementPropEditComp"
  16. :is="curEditComponent"
  17. :instance="curElement"
  18. :key="curElement.id"
  19. @modified="modified"
  20. ></component>
  21. <div slot="footer">
  22. <el-button type="primary" :disabled="loading" @click="submit"
  23. >确认</el-button
  24. >
  25. <el-button @click="cancel">取消</el-button>
  26. </div>
  27. </el-dialog>
  28. </template>
  29. <script>
  30. import { mapState, mapMutations, mapActions } from "vuex";
  31. import { getElementName } from "../elementModel";
  32. import EditComposition from "../elements/composition/EditComposition";
  33. import EditExplain from "../elements/explain/EditExplain";
  34. import EditFillLine from "../elements/fill-line/EditFillLine";
  35. import EditFillQuestion from "../elements/fill-question/EditFillQuestion";
  36. import EditText from "../elements/text/EditText";
  37. import EditImage from "../elements/image/EditImage";
  38. import EditLine from "../elements/line/EditLine";
  39. import EditLines from "../elements/lines/EditLines";
  40. import EditGrids from "../elements/grids/EditGrids";
  41. export default {
  42. name: "element-prop-edit",
  43. components: {
  44. EditComposition,
  45. EditExplain,
  46. EditFillLine,
  47. EditFillQuestion,
  48. EditText,
  49. EditImage,
  50. EditLine,
  51. EditLines,
  52. EditGrids,
  53. },
  54. data() {
  55. return { loading: false };
  56. },
  57. computed: {
  58. ...mapState("card", ["curElement", "topics", "openElementEditDialog"]),
  59. title() {
  60. return this.curElement.type
  61. ? getElementName(this.curElement.type)
  62. : "属性编辑";
  63. },
  64. curEditComponent() {
  65. if (!this.curElement.type) return;
  66. let type = this.curElement.type.toLowerCase().replace("_", "-");
  67. if (type.indexOf("line-") === 0) type = "line";
  68. return `edit-${type}`;
  69. },
  70. },
  71. methods: {
  72. ...mapMutations("card", ["setOpenElementEditDialog"]),
  73. ...mapActions("card", [
  74. "addElement",
  75. "modifyElement",
  76. "modifyElementChild",
  77. "rebuildPages",
  78. "scrollToElementPage",
  79. ]),
  80. cancel() {
  81. this.setOpenElementEditDialog(false);
  82. },
  83. open() {
  84. this.setOpenElementEditDialog(true);
  85. },
  86. submit() {
  87. if (this.loading) return;
  88. this.loading = true;
  89. setTimeout(() => {
  90. this.loading = false;
  91. }, 500);
  92. this.$refs.ElementPropEditComp.submit();
  93. },
  94. equalTopicType(topic1, topic2) {
  95. if (topic1.type === topic2.type) {
  96. if (topic1.type !== "FILL_QUESTION") {
  97. return true;
  98. }
  99. return (
  100. topic1.isBoolean === topic2.isBoolean &&
  101. topic1.isMultiply === topic2.isMultiply
  102. );
  103. }
  104. return false;
  105. },
  106. checkTopicType(element) {
  107. const relateTopics = this.topics.filter(
  108. (item) =>
  109. item.topicNo === element.topicNo &&
  110. item.parent &&
  111. item.parent.id !== element.id
  112. );
  113. if (!relateTopics.length) return true;
  114. return !relateTopics.some(
  115. (topic) => !this.equalTopicType(element, topic)
  116. );
  117. },
  118. checkTopicNo(element) {
  119. if (element.type === "COMPOSITION") return true;
  120. const relateTopics = this.topics.filter(
  121. (item) =>
  122. item.topicNo === element.topicNo &&
  123. item.parent &&
  124. item.parent.id !== element.id
  125. );
  126. if (!relateTopics.length) return true;
  127. let er = [
  128. element.startNumber,
  129. element.startNumber + element.questionsCount - 1,
  130. ];
  131. const unvalid = relateTopics.some((item) => {
  132. const topic = item.type === "EXPLAIN" ? item.parent : item;
  133. const tr = [
  134. topic.startNumber,
  135. topic.startNumber + topic.questionsCount - 1,
  136. ];
  137. return (
  138. (er[0] <= tr[0] && er[1] >= tr[0]) ||
  139. (er[0] <= tr[1] && er[1] >= tr[1]) ||
  140. (er[0] >= tr[0] && er[1] <= tr[1])
  141. );
  142. });
  143. return !unvalid;
  144. },
  145. modified(element) {
  146. if (!element["container"]) {
  147. if (!this.checkTopicType(element)) {
  148. this.$message.error("同一大题号的所有试题题型必须相同");
  149. return;
  150. }
  151. // 在不校验大题号重复的情况下,需要校验小题号重复
  152. if (!this.checkTopicNo(element)) {
  153. this.$message.error("小题号重复,请重新设置小题号");
  154. return;
  155. }
  156. }
  157. // 编辑试题
  158. // 属性存在的条件:parent:大题的小题,container:题目内的子元素
  159. if (this.curElement["_edit"]) {
  160. if (element["container"]) {
  161. this.modifyElementChild(element);
  162. } else {
  163. this.modifyElement(element);
  164. }
  165. } else {
  166. this.addElement(element);
  167. }
  168. this.cancel();
  169. this.$nextTick(() => {
  170. this.rebuildPages();
  171. this.$nextTick(() => {
  172. this.scrollToElementPage(element);
  173. });
  174. });
  175. },
  176. },
  177. };
  178. </script>