diff --git a/App.vue b/App.vue index 0150f73..e865a4e 100644 --- a/App.vue +++ b/App.vue @@ -2,6 +2,7 @@ import Member from "@/api/member"; import { mapActions } from "vuex"; import app from "@/app.js" +import Home from "@/api/home"; export default { onLaunch: function () { setInterval(() => { @@ -26,6 +27,34 @@ export default { }); }); }, + + sendHeartbeat() { + Home.online().then((response) => { + console.log('心跳机制'); + }).catch((err) => {}); + }, + startHeartbeat() { + if (!this.heartbeatInterval && this.isLogin) { + this.heartbeatInterval = setInterval(this.sendHeartbeat, 100000); // 每3秒发送一次心跳 + console.log('心跳机制已启动'); + } + }, + stopHeartbeat() { + if (this.heartbeatInterval) { + clearInterval(this.heartbeatInterval); + this.heartbeatInterval = null; + console.log('心跳机制已停止'); + } + }, + handleVisibilityChange() { + if (document.visibilityState === 'visible') { + // 页面可见,启动心跳机制 + this.startHeartbeat(); + } else { + // 页面不可见,停止心跳机制 + this.stopHeartbeat(); + } + } // update(){ // var baseUrl=app.baseUrl + '/api/app/getNewestVersion' // console.log(baseUrl) @@ -128,7 +157,23 @@ export default { uni.$emit("appShow"); this.$navFontColor(); }, + computed:{ + isLogin() { + return Boolean(uni.getStorageSync("token")); + }, + }, + beforeDestroy() { + // 清理事件监听器和心跳请求 + document.removeEventListener('visibilitychange', this.handleVisibilityChange); + this.stopHeartbeat(); + }, onHide: function () {}, + mounted() { + // 监听页面可见性变化 + document.addEventListener('visibilitychange', this.handleVisibilityChange); + // 启动心跳机制 + this.startHeartbeat(); + }, }; diff --git a/api/home.js b/api/home.js index 7fdb8f6..d9303a8 100644 --- a/api/home.js +++ b/api/home.js @@ -20,6 +20,13 @@ class Home { static option(data){ return Serve.post('/option',data) } + + /* + * 获取用户在线接口 + */ + static online(){ + return Serve.get('/online') + } } export default Home; \ No newline at end of file diff --git a/pages/auth/certification.vue b/pages/auth/certification.vue index 196baa3..9d6fbcb 100644 --- a/pages/auth/certification.vue +++ b/pages/auth/certification.vue @@ -304,7 +304,7 @@ // 修改uni-datetime-picker的年月列表样式 .uni-picker-view-indicator, .uni-picker-view-mask { - background-color: rgba(255, 255, 255, 0.5) !important; + background-color: rgba(255, 255, 255, 0.7) !important; } // 修改uni-datetime-picker的年月列表样式,以下的修改无效 diff --git a/pages/exchange/open-position.vue b/pages/exchange/open-position.vue index 6d55e53..a7be7c9 100644 --- a/pages/exchange/open-position.vue +++ b/pages/exchange/open-position.vue @@ -215,7 +215,7 @@ @input="sliderChange" -->