From 05cad5735833bcbc55f0b06cd65351cdc0d56798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=A1=E5=A4=8D=E4=B9=A0?= <2353956224@qq.com> Date: Wed, 16 Apr 2025 15:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E7=82=B9=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/axios.js | 75 ++++++++++++++++++----------------- src/utils/pythonBridge.js | 1 + src/views/hosts/hostsList.vue | 3 +- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/utils/axios.js b/src/utils/axios.js index af34614..56b46cd 100644 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -14,7 +14,7 @@ let baseURL = '' if (process.env.NODE_ENV === 'development') { // 生产环境 baseURL = "http://120.26.251.180:8085/" - // baseURL = "http://192.168.0.114:8085/" + // baseURL = "http://192.168.0.115:8085/" } else { // 开发环境 baseURL = "http://120.26.251.180:8085/" @@ -38,11 +38,6 @@ axios.interceptors.request.use((config) => { // 响应拦截器 axios.interceptors.response.use((response) => { - /** - * 可添加请求响应的处理逻辑, 例如接口自定义的response.data.code不是200代表失败。 - * 错误的话 return Promise.reject(response) - * 正确的话 return response - */ return response }, (error) => { // 可添加请求失败后的处理逻辑 @@ -52,8 +47,6 @@ axios.interceptors.response.use((response) => { // axios的get请求 -// 导出一个函数,用于发送GET请求 -// 返回一个Promise对象 export function getAxios({ url, params }) { // 使用axios发送GET请求 return new Promise((resolve, reject) => { @@ -74,35 +67,7 @@ export function getAxios({ url, params }) { export function postAxios({ url, data }) { if (url != 'api/account/login') { - axios.post('api/account/cheekalive', { - userId: getUser().userId, - currcode: getToken(), - }, - { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - } - } - ).then(res => { - if (res) { - - } else { - alert("账号在其他地方登录!") - router.push('/login') - } - - - }).catch(err => { - if (err.message == "Network Error") { - // alert("网络错误,请检查网络连接") - ElMessage.error('网络连接错误'); - } else { - ElMessage.error(err.message); - } - // console.log(err) - // reject(err) - - }) + throttledCheekalive(); } @@ -165,7 +130,43 @@ export const downFile = async (urlstr, data) => { } +//请求前验证 +function cheekalive() { + axios.post('api/account/cheekalive', { + userId: getUser().userId, + currcode: getToken(), + }, + { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + ).then(res => { + console.log(res.data) + if (res.data) { + + } else { + alert("账号在其他地方登录!") + window.location.href = '/'; + } + }) +} +//节流函数 +function throttle(func, limit) { + let inThrottle; + return function () { + const args = arguments; + const context = this; + if (!inThrottle) { + func.apply(context, args); + inThrottle = true; + setTimeout(() => inThrottle = false, limit); + } + } +} + +const throttledCheekalive = throttle(cheekalive, 5000); export default axios \ No newline at end of file diff --git a/src/utils/pythonBridge.js b/src/utils/pythonBridge.js index 72a6de2..b92164f 100644 --- a/src/utils/pythonBridge.js +++ b/src/utils/pythonBridge.js @@ -3,6 +3,7 @@ import { ref, onMounted } from 'vue'; const bridge = ref(null); // 初始化 QWebChannel const initBridge = () => { + if (/localhost/.test(window.location.href)) return new QWebChannel(qt.webChannelTransport, (channel) => { bridge.value = channel.objects.bridge; }); diff --git a/src/views/hosts/hostsList.vue b/src/views/hosts/hostsList.vue index 054a5f6..22e783d 100644 --- a/src/views/hosts/hostsList.vue +++ b/src/views/hosts/hostsList.vue @@ -40,7 +40,7 @@ -