2026-02-25 10:37:16 +08:00
|
|
|
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 {
|
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) => {
|
|
|
|
|
return adminApi.post<AdminLoginResponse>('/admin/auth/login', data)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
logout: () => {
|
|
|
|
|
return adminApi.post('/admin/auth/logout')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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: () => {
|
|
|
|
|
return adminApi.get<DashboardStats>('/admin/dashboard/stats')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-25 14:32:34 +08:00
|
|
|
return adminApi.get<ProductListResponse>('/admin/product/list', { params })
|
|
|
|
|
},
|
|
|
|
|
createProduct: (data: CreateProductRequest) => {
|
|
|
|
|
return adminApi.post<number>('/admin/product/create', data)
|
|
|
|
|
},
|
|
|
|
|
updateProduct: (id: number, data: CreateProductRequest) => {
|
|
|
|
|
return adminApi.put<boolean>(`/admin/product/update/${id}`, data)
|
|
|
|
|
},
|
|
|
|
|
deleteProduct: (id: number) => {
|
|
|
|
|
return adminApi.delete<boolean>(`/admin/product/delete/${id}`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 14:44:50 +08:00
|
|
|
export interface Shop {
|
|
|
|
|
id: number
|
|
|
|
|
shopName: string
|
|
|
|
|
description: string
|
|
|
|
|
address: string
|
|
|
|
|
businessHours: string
|
|
|
|
|
coverImageFileId: string
|
|
|
|
|
coverImageUrl?: string
|
|
|
|
|
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
|
|
|
|
|
coverImageFileId: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const adminShopApi = {
|
2026-02-25 16:50:32 +08:00
|
|
|
listShops: (params: { page: number; size: number; keyword?: string; shopId?: number }) => {
|
2026-02-25 14:44:50 +08:00
|
|
|
return adminApi.get<ShopListResponse>('/admin/shops/list', { params })
|
|
|
|
|
},
|
2026-02-25 17:27:52 +08:00
|
|
|
listAllShops: () => {
|
|
|
|
|
return adminApi.get<Shop[]>('/admin/shops/list/all')
|
|
|
|
|
},
|
2026-02-25 14:44:50 +08:00
|
|
|
createShop: (data: CreateShopRequest) => {
|
|
|
|
|
return adminApi.post<number>('/admin/shops/create', data)
|
|
|
|
|
},
|
|
|
|
|
updateShop: (id: number, data: CreateShopRequest) => {
|
|
|
|
|
return adminApi.put<boolean>(`/admin/shops/update/${id}`, data)
|
|
|
|
|
},
|
|
|
|
|
deleteShop: (id: number) => {
|
|
|
|
|
return adminApi.delete<boolean>(`/admin/shops/delete/${id}`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 10:37:16 +08:00
|
|
|
export default adminApi
|