瀏覽代碼

登录修改

zaijin 2 年之前
父節點
當前提交
f1aded1cec
共有 9 個文件被更改,包括 461 次插入362 次删除
  1. 40 0
      App.vue
  2. 9 0
      common/apiurl.js
  3. 7 1
      common/http.api.js
  4. 6 8
      common/http.interceptor.js
  5. 1 1
      manifest.json
  6. 241 234
      pages/center/phoneLogin/phoneLogin.vue
  7. 1 5
      pages/parkingLock/parkingLock.vue
  8. 154 111
      pages/wechatLogin/wechatLogin.vue
  9. 2 2
      store/index.js

+ 40 - 0
App.vue

@@ -35,9 +35,49 @@ export default {
   },
   onShow: function () {
     // console.log('App Show')
+    const backUrl = location.href,
+      openidPage = ['/pages/parkingLock/parkingLock'], // 只需要穿openid的页面集合
+      needValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1); // 是否为需要验证的页面集合
+    const { openId } = this.vuex_wxinfo;
+    if (openId && needValidPage.length === 0) {
+      this.getUserInfo(openId);
+    }
   },
   onHide: function () {
     // console.log('App Hide')
+  },
+  methods: {
+    /**
+     * @description:
+     * @param {*} openId
+     * @return {*}
+     */
+    async getUserInfo(openId) {
+      try {
+        const queryParams = {
+          loginType: 1,
+          openid: openId,
+          nickName: this?.vuex_wxinfo?.nickname,
+          avatar: this?.vuex_wxinfo?.headImgUrl
+        };
+        const userInfo = await this.$u.api.userLoginApi.openidLoginApi({ ...queryParams });
+        const { accessToken, needVerify } = userInfo.data;
+        this.$u.vuex('vuex_token', accessToken);
+        this.$u.vuex('vuex_hasLogin', true);
+        if (needVerify) {
+          localStorage.setItem('backUrl', this.backUrl);
+          this.$u.route({
+            url: 'pages/center/phoneLogin/phoneLogin',
+            type: 'reLaunch'
+          });
+        }
+      } catch (error) {
+        this.$refs.uToast.show({
+          title: '获取用户信息失败!',
+          type: 'error'
+        });
+      }
+    }
   }
 };
 </script>

+ 9 - 0
common/apiurl.js

@@ -96,6 +96,15 @@ export const apiurl = {
     // 登出
     logoutUrl: '/client/auth/loginout'
   },
+  // 用户登录区分手机号和微信openid登录
+  userLoginUrl: {
+    // openid登录
+    openidLoginUrl: '/client/auth/loginToWxOpenId',
+    // 发送验证码
+    sendSmsCodeUrl: '/client/auth/sendSmsCodeV3',
+    // 手机号登录
+    mobileLoginUrl: '/client/auth/loginToMobile'
+  },
   // 地磁获取小票详情
   geomaLockDetailsUrl: '/client/orderinfo/detailByQrcode',
   //入场扫码信息

+ 7 - 1
common/http.api.js

@@ -100,6 +100,11 @@ const install = (Vue, vm) => {
     // 登出
     logoutApi: (params = {}) => vm.$u.post(apiurl.codeV2Url.logoutUrl, params)
   };
+  let userLoginApi = {
+    openidLoginApi: (params = {}) => vm.$u.post(apiurl.userLoginUrl.openidLoginUrl, params),
+    sendSmsCodeApi: (params = {}) => vm.$u.post(apiurl.userLoginUrl.sendSmsCodeUrl, params),
+    mobileLoginApi: (params = {}) => vm.$u.post(apiurl.userLoginUrl.mobileLoginUrl, params),
+  }
   let geomaLockDetailsApi = (params = {}) => vm.$u.post(apiurl.geomaLockDetailsUrl, params);
   let getDetailEntranceApi = (params = {}) => vm.$u.post(apiurl.getDetailEntrance, params);
   let getDetailAdvanceApi = (params = {}) => vm.$u.post(apiurl.getDetailAdvance, params);
