|
@@ -1,66 +1,29 @@
|
|
|
<template>
|
|
|
- <base-form
|
|
|
- ref="formRef"
|
|
|
- :label-width="useVW(88)"
|
|
|
- :groups="groups"
|
|
|
- :rules="rules"
|
|
|
- :items="items"
|
|
|
- :model="model"
|
|
|
- :disabled="loading"
|
|
|
- >
|
|
|
+ <base-form :label-width="useVW(88)" :groups="groups" :rules="rules" :items="items" :model="model">
|
|
|
<template #form-item-address>
|
|
|
<span class="flex items-center">
|
|
|
{{ filePath }}
|
|
|
</span>
|
|
|
</template>
|
|
|
- <template #form-item-upload>
|
|
|
- <div class="flex items-center">
|
|
|
- <el-input v-model="fileName" disabled placeholder="导入文件"></el-input>
|
|
|
- <el-upload
|
|
|
- ref="upload"
|
|
|
- v-model:file-list="fileList"
|
|
|
- :limit="1"
|
|
|
- :show-file-list="false"
|
|
|
- :on-exceed="onExceed"
|
|
|
- :auto-upload="false"
|
|
|
- >
|
|
|
- <el-button class="m-l-base" type="primary">浏览</el-button>
|
|
|
- </el-upload>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- <template #form-item-progress>
|
|
|
- <el-progress v-show="showProgress" class="flex-1" :percentage="percentage" color="#00BA97" />
|
|
|
- </template>
|
|
|
- <el-form-item class="m-t-base form-footer">
|
|
|
- <el-button type="primary" :loading="loading" @click="onSubmit">确定导入</el-button>
|
|
|
- </el-form-item>
|
|
|
</base-form>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts" name="ImportStandard">
|
|
|
/** 导入评分标准 */
|
|
|
import { reactive, watch, computed, ref } from 'vue'
|
|
|
-import { ElFormItem, ElButton, ElUpload, ElInput, ElMessage, ElProgress } from 'element-plus'
|
|
|
import BaseForm from '@/components/element/BaseForm.vue'
|
|
|
import useFetch from '@/hooks/useFetch'
|
|
|
import useForm from '@/hooks/useForm'
|
|
|
import useOptions from '@/hooks/useOptions'
|
|
|
-import useUploadFile from '@/hooks/useUploadFile'
|
|
|
import useVW from '@/hooks/useVW'
|
|
|
|
|
|
import type { FormGroup, EpFormItem, EpFormRules } from 'global-type'
|
|
|
-import type { ExtractApiParams } from 'api-type'
|
|
|
-
|
|
|
-const showProgress = ref(false)
|
|
|
-
|
|
|
-const { fileList, upload, percentage, setPercentage, onExceed, onUploadProgress, reset } = useUploadFile()
|
|
|
|
|
|
const { fetch: getImportFilePath, result: filePath } = useFetch('getImportFilePath')
|
|
|
|
|
|
-const { fetch, loading } = useFetch('importMarkStandard', { onUploadProgress })
|
|
|
+const { subjectList, mainQuestionList, dataModel, changeModelValue } = useOptions(['subject', 'question'])
|
|
|
|
|
|
-const model = reactive<ExtractApiParams<'importMarkStandard'>>({
|
|
|
- file: void 0,
|
|
|
+const model = reactive<{ subjectCode: string; mainNumber?: number }>({
|
|
|
subjectCode: '',
|
|
|
mainNumber: void 0,
|
|
|
})
|
|
@@ -76,35 +39,21 @@ watch([() => model.subjectCode, () => model.mainNumber], () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
-const { subjectList, mainQuestionList, dataModel, changeModelValue } = useOptions(['subject', 'question'])
|
|
|
-
|
|
|
watch(dataModel, () => {
|
|
|
model.subjectCode = dataModel.subject || ''
|
|
|
model.mainNumber = dataModel.question
|
|
|
})
|
|
|
|
|
|
-const { formRef, elFormRef, defineColumn, _ } = useForm()
|
|
|
-
|
|
|
-const fileName = computed(() => fileList.value?.[0]?.name)
|
|
|
-
|
|
|
-watch(
|
|
|
- fileList,
|
|
|
- () => {
|
|
|
- model.file = fileList.value?.[0]?.raw
|
|
|
- },
|
|
|
- { deep: true }
|
|
|
-)
|
|
|
+const { defineColumn, _ } = useForm()
|
|
|
|
|
|
const rules: EpFormRules = {
|
|
|
subjectCode: [{ required: true, message: '请选择科目' }],
|
|
|
mainNumber: [{ required: true, message: '请选择大题' }],
|
|
|
- file: [{ required: true, message: '请选择导入文件' }],
|
|
|
}
|
|
|
|
|
|
const groups: FormGroup[] = [
|
|
|
{ groupTitle: '选择大题', rowKeys: ['row-1'] },
|
|
|
{ groupTitle: '试卷设置', rowKeys: ['row-2'] },
|
|
|
- { groupTitle: '选择文件', rowKeys: ['row-3'] },
|
|
|
]
|
|
|
|
|
|
const span6 = defineColumn(_, '', { span: 6 })
|
|
@@ -132,37 +81,8 @@ const items = computed<EpFormItem[]>(() => {
|
|
|
slotName: 'address',
|
|
|
itemDescription: { description: '试卷图片请按路径存放' },
|
|
|
}),
|
|
|
- span6({
|
|
|
- rowKey: 'row-3',
|
|
|
- label: '导入文件',
|
|
|
- prop: 'file',
|
|
|
- slotName: 'upload',
|
|
|
- }),
|
|
|
- span6({
|
|
|
- rowKey: 'row-4',
|
|
|
- slotName: 'progress',
|
|
|
- }),
|
|
|
]
|
|
|
})
|
|
|
-
|
|
|
-async function onSubmit() {
|
|
|
- try {
|
|
|
- const valid = await elFormRef?.value?.validate()
|
|
|
- if (valid) {
|
|
|
- showProgress.value = true
|
|
|
- setPercentage(0)
|
|
|
- await fetch(model)
|
|
|
- setPercentage(100)
|
|
|
- ElMessage.success(`导入成功`)
|
|
|
- elFormRef?.value?.resetFields()
|
|
|
- reset()
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- showProgress.value = false
|
|
|
- setPercentage(0)
|
|
|
- console.error(error)
|
|
|
- }
|
|
|
-}
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss"></style>
|