2026-02-25 10:37:16 +08:00
|
|
|
import axios, { AxiosError } from 'axios'
|
|
|
|
|
import router from '../router'
|
|
|
|
|
import { message } from 'ant-design-vue'
|
|
|
|
|
|
2026-02-26 23:28:24 +08:00
|
|
|
// 防重复提示标志
|
|
|
|
|
let lastErrorTime = 0
|
|
|
|
|
let lastErrorMessage = ''
|
|
|
|
|
const ERROR_DEBOUNCE_TIME = 1000 // 1秒内不重复显示相同错误
|
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
const adminApi = axios.create({
|
2026-02-27 14:20:20 +08:00
|
|
|
baseURL: 'http://wcy111.top:8088/admin/api',
|
2026-02-25 10:37:16 +08:00
|
|
|
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 => {
|
2026-02-25 19:07:39 +08:00
|
|
|
const res = response.data
|
|
|
|
|
if (res.code !== 200) {
|
2026-02-26 23:28:24 +08:00
|
|
|
// 检查是否是权限不足的错误
|
|
|
|
|
const errorMsg = res.message || '请求失败'
|
|
|
|
|
if (!errorMsg.includes('权限') && !errorMsg.includes('permission')) {
|
|
|
|
|
message.error(errorMsg)
|
|
|
|
|
} else {
|
|
|
|
|
console.error('权限不足:', errorMsg)
|
|
|
|
|
}
|
|
|
|
|
return Promise.reject(new Error(errorMsg))
|
2026-02-25 19:07:39 +08:00
|
|
|
}
|
|
|
|
|
return res.data
|
2026-02-25 10:37:16 +08:00
|
|
|
},
|
|
|
|
|
async (error: AxiosError) => {
|
2026-02-26 23:28:24 +08:00
|
|
|
// 防抖处理错误提示
|
|
|
|
|
const showError = (msg: string) => {
|
|
|
|
|
const now = Date.now()
|
|
|
|
|
if (now - lastErrorTime > ERROR_DEBOUNCE_TIME || msg !== lastErrorMessage) {
|
|
|
|
|
lastErrorTime = now
|
|
|
|
|
lastErrorMessage = msg
|
|
|
|
|
message.error(msg)
|
2026-02-25 10:37:16 +08:00
|
|
|
}
|
2026-02-26 23:28:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error.response?.status === 401) {
|
|
|
|
|
// 登录过期,只提示一次
|
|
|
|
|
if (Date.now() - lastErrorTime > ERROR_DEBOUNCE_TIME || lastErrorMessage !== '登录已过期,请重新登录') {
|
|
|
|
|
localStorage.removeItem('adminAccessToken')
|
|
|
|
|
localStorage.removeItem('adminRefreshToken')
|
|
|
|
|
localStorage.removeItem('adminUserInfo')
|
|
|
|
|
sessionStorage.removeItem('adminAccessToken')
|
|
|
|
|
showError('登录已过期,请重新登录')
|
|
|
|
|
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'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (error.response?.status !== 403) { // 403权限不足不提示
|
2026-02-25 19:07:39 +08:00
|
|
|
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
2026-02-26 23:28:24 +08:00
|
|
|
showError(errorMsg)
|
|
|
|
|
} else {
|
|
|
|
|
console.error('权限不足:', error)
|
2026-02-25 10:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.error('Admin API Error:', error)
|
|
|
|
|
return Promise.reject(error)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
export interface AdminLoginRequest {
|
2026-02-25 11:08:02 +08:00
|
|
|
account: string
|
2026-02-25 10:37:16 +08:00
|
|
|
password: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AdminLoginResponse {
|
|
|
|
|
accessToken: string
|
|
|
|
|
refreshToken: string
|
|
|
|
|
userInfo: any
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:28:42 +08:00
|
|
|
export interface HotProduct {
|
|
|
|
|
id: number
|
|
|
|
|
title: string
|
|
|
|
|
price: number
|
|
|
|
|
likeCount: number
|
|
|
|
|
collectCount: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RecentActivity {
|
|
|
|
|
id: number
|
|
|
|
|
type: string
|
|
|
|
|
title: string
|
|
|
|
|
description: string
|
|
|
|
|
time: string
|
|
|
|
|
color: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:17:11 +08:00
|
|
|
export interface DashboardStats {
|
|
|
|
|
totalUsers: number
|
|
|
|
|
totalProducts: number
|
|
|
|
|
totalShops: number
|
|
|
|
|
todayOrders: number
|
2026-02-25 11:28:42 +08:00
|
|
|
hotProducts: HotProduct[]
|
|
|
|
|
recentActivities: RecentActivity[]
|
2026-02-25 11:17:11 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
export const adminAuthApi = {
|
|
|
|
|
login: (data: AdminLoginRequest) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.post<AdminLoginResponse>('/auth/login', data)
|
2026-02-25 10:37:16 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
logout: () => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.post('/auth/logout')
|
2026-02-25 10:37:16 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 14:32:34 +08:00
|
|
|
export interface Product {
|
|
|
|
|
id: number
|
|
|
|
|
shopId: number
|
|
|
|
|
title: string
|
|
|
|
|
description: string
|
|
|
|
|
imageFileIds: string
|
|
|
|
|
imageUrls?: string[]
|
|
|
|
|
price: number
|
|
|
|
|
tags: string
|
|
|
|
|
tagList?: string[]
|
|
|
|
|
tagInfos?: any[]
|
|
|
|
|
likeCount: number
|
|
|
|
|
collectCount: number
|
|
|
|
|
approximateDuration: string
|
|
|
|
|
bookableArtists: string
|
|
|
|
|
availableCoupons: string
|
|
|
|
|
createTime: string
|
|
|
|
|
updateTime: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ProductListResponse {
|
|
|
|
|
list: Product[]
|
|
|
|
|
total: number
|
|
|
|
|
page: number
|
|
|
|
|
size: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateProductRequest {
|
|
|
|
|
shopId: number
|
|
|
|
|
title: string
|
|
|
|
|
description: string
|
|
|
|
|
imageFileIds: string
|
|
|
|
|
price: number
|
|
|
|
|
tags: string
|
|
|
|
|
approximateDuration: string
|
|
|
|
|
bookableArtists: string
|
|
|
|
|
availableCoupons: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 11:17:11 +08:00
|
|
|
export const adminDashboardApi = {
|
|
|
|
|
getStats: () => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<DashboardStats>('/dashboard/stats')
|
2026-02-25 11:17:11 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 14:32:34 +08:00
|
|
|
export const adminProductApi = {
|
2026-02-25 16:50:32 +08:00
|
|
|
listProducts: (params: { page: number; size: number; keyword?: string; shopId?: number }) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<ProductListResponse>('/product/list', { params })
|
2026-02-25 14:32:34 +08:00
|
|
|
},
|
|
|
|
|
createProduct: (data: CreateProductRequest) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.post<number>('/product/create', data)
|
2026-02-25 14:32:34 +08:00
|
|
|
},
|
|
|
|
|
updateProduct: (id: number, data: CreateProductRequest) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.put<boolean>(`/product/update/${id}`, data)
|
2026-02-25 14:32:34 +08:00
|
|
|
},
|
|
|
|
|
deleteProduct: (id: number) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.delete<boolean>(`/product/delete/${id}`)
|
2026-02-25 14:32:34 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 14:44:50 +08:00
|
|
|
export interface Shop {
|
|
|
|
|
id: number
|
|
|
|
|
shopName: string
|
|
|
|
|
description: string
|
|
|
|
|
address: string
|
|
|
|
|
businessHours: string
|
2026-02-26 14:20:35 +08:00
|
|
|
imageFileIds: string
|
|
|
|
|
imageUrls?: string[]
|
2026-02-25 14:44:50 +08:00
|
|
|
createTime: string
|
|
|
|
|
updateTime: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ShopListResponse {
|
|
|
|
|
list: Shop[]
|
|
|
|
|
total: number
|
|
|
|
|
page: number
|
|
|
|
|
size: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateShopRequest {
|
|
|
|
|
shopName: string
|
|
|
|
|
description: string
|
|
|
|
|
address: string
|
|
|
|
|
businessHours: string
|
2026-02-26 14:20:35 +08:00
|
|
|
imageFileIds: string
|
2026-02-25 14:44:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const adminShopApi = {
|
2026-02-25 16:50:32 +08:00
|
|
|
listShops: (params: { page: number; size: number; keyword?: string; shopId?: number }) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<ShopListResponse>('/shops/list', { params })
|
2026-02-25 14:44:50 +08:00
|
|
|
},
|
2026-02-25 17:27:52 +08:00
|
|
|
listAllShops: () => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<Shop[]>('/shops/list/all')
|
2026-02-25 17:27:52 +08:00
|
|
|
},
|
2026-02-25 14:44:50 +08:00
|
|
|
createShop: (data: CreateShopRequest) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.post<number>('/shops/create', data)
|
2026-02-25 14:44:50 +08:00
|
|
|
},
|
|
|
|
|
updateShop: (id: number, data: CreateShopRequest) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.put<boolean>(`/shops/update/${id}`, data)
|
2026-02-25 14:44:50 +08:00
|
|
|
},
|
|
|
|
|
deleteShop: (id: number) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.delete<boolean>(`/shops/delete/${id}`)
|
2026-02-25 14:44:50 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 19:07:39 +08:00
|
|
|
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 = {
|
2026-02-25 19:38:13 +08:00
|
|
|
getUserInfo: () => {
|
2026-02-26 17:54:18 +08:00
|
|
|
return adminApi.get<UserVO>('/user/info')
|
2026-02-25 19:38:13 +08:00
|
|
|
},
|
2026-02-26 23:28:24 +08:00
|
|
|
listUsers: (params: { page: number; size: number; keyword?: string; shopId?: number; status?: number }) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<UserListResponse>('/user/list', { params })
|
2026-02-25 19:07:39 +08:00
|
|
|
},
|
|
|
|
|
createUser: (data: CreateUserRequest) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.post<number>('/user/create', data)
|
2026-02-25 19:07:39 +08:00
|
|
|
},
|
|
|
|
|
updateUser: (id: number, data: Partial<CreateUserRequest>) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.put<boolean>(`/user/update/${id}`, data)
|
2026-02-25 19:07:39 +08:00
|
|
|
},
|
|
|
|
|
updateUserStatus: (id: number, status: number) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.put(`/user/status/${id}`, { status })
|
2026-02-25 19:07:39 +08:00
|
|
|
},
|
|
|
|
|
deleteUser: (id: number) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.delete<boolean>(`/user/delete/${id}`)
|
2026-02-25 19:07:39 +08:00
|
|
|
},
|
|
|
|
|
resetPassword: (id: number) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.post(`/user/reset-password/${id}`)
|
2026-02-25 19:07:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface PermissionVO {
|
|
|
|
|
id: number
|
|
|
|
|
permissionName: string
|
|
|
|
|
permissionCode: string
|
|
|
|
|
description: string
|
|
|
|
|
module: string
|
|
|
|
|
createTime: string
|
|
|
|
|
updateTime: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 10:21:02 +08:00
|
|
|
export interface ObjectStorageFileVO {
|
|
|
|
|
id: number
|
|
|
|
|
fileName: string
|
|
|
|
|
fileUrl: string
|
|
|
|
|
status: number
|
|
|
|
|
createTime: string
|
|
|
|
|
updateTime: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const adminFileApi = {
|
|
|
|
|
uploadFile: (file: File) => {
|
|
|
|
|
const formData = new FormData()
|
|
|
|
|
formData.append('file', file)
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.post<ObjectStorageFileVO>('/object-storage-file/upload', formData, {
|
2026-02-26 10:21:02 +08:00
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'multipart/form-data'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getSignedUrl: (fileId: number, expiryTimeInMinutes?: number) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<string>(`/object-storage-file/get-signed-url/${fileId}`, {
|
2026-02-26 10:21:02 +08:00
|
|
|
params: { expiryTimeInMinutes }
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 17:54:18 +08:00
|
|
|
export interface PermissionVO {
|
|
|
|
|
id: number
|
|
|
|
|
permissionCode: string
|
|
|
|
|
permissionName: string
|
|
|
|
|
permissionGroup: string
|
|
|
|
|
description: string
|
|
|
|
|
createTime: string
|
|
|
|
|
updateTime: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 19:07:39 +08:00
|
|
|
export const permissionApi = {
|
|
|
|
|
listAllPermissions: () => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<PermissionVO[]>('/permission/list/all')
|
2026-02-25 19:07:39 +08:00
|
|
|
},
|
2026-02-26 17:54:18 +08:00
|
|
|
getUserPermissions: (userId?: number) => {
|
|
|
|
|
if (userId) {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<PermissionVO[]>(`/permission/user/${userId}`)
|
2026-02-26 17:54:18 +08:00
|
|
|
}
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<PermissionVO[]>('/permission/user/current')
|
2026-02-26 17:54:18 +08:00
|
|
|
},
|
|
|
|
|
assignUserPermissions: (userId: number, permissionIds: number[]) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.post(`/permission/assign/${userId}`, { permissionIds })
|
2026-02-25 19:07:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:39:39 +08:00
|
|
|
export const adminTagApi = {
|
|
|
|
|
listAllTags: () => {
|
|
|
|
|
return adminApi.get<any[]>('/tag/list/all')
|
|
|
|
|
},
|
|
|
|
|
listTagsByShopId: (shopId: number) => {
|
|
|
|
|
return adminApi.get<any[]>('/tag/list/by-shop/' + shopId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const adminArtistApi = {
|
|
|
|
|
listArtists: (shopId?: number) => {
|
2026-02-27 14:20:20 +08:00
|
|
|
return adminApi.get<UserVO[]>('/user/list', { params: { shopId, type: 3 } })
|
2026-02-26 15:39:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const adminCouponApi = {
|
|
|
|
|
listAllCoupons: () => {
|
2026-02-27 11:05:15 +08:00
|
|
|
return adminApi.get<any[]>('/coupon/list', { params: { page: 1, size: 100 } })
|
|
|
|
|
},
|
|
|
|
|
createCoupon: (data: any) => {
|
|
|
|
|
return adminApi.post('/coupon/create', data)
|
|
|
|
|
},
|
|
|
|
|
updateCoupon: (id: number, data: any) => {
|
|
|
|
|
return adminApi.put(`/coupon/update/${id}`, data)
|
|
|
|
|
},
|
|
|
|
|
deleteCoupon: (id: number) => {
|
|
|
|
|
return adminApi.delete(`/coupon/delete/${id}`)
|
2026-02-27 15:57:14 +08:00
|
|
|
},
|
|
|
|
|
distributeCoupon: (data: { couponId: number; userIds: number[]; quantity: number }) => {
|
|
|
|
|
return adminApi.post('/coupon/distribute', data)
|
2026-02-26 15:39:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-27 11:05:15 +08:00
|
|
|
export default adminApi
|