فهرست منبع

登录流程优化

shish 3 سال پیش
والد
کامیت
63350b4b39
2فایلهای تغییر یافته به همراه29 افزوده شده و 2 حذف شده
  1. 23 1
      ghsApp/src/admin/home/login.vue
  2. 6 1
      hdApp/src/admin/home/login.vue

+ 23 - 1
ghsApp/src/admin/home/login.vue

@@ -52,7 +52,7 @@
 import { mapActions } from "vuex";
 import { getShopInfo} from "@/utils/auth";
 import {appLogin} from '@/api/common'
-import { getDictionaries } from '@/api/mini'
+import { getDictionaries,postWxCode } from '@/api/mini'
 import { replaceClientId } from '@/api/admin'
 import { phoneLogin,wxMobileLogin } from "@/api/auth";
 export default {
@@ -77,6 +77,28 @@ export default {
 			}
 		})
 		uni.onNetworkStatusChange(this.dealLogin)
+
+		//如果登录状态失效了,重新登录一次,更新session_key,这样session_key才有效,微信手机号登录才会成功
+		uni.checkSession({
+			success(){
+				console.log('checkSession success')
+			},
+			fail(){
+				uni.login({
+					provider: 'weixin',
+					success: res => {
+						uni.setStorageSync('code', res.code)
+						postWxCode({ code: res.code }).then(subRes => {
+							if(subRes.data.currentMiniOpenId){
+								let currentMiniOpenId = subRes.data.currentMiniOpenId
+								uni.setStorageSync('currentMiniOpenId', currentMiniOpenId)
+							}
+						 })
+					}
+				})
+			}  
+		})
+
 	},
 	onUnload(){
 		uni.offNetworkStatusChange(this.dealLogin)

+ 6 - 1
hdApp/src/admin/home/login.vue

@@ -89,7 +89,12 @@ export default {
 					provider: 'weixin',
 					success: res => {
 						uni.setStorageSync('code', res.code)
-						postWxCode({ code: res.code }).then(subRes => { })
+						postWxCode({ code: res.code }).then(subRes => {
+							if(subRes.data.currentMiniOpenId){
+								let currentMiniOpenId = subRes.data.currentMiniOpenId
+								uni.setStorageSync('currentMiniOpenId', currentMiniOpenId)
+							}
+						 })
 					}
 				})
 			}