EditFillLine.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <div class="edit-fill-line ">
  3. <el-form
  4. ref="modalFormComp"
  5. :model="modalForm"
  6. :rules="rules"
  7. :key="modalForm.id"
  8. label-width="120px"
  9. >
  10. <el-form-item prop="topicName" label="题目名称:">
  11. <el-input
  12. v-model.trim="modalForm.topicName"
  13. type="textarea"
  14. :autosize="{ minRows: 2, maxRows: 5 }"
  15. resize="none"
  16. placeholder="请输入题目名称"
  17. clearable
  18. ></el-input>
  19. </el-form-item>
  20. <el-form-item prop="endNumber" label="起止题号:">
  21. <el-input-number
  22. style="width:40px;"
  23. v-model="modalForm.startNumber"
  24. :min="0"
  25. :max="999"
  26. :step="1"
  27. step-strictly
  28. :controls="false"
  29. ></el-input-number>
  30. <span class="el-input-split"></span>
  31. <el-input-number
  32. style="width:40px;"
  33. v-model="modalForm.endNumber"
  34. :min="0"
  35. :max="999"
  36. :step="1"
  37. step-strictly
  38. :controls="false"
  39. ></el-input-number>
  40. </el-form-item>
  41. <el-form-item prop="lineSpacing" label="空位上下间距:">
  42. <el-input-number
  43. style="width:125px;"
  44. v-model.number="modalForm.lineSpacing"
  45. :min="20"
  46. :max="100"
  47. :step="1"
  48. step-strictly
  49. :controls="false"
  50. ></el-input-number>
  51. </el-form-item>
  52. <el-form-item prop="questionNumberPerLine" label="每行空数:">
  53. <el-input-number
  54. style="width:125px;"
  55. v-model="modalForm.questionNumberPerLine"
  56. :min="1"
  57. :max="10"
  58. :step="1"
  59. step-strictly
  60. :controls="false"
  61. ></el-input-number>
  62. <span class="el-input-tips">*指一行显示空位数量</span>
  63. </el-form-item>
  64. <el-form-item label="题号前缀:">
  65. <el-input
  66. style="width:125px;"
  67. v-model.trim="modalForm.numberPre"
  68. clearable
  69. ></el-input>
  70. </el-form-item>
  71. <el-form-item label="空位排列方向:" required>
  72. <el-radio-group v-model="modalForm.questionDirection" size="small">
  73. <el-radio-button
  74. v-for="(val, key) in DIRECTION_TYPE"
  75. :key="key"
  76. :label="key"
  77. >{{ val }}</el-radio-button
  78. >
  79. </el-radio-group>
  80. </el-form-item>
  81. <el-form-item label="小题空数类型:">
  82. <el-radio-group
  83. v-model="modalForm.questionLineType"
  84. size="small"
  85. @change="lineTypeChange"
  86. >
  87. <el-radio-button label="norm">标准</el-radio-button>
  88. <el-radio-button label="custom">自定义</el-radio-button>
  89. </el-radio-group>
  90. </el-form-item>
  91. <el-form-item
  92. v-if="modalForm.questionLineType === 'norm'"
  93. prop="lineNumberPerQuestion"
  94. label="每题空数:"
  95. >
  96. <el-input-number
  97. style="width:125px;"
  98. v-model="modalForm.lineNumberPerQuestion"
  99. :min="1"
  100. :max="15"
  101. :step="1"
  102. step-strictly
  103. :controls="false"
  104. ></el-input-number>
  105. <span class="el-input-tips">*指每一小题的空位数量</span>
  106. </el-form-item>
  107. <el-form-item v-else prop="questionLineNums" label="各小题空数:">
  108. <table class="table table-white">
  109. <tr>
  110. <th>题号</th>
  111. <th>空数</th>
  112. </tr>
  113. <tr v-for="option in questionLineNumOptions" :key="option.no">
  114. <td>{{ option.no }}</td>
  115. <td>
  116. <el-input-number
  117. v-model="option.count"
  118. size="mini"
  119. :min="1"
  120. :max="50"
  121. :step="1"
  122. step-strictly
  123. :controls="false"
  124. style="width:125px;"
  125. ></el-input-number>
  126. </td>
  127. </tr>
  128. </table>
  129. </el-form-item>
  130. </el-form>
  131. </div>
  132. </template>
  133. <script>
  134. import { DIRECTION_TYPE } from "../../enumerate";
  135. const initModalForm = {
  136. id: "",
  137. topicName: "",
  138. startNumber: 1,
  139. endNumber: 2,
  140. questionsCount: 2,
  141. questionNumberPerLine: 1,
  142. lineNumberPerQuestion: 1,
  143. lineSpacing: 40,
  144. questionDirection: "horizontal",
  145. questionLineType: "norm",
  146. questionLineNums: [],
  147. numberPre: ""
  148. };
  149. export default {
  150. name: "edit-fill-line",
  151. props: {
  152. instance: {
  153. type: Object,
  154. default() {
  155. return {};
  156. }
  157. }
  158. },
  159. data() {
  160. const numberRangeValidater = (rule, value, callback) => {
  161. if (!this.modalForm.startNumber || !this.modalForm.endNumber) {
  162. return callback(new Error("请输入起止题号"));
  163. }
  164. if (this.modalForm.startNumber > this.modalForm.endNumber) {
  165. callback(new Error("开始题号不能大于结束题号"));
  166. } else {
  167. callback();
  168. }
  169. };
  170. return {
  171. modalForm: { ...initModalForm },
  172. DIRECTION_TYPE,
  173. questionLineNumOptions: [{ no: 1, count: 1 }],
  174. rules: {
  175. topicName: [
  176. {
  177. required: true,
  178. message: "请输入题目名称",
  179. trigger: "change"
  180. }
  181. ],
  182. endNumber: [
  183. {
  184. required: true,
  185. message: "请输入起止题号",
  186. trigger: "change"
  187. },
  188. {
  189. type: "number",
  190. validator: numberRangeValidater,
  191. trigger: "change"
  192. }
  193. ],
  194. lineSpacing: [
  195. {
  196. required: true,
  197. type: "number",
  198. message: "请输入空位上下间距",
  199. trigger: "change"
  200. }
  201. ],
  202. questionNumberPerLine: [
  203. {
  204. required: true,
  205. type: "number",
  206. message: "请输入每行空数",
  207. trigger: "change"
  208. }
  209. ],
  210. lineNumberPerQuestion: [
  211. {
  212. required: true,
  213. type: "number",
  214. message: "请输入每题空数",
  215. trigger: "change"
  216. }
  217. ]
  218. }
  219. };
  220. },
  221. mounted() {
  222. this.initData(this.instance);
  223. },
  224. methods: {
  225. initData(val) {
  226. const valInfo = val.parent || val;
  227. this.modalForm = { ...valInfo };
  228. this.modalForm.endNumber =
  229. this.modalForm.startNumber + this.modalForm.questionsCount - 1;
  230. this.questionLineNumOptions = this.modalForm.questionLineNums;
  231. },
  232. lineTypeChange() {
  233. // check start end number
  234. if (this.modalForm.questionLineType === "custom") {
  235. let questionLineNumOptions = [];
  236. for (
  237. let i = this.modalForm.startNumber;
  238. i <= this.modalForm.endNumber;
  239. i++
  240. ) {
  241. questionLineNumOptions.push({
  242. no: i,
  243. count: this.modalForm.lineNumberPerQuestion
  244. });
  245. }
  246. this.questionLineNumOptions = questionLineNumOptions;
  247. } else {
  248. this.questionLineNumOptions = [];
  249. }
  250. },
  251. async submit() {
  252. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  253. if (!valid) return;
  254. this.modalForm.questionsCount =
  255. this.modalForm.endNumber - this.modalForm.startNumber + 1;
  256. this.modalForm.questionLineNums = this.questionLineNumOptions;
  257. this.$emit("modified", this.modalForm);
  258. }
  259. }
  260. };
  261. </script>