rf.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 } = 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 } = useOptions(['subject', 'question'])
  71. const { formRef, elFormRef, defineColumn, _ } = useForm()
  72. const fileName = computed(() => fileList.value?.[0]?.name)
  73. watch(
  74. fileList,
  75. () => {
  76. model.file = fileList.value?.[0]?.raw
  77. },
  78. { deep: true }
  79. )
  80. const groups: FormGroup[] = [
  81. { groupTitle: '选择大题', rowKeys: ['row-1'] },
  82. { groupTitle: '试卷设置', rowKeys: ['row-2', 'row-3', 'row-4'] },
  83. { groupTitle: '选择文件', rowKeys: ['row-5'] },
  84. ]
  85. const span6 = defineColumn(_, '', { span: 6 })
  86. const items = computed<EpFormItem[]>(() => {
  87. return [
  88. span6({
  89. rowKey: 'row-1',
  90. label: '科目',
  91. prop: 'subjectCode',
  92. slotType: 'select',
  93. slot: { placeholder: '选择科目', options: subjectList.value },
  94. }),
  95. span6({
  96. rowKey: 'row-1',
  97. label: '大题',
  98. labelWidth: useVW(100),
  99. prop: 'mainNumber',
  100. slotType: 'select',
  101. slot: { placeholder: '选择大题', options: mainQuestionList.value },
  102. }),
  103. span6({
  104. rowKey: 'row-2',
  105. label: '试卷密码前缀',
  106. prop: 'prefix',
  107. slotName: 'prefix',
  108. itemDescription: { description: '导用区别正常考生说试卷,导入卷密号为8位,如20000000' },
  109. }),
  110. span6({
  111. rowKey: 'row-3',
  112. label: '分隔符',
  113. prop: 'separator',
  114. slotType: 'input',
  115. itemDescription: { description: '文件格式为:图象文件名|标准分数' },
  116. }),
  117. span6({
  118. rowKey: 'row-4',
  119. label: '图片路径',
  120. slotName: 'address',
  121. itemDescription: { description: '试卷图片请按路径存放' },
  122. }),
  123. span6({
  124. rowKey: 'row-5',
  125. label: '导入文件',
  126. prop: 'file',
  127. slotName: 'upload',
  128. }),
  129. span6({
  130. rowKey: 'row-6',
  131. slotName: 'progress',
  132. }),
  133. ]
  134. })
  135. async function onSubmit() {
  136. try {
  137. const valid = await elFormRef?.value?.validate()
  138. if (valid) {
  139. showProgress.value = true
  140. await fetch(model)
  141. setPercentage(100)
  142. ElMessage.success(`导入成功`)
  143. }
  144. } catch (error) {
  145. showProgress.value = false
  146. setPercentage(0)
  147. console.error(error)
  148. }
  149. }
  150. </script>
  151. <style scoped lang="scss"></style>