后台管理页面用户管理初版
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
import api from './index'
|
||||
import type { UserInfo } from './auth'
|
||||
|
||||
export type UserVO = UserInfo
|
||||
export interface UserVO extends UserInfo {
|
||||
id: number
|
||||
shopId?: number
|
||||
shopName?: string
|
||||
nickname: string
|
||||
account: string
|
||||
avatar: string
|
||||
signature?: string
|
||||
level?: string
|
||||
type: number
|
||||
vipId?: number
|
||||
createTime: string
|
||||
updateTime: string
|
||||
status: number
|
||||
phone?: string
|
||||
}
|
||||
|
||||
export interface UpdateUserInfoRequest {
|
||||
nickname?: string
|
||||
@@ -16,18 +31,18 @@ export interface ListUsersParams {
|
||||
}
|
||||
|
||||
export interface CreateUserRequest {
|
||||
username: string
|
||||
account: string
|
||||
nickname: string
|
||||
phone: string
|
||||
password: string
|
||||
userType: number
|
||||
type: number
|
||||
}
|
||||
|
||||
export interface UpdateUserRequest {
|
||||
username?: string
|
||||
account?: string
|
||||
nickname?: string
|
||||
phone?: string
|
||||
userType?: number
|
||||
type?: number
|
||||
}
|
||||
|
||||
export const userApi = {
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
<template v-if="column.key === 'avatar'">
|
||||
<a-avatar :size="40" :src="record.avatar || DEFAULT_AVATAR" />
|
||||
</template>
|
||||
<template v-else-if="column.key === 'userType'">
|
||||
<a-tag :color="getUserTypeColor(record.userType)">
|
||||
{{ getUserTypeText(record.userType) }}
|
||||
<template v-else-if="column.key === 'type'">
|
||||
<a-tag :color="getUserTypeColor(record.type)">
|
||||
{{ getUserTypeText(record.type) }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
@@ -79,8 +79,8 @@
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 16 }"
|
||||
>
|
||||
<a-form-item label="用户名" name="username">
|
||||
<a-input v-model:value="formState.username" placeholder="请输入用户名" />
|
||||
<a-form-item label="账号" name="account">
|
||||
<a-input v-model:value="formState.account" placeholder="请输入账号" />
|
||||
</a-form-item>
|
||||
<a-form-item label="昵称" name="nickname">
|
||||
<a-input v-model:value="formState.nickname" placeholder="请输入昵称" />
|
||||
@@ -91,8 +91,8 @@
|
||||
<a-form-item v-if="!isEdit" label="密码" name="password">
|
||||
<a-input-password v-model:value="formState.password" placeholder="请输入密码" />
|
||||
</a-form-item>
|
||||
<a-form-item label="用户类型" name="userType">
|
||||
<a-select v-model:value="formState.userType" placeholder="请选择用户类型">
|
||||
<a-form-item label="用户类型" name="type">
|
||||
<a-select v-model:value="formState.type" placeholder="请选择用户类型">
|
||||
<a-select-option :value="0">用户</a-select-option>
|
||||
<a-select-option :value="2">店长</a-select-option>
|
||||
<a-select-option :value="3">美甲师</a-select-option>
|
||||
@@ -131,27 +131,27 @@ const pagination = reactive({
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
username: '',
|
||||
account: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
userType: 0
|
||||
type: 0
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
|
||||
nickname: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
||||
phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
userType: [{ required: true, message: '请选择用户类型', trigger: 'change' }]
|
||||
type: [{ required: true, message: '请选择用户类型', trigger: 'change' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '头像', key: 'avatar', width: 80 },
|
||||
{ title: '用户名', dataIndex: 'username', key: 'username' },
|
||||
{ title: '账号', dataIndex: 'account', key: 'account' },
|
||||
{ title: '昵称', dataIndex: 'nickname', key: 'nickname' },
|
||||
{ title: '手机号', dataIndex: 'phone', key: 'phone' },
|
||||
{ title: '用户类型', key: 'userType', width: 120 },
|
||||
{ title: '用户类型', key: 'type', width: 120 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 200, fixed: 'right' as const }
|
||||
@@ -208,11 +208,11 @@ const handleTableChange = (pag: any) => {
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
Object.assign(formState, {
|
||||
username: '',
|
||||
account: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
userType: 0
|
||||
type: 0
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
@@ -221,11 +221,11 @@ const showEditModal = (record: UserVO) => {
|
||||
isEdit.value = true
|
||||
currentUser.value = record
|
||||
Object.assign(formState, {
|
||||
username: record.username,
|
||||
account: record.account,
|
||||
nickname: record.nickname,
|
||||
phone: record.phone,
|
||||
password: '',
|
||||
userType: record.userType
|
||||
type: record.type
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
@@ -22,53 +22,79 @@ import java.lang.reflect.Method;
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionAspect {
|
||||
|
||||
// 注入权限服务
|
||||
private final PermissionService permissionService;
|
||||
// 注入用户数据访问对象
|
||||
private final UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 环绕通知,用于检查权限
|
||||
* @param joinPoint 连接点,可以获取方法执行的相关信息
|
||||
* @return 方法执行结果或错误信息
|
||||
* @throws Throwable 方法执行可能抛出的异常
|
||||
*/
|
||||
@Around("@annotation(com.xiaowang.yuminailcore.annotation.RequirePermission)")
|
||||
public Object checkPermission(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
// 获取请求属性
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
// 如果无法获取请求信息,返回错误
|
||||
if (attributes == null) {
|
||||
return Result.error(403, "无法获取请求信息");
|
||||
}
|
||||
|
||||
// 获取HTTP请求对象
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
// 从请求中获取用户ID
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
|
||||
// 如果用户ID为空,表示未登录
|
||||
if (userId == null) {
|
||||
return Result.error(401, "未登录");
|
||||
}
|
||||
|
||||
// 获取方法签名
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
// 获取目标方法
|
||||
Method method = signature.getMethod();
|
||||
// 获取方法上的权限注解
|
||||
RequirePermission requirePermission = method.getAnnotation(RequirePermission.class);
|
||||
|
||||
// 如果方法没有权限注解,直接执行方法
|
||||
if (requirePermission == null) {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
|
||||
// 根据用户ID查询用户信息
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
// 如果用户不存在,返回错误
|
||||
if (userDO == null) {
|
||||
return Result.error(404, "用户不存在");
|
||||
}
|
||||
|
||||
// 获取权限码
|
||||
String permissionCode = requirePermission.value();
|
||||
// 获取需要的用户类型
|
||||
int requireUserType = requirePermission.requireUserType();
|
||||
|
||||
// 默认有权限
|
||||
boolean hasPermission = true;
|
||||
|
||||
// 如果权限码不为空,检查用户是否拥有该权限
|
||||
if (!permissionCode.isEmpty()) {
|
||||
hasPermission = permissionService.hasPermission(userId, permissionCode);
|
||||
}
|
||||
|
||||
// 如果需要检查用户类型,则进行类型检查
|
||||
if (hasPermission && requireUserType >= 0) {
|
||||
hasPermission = permissionService.hasPermissionByType(userDO.getType(), requireUserType);
|
||||
}
|
||||
|
||||
// 如果没有权限,返回错误
|
||||
if (!hasPermission) {
|
||||
return Result.error(403, "权限不足");
|
||||
}
|
||||
|
||||
// 有权限,执行目标方法
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
|
||||
import java.util.List;
|
||||
@@ -47,4 +48,8 @@ public interface UserService extends IService<UserDO> {
|
||||
boolean bindEmail(Long userId, BindEmailRequestDTO bindEmailRequestDTO);
|
||||
|
||||
boolean resetPassword(Long targetUserId, Long currentUserId);
|
||||
|
||||
PageResultVO<UserVO> pageUsers(Integer page, Integer size, String keyword);
|
||||
|
||||
boolean updateUserStatus(Long id, Integer status);
|
||||
}
|
||||
|
||||
+40
@@ -1,6 +1,8 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.dto.BindEmailRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindPhoneRequestDTO;
|
||||
@@ -13,10 +15,12 @@ import com.xiaowang.yuminailcore.service.ShopService;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -173,6 +177,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
}
|
||||
userVO.setNickname(userDO.getNickname());
|
||||
userVO.setAccount(userDO.getAccount());
|
||||
userVO.setPhone(userDO.getPhone());
|
||||
String defaultAvatar = "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
|
||||
userVO.setAvatar(userDO.getAvatar() != null && !userDO.getAvatar().isEmpty() ? userDO.getAvatar() : defaultAvatar);
|
||||
userVO.setSignature(userDO.getSignature());
|
||||
@@ -181,6 +186,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userVO.setVipId(userDO.getVipId());
|
||||
userVO.setCreateTime(userDO.getCreateTime());
|
||||
userVO.setUpdateTime(userDO.getUpdateTime());
|
||||
userVO.setStatus(userDO.getIsDelete() != null && userDO.getIsDelete() == 0 ? 1 : 0);
|
||||
return userVO;
|
||||
}
|
||||
|
||||
@@ -383,4 +389,38 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
|
||||
return userMapper.updateById(targetUser) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<UserVO> pageUsers(Integer page, Integer size, String keyword) {
|
||||
Page<UserDO> pageParam = new Page<>(page, size);
|
||||
|
||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
||||
if (StringUtils.hasText(keyword)) {
|
||||
wrapper.and(w -> w.like(UserDO::getAccount, keyword)
|
||||
.or().like(UserDO::getNickname, keyword)
|
||||
.or().like(UserDO::getPhone, keyword));
|
||||
}
|
||||
wrapper.orderByDesc(UserDO::getCreateTime);
|
||||
|
||||
Page<UserDO> userPage = userMapper.selectPage(pageParam, wrapper);
|
||||
|
||||
PageResultVO<UserVO> result = new PageResultVO<>();
|
||||
result.setList(userPage.getRecords().stream().map(this::convertToVO).collect(Collectors.toList()));
|
||||
result.setTotal(userPage.getTotal());
|
||||
result.setPage(page);
|
||||
result.setSize(size);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateUserStatus(Long id, Integer status) {
|
||||
UserDO userDO = userMapper.selectById(id);
|
||||
if (userDO == null) {
|
||||
return false;
|
||||
}
|
||||
userDO.setIsDelete(status == 1 ? 0 : 1);
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,4 +83,14 @@ public class UserVO {
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 用户状态:1-正常,0-禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user