init
This commit is contained in:
18
pc/middleware/route.global.ts
Normal file
18
pc/middleware/route.global.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { useAppStore } from '~~/stores/app'
|
||||
import { useUserStore } from '~~/stores/user'
|
||||
import { isEmptyObject } from '~~/utils/validate'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const userStore = useUserStore()
|
||||
const appStore = useAppStore()
|
||||
try {
|
||||
if (isEmptyObject(appStore.config)) {
|
||||
await appStore.getConfig()
|
||||
}
|
||||
if (userStore.isLogin && isEmptyObject(userStore.userInfo)) {
|
||||
await userStore.getUser()
|
||||
}
|
||||
} catch (error) {
|
||||
userStore.$reset()
|
||||
}
|
||||
})
|
||||
33
pc/middleware/wxlogin.global.ts
Normal file
33
pc/middleware/wxlogin.global.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { wxLogin } from '~~/api/account'
|
||||
import {
|
||||
PopupTypeEnum,
|
||||
useAccount
|
||||
} from '~~/layouts/components/account/useAccount'
|
||||
import { useAppStore } from '~~/stores/app'
|
||||
import { useUserStore } from '~~/stores/user'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const appStore = useAppStore()
|
||||
const userStore = useUserStore()
|
||||
const { setPopupType, toggleShowPopup } = useAccount()
|
||||
const isForceBindMobile = appStore.getLoginConfig.forceBindMobile
|
||||
const { code, state } = to.query
|
||||
delete to.query.code
|
||||
delete to.query.state
|
||||
try {
|
||||
if (code && state) {
|
||||
const data = await wxLogin({ code, state })
|
||||
if (isForceBindMobile && !data.isBindMobile) {
|
||||
userStore.temToken = data.token
|
||||
setPopupType(PopupTypeEnum.BIND_MOBILE)
|
||||
toggleShowPopup(true)
|
||||
return
|
||||
}
|
||||
userStore.login(data.token)
|
||||
await userStore.getUser()
|
||||
return navigateTo(to)
|
||||
}
|
||||
} catch (error) {
|
||||
return navigateTo(to)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user