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

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

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

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

@ -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参数 */ /** 解析路由hash模式下url参数 */
const hashUrlParamsRegex = /(?:\?|&)([^=&]+)(?:=([^&]*))?/g const hashUrlParamsRegex = /(?:\?|&)([^=&]+)(?:=([^&]*))?/g
export function parseUrlParams() { export function parseUrlParams() {

Loading…
Cancel
Save