更新
This commit is contained in:
35
resources/mobile/mixins/auth.js
Normal file
35
resources/mobile/mixins/auth.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { checkLogin, isLogin } from '@/utils/auth.js'
|
||||
|
||||
export default {
|
||||
onLoad() {
|
||||
// 页面加载时检查登录状态
|
||||
this.checkAuth()
|
||||
},
|
||||
onShow() {
|
||||
// 页面显示时检查登录状态
|
||||
this.checkAuth()
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 检查登录状态
|
||||
* 如果页面设置了需要登录(needLogin: true),则进行登录验证
|
||||
*/
|
||||
checkAuth() {
|
||||
// 如果页面明确标记不需要登录,则跳过检查
|
||||
if (this.needLogin === false) {
|
||||
return
|
||||
}
|
||||
|
||||
// 默认需要登录验证
|
||||
checkLogin()
|
||||
},
|
||||
|
||||
/**
|
||||
* 检查是否已登录
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLoggedIn() {
|
||||
return isLogin()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user