后台管理页面初版
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import axios, { AxiosError } from 'axios'
|
||||
import router from '../router'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const adminApi = axios.create({
|
||||
baseURL: 'http://wcy111.top:8088/api',
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
adminApi.interceptors.request.use(
|
||||
config => {
|
||||
let token = localStorage.getItem('adminAccessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('adminAccessToken')
|
||||
}
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
adminApi.interceptors.response.use(
|
||||
response => {
|
||||
return response.data.data
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
message.error('登录已过期,请重新登录')
|
||||
try {
|
||||
router.push('/admin/login').catch(err => {
|
||||
console.error('跳转到登录页失败:', err)
|
||||
window.location.href = '/admin/login'
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
}
|
||||
|
||||
console.error('Admin API Error:', error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export interface AdminLoginRequest {
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export interface AdminLoginResponse {
|
||||
accessToken: string
|
||||
refreshToken: string
|
||||
userInfo: any
|
||||
}
|
||||
|
||||
export const adminAuthApi = {
|
||||
login: (data: AdminLoginRequest) => {
|
||||
return adminApi.post<AdminLoginResponse>('/admin/auth/login', data)
|
||||
},
|
||||
|
||||
logout: () => {
|
||||
return adminApi.post('/admin/auth/logout')
|
||||
}
|
||||
}
|
||||
|
||||
export default adminApi
|
||||
@@ -0,0 +1,54 @@
|
||||
import api from './index'
|
||||
|
||||
export interface PermissionVO {
|
||||
id: number
|
||||
permissionCode: string
|
||||
permissionName: string
|
||||
permissionGroup: string
|
||||
description: string
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface CreatePermissionRequest {
|
||||
permissionCode: string
|
||||
permissionName: string
|
||||
permissionGroup: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface UpdatePermissionRequest {
|
||||
permissionCode?: string
|
||||
permissionName?: string
|
||||
permissionGroup?: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export const permissionApi = {
|
||||
getUserPermissions: (userId?: number) => {
|
||||
if (userId) {
|
||||
return api.get<PermissionVO[]>(`/admin/permission/user/${userId}`)
|
||||
}
|
||||
return api.get<PermissionVO[]>('/permission/list/user/current')
|
||||
},
|
||||
|
||||
listAllPermissions: () => {
|
||||
return api.get<PermissionVO[]>('/permission/list/all')
|
||||
},
|
||||
|
||||
createPermission: (data: CreatePermissionRequest) => {
|
||||
return api.post('/admin/permission/create', data)
|
||||
},
|
||||
|
||||
updatePermission: (id: number, data: UpdatePermissionRequest) => {
|
||||
return api.put(`/admin/permission/update/${id}`, data)
|
||||
},
|
||||
|
||||
deletePermission: (id: number) => {
|
||||
return api.delete(`/admin/permission/delete/${id}`)
|
||||
},
|
||||
|
||||
assignUserPermissions: (userId: number, permissionIds: number[]) => {
|
||||
return api.post(`/admin/permission/assign/${userId}`, { permissionIds })
|
||||
}
|
||||
}
|
||||
+40
-26
@@ -2,34 +2,44 @@ import api from './index'
|
||||
|
||||
export interface ProductVO {
|
||||
id: number
|
||||
shopId: number
|
||||
shopName: string
|
||||
title: string
|
||||
shopId: number | null
|
||||
name: string
|
||||
description: string
|
||||
imageFileIds: string
|
||||
imageUrls: string[]
|
||||
image: string
|
||||
price: number
|
||||
tags: string
|
||||
tagList: string[]
|
||||
likeCount: number
|
||||
collectCount: number
|
||||
approximateDuration: string
|
||||
bookableArtists: string
|
||||
availableCoupons: string
|
||||
estimatedTime: number
|
||||
category: string
|
||||
status: number
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface ProductDTO {
|
||||
shopId: number
|
||||
title: string
|
||||
export interface ListProductsParams {
|
||||
page: number
|
||||
size: number
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
export interface CreateProductRequest {
|
||||
name: string
|
||||
description: string
|
||||
imageFileIds: string
|
||||
image: string
|
||||
price: number
|
||||
tags: string
|
||||
approximateDuration: string
|
||||
bookableArtists: string
|
||||
availableCoupons: string
|
||||
estimatedTime: number
|
||||
category: string
|
||||
status: number
|
||||
shopId: number | null
|
||||
}
|
||||
|
||||
export interface UpdateProductRequest {
|
||||
name?: string
|
||||
description?: string
|
||||
image?: string
|
||||
price?: number
|
||||
estimatedTime?: number
|
||||
category?: string
|
||||
status?: number
|
||||
shopId?: number | null
|
||||
}
|
||||
|
||||
export const productApi = {
|
||||
@@ -45,15 +55,19 @@ export const productApi = {
|
||||
return api.get<ProductVO[]>(`/product/list/tag/${tag}`)
|
||||
},
|
||||
|
||||
createProduct: (data: ProductDTO) => {
|
||||
return api.post<ProductVO>('/product/add', data)
|
||||
listProducts: (params: ListProductsParams) => {
|
||||
return api.get<any>('/admin/product/list', { params })
|
||||
},
|
||||
|
||||
updateProduct: (id: number, data: ProductDTO) => {
|
||||
return api.put<ProductVO>(`/product/update/${id}`, data)
|
||||
createProduct: (data: CreateProductRequest) => {
|
||||
return api.post('/admin/product/create', data)
|
||||
},
|
||||
|
||||
updateProduct: (id: number, data: UpdateProductRequest) => {
|
||||
return api.put(`/admin/product/update/${id}`, data)
|
||||
},
|
||||
|
||||
deleteProduct: (id: number) => {
|
||||
return api.delete(`/product/delete/${id}`)
|
||||
return api.delete(`/admin/product/delete/${id}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,46 @@ import api from './index'
|
||||
|
||||
export interface ShopVO {
|
||||
id: number
|
||||
shopName: string
|
||||
address: string
|
||||
phone: string
|
||||
businessHours: string
|
||||
name: string
|
||||
description: string
|
||||
image: string
|
||||
phone: string
|
||||
address: string
|
||||
businessHours: string
|
||||
status: number
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface ShopSimpleVO {
|
||||
id: number
|
||||
shopName: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface ListShopsParams {
|
||||
page: number
|
||||
size: number
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
export interface CreateShopRequest {
|
||||
name: string
|
||||
description: string
|
||||
image: string
|
||||
phone: string
|
||||
address: string
|
||||
businessHours: string
|
||||
status: number
|
||||
}
|
||||
|
||||
export interface UpdateShopRequest {
|
||||
name?: string
|
||||
description?: string
|
||||
image?: string
|
||||
phone?: string
|
||||
address?: string
|
||||
businessHours?: string
|
||||
status?: number
|
||||
}
|
||||
|
||||
export const shopApi = {
|
||||
@@ -27,5 +55,21 @@ export const shopApi = {
|
||||
|
||||
getShopById: (id: number) => {
|
||||
return api.get<ShopVO>(`/shop/get/${id}`)
|
||||
},
|
||||
|
||||
listShops: (params: ListShopsParams) => {
|
||||
return api.get<any>('/admin/shop/list', { params })
|
||||
},
|
||||
|
||||
createShop: (data: CreateShopRequest) => {
|
||||
return api.post('/admin/shop/create', data)
|
||||
},
|
||||
|
||||
updateShop: (id: number, data: UpdateShopRequest) => {
|
||||
return api.put(`/admin/shop/update/${id}`, data)
|
||||
},
|
||||
|
||||
deleteShop: (id: number) => {
|
||||
return api.delete(`/admin/shop/delete/${id}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,50 @@ export interface UpdateUserInfoRequest {
|
||||
signature?: string
|
||||
}
|
||||
|
||||
export interface ListUsersParams {
|
||||
page: number
|
||||
size: number
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
export interface CreateUserRequest {
|
||||
username: string
|
||||
nickname: string
|
||||
phone: string
|
||||
password: string
|
||||
userType: number
|
||||
}
|
||||
|
||||
export interface UpdateUserRequest {
|
||||
username?: string
|
||||
nickname?: string
|
||||
phone?: string
|
||||
userType?: number
|
||||
}
|
||||
|
||||
export const userApi = {
|
||||
getUserInfo: () => {
|
||||
return api.get<UserVO>('/user/info')
|
||||
},
|
||||
updateUserInfo: (data: UpdateUserInfoRequest) => {
|
||||
return api.put('/user/info', data)
|
||||
},
|
||||
listUsers: (params: ListUsersParams) => {
|
||||
return api.get<any>('/admin/user/list', { params })
|
||||
},
|
||||
createUser: (data: CreateUserRequest) => {
|
||||
return api.post('/admin/user/create', data)
|
||||
},
|
||||
updateUser: (id: number, data: UpdateUserRequest) => {
|
||||
return api.put(`/admin/user/update/${id}`, data)
|
||||
},
|
||||
updateUserStatus: (id: number, status: number) => {
|
||||
return api.put(`/admin/user/status/${id}`, { status })
|
||||
},
|
||||
resetPassword: (id: number) => {
|
||||
return api.post(`/admin/user/reset-password/${id}`)
|
||||
},
|
||||
deleteUser: (id: number) => {
|
||||
return api.delete(`/admin/user/delete/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user