rf.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <base-form ref="formRef" :label-width="useVW(88)" :groups="groups" :items="items" :model="model" :disabled="loading">
  3. <template #form-item-prefix>
  4. <span class="flex items-center">
  5. <el-input v-model="model.prefix"></el-input>
  6. <span class="m-l-mini">0000000</span>
  7. </span>
  8. </template>
  9. <template #form-item-address>
  10. <span class="flex items-center">
  11. {{ filePath }}
  12. </span>
  13. </template>
  14. <template #form-item-upload>
  15. <div class="flex items-center">
  16. <el-input v-model="fileName" disabled placeholder="导入文件"></el-input>
  17. <el-upload
  18. ref="upload"
  19. v-model:file-list="fileList"
  20. :limit="1"
  21. :show-file-list="false"
  22. :on-exceed="onExceed"
  23. :auto-upload="false"
  24. >
  25. <el-button class="m-l-base" type="primary">浏览</el-button>
  26. </el-upload>
  27. </div>
  28. </template>
  29. <template #form-item-progress>
  30. <el-progress v-show="showProgress" class="flex-1" :percentage="percentage" color="#00BA97" />
  31. </template>
  32. <el-form-item class="m-t-base form-footer">
  33. <el-button type="primary" :loading="loading" @click="onSubmit">确定导入</el-button>
  34. </el-form-item>
  35. </base-form>
  36. </template>
  37. <script setup lang="ts" name="ImportRF">
  38. /** 导入RF卷 */
  39. import { reactive, watch, computed, ref } from 'vue'
  40. import { ElFormItem, ElButton, ElUpload, ElInput, ElMessage, ElProgress } from 'element-plus'
  41. import BaseForm from '@/components/element/BaseForm.vue'
  42. import useFetch from '@/hooks/useFetch'
  43. import useForm from '@/hooks/useForm'
  44. import useOptions from '@/hooks/useOptions'
  45. import useUploadFile from '@/hooks/useUploadFile'
  46. import useVW from '@/hooks/useVW'
  47. import type { FormGroup, EpFormItem } from 'global-type'
  48. import type { ExtractApiParams } from 'api-type'
  49. const showProgress = ref(false)
  50. const { fileList, upload, percentage, setPercentage, onExceed, onUploadProgress, reset } = useUploadFile()
  51. const { fetch: getImportFilePath, result: filePath } = useFetch('getImportFilePath')
  52. const { fetch, loading } = useFetch('importRfPaper', { onUploadProgress })
  53. const model = reactive<ExtractApiParams<'importRfPaper'>>({
  54. file: void 0,
  55. subjectCode: '',
  56. mainNumber: void 0,
  57. prefix: '',
  58. separator: '',
  59. })
  60. watch([() => model.subjectCode, () => model.mainNumber], () => {
  61. /** 获取导入文件路径 */
  62. model.subjectCode &&
  63. model.mainNumber &&
  64. getImportFilePath({
  65. filePathType: 'RF',
  66. subjectCode: model.subjectCode,
  67. mainNumber: model.mainNumber,
  68. })
  69. })
  70. const { subjectList, mainQuestionList, dataModel, changeModelValue } = useOptions(['subject', 'question'])
  71. watch(dataModel, () => {
  72. model.subjectCode = dataModel.subject || ''
  73. model.mainNumber = dataModel.question
  74. })
  75. const { formRef, elFormRef, defineColumn, _ } = useForm()
  76. const fileName = computed(() => fileList.value?.[0]?.name)
  77. watch(
  78. fileList,
  79. () => {
  80. model.file = fileList.value?.[0]?.raw
  81. },
  82. { deep: true }
  83. )
  84. const groups: FormGroup[] = [
  85. { groupTitle: '选择大题', rowKeys: ['row-1'] },
  86. { groupTitle: '试卷设置', rowKeys: ['row-2', 'row-3', 'row-4'] },
  87. { groupTitle: '选择文件', rowKeys: ['row-5'] },
  88. ]
  89. const span6 = defineColumn(_, '', { span: 6 })
  90. const items = computed<EpFormItem[]>(() => {
  91. return [
  92. span6({
  93. rowKey: 'row-1',
  94. label: '科目',
  95. prop: 'subjectCode',
  96. slotType: 'select',
  97. slot: { placeholder: '选择科目', options: subjectList.value, onChange: changeModelValue('subject') },
  98. }),
  99. span6({
  100. rowKey: 'row-1',
  101. label: '大题',
  102. labelWidth: useVW(100),
  103. prop: 'mainNumber',
  104. slotType: 'select',
  105. slot: { placeholder: '选择大题', options: mainQuestionList.value, onChange: changeModelValue('question') },
  106. }),
  107. span6({
  108. rowKey: 'row-2',
  109. label: '试卷密码前缀',
  110. prop: 'prefix',
  111. slotName: 'prefix',
  112. itemDescription: { description: '导用区别正常考生说试卷,导入卷密号为8位,如20000000' },
  113. }),
  114. span6({
  115. rowKey: 'row-3',
  116. label: '分隔符',
  117. prop: 'separator',
  118. slotType: 'input',
  119. itemDescription: { description: '文件格式为:图象文件名|标准分数' },
  120. }),
  121. span6({
  122. rowKey: 'row-4',
  123. label: '图片路径',
  124. slotName: 'address',
  125. itemDescription: { description: '试卷图片请按路径存放' },
  126. }),
  127. span6({
  128. rowKey: 'row-5',
  129. label: '导入文件',
  130. prop: 'file',
  131. slotName: 'upload',
  132. }),
  133. span6({
  134. rowKey: 'row-6',
  135. slotName: 'progress',
  136. }),
  137. ]
  138. })
  139. async function onSubmit() {
  140. try {
  141. const valid = await elFormRef?.value?.validate()
  142. if (valid) {
  143. showProgress.value = true
  144. await fetch(model)
  145. setPercentage(100)
  146. ElMessage.success(`导入成功`)
  147. elFormRef?.value?.resetFields()
  148. reset()
  149. }
  150. } catch (error) {
  151. showProgress.value = false
  152. setPercentage(0)
  153. console.error(error)
  154. }
  155. }
  156. </script>
  157. <style scoped lang="scss"></style>