Browse Source

feat(App): 添加浏览器关闭时自动退出登录功能

- 在 mounted 钩子中监听 beforeunload 事件
- 在 beforeDestroy 钩子中移除事件监听
- 实现 handleBeforeUnload 方法处理退出逻辑
- 使用 sendBeacon 发送可靠的安全退出请求
- 检查 token 存在时才执行退出操作
- 集成现有登出 API 接口
master
常熟吴彦祖 4 days ago
parent
commit
d29fd40cef
  1. 17
      src/App.vue

17
src/App.vue

@ -22,6 +22,14 @@
created () { created () {
this.versionReload() this.versionReload()
}, },
mounted() {
// 退 - rqrq
window.addEventListener('beforeunload', this.handleBeforeUnload)
},
beforeDestroy() {
// - rqrq
window.removeEventListener('beforeunload', this.handleBeforeUnload)
},
methods: { methods: {
versionReload(){ versionReload(){
let version = this.version //线 let version = this.version //线
@ -33,6 +41,15 @@
this.version=versionLocal; this.version=versionLocal;
location.reload(); location.reload();
} }
},
// 退 - rqrq
handleBeforeUnload() {
const token = this.$cookie.get('token')
if (token && token.trim()) {
// 使 sendBeacon 退 - rqrq
const url = this.$http.adornUrl('/sys/logout')
navigator.sendBeacon(url, new Blob([JSON.stringify({ token })], { type: 'application/json' }))
}
} }
}, },
watch: { watch: {

Loading…
Cancel
Save