diff --git a/src/api/system/user.ts b/src/api/system/user.ts index c0125a7..f31e32a 100644 --- a/src/api/system/user.ts +++ b/src/api/system/user.ts @@ -54,6 +54,7 @@ export interface UserRequest { sex?: number; status?: number; username?: string; + clientId?: number; } /** @@ -76,6 +77,14 @@ export interface ResetPasswordRequest { userId?: number; } +/** + * SysClientVO + */ +export interface SysClientVO { + id: number; + clientName: string; +} + /** * 修改密码 */ @@ -86,46 +95,60 @@ export interface PasswordRequest { /** 获取用户列表 */ export const getUserListApi = (params?: UserQuery) => { - return http.request>("get", "/system/users", { + return http.request>("get", "/system/users/list", { params }); }; /** 新增用户 */ export const addUserApi = (data?: UserRequest) => { - return http.request>("post", "/system/users", { + return http.request>("post", "/system/users/create", { data }); }; /** 编辑用户 */ export const updateUserApi = (userId: number, data?: UserRequest) => { - return http.request>("put", `/system/users/${userId}`, { - data - }); -}; - -/** 更改用户密码 */ -export const updateUserPasswordApi = (data?: PasswordRequest) => { return http.request>( - "put", - `/system/users/${data.userId}/password`, + "post", + `/system/users/update/${userId}`, { data } ); }; +/** 管理员更改用户密码 */ +export const updateUserPasswordByAdminApi = (data?: PasswordRequest) => { + return http.request>( + "post", + `/system/users/re_pwd_ad/${data.userId}`, + { + data + } + ); +}; + +/** 更改自己密码 */ +export const updatePasswordApi = (data?: PasswordRequest) => { + return http.request>("post", `/system/users/re_pwd`, { + data + }); +}; + /** 删除用户 */ export const deleteUserApi = (userId: number) => { - return http.request>("delete", `/system/users/${userId}`); + return http.request>( + "post", + `/system/users/del/${userId}` + ); }; /** 修改用户状态 */ export const updateUserStatusApi = (userId: number, status: number) => { return http.request>>( - "put", - `/system/users/${userId}/status`, + "post", + `/system/users/status/${userId}`, { data: { status: status @@ -174,3 +197,11 @@ export const updateCurrentUserPasswordApi = (data?: ResetPasswordRequest) => { } ); }; + +/** 获取客户端列表 */ +export const getClientListApi = () => { + return http.request>( + "get", + "/system/users/client" + ); +}; diff --git a/src/views/system/user/form.vue b/src/views/system/user/form.vue index 90fb2f0..209d3af 100644 --- a/src/views/system/user/form.vue +++ b/src/views/system/user/form.vue @@ -2,7 +2,7 @@ import { ref } from "vue"; import ReCol from "@/components/ReCol"; import { formRules } from "./rule"; -import { UserRequest } from "@/api/system/user"; +import { UserRequest, SysClientVO } from "@/api/system/user"; import { PostPageResponse } from "@/api/system/post"; import { RoleDTO } from "@/api/system/role"; import { useUserStoreHook } from "@/store/modules/user"; @@ -12,6 +12,7 @@ interface FormProps { deptOptions: any[]; postOptions: PostPageResponse[]; roleOptions: RoleDTO[]; + clientOptions: SysClientVO[]; } const props = withDefaults(defineProps(), { @@ -31,13 +32,15 @@ const props = withDefaults(defineProps(), { }), deptOptions: () => [], postOptions: () => [], - roleOptions: () => [] + roleOptions: () => [], + clientOptions: () => [] }); const newFormInline = ref(props.formInline); const deptOptions = ref(props.deptOptions); const roleOptions = ref(props.roleOptions); const postOptions = ref(props.postOptions); +const clientOptions = ref(props.clientOptions); const formRuleRef = ref(); @@ -171,11 +174,31 @@ defineExpose({ getFormRuleRef }); + + + + + + + + {{ item.label }} diff --git a/src/views/system/user/hook.tsx b/src/views/system/user/hook.tsx index 2b14729..f12b370 100644 --- a/src/views/system/user/hook.tsx +++ b/src/views/system/user/hook.tsx @@ -10,7 +10,8 @@ import { UserRequest, deleteUserApi, PasswordRequest, - updateUserPasswordApi + updateUserPasswordByAdminApi, + getClientListApi } from "@/api/system/user"; import editForm from "./form.vue"; import passwordForm from "./passwordForm.vue"; @@ -24,6 +25,7 @@ import { handleTree, setDisabledForTreeOptions } from "@/utils/tree"; import { getDeptListApi } from "@/api/system/dept"; import { getPostListApi } from "@/api/system/post"; import { getRoleListApi } from "@/api/system/role"; +import { useUserStoreHook } from "@/store/modules/user"; export function useHook() { const searchFormParams = reactive({ @@ -50,13 +52,15 @@ export function useHook() { const deptTreeList = ref([]); const postOptions = ref([]); const roleOptions = ref([]); + const clientOptions = ref([]); const columns: TableColumnList = [ { label: "用户编号", prop: "userId", width: 90, - fixed: "left" + fixed: "left", + showOverflowTooltip: true }, { label: "用户名", @@ -112,19 +116,26 @@ export function useHook() { { label: "状态", prop: "status", - minWidth: 90, + minWidth: 100, cellRenderer: scope => ( - { + // 在选择之前保存原始状态 + if (!switchLoadMap.value[scope.index]) { + switchLoadMap.value[scope.index] = {}; + } + switchLoadMap.value[scope.index].originalStatus = scope.row.status; + }} onChange={() => onChange(scope as any)} - /> + > + {useUserStoreHook().dictionaryList["sysUser.status"]?.map(dict => ( + + ))} + ) }, { @@ -152,12 +163,17 @@ export function useHook() { }); function onChange({ row, index }) { + // 保存原始状态用于取消时恢复 + const originalStatus = + switchLoadMap.value[index]?.originalStatus || row.status; + + // 根据字典获取状态名称 + const statusDict = useUserStoreHook().dictionaryList["sysUser.status"]; + const currentStatusLabel = + statusDict?.find(item => item.value === row.status)?.label || "未知状态"; + ElMessageBox.confirm( - `确认要${ - row.status === 0 ? "停用" : "启用" - }${ - row.username - }用户吗?`, + `确认要将${row.username}用户的状态修改为${currentStatusLabel}吗?`, "系统提示", { confirmButtonText: "确定", @@ -175,13 +191,21 @@ export function useHook() { message("已成功修改用户状态", { type: "success" }); + // 更新完成后,更新原始状态 + switchLoadMap.value[index] = Object.assign( + {}, + switchLoadMap.value[index], + { + originalStatus: row.status + } + ); }) .catch(() => { message("取消操作", { type: "info" }); // 如果取消的话 恢复更改前的状态 - row.status === 0 ? (row.status = 1) : (row.status = 0); + row.status = originalStatus; }); } @@ -229,7 +253,7 @@ export function useHook() { } async function handleResetPassword(row, request, done) { - await updateUserPasswordApi(request).then(() => { + await updateUserPasswordByAdminApi(request).then(() => { message(`您修改了用户${row.username}的密码`, { type: "success" }); // 刷新列表 done(); @@ -260,11 +284,13 @@ export function useHook() { status: row?.status ?? undefined, postId: row?.postId ?? undefined, roleId: row?.roleId ?? undefined, - remark: row?.remark ?? "" + remark: row?.remark ?? "", + clientId: row?.clientId ?? undefined }, deptOptions: deptTreeList, postOptions: postOptions, - roleOptions: roleOptions + roleOptions: roleOptions, + clientOptions: clientOptions }, width: "40%", @@ -367,6 +393,9 @@ export function useHook() { const roleResponse = await getRoleListApi({}); roleOptions.value = roleResponse.rows; + + const clientResponse = await getClientListApi(); + clientOptions.value = clientResponse.data; }); return { diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 272a71d..2692fab 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -88,7 +88,9 @@ watch( class="!w-[160px]" >