yolo
This commit is contained in:
@@ -4,33 +4,37 @@
|
||||
*/
|
||||
import axios from 'axios'
|
||||
import { getToken, getUser } from '@/utils/storage'
|
||||
import { useRouter } from 'vue-router';
|
||||
import router from '@/router'
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { usePythonBridge, } from '@/utils/pythonBridge'
|
||||
|
||||
const { stopScript } = usePythonBridge();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
// 请求地址前缀
|
||||
let baseURL = ''
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
// 生产环境
|
||||
baseURL = "http://api.tkpage.vvtiktok.cn"
|
||||
// baseURL = "http://120.26.251.180:8085/"
|
||||
// baseURL = "https://api.tkpage.yolozs.com"
|
||||
baseURL = "http://192.168.1.174:8101"
|
||||
// baseURL = "http://192.168.0.103:8085/"
|
||||
} else {
|
||||
// 测试环境
|
||||
// baseURL = "http://120.26.251.180:8085/"
|
||||
// 开发环境
|
||||
baseURL = "http://api.tkpage.vvtiktok.cn"
|
||||
baseURL = "https://api.tkpage.yolozs.com"
|
||||
// baseURL = "http://api.tkpage.vvtiktok.cn"
|
||||
}
|
||||
|
||||
// 请求拦截器
|
||||
axios.interceptors.request.use((config) => {
|
||||
// if (getToken()) {
|
||||
// config.headers['token'] = getToken();
|
||||
// }
|
||||
console.log("config", config)
|
||||
const url = sliceUrl(config.url)
|
||||
console.log("url", url)
|
||||
if (!(config.url == 'doLogin' || config.url == 'get-id-by-name')) {
|
||||
config.headers['vvtoken'] = getToken();
|
||||
}
|
||||
|
||||
// 请求超时时间 - 毫秒
|
||||
config.timeout = 60000
|
||||
@@ -44,7 +48,15 @@ axios.interceptors.request.use((config) => {
|
||||
|
||||
// 响应拦截器
|
||||
axios.interceptors.response.use((response) => {
|
||||
return response
|
||||
console.log("response", response.data)
|
||||
if (response.data.code == 0) {
|
||||
console.log("response", response.data.data)
|
||||
return response.data.data
|
||||
} else {
|
||||
router.push('/')
|
||||
ElMessage.error(response.data.code + '' + response.data.message);
|
||||
}
|
||||
|
||||
}, (error) => {
|
||||
// 可添加请求失败后的处理逻辑
|
||||
return Promise.reject(error)
|
||||
@@ -60,10 +72,9 @@ export function getAxios({ url, params }) {
|
||||
params
|
||||
// 请求成功,将返回的数据传递给resolve函数
|
||||
}).then(res => {
|
||||
resolve(res.data)
|
||||
resolve(res)
|
||||
// 请求失败,将错误信息传递给reject函数
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
@@ -71,13 +82,6 @@ export function getAxios({ url, params }) {
|
||||
|
||||
// axios的post请求
|
||||
export function postAxios({ url, data }) {
|
||||
if (url != 'api/account/login') {
|
||||
|
||||
throttledCheekalive();
|
||||
|
||||
}
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(
|
||||
url,
|
||||
@@ -88,21 +92,9 @@ export function postAxios({ url, data }) {
|
||||
}
|
||||
}
|
||||
).then(res => {
|
||||
resolve(res.data)
|
||||
resolve(res)
|
||||
}).catch(err => {
|
||||
if (err.message == "Network Error") {
|
||||
// alert("网络错误,请检查网络连接")
|
||||
// ElMessage.error('网络连接错误');
|
||||
reject('网络连接错误')
|
||||
|
||||
} else {
|
||||
console.log(err)
|
||||
ElMessage.error('报错啦' + err.response.status);
|
||||
// reject(err)
|
||||
|
||||
|
||||
}
|
||||
// console.log(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -175,6 +167,18 @@ function throttle(func, limit) {
|
||||
}
|
||||
}
|
||||
|
||||
const throttledCheekalive = throttle(cheekalive, 5000);
|
||||
function sliceUrl(url) {
|
||||
const lastSlash = url.lastIndexOf('/');
|
||||
const questionMark = url.indexOf('?');
|
||||
if (questionMark == -1) {
|
||||
const result = url.slice(lastSlash + 1, url.length);
|
||||
return result;
|
||||
} else {
|
||||
const result = url.slice(lastSlash + 1, questionMark);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default axios
|
||||
Reference in New Issue
Block a user