后台管理页面用户管理新增用户问题修复
This commit is contained in:
@@ -28,7 +28,12 @@ adminApi.interceptors.request.use(
|
||||
|
||||
adminApi.interceptors.response.use(
|
||||
response => {
|
||||
return response.data.data
|
||||
const res = response.data
|
||||
if (res.code !== 200) {
|
||||
message.error(res.message || '请求失败')
|
||||
return Promise.reject(new Error(res.message || '请求失败'))
|
||||
}
|
||||
return res.data
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
if (error.response?.status === 401) {
|
||||
@@ -46,6 +51,9 @@ adminApi.interceptors.response.use(
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
} else {
|
||||
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
||||
message.error(errorMsg)
|
||||
}
|
||||
|
||||
console.error('Admin API Error:', error)
|
||||
@@ -205,4 +213,77 @@ export const adminShopApi = {
|
||||
}
|
||||
}
|
||||
|
||||
export interface UserVO {
|
||||
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 UserListResponse {
|
||||
list: UserVO[]
|
||||
total: number
|
||||
page: number
|
||||
size: number
|
||||
}
|
||||
|
||||
export interface CreateUserRequest {
|
||||
shopId: number
|
||||
nickname: string
|
||||
account: string
|
||||
phone: string
|
||||
password: string
|
||||
type: number
|
||||
}
|
||||
|
||||
export const userApi = {
|
||||
listUsers: (params: { page: number; size: number; keyword?: string; shopId?: number }) => {
|
||||
return adminApi.get<UserListResponse>('/admin/user/list', { params })
|
||||
},
|
||||
createUser: (data: CreateUserRequest) => {
|
||||
return adminApi.post<number>('/admin/user/create', data)
|
||||
},
|
||||
updateUser: (id: number, data: Partial<CreateUserRequest>) => {
|
||||
return adminApi.put<boolean>(`/admin/user/update/${id}`, data)
|
||||
},
|
||||
updateUserStatus: (id: number, status: number) => {
|
||||
return adminApi.put(`/admin/user/status/${id}`, { status })
|
||||
},
|
||||
deleteUser: (id: number) => {
|
||||
return adminApi.delete<boolean>(`/admin/user/delete/${id}`)
|
||||
},
|
||||
resetPassword: (id: number) => {
|
||||
return adminApi.post(`/admin/user/reset-password/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
export interface PermissionVO {
|
||||
id: number
|
||||
permissionName: string
|
||||
permissionCode: string
|
||||
description: string
|
||||
module: string
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export const permissionApi = {
|
||||
listAllPermissions: () => {
|
||||
return adminApi.get<PermissionVO[]>('/permission/list/all')
|
||||
},
|
||||
getUserPermissions: () => {
|
||||
return adminApi.get<PermissionVO[]>('/permission/list/user/current')
|
||||
}
|
||||
}
|
||||
|
||||
export default adminApi
|
||||
|
||||
@@ -64,11 +64,16 @@ api.interceptors.request.use(
|
||||
|
||||
api.interceptors.response.use(
|
||||
response => {
|
||||
return response.data.data
|
||||
const res = response.data
|
||||
if (res.code !== 200) {
|
||||
message.error(res.message || '请求失败')
|
||||
return Promise.reject(new Error(res.message || '请求失败'))
|
||||
}
|
||||
return res.data
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
const originalRequest = error.config as any
|
||||
|
||||
|
||||
const isWhitelistedPath = (url: string) => {
|
||||
return url?.includes('/user/login') ||
|
||||
url?.includes('/user/register') ||
|
||||
@@ -123,6 +128,9 @@ api.interceptors.response.use(
|
||||
handleTokenExpired()
|
||||
return Promise.reject(error)
|
||||
}
|
||||
} else {
|
||||
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
||||
message.error(errorMsg)
|
||||
}
|
||||
|
||||
console.error('API Error:', error)
|
||||
@@ -130,4 +138,4 @@ api.interceptors.response.use(
|
||||
}
|
||||
)
|
||||
|
||||
export default api
|
||||
export default api
|
||||
|
||||
@@ -144,8 +144,7 @@ import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
import { adminShopApi, type Shop } from '@/api/admin'
|
||||
import { userApi, type UserVO, adminShopApi, type Shop } from '@/api/admin'
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
|
||||
@@ -56,4 +56,9 @@ public class UserDTO {
|
||||
* 关联VIP信息表主键(0表示非VIP)
|
||||
*/
|
||||
private Long vipId;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
}
|
||||
|
||||
+36
-4
@@ -43,11 +43,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
|
||||
@Override
|
||||
public Long createUser(UserDTO userDTO) {
|
||||
UserDO existingUser = userMapper.selectOne(
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, userDTO.getAccount())
|
||||
.eq(UserDO::getIsDelete, 0)
|
||||
);
|
||||
if (existingUser != null) {
|
||||
throw new RuntimeException("账号已存在");
|
||||
}
|
||||
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setShopId(userDTO.getShopId());
|
||||
userDO.setNickname(userDTO.getNickname());
|
||||
userDO.setAccount(userDTO.getAccount());
|
||||
userDO.setPassword(userDTO.getPassword());
|
||||
userDO.setPhone(userDTO.getPhone());
|
||||
userDO.setSignature(userDTO.getSignature());
|
||||
userDO.setLevel(userDTO.getLevel());
|
||||
userDO.setType(userDTO.getType());
|
||||
@@ -56,7 +66,16 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setStatus(1);
|
||||
String defaultAvatar = "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
|
||||
userDO.setAvatar(defaultAvatar);
|
||||
userMapper.insert(userDO);
|
||||
|
||||
try {
|
||||
userMapper.insert(userDO);
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage() != null && e.getMessage().contains("Duplicate entry")) {
|
||||
throw new RuntimeException("账号已存在");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
return userDO.getId();
|
||||
}
|
||||
|
||||
@@ -66,18 +85,31 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
if (userDO == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (userDTO.getAccount() != null && !userDTO.getAccount().equals(userDO.getAccount())) {
|
||||
UserDO existingUser = userMapper.selectOne(
|
||||
Wrappers.lambdaQuery(UserDO.class)
|
||||
.eq(UserDO::getAccount, userDTO.getAccount())
|
||||
.eq(UserDO::getIsDelete, 0)
|
||||
);
|
||||
if (existingUser != null) {
|
||||
throw new RuntimeException("账号已存在");
|
||||
}
|
||||
userDO.setAccount(userDTO.getAccount());
|
||||
}
|
||||
|
||||
if (userDTO.getShopId() != null) {
|
||||
userDO.setShopId(userDTO.getShopId());
|
||||
}
|
||||
if (userDTO.getNickname() != null) {
|
||||
userDO.setNickname(userDTO.getNickname());
|
||||
}
|
||||
if (userDTO.getAccount() != null) {
|
||||
userDO.setAccount(userDTO.getAccount());
|
||||
}
|
||||
if (userDTO.getPassword() != null) {
|
||||
userDO.setPassword(userDTO.getPassword());
|
||||
}
|
||||
if (userDTO.getPhone() != null) {
|
||||
userDO.setPhone(userDTO.getPhone());
|
||||
}
|
||||
if (userDTO.getAvatar() != null) {
|
||||
if (userDTO.getAvatar().isEmpty()) {
|
||||
userDO.setAvatar(null);
|
||||
|
||||
Reference in New Issue
Block a user