ClientParamSet.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div class="client-param-set">
  3. <Row :gutter="20" type="flex">
  4. <Col span="12">
  5. <div class="part-box">
  6. <h2 class="client-param-title">科目名称设置</h2>
  7. <Button type="success" icon="md-add" @click="toAdd">新增</Button>
  8. <Table
  9. ref="TableList"
  10. :columns="columes"
  11. :data="subjects"
  12. border
  13. ></Table></div
  14. ></Col>
  15. <Col span="12">
  16. <div class=" part-box">
  17. <h2 class="client-param-title">其他设置</h2>
  18. <Form ref="modalFormComp" :model="modalForm" :label-width="100">
  19. <FormItem prop="name">
  20. <Checkbox v-model="modalForm.isScanPackage"
  21. >是否整包扫描</Checkbox
  22. >
  23. </FormItem>
  24. <FormItem prop="name">
  25. <Checkbox v-model="modalForm.isImageEncryption"
  26. >图片是否加密</Checkbox
  27. >
  28. </FormItem>
  29. <FormItem prop="imageNameRule" label="图片命名规则">
  30. <Select
  31. v-model="modalForm.imageNameRule"
  32. placeholder="请选择图片命名规则"
  33. >
  34. <Option value=""></Option>
  35. </Select>
  36. </FormItem>
  37. <FormItem prop="paperGrading" label="试卷档位">
  38. <Select
  39. v-model="modalForm.imageNameRule"
  40. placeholder="请选择试卷档位"
  41. >
  42. <Option value=""></Option>
  43. </Select>
  44. </FormItem>
  45. <FormItem>
  46. <Button type="primary" @click="toSubmit">保存</Button>
  47. </FormItem>
  48. </Form>
  49. </div>
  50. </Col>
  51. </Row>
  52. </div>
  53. </template>
  54. <script>
  55. import { subjectList, uploadSubject, deleteSubject } from "@/api";
  56. const initSubject = {
  57. id: "",
  58. subjectName: "",
  59. subjectCode: "",
  60. password: ""
  61. };
  62. export default {
  63. name: "client-param-set",
  64. data() {
  65. return {
  66. subjects: [],
  67. columes: [
  68. {
  69. type: "index",
  70. title: "序号",
  71. width: 60,
  72. align: "center"
  73. },
  74. {
  75. title: "科目名称",
  76. key: "subjectName",
  77. render: (h, param) => {
  78. return h("Input", {
  79. props: {
  80. value: param.row.subjectName,
  81. clearable: true
  82. },
  83. style: {
  84. width: "120px"
  85. },
  86. on: {
  87. input: function(value) {
  88. param.row.subjectName = value;
  89. }
  90. }
  91. });
  92. }
  93. },
  94. {
  95. title: "科目代码",
  96. key: "subjectCode",
  97. render: (h, param) => {
  98. return h("Input", {
  99. props: {
  100. value: param.row.subjectCode,
  101. clearable: true
  102. },
  103. style: {
  104. width: "120px"
  105. },
  106. on: {
  107. input: function(value) {
  108. param.row.subjectCode = value;
  109. }
  110. }
  111. });
  112. }
  113. },
  114. {
  115. title: "操作",
  116. key: "action",
  117. width: 120,
  118. align: "center",
  119. render: (h, param) => {
  120. let actions = [
  121. {
  122. name: "保存",
  123. action: () => {
  124. this.toSave(param.row);
  125. }
  126. },
  127. {
  128. name: "删除",
  129. type: "error",
  130. action: () => {
  131. this.toDelete(param.row);
  132. }
  133. }
  134. ];
  135. return h("div", this.$tableAction(h, actions));
  136. }
  137. }
  138. ],
  139. // other param
  140. modalForm: {
  141. isScanPackage: false,
  142. isImageEncryption: false,
  143. imageNameRule: "",
  144. paperGrading: ""
  145. }
  146. };
  147. },
  148. mounted() {
  149. this.getList();
  150. },
  151. methods: {
  152. async getList() {
  153. const datas = {
  154. workId: this.workId
  155. };
  156. const data = await subjectList(datas);
  157. console.log(data);
  158. if (!this.subjects.length) this.toAdd();
  159. },
  160. toAdd() {
  161. this.subjects.push({ ...initSubject });
  162. },
  163. async toSave(row) {
  164. if (!row.subjectName || row.subjectName.length > 20) {
  165. this.$Message.error("必须输入科目名称,且科目名称长度不能超过20个字符");
  166. return;
  167. }
  168. if (!row.subjectCode.match(new RegExp(`^[a-zA-Z0-9_]{3,20}$`))) {
  169. this.$Message.error(
  170. "当前科目代码只能由数字、字母和下划线组成,长度2-20个字符"
  171. );
  172. return;
  173. }
  174. await uploadSubject(row);
  175. this.$Message.success("保存成功!");
  176. this.getList();
  177. },
  178. toDelete(row) {
  179. if (!row.id) {
  180. // TODO:
  181. return;
  182. }
  183. this.$Modal.confirm({
  184. title: "删除警告",
  185. content: "确定要删除当前科目吗?",
  186. onOk: () => {
  187. this.toDel(row.id);
  188. }
  189. });
  190. },
  191. async toDel(id) {
  192. await deleteSubject(id);
  193. this.$Message.success("删除成功!");
  194. this.getList();
  195. },
  196. toSubmit() {}
  197. }
  198. };
  199. </script>