index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class="p-base full">
  3. <el-card shadow="never">
  4. <base-form
  5. ref="formRef"
  6. :label-width="useVW(120)"
  7. size="small"
  8. :groups="groups"
  9. :model="model"
  10. :items="items"
  11. :rules="rules"
  12. :disabled="adding || editing"
  13. >
  14. <template #form-item-expand>
  15. <el-button type="primary" link @click="expand = !expand">高级设置</el-button>
  16. </template>
  17. <template #form-item-operation>
  18. <confirm-button ok-text="保存" @confirm="onSubmit" @cancel="onCancel"></confirm-button>
  19. </template>
  20. </base-form>
  21. </el-card>
  22. </div>
  23. </template>
  24. <script setup lang="ts" name="SubjectAddQuestion">
  25. /** 添加大题 */
  26. import { computed, reactive, ref } from 'vue'
  27. import { useRouter } from 'vue-router'
  28. import { ElCard, ElButton, ElMessage } from 'element-plus'
  29. import { omit } from 'lodash-es'
  30. import ConfirmButton from '@/components/common/ConfirmButton.vue'
  31. import BaseForm from '@/components/element/BaseForm.vue'
  32. import useFetch from '@/hooks/useFetch'
  33. import useForm from '@/hooks/useForm'
  34. import useVW from '@/hooks/useVW'
  35. import type { ExtractApiParams } from 'api-type'
  36. import type { EpFormItem, EpFormRules, FormGroup } from 'global-type'
  37. const { back } = useRouter()
  38. const props = defineProps<{ subjectCode: string; mainNumber?: number | string }>()
  39. const isEdit = !!props.mainNumber
  40. const { fetch: getMainQuestionInfo, result: MainQuestionInfo } = useFetch('getMainQuestionInfo')
  41. const { fetch: addMainQuestion, loading: adding } = useFetch('addMainQuestion')
  42. const { fetch: editMainQuestion, loading: editing } = useFetch('editMainQuestion')
  43. const model = reactive<ExtractApiParams<'addMainQuestion'>>({
  44. subjectCode: props.subjectCode,
  45. groupNumber: void 0,
  46. category: void 0,
  47. intervalScore: void 0,
  48. mainNumber: void 0,
  49. mainTitle: '',
  50. minMarkTime: void 0,
  51. questionCount: void 0,
  52. questionScore: void 0,
  53. remarkNumber: void 0,
  54. remarkType: 'QUANTITY',
  55. levelRange: [],
  56. standardRate: void 0,
  57. selfRate: void 0,
  58. systemRate: void 0,
  59. startNumber: 1,
  60. })
  61. const { formRef, elFormRef, defineColumn, _ } = useForm()
  62. const rules = computed<EpFormRules>(() => {
  63. return {
  64. groupNumber: [{ required: true, message: '请输入小组数量' }],
  65. category: [{ required: false, message: '请选择成绩表对应字段' }],
  66. intervalScore: [{ required: true, message: '请输入小题间隔分' }],
  67. mainNumber: [{ required: true, message: '请输入大题号' }],
  68. mainTitle: [{ required: true, message: '请输入大题名称' }],
  69. minMarkTime: [{ required: true, message: '请输入最小阅卷时长' }],
  70. questionCount: [{ required: true, message: '请输入小题数量' }],
  71. questionScore: [{ required: true, message: '请输入小题满分' }],
  72. remarkType: [{ required: true, message: '请选择回评设置' }],
  73. remarkNumber: [{ required: true, message: '请输入回评设置' }],
  74. startNumber: [{ required: true, message: '请输入小题起始号' }],
  75. systemRate: [{ required: !!model.levelRange?.length, message: '请设置系统抽查比例' }],
  76. }
  77. })
  78. const expand = ref<boolean>(false)
  79. const groups = computed<FormGroup[]>(() => {
  80. return [
  81. {
  82. rowKeys: Array.from({ length: 10 }).map((_, i) => `row-${i + 1}`),
  83. },
  84. {
  85. rowKeys: ['row-11', 'row-12'],
  86. groupTitle: '高级设置',
  87. hidden: !expand.value,
  88. },
  89. {
  90. rowKeys: ['expand'],
  91. hidden: expand.value,
  92. },
  93. ]
  94. })
  95. const Span6 = defineColumn(_, _, { span: 6 })
  96. const items = computed<EpFormItem[]>(() => [
  97. Span6(
  98. {
  99. label: '大题号',
  100. slotType: 'input',
  101. prop: 'mainNumber',
  102. slot: {
  103. placeholder: '大题号',
  104. disabled: isEdit,
  105. },
  106. },
  107. 'row-1'
  108. ),
  109. Span6({ label: '大题名称', slotType: 'input', prop: 'mainTitle', slot: { placeholder: '大题名称' } }, 'row-2'),
  110. Span6(
  111. {
  112. label: '成绩表对应字段',
  113. slotType: 'select',
  114. prop: 'category',
  115. slot: {
  116. placeholder: '成绩表对应字段',
  117. clearable: true,
  118. options: [
  119. { label: '作文分', value: 'WRITING' },
  120. { label: '翻译分', value: 'TRANSLATE' },
  121. ],
  122. },
  123. },
  124. 'row-2'
  125. ),
  126. Span6(
  127. {
  128. label: '小题起始号',
  129. slotType: 'input',
  130. prop: 'startNumber',
  131. slot: { placeholder: '小题起始号', disabled: isEdit },
  132. },
  133. 'row-3'
  134. ),
  135. Span6({ label: '小题数量', slotType: 'input', prop: 'questionCount', slot: { placeholder: '小题数量' } }, 'row-4'),
  136. Span6({ label: '小题满分', slotType: 'input', prop: 'questionScore', slot: { placeholder: '小题满分' } }, 'row-5'),
  137. Span6({ label: '间隔分', slotType: 'input', prop: 'intervalScore', slot: { placeholder: '间隔分' } }, 'row-6'),
  138. Span6(
  139. {
  140. label: '最小阅卷时长(秒)',
  141. slotType: 'input',
  142. prop: 'minMarkTime',
  143. slot: { placeholder: '最小阅卷时长(秒)' },
  144. },
  145. 'row-7'
  146. ),
  147. Span6(
  148. { label: '评卷小组数量', slotType: 'input', prop: 'groupNumber', slot: { placeholder: '评卷小组数量' } },
  149. 'row-8'
  150. ),
  151. Span6(
  152. {
  153. label: '回评设置',
  154. slotType: 'select',
  155. prop: 'remarkType',
  156. slot: {
  157. placeholder: '回评设置',
  158. options: [
  159. { value: 'QUANTITY', label: '按数量' },
  160. { value: 'TIME', label: '按时间' },
  161. ],
  162. },
  163. },
  164. 'row-9'
  165. ),
  166. Span6(
  167. { label: model.remarkType === 'QUANTITY' ? '数量' : '时间:(近N秒)', prop: 'remarkNumber', slotType: 'input' },
  168. 'row-10'
  169. ),
  170. Span6(
  171. { label: '标准卷分发频度', slotType: 'input', prop: 'standardRate', slot: { placeholder: '标准卷分发频度' } },
  172. 'row-11'
  173. ),
  174. Span6(
  175. { label: '自查卷分发频度', slotType: 'input', prop: 'selfRate', slot: { placeholder: '自查卷分发频度' } },
  176. 'row-11'
  177. ),
  178. Span6(
  179. { label: '系统抽查卷比例', slotType: 'input', prop: 'systemRate', slot: { placeholder: '系统抽查卷比例' } },
  180. 'row-12'
  181. ),
  182. Span6(
  183. { label: '档次抽查比例', slotType: 'input', prop: 'levelRange', slot: { placeholder: '档次抽查比例' } },
  184. 'row-12'
  185. ),
  186. Span6({ slotName: 'expand' }, 'expand'),
  187. Span6({ slotName: 'operation' }, 'operation'),
  188. ])
  189. if (isEdit) {
  190. getMainQuestionInfo({ subjectCode: props.subjectCode, mainNumber: +props.mainNumber }).then((result) => {
  191. Object.assign(model, omit(result, 'examId'))
  192. })
  193. }
  194. const onSubmit = async () => {
  195. try {
  196. const valid = await elFormRef?.value?.validate().catch((error: object) => {
  197. if (
  198. !expand.value &&
  199. Object.keys(error).some((k) => ['standardRate', 'selfRate', 'systemRate', 'levelRange'].includes(k))
  200. ) {
  201. expand.value = true
  202. }
  203. })
  204. if (valid) {
  205. const data = { ...model, levelRange: model.levelRange || [] }
  206. await (isEdit ? editMainQuestion(data) : addMainQuestion(data))
  207. ElMessage.success('保存成功')
  208. }
  209. } catch (error) {
  210. console.error(error)
  211. }
  212. }
  213. const onCancel = () => {
  214. back()
  215. }
  216. </script>
  217. <style scoped lang="scss"></style>