Ver código fonte

登录成功后调整

Xiao_123 8 meses atrás
pai
commit
cbfd3857ee
2 arquivos alterados com 23 adições e 5 exclusões
  1. 4 1
      pages/login/index.vue
  2. 19 4
      store/user.js

+ 4 - 1
pages/login/index.vue

@@ -86,6 +86,9 @@ const state = ref({
   }
 })
 
+// 登录成功后的返回页面
+const backUrl = getCurrentPages().length ? getCurrentPages()[getCurrentPages().length - 2].route : ''
+
 const onClickItem = (e) => {
   current.value = e.currentIndex
 }
@@ -107,7 +110,7 @@ const handleCode = () => {
 const handleLogin = async () => {
   const validate = await unref(current.value === 0 ? smsLoginRef : accountLoginRef).validate()
   if (!validate) return
-  await useUserStore.handleSmsLogin(current.value === 0 ? state.value.sms : state.value.account, current.value === 0 ? true : false)
+  await useUserStore.handleSmsLogin(current.value === 0 ? state.value.sms : state.value.account, current.value === 0 ? true : false, backUrl || 'pages/index/my')
 }
 </script>
 

+ 19 - 4
store/user.js

@@ -21,6 +21,13 @@ const defaultAccountInfo = {
   userId: ''
 }
 
+const tabUrl = [
+  'pages/index/index',
+  'pages/index/position',
+  'pages/index/communicate',
+  'pages/index/my'
+]
+
 export const userStore = defineStore({
   id: 'user',
   state: () => ({
@@ -32,7 +39,7 @@ export const userStore = defineStore({
 
   actions: {
     // 登录
-    async handleSmsLogin (query, type) {
+    async handleSmsLogin (query, type, route) {
       const api = type ? smsLogin : passwordLogin
       const { data, code } = await api(query)
       if (code === 0) {
@@ -42,9 +49,17 @@ export const userStore = defineStore({
       }
       this.accountInfo = data
       this.getInfo()
-      uni.switchTab({
-        url: '/pages/index/my'
-      })
+
+      // 登录成功后的跳转地址
+      if (tabUrl.includes(route)) {
+        uni.switchTab({
+          url: '/' + route
+        })
+      } else {
+        uni.navigateTo({
+          url: '/' + route
+        })
+      }
     },
     // 获取用户信息
     async getInfo() {