Procházet zdrojové kódy

注册页面修改

XSLu08042 před 1 týdnem
rodič
revize
ea5912e9b2
2 změnil soubory, kde provedl 79 přidání a 16 odebrání
  1. 3 3
      common/request.js
  2. 76 13
      pages_course/register.vue

+ 3 - 3
common/request.js

@@ -16,7 +16,8 @@ export default class Request {
 			token= uni.getStorageSync('AppTokenmini_RTCourse')
 			if(router.indexOf("/course_register")!=-1){
 				router = router.replace('/course_register','')
-				token= uni.getStorageSync('TOKEN_WEXIN')
+				//如果注册页面是服务号授权就放开
+				// token= uni.getStorageSync('TOKEN_WEXIN')
 			}
 		}
 		else{
@@ -28,7 +29,6 @@ export default class Request {
 		// 	title: '加载中'
 		// });
 		return new Promise((resolve, reject) => {
-			let token = uni.getStorageSync('AppToken');
 			var httpContentType='application/x-www-form-urlencoded';
 			if(contentType!=undefined){
 				//application/json;charset=UTF-8
@@ -78,7 +78,7 @@ export default class Request {
 						})
 						return;
 					}
-					if (res.data.token) {
+					if (res.data.token&&type != 1) {
 						uni.setStorageSync('AppToken',res.data.token)
 					}
 					resolve(res.data)

+ 76 - 13
pages_course/register.vue

@@ -16,7 +16,7 @@
 
 <script>
 	import { mapGetters } from 'vuex';
-	import {getRealLink,handleFsUserWx,isAddCompanyUser} from "@/api/course.js"
+	import {getRealLink,handleFsUserWx,isAddCompanyUser,loginByMp} from "@/api/course.js"
 	export default {
 		data() {
 			return {
@@ -24,7 +24,8 @@
 				isRegister: 0,
 				isLoading: false,
 				urlOption: {},
-				sortLink: ''
+				sortLink: '',
+				isLoginH5: 0, // 1服务号授权
 			}
 		},
 		computed:{
@@ -77,17 +78,31 @@
 					if(res.code == 200) {
 						if(res.config&&res.config.userCourseAuthDomain) {
 							uni.setStorageSync('weixinOauth',res.config.userCourseAuthDomain)
-							this.utils.isLoginResCourse().then(
-								isLogin => {
-									this.isLogin = isLogin
-									if(this.isLogin) {
-										this.getAddCompanyUser()
-									} else {
-										this.goLogin()
-									}
-								},
-								rej => {}
-							);
+							if(this.isLoginH5==0) {
+								this.utils.isLoginCourse().then(
+									isLogin => {
+										this.isLogin = isLogin
+										if(this.isLogin) {
+											this.getAddCompanyUser()
+										} else {
+											this.goLogin()
+										}
+									},
+									rej => {}
+								);
+							}else {
+								this.utils.isLoginResCourse().then(
+									isLogin => {
+										this.isLogin = isLogin
+										if(this.isLogin) {
+											this.getAddCompanyUser()
+										} else {
+											this.goLogin()
+										}
+									},
+									rej => {}
+								);
+							}
 						}else {
 							uni.showToast({
 								title: '授权地址错误',
@@ -109,6 +124,10 @@
 				})
 			},
 			goLogin(data) {
+				if(this.isLoginH5==0) {
+					this.goWXLogin()
+					return
+				}
 				if(data) {
 					this.utils.getProvider().then(provider=>{
 						console.log('当前的环境商',provider)
@@ -171,6 +190,50 @@
 						});
 					}
 				})
+			},
+			goWXLogin() {
+				this.utils.getProvider().then(provider=>{
+					console.log('当前的环境商',provider)
+					if (!provider) {
+					  reject()
+					}
+					uni.login({
+						provider: provider,
+						success: async loginRes => {
+							console.log(loginRes)
+							uni.getUserInfo({
+							   provider: provider,
+							   success: (infoRes)=> {
+								    uni.showToast({
+										title: '注册中...',
+										icon: 'loading'
+								    });
+									loginByMp({code: loginRes.code,encryptedData:infoRes.encryptedData,iv:infoRes.iv,appId:getApp().globalData.appId}).then(res=>{
+										 uni.hideLoading();
+										 if (res.code == 200) {
+											this.$store.commit('setCoureLogin', 1);
+											uni.setStorageSync('AppTokenmini_RTCourse', res.token);
+											uni.setStorageSync('auto_userInfo', JSON.stringify(res.user));
+											this.isLogin = true
+											this.getAddCompanyUser()
+										 } else {
+											uni.showToast({
+												title: res.msg,
+												icon: 'none'
+											});
+										 }
+									 }).catch(err=>{
+										uni.hideLoading();
+										uni.showToast({
+											icon:'none',
+											title: "登录失败,请重新登录",
+										});
+									});
+							   }
+							});
+						}
+					})
+				}).catch(err => {})
 			}
 		}
 	}