⚡ 优化用户状态交互逻辑.
This commit is contained in:
@@ -38,7 +38,7 @@ public enum ErrorCode implements CodeInfo {
|
||||
|
||||
PAYLOAD_TOO_LARGE(413, "请求过大"),
|
||||
|
||||
LOCKED(423, "当前已被锁定"),
|
||||
LOCKED(423, "当前操作已被锁定"),
|
||||
|
||||
TOO_MANY_REQUESTS(429, "请求过快"),
|
||||
|
||||
@@ -48,11 +48,9 @@ public enum ErrorCode implements CodeInfo {
|
||||
|
||||
USER_DISABLED(700, "当前用户已禁用"),
|
||||
|
||||
USER_LOCKED(701, "当前用户已被锁定"),
|
||||
USER_OTHER_DEVICE_LOGIN(701, "该账号于 {} 已在其他设备登录 {}({})"),
|
||||
|
||||
OTHER_DEVICE_LOGIN(702, "该账号于 {} 已在其他设备登录 {}({})"),
|
||||
|
||||
SESSION_OFFLINE(703, "该账号于 {} 已被强制下线 {}({})"),
|
||||
USER_OFFLINE(702, "该账号于 {} 已被强制下线 {}({})"),
|
||||
|
||||
// -------------------- 自定义 - 通用 --------------------
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SystemUserDTO implements Serializable {
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "用户状态 0停用 1启用 2锁定")
|
||||
@Schema(description = "用户状态 0停用 1启用")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "最后登录时间")
|
||||
|
||||
@@ -56,7 +56,7 @@ public class SystemUserDO extends BaseDO {
|
||||
@TableField("email")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "用户状态 0停用 1启用 2锁定")
|
||||
@Schema(description = "用户状态 0停用 1启用")
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class UserInfoDTO implements LongCacheIdModel, Serializable {
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "用户状态 0停用 1启用 2锁定")
|
||||
@Schema(description = "用户状态 0停用 1启用")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SystemUserQueryRequest extends PageRequest {
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "用户状态 0停用 1启用 2锁定")
|
||||
@Schema(description = "用户状态 0停用 1启用")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class SystemUserUpdateStatusRequest implements Serializable {
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "用户状态 0停用 1启用 2锁定")
|
||||
@Schema(description = "用户状态 0停用 1启用")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SystemUserVO implements Serializable {
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "用户状态 0停用 1启用 2锁定")
|
||||
@Schema(description = "用户状态 0停用 1启用")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "最后登录时间")
|
||||
|
||||
@@ -32,7 +32,7 @@ public enum LoginTokenStatusEnum {
|
||||
@Override
|
||||
public RuntimeException toException(LoginTokenDTO token) {
|
||||
LoginTokenIdentityDTO override = token.getOverride();
|
||||
return ErrorCode.OTHER_DEVICE_LOGIN.exception(
|
||||
return ErrorCode.USER_OTHER_DEVICE_LOGIN.exception(
|
||||
Dates.format(new Date(override.getLoginTime()), Dates.MD_HM),
|
||||
override.getAddress(),
|
||||
override.getLocation());
|
||||
@@ -47,7 +47,7 @@ public enum LoginTokenStatusEnum {
|
||||
@Override
|
||||
public RuntimeException toException(LoginTokenDTO token) {
|
||||
LoginTokenIdentityDTO override = token.getOverride();
|
||||
return ErrorCode.SESSION_OFFLINE.exception(
|
||||
return ErrorCode.USER_OFFLINE.exception(
|
||||
Dates.format(new Date(override.getLoginTime()), Dates.MD_HM),
|
||||
override.getAddress(),
|
||||
override.getLocation());
|
||||
|
||||
@@ -25,11 +25,6 @@ public enum UserStatusEnum {
|
||||
*/
|
||||
ENABLED(1),
|
||||
|
||||
/**
|
||||
* 2 锁定
|
||||
*/
|
||||
LOCKED(2),
|
||||
|
||||
;
|
||||
|
||||
private final Integer status;
|
||||
@@ -55,9 +50,6 @@ public enum UserStatusEnum {
|
||||
if (UserStatusEnum.DISABLED.getStatus().equals(status)) {
|
||||
// 禁用状态
|
||||
throw ErrorCode.USER_DISABLED.exception();
|
||||
} else if (UserStatusEnum.LOCKED.getStatus().equals(status)) {
|
||||
// 锁定状态
|
||||
throw ErrorCode.USER_LOCKED.exception();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -242,22 +242,6 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
String failedCountKey = UserCacheKeyDefine.LOGIN_FAILED_COUNT.format(request.getUsername());
|
||||
Long failedLoginCount = redisTemplate.opsForValue().increment(failedCountKey);
|
||||
RedisUtils.setExpire(failedCountKey, appAuthenticationConfig.getLoginFailedLockTime(), TimeUnit.MINUTES);
|
||||
// // 锁定用户
|
||||
// if (failedLoginCount >= appAuthenticationConfig.getLoginFailedLockCount()) {
|
||||
// // 更新用户表
|
||||
// SystemUserDO updateUser = new SystemUserDO();
|
||||
// updateUser.setId(user.getId());
|
||||
// updateUser.setStatus(UserStatusEnum.LOCKED.getStatus());
|
||||
// systemUserDAO.updateById(updateUser);
|
||||
// // 修改缓存状态
|
||||
// String userInfoKey = UserCacheKeyDefine.USER_INFO.format(user.getId());
|
||||
// String userInfoCache = redisTemplate.opsForValue().get(userInfoKey);
|
||||
// if (userInfoCache != null) {
|
||||
// LoginUser loginUser = JSON.parseObject(userInfoCache, LoginUser.class);
|
||||
// loginUser.setStatus(UserStatusEnum.LOCKED.getStatus());
|
||||
// RedisStrings.setJson(userInfoKey, UserCacheKeyDefine.USER_INFO, loginUser);
|
||||
// }
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,11 +130,7 @@ public class SystemUserServiceImpl implements SystemUserService {
|
||||
if (id.equals(SecurityUtils.getLoginUserId())) {
|
||||
throw ErrorCode.UNSUPPOETED.exception();
|
||||
}
|
||||
// 检查状态
|
||||
UserStatusEnum status = Valid.valid(UserStatusEnum::of, request.getStatus());
|
||||
if (!status.equals(UserStatusEnum.DISABLED) && !status.equals(UserStatusEnum.ENABLED)) {
|
||||
throw ErrorCode.BAD_REQUEST.exception();
|
||||
}
|
||||
// 查询用户
|
||||
SystemUserDO record = systemUserDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.USER_ABSENT);
|
||||
@@ -146,8 +142,8 @@ public class SystemUserServiceImpl implements SystemUserService {
|
||||
// 更新用户
|
||||
int effect = systemUserDAO.updateById(updateRecord);
|
||||
log.info("SystemUserService-updateUserStatus effect: {}, updateRecord: {}", effect, JSON.toJSONString(updateRecord));
|
||||
// 如果之前是锁定则删除登录失败次数缓存
|
||||
if (UserStatusEnum.LOCKED.getStatus().equals(record.getStatus())) {
|
||||
// 改为启用则删除登录失败次数缓存
|
||||
if (UserStatusEnum.ENABLED.equals(status)) {
|
||||
RedisUtils.delete(UserCacheKeyDefine.LOGIN_FAILED_COUNT.format(record.getUsername()));
|
||||
}
|
||||
// 更新用户缓存中的 status
|
||||
|
||||
@@ -46,7 +46,7 @@ axios.interceptors.response.use(
|
||||
return res;
|
||||
}
|
||||
// 异常判断
|
||||
if ([401, 700, 701, 702, 703].includes(code)) {
|
||||
if ([401, 700, 701, 702].includes(code)) {
|
||||
// 提示
|
||||
Message.error({
|
||||
content: res.msg || 'Error',
|
||||
|
||||
@@ -68,27 +68,27 @@
|
||||
</template>
|
||||
<!-- 状态 -->
|
||||
<template #status="{ record }">
|
||||
<span class="circle" :style="{
|
||||
background: getDictValue(roleStatusKey, record.status, 'color')
|
||||
}" />
|
||||
{{ getDictValue(roleStatusKey, record.status) }}
|
||||
<!-- 有修改权限 -->
|
||||
<a-switch v-if="hasPermission('infra:system-role:update-status')"
|
||||
type="round"
|
||||
v-model="record.status"
|
||||
:disabled="record.code === AdminRoleCode"
|
||||
:checked-text="getDictValue(roleStatusKey, RoleStatus.ENABLED)"
|
||||
:unchecked-text="getDictValue(roleStatusKey, RoleStatus.DISABLED)"
|
||||
:checked-value="RoleStatus.ENABLED"
|
||||
:unchecked-value="RoleStatus.DISABLED"
|
||||
:before-change="(s) => updateStatus(record.id, s as number)" />
|
||||
<!-- 无修改权限 -->
|
||||
<span v-else>
|
||||
<span class="circle" :style="{
|
||||
background: getDictValue(roleStatusKey, record.status, 'color')
|
||||
}" />
|
||||
{{ getDictValue(roleStatusKey, record.status) }}
|
||||
</span>
|
||||
</template>
|
||||
<!-- 操作 -->
|
||||
<template #handle="{ record }">
|
||||
<div class="table-handle-wrapper">
|
||||
<!-- 修改状态 -->
|
||||
<a-popconfirm :content="`确定要${toggleDictValue(roleStatusKey, record.status, 'label')}当前角色吗?`"
|
||||
position="left"
|
||||
type="warning"
|
||||
@ok="toggleRoleStatus(record)">
|
||||
<a-button v-permission="['infra:system-role:delete']"
|
||||
:disabled="record.code === AdminRoleCode"
|
||||
:status="toggleDictValue(roleStatusKey, record.status, 'status')"
|
||||
type="text"
|
||||
size="mini">
|
||||
{{ toggleDictValue(roleStatusKey, record.status, 'label') }}
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<!-- 分配菜单 -->
|
||||
<a-button v-permission="['infra:system-role:grant-menu']"
|
||||
:disabled="record.code === AdminRoleCode"
|
||||
@@ -136,8 +136,9 @@
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import columns from '../types/table.columns';
|
||||
import { roleStatusKey } from '../types/const';
|
||||
import { RoleStatus, roleStatusKey } from '../types/const';
|
||||
import { usePagination } from '@/types/table';
|
||||
import usePermission from '@/hooks/permission';
|
||||
import { useDictStore } from '@/store';
|
||||
import { AdminRoleCode } from '@/types/const';
|
||||
|
||||
@@ -146,8 +147,9 @@
|
||||
const tableRenderData = ref<RoleQueryResponse[]>([]);
|
||||
|
||||
const pagination = usePagination();
|
||||
const { hasPermission } = usePermission();
|
||||
const { loading, setLoading } = useLoading();
|
||||
const { toOptions, getDictValue, toggleDictValue, toggleDict } = useDictStore();
|
||||
const { toOptions, getDictValue } = useDictStore();
|
||||
|
||||
const formModel = reactive<RoleQueryRequest>({
|
||||
id: undefined,
|
||||
@@ -156,23 +158,13 @@
|
||||
status: undefined,
|
||||
});
|
||||
|
||||
// 修改状态
|
||||
const toggleRoleStatus = async (record: any) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const toggleStatus = toggleDict(roleStatusKey, record.status);
|
||||
// 调用修改接口
|
||||
await updateRoleStatus({
|
||||
id: record.id,
|
||||
status: toggleStatus.value as number
|
||||
});
|
||||
Message.success(`${toggleStatus.label}成功`);
|
||||
// 修改行状态
|
||||
record.status = toggleStatus.value;
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
// 更新状态
|
||||
const updateStatus = (id: number, status: number) => {
|
||||
return updateRoleStatus({
|
||||
id, status
|
||||
}).then(() => {
|
||||
Message.success('已' + getDictValue(roleStatusKey, status, 'label'));
|
||||
});
|
||||
};
|
||||
|
||||
// 删除当前行
|
||||
|
||||
@@ -18,11 +18,11 @@ const columns = [
|
||||
dataIndex: 'code',
|
||||
slotName: 'code',
|
||||
}, {
|
||||
title: '状态',
|
||||
title: '角色状态',
|
||||
dataIndex: 'status',
|
||||
slotName: 'status',
|
||||
align: 'center',
|
||||
width: 84,
|
||||
width: 128,
|
||||
}, {
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
@@ -35,7 +35,7 @@ const columns = [
|
||||
}, {
|
||||
title: '操作',
|
||||
slotName: 'handle',
|
||||
width: 240,
|
||||
width: 198,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
},
|
||||
|
||||
@@ -77,37 +77,32 @@
|
||||
<template #username="{ record }">
|
||||
<span class="span-blue text-copy"
|
||||
@click="copy(record.username)">
|
||||
{{ record.username }}`
|
||||
{{ record.username }}
|
||||
</span>
|
||||
</template>
|
||||
<!-- 状态 -->
|
||||
<template #status="{ record }">
|
||||
<span class="circle" :style="{
|
||||
background: getDictValue(userStatusKey, record.status, 'color')
|
||||
}" />
|
||||
{{ getDictValue(userStatusKey, record.status) }}
|
||||
<!-- 有修改权限 -->
|
||||
<a-switch v-if="hasPermission('infra:system-user:update-status')"
|
||||
type="round"
|
||||
v-model="record.status"
|
||||
:disabled="record.id === userStore.id"
|
||||
:checked-text="getDictValue(userStatusKey, UserStatus.ENABLED)"
|
||||
:unchecked-text="getDictValue(userStatusKey, UserStatus.DISABLED)"
|
||||
:checked-value="UserStatus.ENABLED"
|
||||
:unchecked-value="UserStatus.DISABLED"
|
||||
:before-change="(s) => updateStatus(record.id, s as number)" />
|
||||
<!-- 无修改权限 -->
|
||||
<span v-else>
|
||||
<span class="circle" :style="{
|
||||
background: getDictValue(userStatusKey, record.status, 'color')
|
||||
}" />
|
||||
{{ getDictValue(userStatusKey, record.status) }}
|
||||
</span>
|
||||
</template>
|
||||
<!-- 操作 -->
|
||||
<template #handle="{ record }">
|
||||
<div class="table-handle-wrapper">
|
||||
<!-- 启用/停用 -->
|
||||
<a-popconfirm :content="`确定要${UserStatus.ENABLED === record.status
|
||||
? getDictValue(userStatusKey, UserStatus.DISABLED)
|
||||
: getDictValue(userStatusKey, UserStatus.ENABLED)}当前用户?`"
|
||||
position="left"
|
||||
type="warning"
|
||||
@ok="updateStatus(record)">
|
||||
<a-button v-permission="['infra:system-user:update-status']"
|
||||
type="text"
|
||||
size="mini"
|
||||
:disabled="record.id === userStore.id">
|
||||
{{
|
||||
UserStatus.ENABLED === record.status
|
||||
? getDictValue(userStatusKey, UserStatus.DISABLED)
|
||||
: getDictValue(userStatusKey, UserStatus.ENABLED)
|
||||
}}
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<!-- 修改 -->
|
||||
<a-button type="text"
|
||||
size="mini"
|
||||
@@ -167,12 +162,13 @@
|
||||
import { reactive, ref, onMounted } from 'vue';
|
||||
import { deleteUser, getUserPage, updateUserStatus } from '@/api/user/user';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import columns from '../types/table.columns';
|
||||
import { userStatusKey, UserStatus } from '../types/const';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import { usePagination } from '@/types/table';
|
||||
import { useDictStore, useUserStore } from '@/store';
|
||||
import usePermission from '@/hooks/permission';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useDictStore, useUserStore } from '@/store';
|
||||
import { copy } from '@/hooks/copy';
|
||||
|
||||
const emits = defineEmits(['openAdd', 'openUpdate', 'openResetPassword', 'openGrantRole']);
|
||||
@@ -180,8 +176,9 @@
|
||||
const tableRenderData = ref<UserQueryResponse[]>([]);
|
||||
|
||||
const pagination = usePagination();
|
||||
const { hasPermission } = usePermission();
|
||||
const { loading, setLoading } = useLoading();
|
||||
const { toOptions, getDictValue, getDict } = useDictStore();
|
||||
const { toOptions, getDictValue } = useDictStore();
|
||||
|
||||
const formModel = reactive<UserQueryRequest>({
|
||||
id: undefined,
|
||||
@@ -216,23 +213,12 @@
|
||||
};
|
||||
|
||||
// 更新状态
|
||||
const updateStatus = async (record: any) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
// 更新状态
|
||||
const newStatus = UserStatus.ENABLED === record.status
|
||||
? getDict(userStatusKey, UserStatus.DISABLED)
|
||||
: getDict(userStatusKey, UserStatus.ENABLED);
|
||||
await updateUserStatus({
|
||||
id: record.id,
|
||||
status: newStatus.value as number
|
||||
});
|
||||
Message.success(`${newStatus.label}成功`);
|
||||
record.status = newStatus.value;
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
const updateStatus = (id: number, status: number) => {
|
||||
return updateUserStatus({
|
||||
id, status
|
||||
}).then(() => {
|
||||
Message.success('已' + getDictValue(userStatusKey, status, 'label'));
|
||||
});
|
||||
};
|
||||
|
||||
// 打开详情
|
||||
|
||||
@@ -4,8 +4,6 @@ export const UserStatus = {
|
||||
DISABLED: 0,
|
||||
// 启用
|
||||
ENABLED: 1,
|
||||
// 锁定
|
||||
LOCKED: 2,
|
||||
};
|
||||
|
||||
// 菜单配置值类型 字典项
|
||||
|
||||
@@ -34,11 +34,11 @@ const columns = [
|
||||
ellipsis: true,
|
||||
tooltip: true,
|
||||
}, {
|
||||
title: '状态',
|
||||
title: '用户状态',
|
||||
dataIndex: 'status',
|
||||
slotName: 'status',
|
||||
align: 'center',
|
||||
width: 84
|
||||
width: 128,
|
||||
}, {
|
||||
title: '最后登录时间',
|
||||
dataIndex: 'lastLoginTime',
|
||||
@@ -51,7 +51,7 @@ const columns = [
|
||||
}, {
|
||||
title: '操作',
|
||||
slotName: 'handle',
|
||||
width: 340,
|
||||
width: 298,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
},
|
||||
|
||||
@@ -669,7 +669,7 @@ CREATE TABLE `system_user`
|
||||
`avatar` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '头像地址',
|
||||
`mobile` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '手机号',
|
||||
`email` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '邮箱',
|
||||
`status` tinyint(0) NULL DEFAULT 1 COMMENT '用户状态 0停用 1启用 2锁定',
|
||||
`status` tinyint(0) NULL DEFAULT 1 COMMENT '用户状态 0停用 1启用',
|
||||
`last_login_time` datetime(0) NULL DEFAULT NULL COMMENT '最后登录时间',
|
||||
`create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '修改时间',
|
||||
|
||||
@@ -165,7 +165,6 @@ INSERT INTO `dict_value` VALUES (15, 8, 'dictValueType', 'BOOLEAN', '布尔值',
|
||||
INSERT INTO `dict_value` VALUES (16, 8, 'dictValueType', 'COLOR', '颜色', '{\"color\": \"magenta\"}', 50, '2023-10-27 01:55:05', '2023-10-27 01:56:39', '1', '1', 0);
|
||||
INSERT INTO `dict_value` VALUES (17, 9, 'systemUserStatus', '0', '停用', '{\"color\": \"orange\"}', 10, '2023-10-27 12:13:08', '2023-10-27 12:13:08', '1', '1', 0);
|
||||
INSERT INTO `dict_value` VALUES (18, 9, 'systemUserStatus', '1', '启用', '{\"color\": \"blue\"}', 20, '2023-10-27 12:13:17', '2023-10-27 12:13:17', '1', '1', 0);
|
||||
INSERT INTO `dict_value` VALUES (19, 9, 'systemUserStatus', '2', '锁定', '{\"color\": \"orange\"}', 30, '2023-10-27 12:13:24', '2023-10-27 12:13:24', '1', '1', 0);
|
||||
INSERT INTO `dict_value` VALUES (20, 10, 'systemRoleStatus', '0', '停用', '{\"color\": \"orange\", \"status\": \"danger\"}', 10, '2023-10-27 12:33:45', '2023-10-27 12:33:45', '1', '1', 0);
|
||||
INSERT INTO `dict_value` VALUES (21, 10, 'systemRoleStatus', '1', '启用', '{\"color\": \"blue\", \"status\": \"default\"}', 20, '2023-10-27 12:33:56', '2023-10-31 01:23:23', '1', '1', 0);
|
||||
INSERT INTO `dict_value` VALUES (22, 11, 'hostSshAuthType', 'PASSWORD', '密码验证', '{}', 10, '2023-10-27 14:29:28', '2023-12-25 15:40:47', '1', '1', 0);
|
||||
|
||||
Reference in New Issue
Block a user