소스 검색

增加微信绑定手机号

jwyu 3 년 전
부모
커밋
7eee34b138
7개의 변경된 파일39개의 추가작업 그리고 10개의 파일을 삭제
  1. 3 3
      App.vue
  2. 5 0
      api/common.js
  3. 4 1
      pages-activity/detail.vue
  4. 21 2
      pages/login.vue
  5. 4 1
      pages/webView.vue
  6. 0 1
      utils/config.js
  7. 2 2
      utils/request.js

+ 3 - 3
App.vue

@@ -1,11 +1,11 @@
 <script>
 	export default {
-		onLaunch: function() {
+		onLaunch: function(options) {
 			console.log('App Launch')
 			this.$store.dispatch('getUserInfo')
 			this.$store.dispatch('getTabBar')
 		},
-		onShow: function() {
+		onShow: function(options) {
 			console.log('App Show')
 		},
 		onHide: function() {
@@ -17,6 +17,6 @@
 <style lang='scss'>
 	@import "/wxcomponents/vant/common/index.wxss";
 	/* 页面公共样式 */
-	@import "./style/common.scss"
+	@import "./style/common.scss";
 	
 </style>

+ 5 - 0
api/common.js

@@ -24,4 +24,9 @@ export const apiGetEmailCode=params=>{
  */
 export const apiGetPermissionList=params=>{
     return httpGet('/public/get_apply_variety_list')
+}
+
+// 获取手机号
+export const apiGetWechatPhone=params=>{
+    return httpPost('/wechat/getEncryptInfo',params)
 }

+ 4 - 1
pages-activity/detail.vue

@@ -275,7 +275,10 @@ export default {
         // 跳转webview 打开报告
         handleOpenReport() {
             uni.navigateTo({
-                url: "/pages/webView?url=" + this.info.reportLink,
+                url: "/pages/webView",
+                success:(res)=>{
+                    res.eventChannel.emit('webUrl', { url:  this.info.reportLink})
+                }
             });
         },
 

+ 21 - 2
pages/login.vue

@@ -26,7 +26,7 @@
                         </view>
                     </picker>
                 </template>
-                <button slot="button" class="tel-btn" open-type="getPhoneNumber">获取手机号</button>
+                <button slot="button" class="tel-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取手机号</button>
             </van-field>
             <van-field
                 :value="verifyCode"
@@ -77,7 +77,7 @@
 </template>
 
 <script>
-import { apiGetSMSCode, apiGetEmailCode } from '@/api/common'
+import { apiGetSMSCode, apiGetEmailCode,apiGetWechatPhone } from '@/api/common'
 import { apiUserLogin } from '@/api/user'
 import { telVerify, emailVerify } from '@/utils/common'
 export default {
@@ -123,6 +123,25 @@ export default {
     },
     methods: {
 
+        // 获取微信绑定的手机号登录
+        async getPhoneNumber({detail}){
+            const res=await apiGetWechatPhone({
+                encryptedData:detail.encryptedData,
+                iv:detail.iv,
+                isBind:true,
+            })
+            if(res.code===200){
+                uni.switchTab({
+                    url: '/pages/activity/activity'
+                })
+                this.$store.dispatch('getUserInfo')
+                this.$store.dispatch('getTabBar')
+            }else if(res.code===400){
+                this.$store.commit('setToken', '')
+                this.$store.dispatch('getUserInfo')
+            }
+        },
+
         handleChange(){
             if(this.active==='手机号'){
                 this.active='邮箱'

+ 4 - 1
pages/webView.vue

@@ -10,7 +10,10 @@ export default {
         }
     },
     onLoad(options){
-        this.url=`${options.url}&token=${this.$store.state.user.token}`
+        const eventChannel = this.getOpenerEventChannel()
+        eventChannel.on('webUrl', (data)=> {
+            this.url=`${data.url}&token=${this.$store.state.user.token}`
+        })
     }
 }
 </script>

+ 0 - 1
utils/config.js

@@ -1,7 +1,6 @@
 // 配置文件
 
 const env=uni.getAccountInfoSync().miniProgram
-console.log(env);
 // 请求根路径
 let baseApiUrl=''
 if(env.envVersion==='develop'){//开发

+ 2 - 2
utils/request.js

@@ -93,7 +93,7 @@ const http=(url,params,method)=>{
 			success(e) {
 				// let res=JSON.parse(CryptoJS.Des3Decrypt(e.data));//解密
 				let res=e.data
-				if(res.code!==200&&res.code!==403&&res.code!==4001){
+				if(res.code!==200&&res.code!==403&&res.code!==4001&&res.code!==401){
 					showError(res)
 				}
 
@@ -108,7 +108,7 @@ const http=(url,params,method)=>{
 			fail(error) {
 				console.log(error);
 				uni.showToast({
-					title:'服务器错误',
+					title:'网络异常,稍后重试!',
 					icon:'none'
 				})
 			},