From 3da0fdfcb6d78855fdf55a0c88bcb24ef2eb686e Mon Sep 17 00:00:00 2001 From: donqi Date: Mon, 9 May 2022 23:10:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/js/commonFun.js | 14 +++++++-- pages/index/index-home.vue | 58 +++++++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/common/js/commonFun.js b/common/js/commonFun.js index cc7792e..aa7771d 100644 --- a/common/js/commonFun.js +++ b/common/js/commonFun.js @@ -31,9 +31,9 @@ export default { }, async login() { // 从缓存中获取登录信息 - let userInfo = uni.getStorageSync('userInfo'); + let userInfo = uni.getStorageSync('userProfile'); if (userInfo) { - return; + return true; } // 获取微信登录凭证 @@ -50,8 +50,16 @@ export default { }); } else { userInfo = loginRes.userInfo; + } + if (!userInfo) { + uni.showToast({ + icon: 'error', + title: '微信用户信息获取失败,请退出小程序重试' + }) + return false; } // 页面存储用户登录有效信息,以便其他页面调用 - uni.setStorageSync('userInfo', userInfo); + uni.setStorageSync('userProfile', userInfo); + return true; } } diff --git a/pages/index/index-home.vue b/pages/index/index-home.vue index 3976e16..4e852b8 100644 --- a/pages/index/index-home.vue +++ b/pages/index/index-home.vue @@ -5,9 +5,9 @@ + :style="'width: 120rpx; height: 120rpx; background-image:url(' + curUserInfo.userInfo.avatarUrl + ');'"> - {{myInfo.name}} + {{curUserInfo.userInfo.nickName}} @@ -99,6 +99,17 @@ @click="chooseEntryType('serv')">服务商 + + + + + + 需先授权微信登录才可正常使用功能 + + + 确认授权 + + @@ -144,29 +155,35 @@ color: 'olive', cuIcon: 'group', pageUrl: '/pages/area-proxy/my-team' - }], + }], + curUserInfo: {}, myInfo: {}, - isShowSteer: false + isShowSteer: false, + isAuthWxLoginModal: false } }, onReady() { this.loadData(); }, methods: { - async loadData() { - this.myInfo = await this.$api.data('myInfo'); - this.isShowSteer = !this.myInfo.entryType; - let newServModules = this.servModules.concat(); - if (this.myInfo.hasCheckedRule) { - newServModules[0].pageUrl = '/pages/demand-center/accept-demand-center'; - } else { - let paramObj = { - hasCheckedRule: this.myInfo.hasCheckedRule, - navigate: true + async loadData() { + this.curUserInfo = uni.getStorageSync('userProfile'); + this.isAuthWxLoginModal = this.curUserInfo ? false : true; + if (!this.isAuthWxLoginModal) { + this.myInfo = await this.$api.data('myInfo'); + this.isShowSteer = !this.myInfo.entryType; + let newServModules = this.servModules.concat(); + if (this.myInfo.hasCheckedRule) { + newServModules[0].pageUrl = '/pages/demand-center/accept-demand-center'; + } else { + let paramObj = { + hasCheckedRule: this.myInfo.hasCheckedRule, + navigate: true + } + newServModules[0].pageUrl = '/pages/demand-center/rule?paramObj=' + encodeURIComponent(JSON.stringify(paramObj)); } - newServModules[0].pageUrl = '/pages/demand-center/rule?paramObj=' + encodeURIComponent(JSON.stringify(paramObj)); - } - this.servModules = newServModules; + this.servModules = newServModules; + } }, chooseEntryType(typeCode) { @@ -182,6 +199,13 @@ uni.navigateTo({ url: '/pages/demand-center/rule?paramObj=' + encodeURIComponent(JSON.stringify(paramObj)) }) + }, + authWxLogin() { + this.$commonFun.login().then(res => { + if (res) { + this.loadData(); + } + }) } }, }