功能:完善多店铺登录与首次部署SQL
This commit is contained in:
+133
-37
@@ -3,10 +3,9 @@ import router from '../router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { ADMIN_API_BASE_URL } from '../config/api'
|
||||
|
||||
// 防重复提示标志
|
||||
let lastErrorTime = 0
|
||||
let lastErrorMessage = ''
|
||||
const ERROR_DEBOUNCE_TIME = 1000 // 1秒内不重复显示相同错误
|
||||
const ERROR_DEBOUNCE_TIME = 1000
|
||||
|
||||
const adminApi = axios.create({
|
||||
baseURL: ADMIN_API_BASE_URL,
|
||||
@@ -16,10 +15,62 @@ const adminApi = axios.create({
|
||||
}
|
||||
})
|
||||
|
||||
let isRefreshing = false
|
||||
let failedQueue: Array<{
|
||||
resolve: (value?: any) => void
|
||||
reject: (reason?: any) => void
|
||||
}> = []
|
||||
|
||||
const processQueue = (error: any, token: string | null = null) => {
|
||||
failedQueue.forEach(prom => {
|
||||
if (error) {
|
||||
prom.reject(error)
|
||||
} else {
|
||||
prom.resolve(token)
|
||||
}
|
||||
})
|
||||
failedQueue = []
|
||||
}
|
||||
|
||||
const showError = (msg: string) => {
|
||||
const now = Date.now()
|
||||
if (now - lastErrorTime > ERROR_DEBOUNCE_TIME || msg !== lastErrorMessage) {
|
||||
lastErrorTime = now
|
||||
lastErrorMessage = msg
|
||||
message.error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
const isAuthFreePath = (url?: string) => {
|
||||
return Boolean(url?.includes('/auth/login') || url?.includes('/auth/refresh'))
|
||||
}
|
||||
|
||||
const handleAdminTokenExpired = () => {
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
localStorage.removeItem('adminRefreshToken')
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
localStorage.removeItem('userPermissions')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
sessionStorage.removeItem('adminRefreshToken')
|
||||
|
||||
if (Date.now() - lastErrorTime > ERROR_DEBOUNCE_TIME || lastErrorMessage !== '登录已过期,请重新登录') {
|
||||
showError('登录已过期,请重新登录')
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
try {
|
||||
router.push('/admin/login').catch(() => {
|
||||
window.location.href = '/admin/login'
|
||||
})
|
||||
} catch {
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
}, 300)
|
||||
}
|
||||
|
||||
adminApi.interceptors.request.use(
|
||||
config => {
|
||||
// 登录请求不需要携带Token
|
||||
if (!config.url?.includes('/auth/login')) {
|
||||
if (!isAuthFreePath(config.url)) {
|
||||
let token = localStorage.getItem('adminAccessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('adminAccessToken')
|
||||
@@ -30,9 +81,7 @@ adminApi.interceptors.request.use(
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
error => Promise.reject(error)
|
||||
)
|
||||
|
||||
adminApi.interceptors.response.use(
|
||||
@@ -41,7 +90,7 @@ adminApi.interceptors.response.use(
|
||||
if (res.code !== 200) {
|
||||
const errorMsg = res.message || '请求失败'
|
||||
if (!errorMsg.includes('权限') && !errorMsg.includes('permission')) {
|
||||
message.error(errorMsg)
|
||||
showError(errorMsg)
|
||||
} else {
|
||||
console.error('权限不足:', errorMsg)
|
||||
}
|
||||
@@ -50,35 +99,56 @@ adminApi.interceptors.response.use(
|
||||
return res.data as any
|
||||
},
|
||||
async (error: AxiosError) => {
|
||||
// 防抖处理错误提示
|
||||
const showError = (msg: string) => {
|
||||
const now = Date.now()
|
||||
if (now - lastErrorTime > ERROR_DEBOUNCE_TIME || msg !== lastErrorMessage) {
|
||||
lastErrorTime = now
|
||||
lastErrorMessage = msg
|
||||
message.error(msg)
|
||||
}
|
||||
}
|
||||
const originalRequest = error.config as any
|
||||
|
||||
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'
|
||||
if (!originalRequest?._retry && !isAuthFreePath(originalRequest?.url)) {
|
||||
if (isRefreshing) {
|
||||
return new Promise((resolve, reject) => {
|
||||
failedQueue.push({ resolve, reject })
|
||||
}).then(token => {
|
||||
if (token) {
|
||||
originalRequest.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return adminApi(originalRequest)
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('跳转到登录页异常:', err)
|
||||
window.location.href = '/admin/login'
|
||||
}
|
||||
|
||||
originalRequest._retry = true
|
||||
isRefreshing = true
|
||||
|
||||
try {
|
||||
let refreshToken = localStorage.getItem('adminRefreshToken')
|
||||
if (!refreshToken) {
|
||||
refreshToken = sessionStorage.getItem('adminRefreshToken')
|
||||
}
|
||||
if (!refreshToken) {
|
||||
throw new Error('No refresh token available')
|
||||
}
|
||||
|
||||
const response = await adminAuthApi.refreshToken(refreshToken)
|
||||
const newToken = (response as any).accessToken
|
||||
const newRefreshToken = (response as any).refreshToken
|
||||
|
||||
localStorage.setItem('adminAccessToken', newToken)
|
||||
localStorage.setItem('adminRefreshToken', newRefreshToken)
|
||||
sessionStorage.setItem('adminAccessToken', newToken)
|
||||
sessionStorage.setItem('adminRefreshToken', newRefreshToken)
|
||||
|
||||
processQueue(null, newToken)
|
||||
originalRequest.headers.Authorization = `Bearer ${newToken}`
|
||||
return adminApi(originalRequest)
|
||||
} catch (refreshError) {
|
||||
processQueue(refreshError, null)
|
||||
handleAdminTokenExpired()
|
||||
return Promise.reject(refreshError)
|
||||
} finally {
|
||||
isRefreshing = false
|
||||
}
|
||||
}
|
||||
} else if (error.response?.status !== 403) { // 403权限不足不提示
|
||||
|
||||
handleAdminTokenExpired()
|
||||
} else if (error.response?.status !== 403) {
|
||||
const errorMsg = (error.response?.data as any)?.message || error.message || '请求失败'
|
||||
showError(errorMsg)
|
||||
} else {
|
||||
@@ -102,10 +172,28 @@ export interface AdminLoginResponse {
|
||||
userInfo: any
|
||||
}
|
||||
|
||||
export interface LoginShopSelectionResponse {
|
||||
allowShoplessLogin: boolean
|
||||
message: string
|
||||
shops: Array<{
|
||||
id: number | string
|
||||
shopName: string
|
||||
}>
|
||||
}
|
||||
|
||||
export const adminAuthApi = {
|
||||
login: (data: AdminLoginRequest) => {
|
||||
return adminApi.post<AdminLoginResponse>('/auth/login', data)
|
||||
},
|
||||
getLoginShops: (account: string) => {
|
||||
return adminApi.get<LoginShopSelectionResponse>(`/auth/login-shops/${encodeURIComponent(account)}`)
|
||||
},
|
||||
logout: () => {
|
||||
return adminApi.post<boolean>('/auth/logout')
|
||||
},
|
||||
switchShop: (shopId?: string | number) => {
|
||||
return adminApi.post<AdminLoginResponse>('/auth/switch-shop', { shopId })
|
||||
},
|
||||
refreshToken: (refreshToken: string) => {
|
||||
return adminApi.post<{ accessToken: string; refreshToken: string }>('/auth/refresh', { refreshToken })
|
||||
}
|
||||
@@ -275,6 +363,7 @@ export interface Shop {
|
||||
description: string
|
||||
address: string
|
||||
businessHours: string
|
||||
status?: number
|
||||
coverImageFileId?: string
|
||||
coverImageUrls?: string[]
|
||||
imageFileIds?: string
|
||||
@@ -297,6 +386,7 @@ export interface CreateShopRequest {
|
||||
businessHours: string
|
||||
coverImageFileId?: string
|
||||
imageFileIds?: string
|
||||
status?: number
|
||||
}
|
||||
|
||||
export const adminShopApi = {
|
||||
@@ -312,6 +402,9 @@ export const adminShopApi = {
|
||||
updateShop: (id: number, data: CreateShopRequest) => {
|
||||
return adminApi.put<boolean>(`/shops/update/${id}`, data)
|
||||
},
|
||||
updateShopStatus: (id: number, status: number) => {
|
||||
return adminApi.put<boolean>(`/shops/status/${id}`, { status })
|
||||
},
|
||||
deleteShop: (id: number) => {
|
||||
return adminApi.delete<boolean>(`/shops/delete/${id}`)
|
||||
}
|
||||
@@ -321,6 +414,8 @@ export interface UserVO {
|
||||
id: number
|
||||
shopId?: number
|
||||
shopName?: string
|
||||
shopIds?: Array<number | string>
|
||||
shopNames?: string[]
|
||||
nickname: string
|
||||
account: string
|
||||
avatar: string
|
||||
@@ -429,7 +524,6 @@ export interface AdminUserVipOverrideRequest {
|
||||
remark?: string
|
||||
}
|
||||
|
||||
// 别名导出,兼容旧代码
|
||||
export const userApi = adminUserApi
|
||||
|
||||
export interface OrderVO {
|
||||
@@ -460,16 +554,18 @@ export const adminOrderApi = {
|
||||
}
|
||||
}
|
||||
|
||||
// 仪表盘相关接口
|
||||
export interface HotProductVO {
|
||||
productId: number
|
||||
productName: string
|
||||
orderCount: number
|
||||
id: number
|
||||
title: string
|
||||
price: number
|
||||
likeCount: number
|
||||
collectCount: number
|
||||
}
|
||||
|
||||
export interface RecentActivityVO {
|
||||
id: number
|
||||
type: string
|
||||
title?: string
|
||||
description: string
|
||||
time: string
|
||||
color?: string
|
||||
|
||||
@@ -8,20 +8,20 @@ export interface LoginRequest {
|
||||
account: string
|
||||
password: string
|
||||
rememberMe?: boolean
|
||||
shopId?: number
|
||||
shopId?: string | number
|
||||
}
|
||||
|
||||
export interface PhoneLoginRequest {
|
||||
phone: string
|
||||
verificationCode: string
|
||||
shopId?: number
|
||||
shopId?: string | number
|
||||
}
|
||||
|
||||
export interface RegisterRequest {
|
||||
account: string
|
||||
password: string
|
||||
nickname: string
|
||||
shopId?: number
|
||||
shopId?: string | number
|
||||
phone?: string
|
||||
verificationCode?: string
|
||||
}
|
||||
@@ -38,7 +38,11 @@ export interface UserInfo {
|
||||
nickname: string
|
||||
avatar?: string
|
||||
signature?: string
|
||||
type?: number
|
||||
shopId?: number | string
|
||||
shopName?: string
|
||||
shopIds?: Array<number | string>
|
||||
shopNames?: string[]
|
||||
createTime: string
|
||||
updateTime?: string
|
||||
}
|
||||
@@ -58,6 +62,10 @@ export interface ResetPasswordRequest {
|
||||
newPassword: string
|
||||
}
|
||||
|
||||
export interface SwitchShopRequest {
|
||||
shopId?: string | number
|
||||
}
|
||||
|
||||
export const authApi = {
|
||||
sendVerificationCode: (data: SendVerificationCodeRequest) => {
|
||||
return api.post('/user/send-verification-code', data)
|
||||
@@ -87,6 +95,10 @@ export const authApi = {
|
||||
return api.post('/user/logout')
|
||||
},
|
||||
|
||||
switchShop: (data: SwitchShopRequest) => {
|
||||
return api.post<LoginResponse>('/user/switch-shop', data)
|
||||
},
|
||||
|
||||
getUserInfo: () => {
|
||||
return api.get<UserInfo>('/user/info')
|
||||
},
|
||||
@@ -94,4 +106,4 @@ export const authApi = {
|
||||
resetPasswordByPhone: (data: ResetPasswordRequest) => {
|
||||
return api.post('/user/reset-password-by-phone', data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,12 +127,12 @@ export const couponApi = {
|
||||
},
|
||||
|
||||
// 获取用户优惠券列表
|
||||
listUserCoupons: (status?: number) => {
|
||||
return request({
|
||||
listUserCoupons: async (status?: number): Promise<UserCoupon[]> => {
|
||||
return await request({
|
||||
url: '/coupon/user/list',
|
||||
method: 'get',
|
||||
params: { status }
|
||||
})
|
||||
}) as UserCoupon[]
|
||||
},
|
||||
|
||||
// 使用优惠券
|
||||
@@ -145,11 +145,11 @@ export const couponApi = {
|
||||
},
|
||||
|
||||
// 获取作品可用的优惠券
|
||||
getAvailableCoupons: (productTags: string, productPrice: number, shopId?: number) => {
|
||||
return request({
|
||||
getAvailableCoupons: async (productTags: string, productPrice: number, shopId?: number): Promise<UserCoupon[]> => {
|
||||
return await request({
|
||||
url: '/coupon/available',
|
||||
method: 'get',
|
||||
params: { productTags, productPrice, shopId }
|
||||
})
|
||||
}) as UserCoupon[]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,13 @@ api.interceptors.response.use(
|
||||
url?.includes('/user/refresh-token') ||
|
||||
url?.includes('/user/send-verification-code') ||
|
||||
url?.includes('/user/phone-login') ||
|
||||
url?.includes('/product/get/') ||
|
||||
url?.includes('/product/list/') ||
|
||||
url?.includes('/shop/get/') ||
|
||||
url?.includes('/shop/list/public') ||
|
||||
url?.includes('/shop/list/simple') ||
|
||||
url?.includes('/tag/list/all') ||
|
||||
url?.includes('/file/get-signed-url/') ||
|
||||
url?.includes('/admin/auth/login') ||
|
||||
url?.includes('/admin/auth/refresh')
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ export const orderApi = {
|
||||
},
|
||||
|
||||
// 获取订单列表
|
||||
getOrderList: () => {
|
||||
return api.get('/order/list')
|
||||
getOrderList: async (): Promise<any[]> => {
|
||||
return await api.get<any[]>('/order/list') as unknown as any[]
|
||||
},
|
||||
|
||||
// 获取订单详情
|
||||
|
||||
@@ -13,6 +13,8 @@ export interface ProductVO {
|
||||
price: number
|
||||
estimatedTime: number
|
||||
approximateDuration?: string
|
||||
bookableArtists?: string
|
||||
availableCoupons?: string
|
||||
category: string
|
||||
tags?: string
|
||||
tagList?: string[]
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface ShopVO {
|
||||
description: string
|
||||
address: string
|
||||
businessHours: string
|
||||
status?: number
|
||||
imageFileIds: string
|
||||
imageUrls?: string[]
|
||||
createTime: string
|
||||
@@ -45,15 +46,19 @@ export interface UpdateShopRequest {
|
||||
}
|
||||
|
||||
export const shopApi = {
|
||||
getAllShops: () => {
|
||||
return api.get<ShopVO[]>('/shop/list/all')
|
||||
getAllShops: async (): Promise<ShopVO[]> => {
|
||||
return await api.get<ShopVO[]>('/shop/list/all') as unknown as ShopVO[]
|
||||
},
|
||||
|
||||
getShopsSimple: () => {
|
||||
return api.get<ShopSimpleVO[]>('/shop/list/simple')
|
||||
getPublicShops: async (): Promise<ShopVO[]> => {
|
||||
return await api.get<ShopVO[]>('/shop/list/public') as unknown as ShopVO[]
|
||||
},
|
||||
|
||||
getShopById: (id: number) => {
|
||||
return api.get<ShopVO>(`/shop/get/${id}`)
|
||||
getShopsSimple: async (): Promise<ShopSimpleVO[]> => {
|
||||
return await api.get<ShopSimpleVO[]>('/shop/list/simple') as unknown as ShopSimpleVO[]
|
||||
},
|
||||
|
||||
getShopById: async (id: number): Promise<ShopVO> => {
|
||||
return await api.get<ShopVO>(`/shop/get/${id}`) as unknown as ShopVO
|
||||
}
|
||||
}
|
||||
|
||||
+34
-12
@@ -5,6 +5,8 @@ export interface UserVO extends UserInfo {
|
||||
id: number
|
||||
shopId?: number
|
||||
shopName?: string
|
||||
shopIds?: Array<number | string>
|
||||
shopNames?: string[]
|
||||
nickname: string
|
||||
account: string
|
||||
avatar: string
|
||||
@@ -39,6 +41,7 @@ export interface CreateUserRequest {
|
||||
password: string
|
||||
type: number
|
||||
shopId?: number
|
||||
shopIds?: Array<number | string>
|
||||
}
|
||||
|
||||
export interface UpdateUserRequest {
|
||||
@@ -47,6 +50,7 @@ export interface UpdateUserRequest {
|
||||
phone?: string
|
||||
type?: number
|
||||
shopId?: number
|
||||
shopIds?: Array<number | string>
|
||||
}
|
||||
|
||||
export interface UpdatePasswordRequest {
|
||||
@@ -70,6 +74,15 @@ export interface LoginAccountCheckResponse {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface LoginShopSelectionResponse {
|
||||
allowShoplessLogin: boolean
|
||||
message: string
|
||||
shops: Array<{
|
||||
id: number | string
|
||||
shopName: string
|
||||
}>
|
||||
}
|
||||
|
||||
export interface UpdatePhoneRequest {
|
||||
oldPhone: string
|
||||
newPhone: string
|
||||
@@ -77,8 +90,8 @@ export interface UpdatePhoneRequest {
|
||||
}
|
||||
|
||||
export const userApi = {
|
||||
getUserInfo: () => {
|
||||
return api.get<UserVO>('/user/info')
|
||||
getUserInfo: async (): Promise<UserVO> => {
|
||||
return await api.get<UserVO>('/user/info') as unknown as UserVO
|
||||
},
|
||||
updateUserInfo: (data: UpdateUserInfoRequest) => {
|
||||
return api.put('/user/update', data)
|
||||
@@ -92,24 +105,33 @@ export const userApi = {
|
||||
updatePhone: (data: UpdatePhoneRequest) => {
|
||||
return api.put('/user/phone', data)
|
||||
},
|
||||
getUserByAccount: (account: string) => {
|
||||
return api.get<UserVO>(`/user/get/account/${account}`)
|
||||
getUserByAccount: async (account: string): Promise<UserVO> => {
|
||||
return await api.get<UserVO>(`/user/get/account/${account}`) as unknown as UserVO
|
||||
},
|
||||
checkAccountAvailability: (account: string) => {
|
||||
return api.get<AvailabilityCheckResponse>(`/user/check/account/${encodeURIComponent(account)}`)
|
||||
checkAccountAvailability: async (account: string): Promise<AvailabilityCheckResponse> => {
|
||||
return await api.get<AvailabilityCheckResponse>(`/user/check/account/${encodeURIComponent(account)}`) as unknown as AvailabilityCheckResponse
|
||||
},
|
||||
checkLoginAccountAvailability: (account: string) => {
|
||||
return api.get<LoginAccountCheckResponse>(`/user/check/login-account/${encodeURIComponent(account)}`)
|
||||
checkLoginAccountAvailability: async (account: string): Promise<LoginAccountCheckResponse> => {
|
||||
return await api.get<LoginAccountCheckResponse>(`/user/check/login-account/${encodeURIComponent(account)}`) as unknown as LoginAccountCheckResponse
|
||||
},
|
||||
checkPhoneAvailability: (phone: string) => {
|
||||
return api.get<AvailabilityCheckResponse>(`/user/check/phone/${encodeURIComponent(phone)}`)
|
||||
getLoginShopsByAccount: async (account: string): Promise<LoginShopSelectionResponse> => {
|
||||
return await api.get<LoginShopSelectionResponse>(`/user/check/login-shops/account/${encodeURIComponent(account)}`) as unknown as LoginShopSelectionResponse
|
||||
},
|
||||
listUsersByType: (type: number) => {
|
||||
return api.get<UserVO[]>(`/user/list/type/${type}`)
|
||||
getLoginShopsByPhone: async (phone: string): Promise<LoginShopSelectionResponse> => {
|
||||
return await api.get<LoginShopSelectionResponse>(`/user/check/login-shops/phone/${encodeURIComponent(phone)}`) as unknown as LoginShopSelectionResponse
|
||||
},
|
||||
checkPhoneAvailability: async (phone: string): Promise<AvailabilityCheckResponse> => {
|
||||
return await api.get<AvailabilityCheckResponse>(`/user/check/phone/${encodeURIComponent(phone)}`) as unknown as AvailabilityCheckResponse
|
||||
},
|
||||
listUsersByType: async (type: number): Promise<UserVO[]> => {
|
||||
return await api.get<UserVO[]>(`/user/list/type/${type}`) as unknown as UserVO[]
|
||||
},
|
||||
sendVerificationCode: (data: { phone: string }) => {
|
||||
return api.post('/user/send-verification-code', data)
|
||||
},
|
||||
switchShop: (shopId?: string | number) => {
|
||||
return api.post('/user/switch-shop', { shopId })
|
||||
},
|
||||
deactivateAccount: () => {
|
||||
return api.delete('/user/deactivate')
|
||||
}
|
||||
|
||||
@@ -27,19 +27,19 @@ export interface WishlistItem {
|
||||
}
|
||||
|
||||
export const wishlistApi = {
|
||||
addToWishlist: (productId: number) => {
|
||||
return api.post('/wishlist/add', { productId })
|
||||
addToWishlist: async (productId: number): Promise<boolean> => {
|
||||
return await api.post<boolean>('/wishlist/add', { productId }) as unknown as boolean
|
||||
},
|
||||
|
||||
removeFromWishlist: (productId: number) => {
|
||||
return api.post('/wishlist/remove', { productId })
|
||||
removeFromWishlist: async (productId: number): Promise<boolean> => {
|
||||
return await api.post<boolean>('/wishlist/remove', { productId }) as unknown as boolean
|
||||
},
|
||||
|
||||
checkWishlist: (productId: number) => {
|
||||
return api.get<boolean>(`/wishlist/check?productId=${productId}`)
|
||||
checkWishlist: async (productId: number): Promise<boolean> => {
|
||||
return await api.get<boolean>(`/wishlist/check?productId=${productId}`) as unknown as boolean
|
||||
},
|
||||
|
||||
getWishlist: () => {
|
||||
return api.get<WishlistItem[]>('/wishlist/list')
|
||||
getWishlist: async (): Promise<WishlistItem[]> => {
|
||||
return await api.get<WishlistItem[]>('/wishlist/list') as unknown as WishlistItem[]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user