Files
taimed-international-app/hooks/usePageAuth.ts
2025-11-04 12:37:04 +08:00

17 lines
402 B
TypeScript

// hooks/usePageAuth.ts
import { onShow } from '@dcloudio/uni-app'
import { useUserStore } from '@/stores/user'
export function usePageAuth(redirect = '/pages/login/login') {
const store = useUserStore()
onShow(() => {
if (!store.token) {
uni.showToast({ title: '请先登录', icon: 'none' })
setTimeout(() => {
uni.reLaunch({ url: redirect })
}, 800)
}
})
}