diff --git a/src/components/ExcelImportDialog/index.vue b/src/components/ExcelImportDialog/index.vue new file mode 100644 index 0000000..85c0a4c --- /dev/null +++ b/src/components/ExcelImportDialog/index.vue @@ -0,0 +1,138 @@ + + + + + 将文件拖到此处,或点击上传 + + + + {{ updateSupportLabel }} + + 仅允许导入xls、xlsx格式文件。 + 下载模板 + + + + + + + + + + diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 0c1dd66..3bb8878 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -173,27 +173,7 @@ - - - - 将文件拖到此处,或点击上传 - - - - 是否更新已经存在的用户数据 - - 仅允许导入xls、xlsx格式文件。 - 下载模板 - - - - - - - + @@ -201,6 +181,7 @@ import { getToken } from "@/utils/auth" import useAppStore from '@/store/modules/app' import TreePanel from "@/components/TreePanel" +import ExcelImportDialog from "@/components/ExcelImportDialog" import { changeUserStatus, listUser, resetUserPwd, delUser, getUser, updateUser, addUser, deptTreeSelect } from "@/api/system/user" import type { SysUser, UserQueryParams, UserFormDataResult } from '@/types/api/system/user' import type { SysRole } from '@/types/api/system/role' @@ -227,21 +208,6 @@ const enabledDeptOptions = ref(undefined) const initPassword = ref(undefined) const postOptions = ref([]) const roleOptions = ref([]) -/*** 用户导入参数 */ -const upload = reactive({ - // 是否显示弹出层(用户导入) - open: false, - // 弹出层标题(用户导入) - title: "", - // 是否禁用上传 - isUploading: false, - // 是否更新已经存在的用户数据 - updateSupport: 0, - // 设置上传的请求头部 - headers: { Authorization: "Bearer " + getToken() }, - // 上传的地址 - url: import.meta.env.VITE_APP_BASE_API + "/system/user/importData" -}) // 列显隐信息 const columns = ref>({ userId: { label: '用户编号', visible: true }, @@ -406,49 +372,7 @@ function handleSelectionChange(selection: SysUser[]) { /** 导入按钮操作 */ function handleImport() { - upload.title = "用户导入" - upload.open = true - upload.selectedFile = null -} - -/** 下载模板操作 */ -function importTemplate() { - proxy.download("system/user/importTemplate", { - }, `user_template_${new Date().getTime()}.xlsx`) -} - -/**文件上传中处理 */ -const handleFileUploadProgress = (event: any, file: any, fileList: any[]) => { - upload.isUploading = true -} - -/** 文件选择处理 */ -const handleFileChange = (file: any, fileList: any[]) => { - upload.selectedFile = file -} - -/** 文件删除处理 */ -const handleFileRemove = (file: any, fileList: any[]) => { - upload.selectedFile = null -} - -/** 文件上传成功处理 */ -const handleFileSuccess = (response: AjaxResult, file: any, fileList: any[]) => { - upload.open = false - upload.isUploading = false - proxy.$refs["uploadRef"].handleRemove(file) - proxy.$alert("" + response.msg + "", "导入结果", { dangerouslyUseHTMLString: true }) - getList() -} - -/** 提交上传文件 */ -function submitFileForm() { - const file = upload.selectedFile - if (!file || file.length === 0 || !file.name.toLowerCase().endsWith('.xls') && !file.name.toLowerCase().endsWith('.xlsx')) { - proxy.$modal.msgError("请选择后缀为 “xls”或“xlsx”的文件。") - return - } - proxy.$refs["uploadRef"].submit() + proxy.$refs["importUserRef"].open() } /** 重置操作表单 */