公众号登录调试

This commit is contained in:
Jason
2022-09-15 15:03:12 +08:00
parent 867845a2dd
commit 2abccd483e
57 changed files with 91 additions and 54 deletions

View File

@@ -4,6 +4,7 @@ import { useAppStore } from './stores/app'
import { useUserStore } from './stores/user'
const appStore = useAppStore()
const { getUser } = useUserStore()
onLaunch(async () => {
await appStore.getConfig()
// #ifdef H5

View File

@@ -5,3 +5,5 @@ export const TOKEN_KEY = 'token'
// 搜索历史记录
export const HISTORY = 'history'
export const BACK_URL = 'back_url'

View File

@@ -1,10 +1,14 @@
import { createSSRApp } from 'vue'
import App from './App.vue'
import plugins from './plugins'
import './router'
import { setupRouter } from './router'
import './styles/index.scss'
export function createApp() {
const app = createSSRApp(App)
Promise.resolve().then(() => {
setupRouter()
})
app.use(plugins)
return {
app

View File

@@ -155,9 +155,11 @@
import { login } from '@/api/account'
import { smsSend } from '@/api/app'
import { SMSEnum } from '@/enums/appEnums'
import { BACK_URL } from '@/enums/cacheEnums'
import { useLockFn } from '@/hooks/useLockFn'
import { useAppStore } from '@/stores/app'
import { useUserStore } from '@/stores/user'
import cache from '@/utils/cache'
import { isWeixinClient } from '@/utils/client'
import { currentPage } from '@/utils/util'
// #ifdef H5
@@ -182,7 +184,7 @@ enum LoginAuthEnum {
}
const isWeixin = ref(true)
// #ifdef H5
// isWeixin.value = isWeixinClient()
isWeixin.value = isWeixinClient()
// #endif
const userStore = useUserStore()
@@ -277,14 +279,23 @@ const loginHandle = async (data: any) => {
await userStore.getUser()
uni.$u.toast('登录成功')
uni.hideLoading()
uni.navigateBack({
success: () => {
// @ts-ignore
const { onLoad, options } = currentPage()
// 刷新上一个页面
onLoad && onLoad(options)
}
})
if (getCurrentPages().length > 1) {
uni.navigateBack({
success: () => {
// @ts-ignore
const { onLoad, options } = currentPage()
// 刷新上一个页面
onLoad && onLoad(options)
}
})
} else if (cache.get(BACK_URL)) {
uni.redirectTo({ url: cache.get(BACK_URL) })
} else {
uni.reLaunch({
url: '/pages/index/index'
})
}
cache.remove(BACK_URL)
}
const { lockFn: handleLogin } = useLockFn(loginFun)

View File

@@ -1,6 +1,10 @@
import { BACK_URL } from '@/enums/cacheEnums'
import { useUserStore } from '@/stores/user'
import { getToken } from '@/utils/auth'
import cache from '@/utils/cache'
import { generateRoutes } from './transformPages'
export const routes = generateRoutes()
const whiteList = ['register', 'login', 'forget_pwd']
const list = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab']
list.forEach((item) => {
uni.addInterceptor(item, {
@@ -25,3 +29,18 @@ list.forEach((item) => {
}
})
})
export function setupRouter() {
// #ifdef H5
const app = getApp()
app.$router.beforeEach((to: any, from: any) => {
const index = whiteList.findIndex((item) => from.path.includes(item))
const userStore = useUserStore()
if (index == -1 && !userStore.isLogin) {
//保存登录前的路径
cache.set(BACK_URL, from.fullPath)
}
})
// #endif
}