hookehuyr

🎈 perf: axios请求头调整

...@@ -2,26 +2,33 @@ import axios from 'axios'; ...@@ -2,26 +2,33 @@ import axios from 'axios';
2 import router from '@/router'; 2 import router from '@/router';
3 import _ from 'lodash' 3 import _ from 'lodash'
4 import qs from 'Qs' 4 import qs from 'Qs'
5 -import { parseQueryString } from '@/utils/tools' 5 +// import { parseQueryString } from '@/utils/tools'
6 +
7 +axios.defaults.params = {
8 + f: 'voice',
9 +};
6 10
7 /** 11 /**
8 * @description 请求拦截器 12 * @description 请求拦截器
9 */ 13 */
10 axios.interceptors.request.use( 14 axios.interceptors.request.use(
11 config => { 15 config => {
12 - const url_params = parseQueryString(location.href); 16 + // const url_params = parseQueryString(location.href);
13 // GET请求默认打上时间戳,避免从缓存中拿数据。 17 // GET请求默认打上时间戳,避免从缓存中拿数据。
14 const timestamp = config.method === 'get' ? (new Date()).valueOf() : ''; 18 const timestamp = config.method === 'get' ? (new Date()).valueOf() : '';
15 - // 发送请求前 19 + // 上传相关接口需要屏蔽掉封装, 不能序列化数据会报错。
16 - if (config.method === 'post' && 20 + if (
17 - (config.url.indexOf('a=upload') === -1 && config.url.indexOf('upload.qiniup.com') === -1)) // 上传相关接口需要屏蔽掉 21 + config.method === 'post' &&
22 + (config.url.indexOf('a=upload') === -1 &&
23 + config.url.indexOf('upload.qiniup.com') === -1
24 + )
25 + )
18 { 26 {
19 // POST PHP需要修改数据格式 27 // POST PHP需要修改数据格式
20 config.data = qs.stringify(config.data) 28 config.data = qs.stringify(config.data)
21 } 29 }
22 // 绑定默认请求头 30 // 绑定默认请求头
23 config.params = _.merge(config.params, { 31 config.params = _.merge(config.params, {
24 - f: 'voice',
25 timestamp, 32 timestamp,
26 }) 33 })
27 return config; 34 return config;
...@@ -36,9 +43,9 @@ axios.interceptors.request.use( ...@@ -36,9 +43,9 @@ axios.interceptors.request.use(
36 */ 43 */
37 axios.interceptors.response.use( 44 axios.interceptors.response.use(
38 response => { 45 response => {
39 - // 默认显示 46 + // 默认显示错误提示
40 response.data.show = true; 47 response.data.show = true;
41 - // C/B授权拼接头特殊标识,openid_x 48 + // C/B 授权拼接头特殊标识,openid_x
42 let userType = router && router.currentRoute.value.href?.indexOf('business') > 0 ? 'b' : 'c'; 49 let userType = router && router.currentRoute.value.href?.indexOf('business') > 0 ? 'b' : 'c';
43 if (response.data.code === 401) { 50 if (response.data.code === 401) {
44 // 特殊标识-带此标识报错不显示 51 // 特殊标识-带此标识报错不显示
......