Files
account/resources/mobile/mixins/auth.js
2026-01-18 18:03:40 +08:00

49 lines
964 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { checkLogin, isLogin } from '@/utils/auth.js'
export default {
data() {
return {
// 记录该页面是否已检查过登录状态
_pageAuthChecked: false
}
},
onLoad() {
// 页面加载时检查登录状态
this.checkAuth()
},
onShow() {
// 页面显示时检查登录状态,但避免重复检查
if (!this._pageAuthChecked) {
this.checkAuth()
this._pageAuthChecked = true
}
},
onHide() {
// 页面隐藏时重置检查标志,下次显示时重新检查
this._pageAuthChecked = false
},
methods: {
/**
* 检查登录状态
* 如果页面设置了需要登录needLogin: true则进行登录验证
*/
checkAuth() {
// 如果页面明确标记不需要登录,则跳过检查
if (this.needLogin === false) {
return
}
// 默认需要登录验证
checkLogin()
},
/**
* 检查是否已登录
* @returns {boolean}
*/
isLoggedIn() {
return isLogin()
}
}
}