Browse Source

chore: 认证方案:使用token进行请求

master
wangxiang 2 years ago
parent
commit
4d85b05dc1
  1. 17
      cloud/bigscreen-design/src/axios.js
  2. 2
      cloud/bigscreen-design/src/option/config.js
  3. 7
      cloud/bigscreen-design/src/router.js

17
cloud/bigscreen-design/src/axios.js

@ -1,21 +1,16 @@ @@ -1,21 +1,16 @@
// import { Loading } from 'element-ui';
import { checkUrl } from '@/utils/utils'
import axios from 'axios';
import axios from 'axios'
import { parseUrlParams } from './router'
window.$glob = {
url: '',
params: {},
params: parseUrlParams(),
query: {},
header: {}
};
function getGlobParams () {
var query = window.location.search.substring(1);
query = query.split("&");
query.forEach(ele => {
var pair = ele.split("=");
window.$glob.params[pair[0]] = pair[1]
})
}
getGlobParams();
// 认证方案:使用token进行请求
window.$glob.params.token &&
(window.$glob.header['Authorization'] = `Bearer ${window.$glob.params.token}`)
axios.defaults.timeout = 10000;
//返回其他状态吗
axios.defaults.validateStatus = function (status) {

2
cloud/bigscreen-design/src/option/config.js

@ -4,7 +4,7 @@ export const config = { @@ -4,7 +4,7 @@ export const config = {
width: 1920,
height: 1080,
query: "function(){\n return window.$glob.params || {}\n}",
header: "function(){\n return window.$glob.params || {}\n}",
header: "function(){\n return window.$glob.header || {}\n}",
screen: 'x',
mark: {
show: false,

7
cloud/bigscreen-design/src/router.js

@ -50,13 +50,6 @@ const vueRouter = createRouter({ @@ -50,13 +50,6 @@ const vueRouter = createRouter({
}]
})
vueRouter.beforeEach((to, from, next) => {
// 获取当前路由的查询参数
const queryParams = parseUrlParams()
queryParams.token && (window.$glob.header['Authorization'] = `Bearer ${queryParams.token}`)
next()
})
/** 解析路由hash模式下url参数 */
const hashUrlParamsRegex = /(?:\?|&)([^=&]+)(?:=([^&]*))?/g
export function parseUrlParams() {

Loading…
Cancel
Save