add tenant to all request header
This commit is contained in:
@ -27,6 +27,7 @@
|
||||
"jsencrypt": "3.3.1",
|
||||
"nprogress": "0.2.0",
|
||||
"pinia": "2.0.22",
|
||||
"pinia-plugin-persistedstate": "^3.1.0",
|
||||
"vue": "3.2.45",
|
||||
"vue-cropper": "1.0.3",
|
||||
"vue-router": "4.1.4"
|
||||
|
@ -1,7 +1,7 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 登录方法
|
||||
export function login(username, password, code, uuid, tenant) {
|
||||
export function login(username, password, code, uuid) {
|
||||
const data = {
|
||||
username,
|
||||
password,
|
||||
@ -12,7 +12,6 @@ export function login(username, password, code, uuid, tenant) {
|
||||
url: '/login',
|
||||
headers: {
|
||||
isToken: false,
|
||||
tenant
|
||||
},
|
||||
method: 'post',
|
||||
data: data
|
||||
|
@ -1,3 +1,5 @@
|
||||
const store = createPinia()
|
||||
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||
|
||||
const store = createPinia()
|
||||
store.use(piniaPluginPersistedstate)
|
||||
export default store
|
@ -10,6 +10,7 @@ const useUserStore = defineStore(
|
||||
name: '',
|
||||
avatar: '',
|
||||
roles: [],
|
||||
tenant: '',
|
||||
permissions: []
|
||||
}),
|
||||
actions: {
|
||||
@ -21,7 +22,8 @@ const useUserStore = defineStore(
|
||||
const code = userInfo.code
|
||||
const uuid = userInfo.uuid
|
||||
return new Promise((resolve, reject) => {
|
||||
login(username, password, code, uuid, tenant).then(res => {
|
||||
this.tenant = tenant
|
||||
login(username, password, code, uuid).then(res => {
|
||||
setToken(res.token)
|
||||
this.token = res.token
|
||||
resolve()
|
||||
@ -65,7 +67,11 @@ const useUserStore = defineStore(
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
persist: [
|
||||
{paths: ['tenant'],storage:localStorage}
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
export default useUserStore
|
||||
|
@ -29,6 +29,9 @@ service.interceptors.request.use(config => {
|
||||
if (getToken() && !isToken) {
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||
}
|
||||
if(useUserStore().tenant){
|
||||
config.headers['tenant'] = useUserStore().tenant
|
||||
}
|
||||
// get请求映射params参数
|
||||
if (config.method === 'get' && config.params) {
|
||||
let url = config.url + '?' + tansParams(config.params);
|
||||
|
Reference in New Issue
Block a user