Commit 854b0328 authored by xioln's avatar xioln

免登录处理

parent b6edece5
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
import { Notify } from 'vant' import { Notify } from 'vant'
import store from '../store' import store from '../store'
import { getToken } from './auth' import { getToken } from './auth'
import Cookies from 'js-cookie'
import RSA from './rsa.js'
// import { VUE_APP_BASE_API } from '../../public/apiUrl' // import { VUE_APP_BASE_API } from '../../public/apiUrl'
// axios.defaults.baseURL = process.env.VUE_APP_BASE_API // axios.defaults.baseURL = process.env.VUE_APP_BASE_API
...@@ -29,9 +31,19 @@ axios.interceptors.request.use( ...@@ -29,9 +31,19 @@ axios.interceptors.request.use(
delete config.data.userAction delete config.data.userAction
} }
if (store.getters.token) { if (store.getters.token) {
config.headers.authorization = getToken() const queryUserAccount = queryURLParams(window.location.href).userAccount || sessionStorage.getItem('Login-free-userAccount') || ''
config.headers['Dex-Token'] = getToken() // eslint-disable-next-line no-prototype-builtins
config.headers['Dex-Auth-Type'] = 'Token' if (queryUserAccount) {
const rsaUserAccount = RSA.rsaPublicData(queryUserAccount)
sessionStorage.setItem('Login-free-userAccount', queryUserAccount)
config.headers.authorization = rsaUserAccount
config.headers['Dex-Ukey-Token'] = rsaUserAccount
config.headers['Dex-Auth-Type'] = 'Ukey'
} else {
config.headers.authorization = getToken()
config.headers['Dex-Token'] = getToken()
config.headers['Dex-Auth-Type'] = 'Token'
}
if (!getToken()) { if (!getToken()) {
delete config.headers.authorization delete config.headers.authorization
delete config.headers['Dex-Token'] delete config.headers['Dex-Token']
...@@ -168,6 +180,43 @@ function del(url, params) { ...@@ -168,6 +180,43 @@ function del(url, params) {
}) })
} }
function queryURLParams(url, paramName) {
// 正则表达式模式,用于匹配URL中的参数部分。正则表达式的含义是匹配不包含 ?、&、= 的字符作为参数名,之后是等号和不包含 & 的字符作为参数值
const pattern = /([^?&=]+)=([^&]+)/g
const params = {}
// match用于存储正则匹配的结果
let match
// while 循环和正则表达式 exec 方法来迭代匹配URL中的参数
while ((match = pattern.exec(url)) !== null) {
// 在字符串url中循环匹配pattern,并对每个匹配项进行解码操作,将解码后的键和值分别存储在key和value变量中
const key = decodeURIComponent(match[1])
const value = decodeURIComponent(match[2])
if (params[key]) {
if (Array.isArray(params[key])) {
params[key].push(value)
} else {
params[key] = [params[key], value]
}
} else {
// 参数名在 params 对象中不存在,将该参数名和对应的值添加到 params 对象中
params[key] = value
}
}
if (!paramName) {
// 没有传入参数名称, 返回含有所有参数的对象params
return params
} else {
if (params[paramName]) {
return params[paramName]
} else {
return ''
}
}
}
export { export {
get, post, put, del, downloadFile, downloadFilePost get, post, put, del, downloadFile, downloadFilePost
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment