|
@@ -1,194 +1,119 @@
|
|
|
<template>
|
|
|
- <Dialog v-model="dialogVisible" title="用户批量导入" width="400">
|
|
|
- <el-upload
|
|
|
- ref="uploadRef"
|
|
|
- v-model:file-list="fileList"
|
|
|
- :action="importUrl + '?updateSupport=' + updateSupport"
|
|
|
- :auto-upload="false"
|
|
|
- :disabled="formLoading"
|
|
|
- :headers="uploadHeaders"
|
|
|
- :on-error="submitFormError"
|
|
|
- :on-success="submitFormSuccess"
|
|
|
- accept=".xlsx, .xls"
|
|
|
- drag
|
|
|
+ <Dialog :title="dialogTitle" v-model="dialogVisible">
|
|
|
+ <el-form
|
|
|
+ ref="formRef"
|
|
|
+ :model="formData"
|
|
|
+ label-width="100px"
|
|
|
+ v-loading="formLoading"
|
|
|
>
|
|
|
- <Icon icon="ep:upload" />
|
|
|
- <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
|
|
- <template #tip>
|
|
|
- <div class="el-upload__tip text-center">
|
|
|
- <!-- <div class="el-upload__tip">
|
|
|
- <el-checkbox v-model="updateSupport" />
|
|
|
- 是否更新已经存在的用户数据
|
|
|
- </div> -->
|
|
|
- <span>仅允许导入 xlsx, xls 格式文件。</span>
|
|
|
- <el-link
|
|
|
- :underline="false"
|
|
|
- style="font-size: 12px; vertical-align: baseline"
|
|
|
- type="primary"
|
|
|
- @click="importTemplate"
|
|
|
- >
|
|
|
- 下载模板
|
|
|
- </el-link>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- </el-upload>
|
|
|
- <el-upload
|
|
|
- ref="uploadZipRef"
|
|
|
- v-model:file-list="zipList"
|
|
|
- drag
|
|
|
- :action="importZipUrl + '?updateSupport=' + updateSupport"
|
|
|
- :on-success="submitZipSuccess"
|
|
|
- :auto-upload="false"
|
|
|
- :disabled="formLoading"
|
|
|
- :headers="uploadHeaders"
|
|
|
- :on-error="submitFormError"
|
|
|
- :http-request="httpRequest"
|
|
|
- accept=".zip,.rar"
|
|
|
- >
|
|
|
- <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">
|
|
|
- <el-checkbox v-model="updateSupport" />
|
|
|
- 是否更新已经存在的用户数据
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- </el-upload>
|
|
|
+ <el-form-item label="照片详情url" prop="photoUrl">
|
|
|
+ <UploadImg v-model="formData.photoUrl" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
<template #footer>
|
|
|
- <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
|
|
+ <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
|
</template>
|
|
|
</Dialog>
|
|
|
</template>
|
|
|
-<script lang="ts" setup>
|
|
|
-// import * as faceApi from '@/api/system/face'
|
|
|
+<script setup lang="ts">
|
|
|
+// import { UserAchievementApi, UserAchievementVO } from '@/api/system/userAchievement'
|
|
|
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: 'SystemUserImportForm' })
|
|
|
+import { UserVO } from '@/api/system/user'
|
|
|
+
|
|
|
|
|
|
+/** 成果 表单 */
|
|
|
+defineOptions({ name: 'UserAchievementForm' })
|
|
|
+
|
|
|
+const { t } = useI18n() // 国际化
|
|
|
const message = useMessage() // 消息弹窗
|
|
|
-const { httpRequest } = useUpload()
|
|
|
-const dialogVisible = ref(false) // 弹窗的是否展示
|
|
|
-const formLoading = ref(false) // 表单的加载中
|
|
|
-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([]) // 压缩文件列表
|
|
|
+const dialogVisible = ref(false) // 弹窗的是否展示
|
|
|
+const dialogTitle = ref('') // 弹窗的标题
|
|
|
+const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
|
|
+const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
|
|
+const formData = ref({
|
|
|
+ userNumber : '',
|
|
|
+ photoUrl: '',
|
|
|
+})
|
|
|
+// const formRules = reactive({
|
|
|
+// userId: [{ required: true, message: '用户id不能为空', trigger: 'blur' }],
|
|
|
+// achievementName: [{ required: true, message: '成果名称不能为空', trigger: 'blur' }],
|
|
|
+// achievementType: [{ required: true, message: '成果类型不能为空', trigger: 'change' }],
|
|
|
+// userName: [{ required: true, message: '用户名称不能为空', trigger: 'blur' }],
|
|
|
+// })
|
|
|
+const formRef = ref() // 表单 Ref
|
|
|
|
|
|
+// /** 获取用户列表 */
|
|
|
+// const users = ref();
|
|
|
+// const getDeptUser = async () => {
|
|
|
+// try {
|
|
|
+// const response = await UserApi.getDeptUser();
|
|
|
+// console.log(response);
|
|
|
+// users.value = response;
|
|
|
+// } catch (error) {
|
|
|
+// console.error("Error fetching user data:", error);
|
|
|
+// }
|
|
|
+// };
|
|
|
|
|
|
/** 打开弹窗 */
|
|
|
-const open = () => {
|
|
|
+const open = async (type: string, id?: number) => {
|
|
|
dialogVisible.value = true
|
|
|
- updateSupport.value = 0
|
|
|
- fileList.value = []
|
|
|
+ dialogTitle.value = t('action.' + type)
|
|
|
+ formType.value = type
|
|
|
resetForm()
|
|
|
- zipList.value = [] // 压缩文件列表
|
|
|
+ // 修改时,设置数据
|
|
|
+ if (id) {
|
|
|
+ formLoading.value = true
|
|
|
+ try {
|
|
|
+ formData.value = await UserApi.getUser(id)
|
|
|
+ } finally {
|
|
|
+ formLoading.value = false
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
|
|
|
|
|
+/** 用户id更新 */
|
|
|
+// const handleUserChange = (selectedNickname: string) => {
|
|
|
+// const selectedUser = users.value.find((user: any) => user.nickname === selectedNickname);
|
|
|
+// formData.value.userId = selectedUser? selectedUser.id : undefined;
|
|
|
+// };
|
|
|
+
|
|
|
/** 提交表单 */
|
|
|
+const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
|
|
const submitForm = async () => {
|
|
|
- // if (fileList.value.length == 0) {
|
|
|
- // message.error('请上传文件')
|
|
|
- // return
|
|
|
- // }
|
|
|
-
|
|
|
- // if (zipList.value.length === 0) {
|
|
|
- // message.error('请上传压缩包')
|
|
|
- // return
|
|
|
- // }
|
|
|
- if (fileList.value.length == 0 && zipList.value.length === 0) {
|
|
|
- message.error('请上传文件或压缩包')
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
+ // 校验表单
|
|
|
+ // await formRef.value.validate()
|
|
|
// 提交请求
|
|
|
- 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.code !== 0) {
|
|
|
- message.error(response.msg)
|
|
|
- formLoading.value = false
|
|
|
- return
|
|
|
- }
|
|
|
- // 拼接提示语
|
|
|
- const data = response.data;
|
|
|
- console.log(response.data,'123');
|
|
|
- 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] + ' >'
|
|
|
- }
|
|
|
- message.alert(text)
|
|
|
- formLoading.value = false
|
|
|
- dialogVisible.value = false
|
|
|
- // 发送操作成功的事件
|
|
|
- emits('success')
|
|
|
-}
|
|
|
-
|
|
|
-const submitZipSuccess = (response: any) => {
|
|
|
- if (response.code !== 0) {
|
|
|
- message.error(response.msg)
|
|
|
+ try {
|
|
|
+ const data = formData.value as unknown as UserVO
|
|
|
+ console.log(data,'data');
|
|
|
+ // const message = await UserApi.updateStudentImg(data.userNumber, data.photoUrl)
|
|
|
+ await UserApi.updateStudentImg(data.userNumber, data.photoUrl)
|
|
|
+ message.success('修改成功')
|
|
|
+
|
|
|
+ dialogVisible.value = false
|
|
|
+ // 发送操作成功的事件
|
|
|
+ emit('success')
|
|
|
+ // 通知父组件重新加载数据
|
|
|
+
|
|
|
+ } finally {
|
|
|
formLoading.value = false
|
|
|
- return
|
|
|
}
|
|
|
- // 处理上传成功的逻辑,例如解压压缩包,处理里面的文件等
|
|
|
- message.success('压缩包上传成功')
|
|
|
- formLoading.value = false
|
|
|
- dialogVisible.value = false
|
|
|
- // 发送操作成功的事件
|
|
|
- emits('success')
|
|
|
-}
|
|
|
-
|
|
|
-/** 上传错误提示 */
|
|
|
-const submitFormError = (): void => {
|
|
|
- message.error('上传失败,请您重新上传!')
|
|
|
- formLoading.value = false
|
|
|
}
|
|
|
|
|
|
/** 重置表单 */
|
|
|
-const resetForm = async (): Promise<void> => {
|
|
|
- // 重置上传状态和文件
|
|
|
- formLoading.value = false
|
|
|
- await nextTick()
|
|
|
- uploadRef.value?.clearFiles()
|
|
|
- uploadZipRef.value?.clearFiles()
|
|
|
+const resetForm = () => {
|
|
|
+ formData.value = {
|
|
|
+ userNumber: '',
|
|
|
+ photoUrl: '',
|
|
|
+ }
|
|
|
+ formRef.value?.resetFields()
|
|
|
}
|
|
|
|
|
|
-/** 下载模板操作 */
|
|
|
-const importTemplate = async () => {
|
|
|
- const res = await UserApi.getAttendanceTemplate()
|
|
|
- console.log(res,'111');
|
|
|
- download.excel(res, '用户导入模版.xls')
|
|
|
-}
|
|
|
-</script>
|
|
|
+onMounted(() => {
|
|
|
+
|
|
|
+})
|
|
|
+</script>
|