|
@@ -1,6 +1,7 @@
|
|
|
<template>
|
|
|
- <Dialog loading="loading" v-model="dialogVisible" title="标本信息导入" width="600">
|
|
|
- <el-alert title="可单独上传xlsx表或者图片压缩包。需确保图片命名规范,不与旧图片命名重复。" type="warning" style="margin-bottom: 10px"/>
|
|
|
+ <Dialog loading="loading" v-model="dialogVisible" title="标本信息导入" width="600">
|
|
|
+ <el-alert title="可单独上传xlsx表或者图片压缩包。需确保图片命名规范,不与旧图片命名重复。"
|
|
|
+ type="warning" style="margin-bottom: 10px"/>
|
|
|
<el-upload
|
|
|
ref="uploadRef"
|
|
|
v-model:file-list="fileList"
|
|
@@ -14,14 +15,10 @@
|
|
|
accept=".xlsx, .xls"
|
|
|
drag
|
|
|
>
|
|
|
- <Icon icon="ep:upload" />
|
|
|
+ <Icon icon="ep:upload"/>
|
|
|
<div class="el-upload__text">将xlsx表拖到此处,或<em>点击上传</em></div>
|
|
|
<template #tip>
|
|
|
<div class="el-upload__tip text-center">
|
|
|
-<!-- <div class="el-upload__tip">-->
|
|
|
-<!-- <el-checkbox v-model="updateSupport" />-->
|
|
|
-<!-- 是否更新已经存在的标本数据-->
|
|
|
-<!-- </div>-->
|
|
|
<span>仅允许导入 xls、xlsx 格式文件。</span>
|
|
|
<el-link
|
|
|
:underline="false"
|
|
@@ -48,20 +45,20 @@
|
|
|
:headers="uploadHeaders"
|
|
|
accept=".zip"
|
|
|
>
|
|
|
- <el-icon class="el-icon--upload" ><upload-filled /></el-icon>
|
|
|
+ <el-icon class="el-icon--upload">
|
|
|
+ <upload-filled/>
|
|
|
+ </el-icon>
|
|
|
<div class="el-upload__text">
|
|
|
<div class="el-upload__text">将图片压缩包拖到此处,或<em>点击上传</em></div>
|
|
|
</div>
|
|
|
<template #tip>
|
|
|
<div class="el-upload__tip text-center">
|
|
|
-<!-- <el-checkbox v-model="updateSupport" />-->
|
|
|
-<!-- 是否更新已经存在的标本图片-->
|
|
|
- <span>仅允许导入 .zip 格式文件。</span>
|
|
|
+ <span>仅允许导入 .zip 格式文件。</span>
|
|
|
<div class="el-upload__tip">
|
|
|
- <el-checkbox v-model="updateSupport" />
|
|
|
+ <el-checkbox v-model="updateSupport"/>
|
|
|
是否更新已经存在的标本数据
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
</el-upload>
|
|
|
<template #footer>
|
|
@@ -73,13 +70,13 @@
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
import download from '@/utils/download'
|
|
|
-import { getAccessToken, getTenantId } from '@/utils/auth'
|
|
|
+import {getAccessToken, getTenantId} from '@/utils/auth'
|
|
|
import {SpecimenInfoApi} from "@/api/museums/specimeninfo";
|
|
|
-import { ref, nextTick } from 'vue';
|
|
|
+import {ref, nextTick} from 'vue';
|
|
|
import {UploadFilled} from "@element-plus/icons-vue";
|
|
|
import {useUpload} from "@/components/UploadFile/src/useUpload";
|
|
|
|
|
|
-defineOptions({ name: 'SpecimenImportForm' })
|
|
|
+defineOptions({name: 'SpecimenImportForm'})
|
|
|
const loading = ref(true) // 列表的加载中
|
|
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
|
|
const formLoading = ref(false) // 表单的加载中
|
|
@@ -88,15 +85,14 @@ const uploadimageRef = ref()
|
|
|
|
|
|
const message = useMessage() // 消息弹窗
|
|
|
import axios from 'axios';
|
|
|
+
|
|
|
const updateSupport = ref(0) // 是否更新已经存在的用户数据
|
|
|
-//const updateImageSupport = ref() //是否更新已经存在的标本图片
|
|
|
const fileList = ref([]) // 文件列表
|
|
|
const imageList = ref([])
|
|
|
const uploadHeaders = ref() // 上传 Header 头
|
|
|
const importUrl =
|
|
|
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/museums/specimen-info/import-specimen-with-images'
|
|
|
-// const importImageUrl =
|
|
|
-// import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/museums/specimen-info/import-specimen-images'
|
|
|
+
|
|
|
/** 打开弹窗 */
|
|
|
const open = () => {
|
|
|
loading.value = true
|
|
@@ -106,8 +102,8 @@ const open = () => {
|
|
|
imageList.value = []
|
|
|
resetForm()
|
|
|
}
|
|
|
-defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
|
|
-const { httpRequest } = useUpload()
|
|
|
+defineExpose({open}) // 提供 open 方法,用于打开弹窗
|
|
|
+const {httpRequest} = useUpload()
|
|
|
|
|
|
/** 提交表单 */
|
|
|
const submitForm = async () => {
|
|
@@ -123,40 +119,40 @@ const submitForm = async () => {
|
|
|
formLoading.value = true
|
|
|
const formData = new FormData()
|
|
|
if (fileList.value.length > 0) {
|
|
|
- formData.append('file', fileList.value[0].raw, fileList.value[0].name)
|
|
|
+ formData.append('file', fileList.value[0].raw)
|
|
|
}
|
|
|
if (imageList.value.length > 0) {
|
|
|
- formData.append('imageFile', imageList.value[0].raw, imageList.value[0].name)
|
|
|
+ formData.append('imageFile', imageList.value[0].raw)
|
|
|
}
|
|
|
|
|
|
- axios.post(importUrl + '?updateSupport=' + updateSupport.value, formData, {
|
|
|
- headers: {
|
|
|
- ...uploadHeaders.value,
|
|
|
- 'Content-Type': 'multipart/form-data'
|
|
|
- }
|
|
|
- }).then((response) => {
|
|
|
+ try {
|
|
|
+ const response = await axios.post(importUrl + '?updateSupport=' + updateSupport.value, formData, {
|
|
|
+ headers: {
|
|
|
+ ...uploadHeaders.value,
|
|
|
+ 'Content-Type': 'multipart/form-data'
|
|
|
+ }
|
|
|
+ });
|
|
|
submitFormSuccess(response)
|
|
|
- }).catch((error) => {
|
|
|
+ } catch (error) {
|
|
|
submitFormError()
|
|
|
- }).finally(() => {
|
|
|
- formLoading.value = false
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
+ } finally {
|
|
|
+ formLoading.value = false;
|
|
|
+ }
|
|
|
+};
|
|
|
/** 文件上传成功 */
|
|
|
const emits = defineEmits(['success'])
|
|
|
const submitFormSuccess = (response: any) => {
|
|
|
-
|
|
|
- console.log(response.data.code != 0 , response.data.code)
|
|
|
+ console.log('上传响应:', response)
|
|
|
+ // console.log(response.data.code != 0 , response.data.code)
|
|
|
+ console.log(666)
|
|
|
if (response.data.code != 0) {
|
|
|
message.error(response.msg)
|
|
|
- formLoading.value = false
|
|
|
+ // formLoading.value = false
|
|
|
return
|
|
|
}
|
|
|
// 拼接提示语
|
|
|
-
|
|
|
const data = response.data.data
|
|
|
- console.log(data)
|
|
|
+ // console.log(data)
|
|
|
let text = '上传成功数量:' + data.createSpecimenNumbers.length + ';'
|
|
|
for (let specimenInfodata of data.createSpecimenNumbers) {
|
|
|
text += '标本编号:' + specimenInfodata + '、'
|
|
@@ -169,32 +165,19 @@ const submitFormSuccess = (response: any) => {
|
|
|
for (const specimenInfodata in data.failureSpecimenNumbers) {
|
|
|
text += '< ' + specimenInfodata + ': ' + data.failureSpecimenNumbers[specimenInfodata] + ' >'
|
|
|
}
|
|
|
+ console.log(555)
|
|
|
message.alert(text)
|
|
|
- formLoading.value = false
|
|
|
+ // formLoading.value = false
|
|
|
dialogVisible.value = false
|
|
|
// 发送操作成功的事件
|
|
|
emits('success')
|
|
|
}
|
|
|
-// ///文件反馈上传
|
|
|
-//
|
|
|
-// const handleExceed = () => {
|
|
|
-// message.error('最多只能上传一个文件,支持修改代码文件和压缩包分开上传!')
|
|
|
-// }
|
|
|
-//
|
|
|
-// const beforeUpload = (file: File) => {
|
|
|
-// // 在这里添加文件类型检查逻辑
|
|
|
-// // 例如,检查文件扩展名是否为 .zip 或 .txt
|
|
|
-// const fileExtension = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase();
|
|
|
-// if (fileExtension !== 'zip' && fileExtension !== 'txt') {
|
|
|
-// message.error('只支持上传.zip或.txt文件!');
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-// return true;
|
|
|
-// }
|
|
|
+
|
|
|
/** 上传错误提示 */
|
|
|
const submitFormError = (): void => {
|
|
|
message.error('上传失败,请您重新上传!')
|
|
|
formLoading.value = false
|
|
|
+ dialogVisible.value = false
|
|
|
}
|
|
|
|
|
|
/** 重置表单 */
|
|
@@ -216,21 +199,22 @@ const importTemplate = async () => {
|
|
|
download.excel(res, '标本批量导入模版.xls')
|
|
|
}
|
|
|
|
|
|
-/** 图片上传成功 */
|
|
|
|
|
|
-const submitImageSuccess = (response: any) => {
|
|
|
- console.log('tj',response)
|
|
|
- if (response.code !== 0) {
|
|
|
- message.error(response.msg)
|
|
|
- formLoading.value = false
|
|
|
- return
|
|
|
- }
|
|
|
- formLoading.value = false
|
|
|
- dialogVisible.value = false
|
|
|
- // 发送操作成功的事件
|
|
|
-
|
|
|
-}
|
|
|
+/** 图片上传成功 */
|
|
|
|
|
|
+// const submitImageSuccess = (response: any) => {
|
|
|
+// console.log('tj',response)
|
|
|
+// if (response.data.code !== 0) {
|
|
|
+// message.error(response.msg)
|
|
|
+// formLoading.value = false
|
|
|
+//
|
|
|
+// return
|
|
|
+// }
|
|
|
+// formLoading.value = false
|
|
|
+// dialogVisible.value = false
|
|
|
+// // 发送操作成功的事件
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
|
|
|
</script>
|