This commit is contained in:
cuijiawang 2025-09-24 11:55:31 +08:00
parent 1a77522dfb
commit f5d2877e1f
4 changed files with 124 additions and 39 deletions

View File

@ -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<PageDTO<UserDTO>>("get", "/system/users", {
return http.request<PageDTO<UserDTO>>("get", "/system/users/list", {
params
});
};
/** 新增用户 */
export const addUserApi = (data?: UserRequest) => {
return http.request<ResponseData<void>>("post", "/system/users", {
return http.request<ResponseData<void>>("post", "/system/users/create", {
data
});
};
/** 编辑用户 */
export const updateUserApi = (userId: number, data?: UserRequest) => {
return http.request<ResponseData<void>>("put", `/system/users/${userId}`, {
data
});
};
/** 更改用户密码 */
export const updateUserPasswordApi = (data?: PasswordRequest) => {
return http.request<ResponseData<void>>(
"put",
`/system/users/${data.userId}/password`,
"post",
`/system/users/update/${userId}`,
{
data
}
);
};
/** 管理员更改用户密码 */
export const updateUserPasswordByAdminApi = (data?: PasswordRequest) => {
return http.request<ResponseData<void>>(
"post",
`/system/users/re_pwd_ad/${data.userId}`,
{
data
}
);
};
/** 更改自己密码 */
export const updatePasswordApi = (data?: PasswordRequest) => {
return http.request<ResponseData<void>>("post", `/system/users/re_pwd`, {
data
});
};
/** 删除用户 */
export const deleteUserApi = (userId: number) => {
return http.request<ResponseData<void>>("delete", `/system/users/${userId}`);
return http.request<ResponseData<void>>(
"post",
`/system/users/del/${userId}`
);
};
/** 修改用户状态 */
export const updateUserStatusApi = (userId: number, status: number) => {
return http.request<ResponseData<PageDTO<UserDTO>>>(
"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<ResponseData<SysClientVO[]>>(
"get",
"/system/users/client"
);
};

View File

@ -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<FormProps>(), {
@ -31,13 +32,15 @@ const props = withDefaults(defineProps<FormProps>(), {
}),
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 });
</el-form-item>
</re-col>
<re-col :value="12">
<el-form-item label="客户端" prop="clientId">
<el-select
class="w-full"
v-model="newFormInline.clientId"
placeholder="请选择客户端"
clearable
>
<el-option
v-for="item in clientOptions"
:key="item.id"
:label="item.clientName"
:value="item.id"
/>
</el-select>
</el-form-item>
</re-col>
<re-col :value="12" :xs="24" :sm="24">
<el-form-item label="状态" prop="status">
<el-radio-group v-model="newFormInline.status">
<el-radio
v-for="item in useUserStoreHook().dictionaryList['common.status']"
v-for="item in useUserStoreHook().dictionaryList[
'sysUser.status'
]"
:key="item.value"
:label="item.value"
>{{ item.label }}

View File

@ -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<UserQuery>({
@ -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 => (
<el-switch
size={scope.props.size === "small" ? "small" : "default"}
loading={switchLoadMap.value[scope.index]?.loading}
<el-select
size="small"
v-model={scope.row.status}
active-value={1}
inactive-value={0}
active-text="正常"
inactive-text="停用"
inline-prompt
placeholder="请选择状态"
style="width: 85px"
onFocus={() => {
// 在选择之前保存原始状态
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 => (
<el-option key={dict.value} label={dict.label} value={dict.value} />
))}
</el-select>
)
},
{
@ -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(
`确认要<strong>${
row.status === 0 ? "停用" : "启用"
}</strong><strong style='color:var(--el-color-primary)'>${
row.username
}</strong>?`,
`确认要将<strong style='color:var(--el-color-primary)'>${row.username}</strong>用户的状态修改为<strong>${currentStatusLabel}</strong>吗?`,
"系统提示",
{
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 {

View File

@ -88,7 +88,9 @@ watch(
class="!w-[160px]"
>
<el-option
v-for="dict in useUserStoreHook().dictionaryList['common.status']"
v-for="dict in useUserStoreHook().dictionaryList[
'sysUser.status'
]"
:key="dict.value"
:label="dict.label"
:value="dict.value"