hookehuyr

写法优化

......@@ -2,13 +2,12 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-28 10:17:40
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-22 09:22:56
* @LastEditTime: 2022-06-29 22:32:15
* @FilePath: /tswj/src/utils/axios.js
* @Description:
*/
import axios from 'axios';
import router from '@/router';
import _ from 'lodash'
import qs from 'Qs'
// import { parseQueryString } from '@/utils/tools'
......@@ -25,20 +24,13 @@ axios.interceptors.request.use(
// GET请求默认打上时间戳,避免从缓存中拿数据。
const timestamp = config.method === 'get' ? (new Date()).valueOf() : '';
// 上传相关接口需要屏蔽掉封装, 不能序列化数据会报错。
if (
config.method === 'post' &&
(config.url.indexOf('a=upload') === -1 &&
config.url.indexOf('upload.qiniup.com') === -1
)
)
{
const excludeUrl = ['a=upload', 'upload.qiniup.com'];
if (config.method === 'post' && !excludeUrl.includes(config.url)) {
// POST PHP需要修改数据格式
config.data = qs.stringify(config.data)
}
// 绑定默认请求头
config.params = _.merge(config.params, {
timestamp,
})
config.params = { ...config.params, timestamp }
return config;
},
error => {
......@@ -55,7 +47,7 @@ axios.interceptors.response.use(
response.data.show = true;
// 判断微信授权状态,进入页面时未授权需要授权跳转
// C/B 授权拼接头特殊标识,openid_x
let prefixAPI = router && router.currentRoute.value.href?.indexOf('business') > 0 ? 'b' : 'c';
let prefixAPI = router?.currentRoute.value.href?.indexOf('business') > 0 ? 'b' : 'c';
if (response.data.code === 401) {
// 特殊标识-带此标识报错不显示
response.data.show = false;
......
/*
* @Date: 2022-04-18 15:59:42
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-15 18:29:40
* @LastEditTime: 2022-06-29 22:35:51
* @FilePath: /tswj/src/utils/tools.js
* @Description: 文件描述
*/
import moment from 'moment';
import { ref } from 'vue'
// 格式化时间
const formatDate = (date) => {
......