功能:完善 YumiNail 全栈修复与打包
This commit is contained in:
@@ -6,6 +6,7 @@ import { message } from 'ant-design-vue'
|
||||
import { API_BASE_URL } from '../config/api'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { clearAdminSessionStorage } from '@/utils/admin-session'
|
||||
import { attachRequestSignature } from '@/utils/request-signature'
|
||||
|
||||
// 防重复提示标志
|
||||
let lastErrorTime = 0
|
||||
@@ -47,6 +48,29 @@ const showError = (msg: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const isAuthFreePath = (url?: string) => {
|
||||
return [
|
||||
'/user/login',
|
||||
'/user/register',
|
||||
'/user/check/',
|
||||
'/user/refresh-token',
|
||||
'/user/send-verification-code',
|
||||
'/user/phone-login',
|
||||
'/user/wechat-mini/',
|
||||
'/user/reset-password-by-phone',
|
||||
'/product/get/',
|
||||
'/product/list/',
|
||||
'/shop/get/',
|
||||
'/shop/list/public',
|
||||
'/shop/list/simple',
|
||||
'/tag/list/all',
|
||||
'/file/get-signed-url/',
|
||||
'/admin/auth/login',
|
||||
'/admin/auth/login-shops/',
|
||||
'/admin/auth/refresh'
|
||||
].some(path => String(url || '').includes(path))
|
||||
}
|
||||
|
||||
const handleTokenExpired = (isAdmin = false) => {
|
||||
// 清理token和用户信息
|
||||
if (isAdmin) {
|
||||
@@ -76,7 +100,7 @@ const handleTokenExpired = (isAdmin = false) => {
|
||||
}
|
||||
|
||||
api.interceptors.request.use(
|
||||
config => {
|
||||
async config => {
|
||||
let token = localStorage.getItem('accessToken')
|
||||
if (!token) {
|
||||
token = sessionStorage.getItem('accessToken')
|
||||
@@ -93,7 +117,9 @@ api.interceptors.request.use(
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
return attachRequestSignature(config, token, {
|
||||
authFree: isAuthFreePath(config.url)
|
||||
})
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
|
||||
Reference in New Issue
Block a user