持续集成分支

This commit is contained in:
aixianling
2024-10-31 14:34:57 +08:00
parent 6a833be062
commit 8c56cf808b
2165 changed files with 4116 additions and 8716 deletions

38
library/common/http.js Normal file
View File

@@ -0,0 +1,38 @@
import axios from 'axios'
const instance = axios.create({
timeout: 600000,
withCredentials: true,
})
const getToken = () => {
let vuex = uni.getStorageSync("vuex")
return !!vuex ? JSON.parse(vuex).user.token : null
}
const source = axios.CancelToken.source();
let throttleMap = {}
instance.interceptors.request.use(config => {
if (config.throttle) {// 节流处理
let timer = throttleMap[config.url]
if (!!timer) {
config.cancelToken = source.token
source.cancel("节流控制,取消请求:" + config.url)
}
throttleMap[config.url] = setTimeout(() => {
throttleMap[config.url] = null
}, config.throttle)
}
if (config.withoutToken) {
return config
} else if (getToken()) {
config.headers["Authorization"] = getToken()
} else {
config.cancelToken = source.token
source.cancel("用户未验证,取消请求:" + config.url)
}
return config
}, err => {
console.error(err)
return Promise.reject(err)
})
export default instance