refactor: simplify noNeedToken judge
This commit is contained in:
parent
40483e09e6
commit
2b2a324a62
@ -3,12 +3,6 @@ import { isNullOrUndef } from '@/utils/is'
|
|||||||
import { removeToken } from '@/utils/token'
|
import { removeToken } from '@/utils/token'
|
||||||
import { toLogin } from '@/utils/auth'
|
import { toLogin } from '@/utils/auth'
|
||||||
|
|
||||||
const WITHOUT_TOKEN_API = [{ url: '/auth/login', method: 'POST' }]
|
|
||||||
|
|
||||||
export function isWithoutToken({ url, method = '' }) {
|
|
||||||
return WITHOUT_TOKEN_API.some((item) => item.url === url && item.method === method.toUpperCase())
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addBaseParams(params) {
|
export function addBaseParams(params) {
|
||||||
if (!params.userId) {
|
if (!params.userId) {
|
||||||
params.userId = useUserStore().userId
|
params.userId = useUserStore().userId
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { getToken } from '@/utils/token'
|
import { getToken } from '@/utils/token'
|
||||||
import { toLogin } from '@/utils/auth'
|
import { toLogin } from '@/utils/auth'
|
||||||
import { isWithoutToken, resolveResError } from './helpers'
|
import { resolveResError } from './helpers'
|
||||||
|
|
||||||
export function reqResolve(config) {
|
export function reqResolve(config) {
|
||||||
// 处理不需要token的请求
|
// 处理不需要token的请求
|
||||||
if (isWithoutToken(config)) {
|
if (config.noNeedToken) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import request from '@/utils/http'
|
import request from '@/utils/http'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
login: (data) => request.post('/auth/login', data),
|
login: (data) => request.post('/auth/login', data, { noNeedToken: true }),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user