@@ -164,6 +169,7 @@ const install = (Vue, vm) => {
     getSysterms,
     bindVehicleNo,
     codeV2Api,
+    userLoginApi,
     geomaLockDetailsApi,
     getDetailEntranceApi,
     getDetailAdvanceApi,
@@ -185,7 +191,7 @@ const install = (Vue, vm) => {
     couponListApi,
     exchangeCouponApi,
     updateCouponStatusApi,
-    getCouponByOrderIdApi
+    getCouponByOrderIdApi,
   };
 };
 

+ 6 - 8
common/http.interceptor.js

@@ -1,11 +1,7 @@
 // vm,就是我们在vue文件里面的this,所以我们能在这里获取vuex的变量,比如存放在里面的token
 const install = (Vue, vm) => {
   Vue.prototype.$u.http.setConfig({
-    baseUrl: vm.config.baseUrl,
-    showLoading: true,
-    loadingText: '加载中...',
-    loadingMask: true,
-    loadingTime: 800
+    baseUrl: vm.config.baseUrl
   });
   // 请求拦截,配置Token等参数
   Vue.prototype.$u.http.interceptor.request = (config) => {
@@ -23,15 +19,17 @@ const install = (Vue, vm) => {
     if (res.code == 200) {
       return res;
     } else if (res.code == 401 || res.code == 400) {
-      const backUrl = location.href;
+      const backUrl = location.href,
+        openidPage = ['/pages/parkingLock/parkingLock'], // 只需要穿openid的页面集合
+        needValidPage = openidPage.filter((item) => backUrl.indexOf(item) > -1); // 是否为需要验证的页面集合
       // 判断浏览器
       const ua = window.navigator.userAgent.toLowerCase();
+      // 微信中打开
       if (ua.match(/MicroMessenger/i) == 'micromessenger') {
         // 防止重复跳转
         if (backUrl.indexOf('backUrl') === -1) {
-          vm.$u.route('pages/wechatLogin/wechatLogin', { backUrl: encodeURIComponent(backUrl) });
+          vm.$u.route('pages/wechatLogin/wechatLogin', { backUrl: encodeURIComponent(backUrl), loginType: needValidPage.length ? 2 : 1 });
         }
-        // 微信中打开
       } else {
         // 普通浏览器中打开
         if (backUrl.indexOf('backUrl') === -1) {

+ 1 - 1
manifest.json

@@ -96,7 +96,7 @@
     "h5" : {
         "template" : "template.h5.html",
         "router" : {
-            "mode" : "history",
+            "mode" : "hash",
             "base" : ""
         },
         "sdkConfigs" : {

+ 241 - 234
pages/center/phoneLogin/phoneLogin.vue

@@ -1,251 +1,258 @@
 <template>
-	<view class="wrap">
-		<view class="content">
-			<view class="title">手机号登录</view>
-			<input class="u-border-bottom" type="number" maxlength="11" v-model="tel" placeholder="请输入手机号" />
-			<view class="u-text-center u-type-error u-m-t-20" v-if="telError">手机号输入错误</view>
-			<button @tap="submit" :style="[inputStyle]" class="getCaptcha">获取短信验证码</button>
-			<u-message-input v-if="show" :focus="true" :value="messageCode" @change="change" @finish="finish"
-				mode="bottomLine" :maxlength="codelength"></u-message-input>
-		</view>
-		<view class="captcha">
-			<text v-if="messageShow">{{ second }}秒后可重新获取验证码</text>
-		</view>
-		<view class="buttom">
-			<view class="hint u-text-center">
-				登录代表同意
-				<text class="link" @tap="jumpToPage(1)">《用户服务条款》</text>和
-				<text class="link" @tap="jumpToPage(2)">《隐私政策》</text>
-				并授权使用您的账号信息(如昵称、头像、收货地址)以便您统一管理
-			</view>
-		</view>
-		<u-toast ref="uToast" />
-	</view>
+  <view class="wrap">
+    <view class="content">
+      <view class="title">手机号登录</view>
+      <input class="u-border-bottom" type="number" maxlength="11" v-model="tel" placeholder="请输入手机号" />
+      <view class="u-text-center u-type-error u-m-t-20" v-if="telError">手机号输入错误</view>
+      <button @tap="submit" :style="[inputStyle]" class="getCaptcha">获取短信验证码</button>
+      <u-message-input
+        v-if="show"
+        :focus="true"
+        :value="messageCode"
+        @change="change"
+        @finish="finish"
+        mode="bottomLine"
+        :maxlength="codelength"
+      ></u-message-input>
+    </view>
+    <view class="captcha">
+      <text v-if="messageShow">{{ second }}秒后可重新获取验证码</text>
+    </view>
+    <view class="buttom">
+      <view class="hint u-text-center">
+        登录代表同意
+        <text class="link" @tap="jumpToPage(1)">《用户服务条款》</text>和
+        <text class="link" @tap="jumpToPage(2)">《隐私政策》</text>
+        并授权使用您的账号信息(如昵称、头像、收货地址)以便您统一管理
+      </view>
+    </view>
+    <u-toast ref="uToast" />
+  </view>
 </template>
 
 <script>
-	import getUrlParams from "./../../../utils/getUrlParams.js";
-	export default {
-		data() {
-			return {
-				tel: '',
-				messageCode: '',
-				messageShow: false,
-				messageDisable: false,
-				codelength: 4,
-				show: false,
-				second: 60,
-				toastMsg: '',
-				toastUrl: '',
-				toastType: '',
-				accessToken: '',
-				userId: '',
-				telError: false,
-				openId: ''
-			}
-		},
-		onLoad(page) {
-			this.openId = this.vuex_wxinfo?.openId
-			const backUrl = location.href
-			if (!this.openId) {
-				// 判断浏览器
-				const ua = window.navigator.userAgent.toLowerCase()
-				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
-					// 微信中打开
-					this.$u.route('pages/wechatLogin/wechatLogin', {
-						backUrl
-					})
-				}
-			}
-			const pages = getCurrentPages();
-			if (pages.length >= 2) {
-				uni.setStorageSync('last_page', pages[pages.length - 2].route);
-				if (pages[pages.length - 2].options) {
-					uni.setStorageSync('last_page_options', pages[pages.length - 2].options);
-				}
-			}
-		},
-		computed: {
-			inputStyle() {
-				let style = {};
-				if (this.tel.length == 11 && this.messageDisable == false && this.$u.test.mobile(this.tel)) {
-					style.color = "#fff";
-					style.backgroundColor = '#5295F5';
-					this.telError = false;
-				} else if (this.tel.length == 11 && !this.$u.test.mobile(this.tel)) {
-					this.telError = true;
-				}
-				return style;
-			}
-		},
-		methods: {
-			showToast() {
-				this.$refs.uToast.show({
-					title: this.toastMsg,
-					type: this.toastType,
-					url: this.toastUrl
-				})
-			},
-			submit() {
-				if (this.$u.test.mobile(this.tel) && this.messageDisable == false) {
-					let that = this;
-					let mobile = this.tel,
-						openId = this.openId
-					this.$u.api.codeV2Api.sendSmsCodeV2api({
-						mobile,
-						openId
-					}).then(res => {
-						this.messageDisable = true;
-						this.messageShow = true;
-						this.show = true;
-						let interval = setInterval(() => {
-							that.second--;
-							if (that.second <= 0) {
-								that.messageDisable = false
-								that.messageShow = false;
-								clearInterval(interval);
-								that.second = 60;
-							}
-						}, 1000);
-						this.accessToken = res.data.accessToken;
-						this.userId = res.data.userId;
-					})
-				}
-			},
-			// change事件侦听
-			change(value) {
-				// console.log('change', value);
-			},
-			// 输入完验证码最后一位执行
-			finish(value) {
-				let params = {
-					token: this.accessToken,
-					code: value,
-					openId: this.vuex_wxinfo?.openId,
-					mobile: this.tel
-				};
-				this.$u.api.codeV2Api.verifyCodeV2Api(params).then(res => {
-					if (res.code == '200') {
-						this.$u.vuex('vuex_token', this.accessToken);
-						this.$u.vuex('vuex_user', res.data);
-						this.$u.vuex('vuex_hasLogin', true);
-						setTimeout(() => {
-							this.jumpIndex()
-						}, 500)
-					} else {
-						this.$refs.uToast.show({
-							title: res.msg,
-							type: 'error'
-						})
-					}
-				}).catch(err => {
-					this.toastMsg = err.msg;
-					this.showToast();
-				});
-			},
-			// 微信已登录则跳转到首页
-			jumpIndex() {
-				let ret = localStorage.getItem('backUrl');
-				ret = decodeURIComponent(ret);
-				if ((ret && ret.indexOf('wechatLogin') > (-1)) || (ret && ret.indexOf('phoneLogin') < 0)) {
-					// 截取url
-					const pagesIndex = ret.indexOf('pages')
-					if (pagesIndex > (-1)) {
-						const pageUrl = ret.slice(pagesIndex)
-						const tabbarUrl = ['pages/center/index', 'pages/parkingLists/parkingLists', 'page/index/index']
-						if (tabbarUrl.indexOf(pageUrl) > (-1)) {
-							setTimeout(() => {
-								uni.switchTab({
-									url: '../../index/index'
-								})
-							}, 100)
-						} else {
-							setTimeout(() => {
-								uni.redirectTo({
-									url: '/' + pageUrl
-								})
-							}, 100)
-						}
-					} else {
-						uni.switchTab({
-							url: '../../index/index'
-						})
-					}
-				} else {
-					uni.switchTab({
-						url: '/pages/index/index'
-					})
-				}
-			},
-			/**
-			 * 跳转页面
-			 * */
-			jumpToPage(flag) {
-				uni.navigateTo({
-					url: "/pages/privacyPolicy/privacyPolicy?termsType=" + flag,
-				})
-			}
-		}
-	};
+import getUrlParams from './../../../utils/getUrlParams.js';
+export default {
+  data() {
+    return {
+      tel: '',
+      messageCode: '',
+      messageShow: false,
+      messageDisable: false,
+      codelength: 4,
+      show: false,
+      second: 60,
+      toastMsg: '',
+      toastUrl: '',
+      toastType: '',
+      accessToken: '',
+      userId: '',
+      telError: false,
+      openId: ''
+    };
+  },
+  onLoad(page) {
+    this.openId = this.vuex_wxinfo?.openId;
+    const backUrl = location.href;
+    if (!this.openId) {
+      // 判断浏览器
+      const ua = window.navigator.userAgent.toLowerCase();
+      if (ua.match(/MicroMessenger/i) == 'micromessenger') {
+        // 微信中打开
+        this.$u.route('pages/wechatLogin/wechatLogin', {
+          backUrl
+        });
+      }
+    }
+    const pages = getCurrentPages();
+    if (pages.length >= 2) {
+      uni.setStorageSync('last_page', pages[pages.length - 2].route);
+      if (pages[pages.length - 2].options) {
+        uni.setStorageSync('last_page_options', pages[pages.length - 2].options);
+      }
+    }
+  },
+  computed: {
+    inputStyle() {
+      let style = {};
+      if (this.tel.length == 11 && this.messageDisable == false && this.$u.test.mobile(this.tel)) {
+        style.color = '#fff';
+        style.backgroundColor = '#5295F5';
+        this.telError = false;
+      } else if (this.tel.length == 11 && !this.$u.test.mobile(this.tel)) {
+        this.telError = true;
+      }
+      return style;
+    }
+  },
+  methods: {
+    showToast() {
+      this.$refs.uToast.show({
+        title: this.toastMsg,
+        type: this.toastType,
+        url: this.toastUrl
+      });
+    },
+    submit() {
+      if (this.$u.test.mobile(this.tel) && this.messageDisable == false) {
+        let that = this;
+        this.$u.api.userLoginApi.sendSmsCodeApi({ mobile: this.tel }).then((res) => {
+          this.messageDisable = true;
+          this.messageShow = true;
+          this.show = true;
+          let interval = setInterval(() => {
+            that.second--;
+            if (that.second <= 0) {
+              that.messageDisable = false;
+              that.messageShow = false;
+              clearInterval(interval);
+              that.second = 60;
+            }
+          }, 1000);
+          this.accessToken = res?.data?.accessToken;
+          this.userId = res?.data?.userId;
+        });
+      }
+    },
+    // change事件侦听
+    change(value) {
+      // console.log('change', value);
+    },
+    // 输入完验证码最后一位执行
+    finish(value) {
+      let params = {
+        loginType: 1,
+        nickName: this.vuex_wxinfo?.nickname,
+        code: value,
+        openId: this.vuex_wxinfo?.openId,
+        mobile: this.tel,
+        avatar: this.vuex_wxinfo?.headImgUrl
+      };
+      this.$u.api.userLoginApi
+        .mobileLoginApi(params)
+        .then((res) => {
+          if (res.code == '200') {
+            this.$u.vuex('vuex_token', res.data.accessToken);
+            this.$u.vuex('vuex_user', res.data);
+            this.$u.vuex('vuex_hasLogin', true);
+            setTimeout(() => {
+              this.jumpIndex();
+            }, 500);
+          } else {
+            this.$refs.uToast.show({
+              title: res.msg,
+              type: 'error'
+            });
+          }
+        })
+        .catch((err) => {
+          this.toastMsg = err.msg;
+          this.showToast();
+        });
+    },
+    // 微信已登录则跳转到首页
+    jumpIndex() {
+      let ret = localStorage.getItem('backUrl');
+      ret = decodeURIComponent(ret);
+      if ((ret && ret.indexOf('wechatLogin') > -1) || (ret && ret.indexOf('phoneLogin') < 0)) {
+        // 截取url
+        const pagesIndex = ret.indexOf('pages');
+        if (pagesIndex > -1) {
+          const pageUrl = ret.slice(pagesIndex);
+          const tabbarUrl = ['pages/center/index', 'pages/parkingLists/parkingLists', 'page/index/index'];
+          if (tabbarUrl.indexOf(pageUrl) > -1) {
+            setTimeout(() => {
+              uni.switchTab({
+                url: '../../index/index'
+              });
+            }, 100);
+          } else {
+            setTimeout(() => {
+              uni.redirectTo({
+                url: '/' + pageUrl
+              });
+            }, 100);
+          }
+        } else {
+          uni.switchTab({
+            url: '../../index/index'
+          });
+        }
+      } else {
+        uni.switchTab({
+          url: '/pages/index/index'
+        });
+      }
+    },
+    /**
+     * 跳转页面
+     * */
+    jumpToPage(flag) {
+      uni.navigateTo({
+        url: '/pages/privacyPolicy/privacyPolicy?termsType=' + flag
+      });
+    }
+  }
+};
 </script>
 
 <style lang="scss" scoped>
-	.hide {
-		display: none !important;
-	}
+.hide {
+  display: none !important;
+}
 
-	.wrap {
-		font-size: 28rpx;
+.wrap {
+  font-size: 28rpx;
 
-		.content {
-			width: 600rpx;
-			margin: 80rpx auto 0;
+  .content {
+    width: 600rpx;
+    margin: 80rpx auto 0;
 
-			.title {
-				text-align: left;
-				font-size: 60rpx;
-				font-weight: 500;
-				margin-bottom: 100rpx;
-			}
+    .title {
+      text-align: left;
+      font-size: 60rpx;
+      font-weight: 500;
+      margin-bottom: 100rpx;
+    }
 
-			input {
-				text-align: left;
-				margin-bottom: 10rpx;
-				padding-bottom: 20rpx;
-				border-bottom: 1px solid #ddd;
-			}
+    input {
+      text-align: left;
+      margin-bottom: 10rpx;
+      padding-bottom: 20rpx;
+      border-bottom: 1px solid #ddd;
+    }
 
-			.getCaptcha {
-				margin: 45rpx auto 130rpx;
-				background-color: #a8c6f1;
-				color: $u-tips-color;
-				border: none;
-				font-size: 30rpx;
-				padding: 12rpx 0;
+    .getCaptcha {
+      margin: 45rpx auto 130rpx;
+      background-color: #a8c6f1;
+      color: $u-tips-color;
+      border: none;
+      font-size: 30rpx;
+      padding: 12rpx 0;
 
-				&::after {
-					border: none;
-				}
-			}
-		}
+      &::after {
+        border: none;
+      }
+    }
+  }
 
-		.buttom {
-			.hint {
-				padding: 20rpx 40rpx;
-				font-size: 20rpx;
-				color: $u-tips-color;
+  .buttom {
+    .hint {
+      padding: 20rpx 40rpx;
+      font-size: 20rpx;
+      color: $u-tips-color;
 
-				.link {
-					color: $u-type-warning;
-				}
-			}
-		}
+      .link {
+        color: $u-type-warning;
+      }
+    }
+  }
 
-		.captcha {
-			color: $u-type-warning;
-			font-size: 30rpx;
-			margin-top: 40rpx;
-			text-align: center;
-		}
-	}
+  .captcha {
+    color: $u-type-warning;
+    font-size: 30rpx;
+    margin-top: 40rpx;
+    text-align: center;
+  }
+}
 </style>

+ 1 - 5
pages/parkingLock/parkingLock.vue

@@ -147,7 +147,7 @@ export default {
       // 重定向地址
       jumpUrl: location.href + '&isBack=1',
       // 订单查询中弹框显示
-      show: true,
+      show: false,
       // 是否为返回标识
       isBack: '',
       // 预支付订单
@@ -262,12 +262,10 @@ export default {
             // 如果没有isBack,则去请求
             if (!isBack) {
               // uni.hideLoading();
-              this.show = false;
               clearInterval(this.timer1);
             }
             this.orderInfo = res.data;
             if (res.data.payStatus === 1) {
-              this.show = false;
               clearInterval(this.timer1);
               this.checkEqupment();
             }
@@ -276,14 +274,12 @@ export default {
               title: res.msg || '订单无数据',
               type: 'error'
             });
-            this.show = false;
             if (this.timer1) {
               clearInterval(this.timer1);
             }
           }
         })
         .catch(() => {
-          this.show = false;
           if (this.timer1) {
             clearInterval(this.timer1);
           }

+ 154 - 111
pages/wechatLogin/wechatLogin.vue

@@ -1,121 +1,164 @@
 <template>
-	<view>
-		<u-toast ref="uToast" />
-	</view>
+  <view>
+    <u-toast ref="uToast" />
+  </view>
 </template>
 
 <script>
-	import getUrlParams from '@/utils/getUrlParams.js';
-	export default {
-		data() {
-			return {
-				backUrl: '',
-				code: ''
-			};
-		},
-		onLoad(page) {
-			let local = window.location.href;
-			let locationLocaturl = window.location.search;
-			// 微信返回的回调地址
-			let backUrl = getUrlParams(local, 'backUrl');
-			if (backUrl) {
-				this.backUrl = decodeURIComponent(backUrl);
-			}
-			console.log('backUrl', decodeURIComponent(backUrl));
-			let code = getUrlParams(locationLocaturl, 'code');
-			console.log('code', code);
-			if (code) {
-				this.code = code;
-				// 判断重复回调问题
-				let wechatLoginKey = localStorage.getItem('wechatLoginKey');
-				if (wechatLoginKey) {
-					wechatLoginKey = JSON.parse(wechatLoginKey);
-					if (code === wechatLoginKey.code) {
-						this.getToken(wechatLoginKey.openId);
-					} else {
-						this.handleGetWXInfo(this.code);
-					}
-				} else {
-					this.handleGetWXInfo(this.code);
-				}
-			} else {
-				location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?
+import getUrlParams from '@/utils/getUrlParams.js';
+export default {
+  data() {
+    return {
+      backUrl: '',
+      code: '',
+      loginType: 2
+    };
+  },
+  onLoad(page) {
+    console.log('page', page);
+    let local = window.location.href;
+    let locationLocaturl = window.location.search;
+    // 微信返回的回调地址
+    let backUrl = getUrlParams(local, 'backUrl');
+    if (backUrl) {
+      this.backUrl = decodeURIComponent(backUrl);
+      
+    }
+    console.log('backUrl', decodeURIComponent(backUrl));
+    let loginType = getUrlParams(local, 'loginType');
+    if (loginType) {
+      this.loginType = loginType;
+    }
+    console.log('loginType', loginType);
+    let code = getUrlParams(locationLocaturl, 'code');
+    console.log('code', code);
+    if (code) {
+      this.code = code;
+      // 判断重复回调问题
+      let wechatLoginKey = localStorage.getItem('wechatLoginKey');
+      if (wechatLoginKey) {
+        wechatLoginKey = JSON.parse(wechatLoginKey);
+        if (code === wechatLoginKey.code) {
+          this.getUserInfo(wechatLoginKey.openId);
+        } else {
+          this.handleGetWXInfo(this.code);
+        }
+      } else {
+        this.handleGetWXInfo(this.code);
+      }
+    } else {
+      location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?
 					appid=${this.config.wxAppid}&
 					redirect_uri=${encodeURIComponent(local)}&
 					response_type=code&
 					scope=snsapi_userinfo&
 					state=STATE#wechat_redirect`;
-			}
-		},
-		methods: {
-			// 通过code获取 openId等用户信息
-			handleGetWXInfo(code) {
-				uni.showLoading({
-					title: '加载中'
-				});
-				this.$u.api
-					.getWXInfo(code)
-					.then((res) => {
-						if (res.code === 200) {
-							this.$u.vuex('vuex_wxinfo', res.data);
-							localStorage.setItem(
-								'wechatLoginKey',
-								JSON.stringify({
-									code,
-									openId: res.data.openId
-								})
-							);
-							this.getToken(res.data.openId);
-						} else {
-							this.$refs.uToast.show({
-								title: res.msg || '获取用户信息失败!',
-								type: 'error'
-							});
-							uni.hideLoading();
-						}
-					})
-					.catch((err) => {
-						uni.hideLoading();
-					});
-			},
-			/**
-			 * 通过openId获取token
-			 * @param {Object} openId
-			 */
-			getToken(openId) {
-				this.$u.api.codeV2Api
-					.sendSmsCodeV2api({
-						openId
-					})
-					.then((res) => {
-						if (res.code === 200) {
-							this.$u.vuex('vuex_token', res.data.accessToken);
-							this.$u.vuex('vuex_hasLogin', true);
-							if (res.data.needVerify) {
-								localStorage.setItem('backUrl', this.backUrl);
-								this.$u.route({
-									url: 'pages/center/phoneLogin/phoneLogin',
-									type: 'reLaunch'
-								});
-							} else {
-								this.$u.vuex('vuex_user', res.data);
-								if (this.backUrl.indexOf('wechatLogin') > -1) {
-									location.href = '/';
-								} else {
-									location.href = this.backUrl;
-								}
-							}
-							uni.hideLoading();
-						} else {
-							this.$refs.uToast.show({
-								title: res.msg || '获取用户信息失败!',
-								type: 'error'
-							});
-							uni.hideLoading();
-						}
-					});
-			}
-		}
-	};
+    }
+  },
+  methods: {
+    // 通过code获取 openId等用户信息
+    handleGetWXInfo(code) {
+      uni.showLoading({
+        title: '加载中'
+      });
+      this.$u.api
+        .getWXInfo(code)
+        .then((res) => {
+          if (res.code === 200) {
+            this.$u.vuex('vuex_wxinfo', res.data);
+            localStorage.setItem(
+              'wechatLoginKey',
+              JSON.stringify({
+                code,
+                openId: res.data.openId
+              })
+            );
+            this.getUserInfo(res.data.openId);
+          } else {
+            uni.hideLoading();
+          }
+        })
+        .catch((err) => {
+          uni.hideLoading();
+        });
+    },
+    /**
+     * 通过openId获取token
+     * @param {Object} openId
+     */
+    getToken(openId) {
+      this.$u.api.codeV2Api
+        .sendSmsCodeV2api({
+          openId
+        })
+        .then((res) => {
+          if (res.code === 200) {
+            this.$u.vuex('vuex_token', res.data.accessToken);
+            this.$u.vuex('vuex_hasLogin', true);
+            if (res.data.needVerify) {
+              localStorage.setItem('backUrl', this.backUrl);
+              this.$u.route({
+                url: 'pages/center/phoneLogin/phoneLogin',
+                type: 'reLaunch'
+              });
+            } else {
+              this.$u.vuex('vuex_user', res.data);
+              if (this.backUrl.indexOf('wechatLogin') > -1) {
+                location.href = '/';
+              } else {
+                location.href = this.backUrl;
+              }
+            }
+            uni.hideLoading();
+          } else {
+            this.$refs.uToast.show({
+              title: res.msg || '获取用户信息失败!',
+              type: 'error'
+            });
+            uni.hideLoading();
+          }
+        });
+    },
+    /**
+     * @description:
+     * @param {*} openId
+     * @return {*}
+     */
+    async getUserInfo(openId) {
+      try {
+        const queryParams = {
+          loginType: this.loginType,
+          openid: openId,
+          nickName: this?.vuex_wxinfo?.nickname,
+          avatar: this?.vuex_wxinfo?.headImgUrl
+        };
+        const userInfo = await this.$u.api.userLoginApi.openidLoginApi({ ...queryParams });
+        const { accessToken, needVerify } = userInfo.data;
+        this.$u.vuex('vuex_token', accessToken);
+        this.$u.vuex('vuex_hasLogin', true);
+        if (needVerify) {
+          localStorage.setItem('backUrl', this.backUrl);
+          this.$u.route({
+            url: 'pages/center/phoneLogin/phoneLogin',
+            type: 'reLaunch'
+          });
+        } else {
+          this.$u.vuex('vuex_user', userInfo.data);
+          if (this.backUrl.indexOf('wechatLogin') > -1) {
+            location.href = '/';
+          } else {
+            location.href = this.backUrl;
+          }
+        }
+        uni.hideLoading();
+      } catch (error) {
+        this.$refs.uToast.show({
+          title: '获取用户信息失败!',
+          type: 'error'
+        });
+        uni.hideLoading();
+      }
+    }
+  }
+};
 </script>
-

+ 2 - 2
store/index.js

@@ -29,8 +29,8 @@ const store = new Vuex.Store({
   state: {
     // 如果上面从本地获取的lifeData对象下有对应的属性,就赋值给state中对应的变量
     // 加上vuex_前缀,是防止变量名冲突,也让人一目了然
-    vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {},
-    vuex_wxinfo: lifeData.vuex_wxinfo ? lifeData.vuex_wxinfo : {},
+    vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {}, // 用户信息
+    vuex_wxinfo: lifeData.vuex_wxinfo ? lifeData.vuex_wxinfo : {}, // 微信用户信息
     vuex_hasLogin: lifeData.vuex_hasLogin ? lifeData.vuex_hasLogin : false,
     vuex_token: lifeData.vuex_token ? lifeData.vuex_token : '',
     free_time: lifeData.free_time || '15',