getHeaders.js 1.2 KB
Newer Older
1
import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
2
import {
3
  getSassApiHeader,
4 5
  getSysCode,
} from '@/webPublic/one_stop_public/2023yunshangguizhou/utils';
钟是志's avatar
钟是志 committed
6 7 8
import { getIsBei_Dian } from '@/webPublic/zyd_public/utils/utils';
import { getUrlInfo } from '@/webPublic/one_stop_public/DetailForAudit/utils';

9 10 11 12 13 14 15 16 17
export function getVisitorToken() {
	let token = getToken();
	const visitor_client =
		sessionStorage.getItem('visitor_client') === 'true' || !!getUrlInfo().visitor;
	if (visitor_client && (token === 'null' || !token)) {
		// 访客token 欢哥喊加的
		token = '704d693b-cc68-49a7-8888-4acc73b5ca73';
	}
	return token;
18 19
}

20 21 22
export function getHeaders(url = '', headersApi = undefined) {
	let token = getVisitorToken();
	const res = {
23
		headers: getSassApiHeader(),
24 25 26 27 28 29 30 31 32 33 34
	};
	if (process.env.NODE_ENV === 'development' && getIsBei_Dian()) {
		res.headers.env = 'test';
	}
	if (url && typeof url === 'string' && url.indexOf('oauthPub=true') > -1) {
		// 公共接口不需要token
		return res;
	}
	if (!token || token === 'null') {
		return res;
	} else {
钟是志's avatar
钟是志 committed
35
	//	res.headers.Authorization = `bearer ${token}`; // 这个必须要带上
36
	}
37

38
	return res;
钟是志's avatar
钟是志 committed
39
}