优化代码
This commit is contained in:
@@ -7,49 +7,33 @@ import { getToken, getUser } from '@/utils/storage'
|
||||
import router from '@/router'
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { usePythonBridge, } from '@/utils/pythonBridge'
|
||||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia'
|
||||
import { tokenStore,UserStore } from '@/stores/notice'
|
||||
|
||||
|
||||
|
||||
|
||||
const { stopScript } = usePythonBridge();
|
||||
import { tokenStore, UserStore } from '@/stores/notice'
|
||||
|
||||
|
||||
// 请求地址前缀
|
||||
let baseURL = ''
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
// 生产环境
|
||||
// baseURL = "https://api.tkpage.yolozs.com"
|
||||
baseURL = "http://47.79.98.113:8101"
|
||||
// baseURL = "http://192.168.0.103:8085/"
|
||||
// baseURL = "http://192.168.1.174:8101"
|
||||
baseURL = "http://192.168.1.174:8086/"
|
||||
} else {
|
||||
// 测试环境
|
||||
// baseURL = "http://120.26.251.180:8085/"
|
||||
// 开发环境
|
||||
// baseURL = "https://api.tkpage.yolozs.com"
|
||||
baseURL = "http://47.79.98.113:8101"
|
||||
// baseURL = "http://192.168.1.174:8101"
|
||||
// baseURL = "http://api.tkpage.vvtiktok.cn"
|
||||
baseURL = "http://192.168.1.174:8086/"
|
||||
}
|
||||
|
||||
// 请求拦截器
|
||||
axios.interceptors.request.use((config) => {
|
||||
const tokenCache = tokenStore()
|
||||
console.log("config", config)
|
||||
const url = sliceUrl(config.url)
|
||||
console.log("url", url)
|
||||
// 请求超时时间 - 毫秒
|
||||
config.timeout = 60000
|
||||
config.baseURL = baseURL
|
||||
// 自定义Content-type
|
||||
config.headers['Content-type'] = 'application/json'
|
||||
if (!(config.url == 'bigbrother-doLogin' || config.url == 'get-id-by-name')) {
|
||||
config.headers['vvtoken'] = tokenCache.token;
|
||||
}
|
||||
// if (!(config.url == '' || config.url == '')) {
|
||||
// config.headers['vvtoken'] = tokenCache.token;
|
||||
// }
|
||||
|
||||
return config;
|
||||
}, (error) => {
|
||||
@@ -59,17 +43,16 @@ axios.interceptors.request.use((config) => {
|
||||
// 响应拦截器
|
||||
axios.interceptors.response.use((response) => {
|
||||
console.log("response", response.data)
|
||||
if (response.data.code == 0) {
|
||||
console.log("response", response.data.data)
|
||||
if (response.data.code == 200) {
|
||||
return response.data.data
|
||||
} else if (response.data.code == 40400) {
|
||||
router.push('/')
|
||||
ElMessage.error(response.data.code + '' + response.data.message);
|
||||
}else{
|
||||
} else {
|
||||
ElMessage.error(response.data.code + '' + response.data.message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}, (error) => {
|
||||
// 可添加请求失败后的处理逻辑
|
||||
@@ -161,7 +144,6 @@ function cheekalive() {
|
||||
if (res.data) {
|
||||
|
||||
} else {
|
||||
stopScript();
|
||||
alert("账号在其他地方登录!")
|
||||
window.location.href = '/';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user