Commit b62da2e6 authored by 张伯涛's avatar 张伯涛

用户管理导入功能完善

parent 29448d8c
......@@ -81,7 +81,21 @@ export function updateUserPassword(businessId: number, password: string) {
params: data
});
}
/**
* 用户状态修改
*
*/
export function changeUserStatus(businessId: number,flag:string) {
const data = {
businessId,
flag
}
return request({
url: '/system/user/changeStatus',
method: 'put',
params: data
});
}
/**
* 删除用户
*
......@@ -127,16 +141,16 @@ export function exportUser(queryParams: UserQuery) {
*
* @param file
*/
export function importUser(deptId: number, file: File) {
const formData = new FormData();
formData.append("file", file);
export function importUser( data: any) {
return request({
url: "/api/v1/users/_import",
url: '/system/user/importExcel',
method: "post",
params: { deptId: deptId },
data: formData,
headers: {
"Content-Type": "multipart/form-data",
'Content-Type': 'multipart/form-data'
},
transformRequest: [(data) => {
return data
}],
data,
});
}
......@@ -6,11 +6,12 @@ defineOptions({
name: "User",
inheritAttrs: false,
});
import { getToken } from '@/utils/auth'
import {
getUserPage,
getUserForm,
deleteUsers,
changeUserStatus,
addUser,
updateUser,
updateUserPassword,
......@@ -82,6 +83,14 @@ const importData = reactive({
deptId: undefined,
file: undefined,
fileList: [],
// 是否禁用上传
isUploading: false,
// 是否更新已经存在的用户数据
updateSupport: 0,
// 设置上传的请求头部
headers: { Authorization: 'Bearer ' + getToken() },
// 上传的地址
url: import.meta.env.VITE_APP_BASE_API + '/system/user/importExcel'
});
const passwordCheck = (rule: any, value: any, callback: any) => {
const pattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/
......@@ -168,6 +177,7 @@ async function loadDeptOptions() {
* @param id 用户ID
*/
async function openDialog(type: string, id?: number) {
dialog.type = type;
if (dialog.type === "user-form") {
// 用户表单弹窗
await loadDeptOptions(); // 加载部门下拉数据源
......@@ -176,12 +186,14 @@ async function openDialog(type: string, id?: number) {
dialog.title = "修改用户";
await getUserForm(id).then(({ data }) => {
Object.assign(formData, { ...data });
const roleIdsList = formData.roleIds.split(',')
formData.roleList = []
roleIdsList.forEach(item => {
const id = Number(item)
formData.roleList.push(id)
})
if(formData.roleIds && formData.roleIds.length > 0) {
const roleIdsList = formData.roleIds.split(',')
formData.roleList = []
roleIdsList.forEach(item => {
const id = Number(item)
formData.roleList.push(id)
})
}
});
} else {
dialog.title = "新增用户";
......@@ -192,7 +204,6 @@ async function openDialog(type: string, id?: number) {
dialog.width = 600;
}
dialog.visible = true;
dialog.type = type;
}
......@@ -254,22 +265,36 @@ const handleSubmit = useThrottleFn(() => {
}
});
} else if (dialog.type === "user-import") {
if (!importData?.deptId) {
ElMessage.warning("请选择部门");
return false;
}
if (!importData?.file) {
ElMessage.warning("上传Excel文件不能为空");
return false;
}
importUser(importData?.deptId, importData?.file).then((response) => {
ElMessage.success(response.data);
var fileData = new FormData() // 当前为空
fileData.append('file', importData.file)
importUser( fileData).then((response) => {
ElMessage.success(response.message);
closeDialog();
resetQuery();
});
}
}, 3000);
/** 用户状态修改*/
function handleStatusChange(row: any) {
const text = row.flag === '1' ? '启用' : '停用'
ElMessageBox.confirm("是否确认操作?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
return changeUserStatus(row.businessId, row.flag)
}).then(() => {
ElMessage.success(text + '成功');
})
.catch(function () {
row.flag = row.flag === '0' ? '1' : '0'
});
}
/** 删除用户 */
function handleDelete(id: number) {
ElMessageBox.confirm("确认删除用户?", "警告", {
......@@ -310,7 +335,6 @@ function downloadTemplate() {
window.URL.revokeObjectURL(downloadUrl);
});
}
/** Excel文件 Change */
function handleFileChange(file: any) {
importData.file = file.raw;
......@@ -392,7 +416,7 @@ onMounted(() => {
class="!w-[100px]"
>
<el-option label="启用" value="1" />
<el-option label="用" value="0" />
<el-option label="用" value="0" />
</el-select>
</el-form-item>
......@@ -648,12 +672,15 @@ onMounted(() => {
>
<el-form-item label="Excel文件">
<el-upload
accept=".xlsx, .xls"
:headers="importData.headers"
:action="importData.url + '?updateSupport=' + importData.updateSupport"
:disabled="importData.isUploading"
:auto-upload="false"
ref="uploadRef"
action=""
drag
accept=".xlsx, .xls"
:limit="1"
:auto-upload="false"
:file-list="importData.fileList"
:on-change="handleFileChange"
:on-exceed="handleFileExceed"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment