|
@@ -11,6 +11,7 @@
|
|
|
:on-success="submitFormSuccess"
|
|
|
accept=".xlsx, .xls"
|
|
|
drag
|
|
|
+ name = "excelFile"
|
|
|
>
|
|
|
<Icon icon="ep:upload" />
|
|
|
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
|
@@ -36,7 +37,7 @@
|
|
|
ref="uploadZipRef"
|
|
|
v-model:file-list="zipList"
|
|
|
drag
|
|
|
- :action="importZipUrl + '?updateSupport=' + updateSupport"
|
|
|
+ :action="importUrl + '?updateSupport=' + updateSupport"
|
|
|
:on-success="submitZipSuccess"
|
|
|
:auto-upload="false"
|
|
|
:disabled="formLoading"
|
|
@@ -44,16 +45,17 @@
|
|
|
:on-error="submitFormError"
|
|
|
:http-request="httpRequest"
|
|
|
accept=".zip,.rar"
|
|
|
+ name = "imageFile"
|
|
|
>
|
|
|
<Icon icon="ep:upload" />
|
|
|
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
|
|
<template #tip>
|
|
|
<div class="el-upload__tip text-center">
|
|
|
<span>仅允许导入 zip、rar 格式压缩包。</span>
|
|
|
- <div class="el-upload__tip">
|
|
|
+ <!-- <div class="el-upload__tip">
|
|
|
<el-checkbox v-model="updateSupport" />
|
|
|
是否更新已经存在的用户数据
|
|
|
- </div>
|
|
|
+ </div> -->
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-upload>
|
|
@@ -64,13 +66,13 @@
|
|
|
</Dialog>
|
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
|
-// import * as faceApi from '@/api/system/face'
|
|
|
import * as UserApi from '@/api/system/user'
|
|
|
import { getAccessToken, getTenantId } from '@/utils/auth'
|
|
|
import download from '@/utils/download'
|
|
|
import {useUpload} from "@/components/UploadFile/src/useUpload";
|
|
|
-defineOptions({ name: 'StudentFaceImport' })
|
|
|
+defineOptions({ name: 'SystemUserImportForm' })
|
|
|
|
|
|
+import axios from 'axios';
|
|
|
const message = useMessage() // 消息弹窗
|
|
|
const { httpRequest } = useUpload()
|
|
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
|
@@ -79,12 +81,9 @@ const uploadRef = ref()
|
|
|
const uploadZipRef = ref()
|
|
|
const importUrl =
|
|
|
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/md/acs/import-data'
|
|
|
-const importZipUrl =
|
|
|
- import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/md/acs/import-data'
|
|
|
const uploadHeaders = ref() // 上传 Header 头
|
|
|
const fileList = ref([]) // 文件列表
|
|
|
const updateSupport = ref(0) // 是否更新已经存在的用户数据
|
|
|
-
|
|
|
const zipList = ref([]) // 压缩文件列表
|
|
|
|
|
|
|
|
@@ -104,54 +103,88 @@ const submitForm = async () => {
|
|
|
// message.error('请上传文件')
|
|
|
// return
|
|
|
// }
|
|
|
-
|
|
|
// if (zipList.value.length === 0) {
|
|
|
// message.error('请上传压缩包')
|
|
|
// return
|
|
|
// }
|
|
|
- if (fileList.value.length == 0 && zipList.value.length === 0) {
|
|
|
- message.error('请上传文件或压缩包')
|
|
|
- return
|
|
|
+ // if (fileList.value.length == 0 && zipList.value.length === 0) {
|
|
|
+ // message.error('请上传文件或压缩包')
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ const formData = new FormData();
|
|
|
+
|
|
|
+ if (fileList.value.length > 0) {
|
|
|
+ formData.append('excelFile', fileList.value[0].raw); // 确保是 .raw
|
|
|
}
|
|
|
|
|
|
- // 提交请求
|
|
|
- uploadHeaders.value = {
|
|
|
- Authorization: 'Bearer ' + getAccessToken(),
|
|
|
- 'tenant-id': getTenantId()
|
|
|
+ if (zipList.value.length > 0) {
|
|
|
+ formData.append('imageFile', zipList.value[0].raw); // 确保是 .raw
|
|
|
}
|
|
|
- formLoading.value = true
|
|
|
- uploadRef.value!.submit()
|
|
|
- uploadZipRef.value!.submit()
|
|
|
+
|
|
|
+ formData.append('updateSupport',updateSupport.value.toString());
|
|
|
+
|
|
|
+ let response = await axios.post(importUrl, formData, {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'multipart/form-data',
|
|
|
+ Authorization: 'Bearer ' + getAccessToken(),
|
|
|
+ 'tenant-id': getTenantId()
|
|
|
+ }
|
|
|
+ });
|
|
|
+ console.log(response,'response');
|
|
|
+ submitFormSuccess(response)
|
|
|
+ // // 提交请求
|
|
|
+ // uploadHeaders.value = {
|
|
|
+ // Authorization: 'Bearer ' + getAccessToken(),
|
|
|
+ // 'tenant-id': getTenantId()
|
|
|
+ // }
|
|
|
+ // formLoading.value = true
|
|
|
+ // uploadRef.value!.submit()
|
|
|
+ // uploadZipRef.value!.submit()
|
|
|
}
|
|
|
-console.log(fileList,'fileList');
|
|
|
+
|
|
|
|
|
|
|
|
|
/** 文件上传成功 */
|
|
|
const emits = defineEmits(['success'])
|
|
|
const submitFormSuccess = (response: any) => {
|
|
|
if (response.data.code !== 0) {
|
|
|
- console.log(response.data.code,'code');
|
|
|
-
|
|
|
+ console.log(response.data.code,'code');
|
|
|
message.error(response.msg)
|
|
|
formLoading.value = false
|
|
|
return
|
|
|
}
|
|
|
// 拼接提示语
|
|
|
const data = response.data.data;
|
|
|
- console.log(data,'123');
|
|
|
- let text = data.msg;
|
|
|
- // let text = '上传成功数量:' + data.createUsernames.length + ';'
|
|
|
- // for (let username of data.createUsernames) {
|
|
|
- // text += '< ' + username + ' >'
|
|
|
- // }
|
|
|
- // text += '更新成功数量:' + data.updateUsernames.length + ';'
|
|
|
- // for (const username of data.updateUsernames) {
|
|
|
- // text += '< ' + username + ' >'
|
|
|
- // }
|
|
|
- // text += '更新失败数量:' + Object.keys(data.failureUsernames).length + ';'
|
|
|
- // for (const username in data.failureUsernames) {
|
|
|
- // text += '< ' + username + ': ' + data.failureUsernames[username] + ' >'
|
|
|
- // }
|
|
|
+ console.log(data,'data');
|
|
|
+ // let text = data;
|
|
|
+ let text = '图片上传成功数量:' + data.imageImportResult.createImages.length + ';'
|
|
|
+ for (let username of data.imageImportResult.createImages) {
|
|
|
+ text += '< ' + username + ' >'
|
|
|
+ }
|
|
|
+ text += '图片错误数量:' + data.imageImportResult.errorImages.length + ';'
|
|
|
+ for (const username of data.imageImportResult.errorImages) {
|
|
|
+ text += '< ' + username + ' >'
|
|
|
+ }
|
|
|
+ text += '图片上传失败数量:' + data.imageImportResult.failureImages.length + ';'
|
|
|
+ for (const username of data.imageImportResult.failureImages) {
|
|
|
+ text += '< ' + username + ' >'
|
|
|
+ }
|
|
|
+ text += '找不到用户数量:' + data.imageImportResult.nullUsers.length + ';'
|
|
|
+ for (const username of data.imageImportResult.nullUsers) {
|
|
|
+ text += '< ' + username + ' >'
|
|
|
+ }
|
|
|
+ text += '文件上传成功数量:' + data.userImportResult.createUsernames.length + ';'
|
|
|
+ for (let username of data.userImportResult.createUsernames) {
|
|
|
+ text += '< ' + username + ' >'
|
|
|
+ }
|
|
|
+ text += '文件更新数量:' + data.userImportResult.updateUsernames.length + ';'
|
|
|
+ for (const username of data.userImportResult.updateUsernames) {
|
|
|
+ text += '< ' + username + ' >'
|
|
|
+ }
|
|
|
+ text += '文件上传失败数量:' + Object.keys(data.userImportResult.failureUsernames).length + ';'
|
|
|
+ for (const username in data.userImportResult.failureUsernames) {
|
|
|
+ text += '< ' + username + ': ' + data.userImportResult.failureUsernames[username] + ' >'
|
|
|
+ }
|
|
|
message.alert(text)
|
|
|
formLoading.value = false
|
|
|
dialogVisible.value = false
|