wangxy 4 mēneši atpakaļ
vecāks
revīzija
fec3d14b9e
5 mainītis faili ar 164 papildinājumiem un 125 dzēšanām
  1. 17 10
      App.vue
  2. 1 1
      pages.json
  3. 132 112
      pages/login/index.vue
  4. 2 2
      pages/my/index.vue
  5. 12 0
      store/isCanBack.js

+ 17 - 10
App.vue

@@ -7,9 +7,10 @@
 		getUserIdentity
 	} from "@/utils/common";
 	import cacheManager from "@/utils/cacheManager.js";
+	import {useIsCanBack} from "@/store/isCanBack.js"
 	export default {
-			
-		// creat by wgy 0619  生命周期 钩子  
+
+		// creat by wgy 0619  生命周期 钩子
 		onLaunch: function() {
 			// #ifdef APP-PLUS
 			if (cacheManager.get('auth')) {
@@ -34,7 +35,6 @@
 					// #endif
 		},
 		onShow: function() {
-
 			// #ifdef APP-PLUS
 			// if (cacheManager.get('auth')) {	
 			// 	uni.reLaunch({
@@ -51,28 +51,33 @@
 			// }
 			const webview = plus.webview.currentWebview();
 			plus.key.addEventListener('backbutton', () => {
-				event.preventDefault();
-				return false
+				const store = useIsCanBack();
+				if (!store.isCanBack) {
+					event.preventDefault();
+					return false
+				} else {
+					return true
+				}
 			});
 			// #endif
 		},
 		onHide: function() {
 	// 	//	console.log('App Hide')
 	// 	// #ifdef APP-PLUS
-	// 	if (cacheManager.get('auth')) {	
+	// 	if (cacheManager.get('auth')) {
 	// 		uni.reLaunch({
 	// 			url: `/pages/study/index`
 	// 		})
 	// 	}else if(!(cacheManager.get('wxLogin').bind)){
 	// 			console.log('asdfadsfadsfasd')
-	// 		// 微信登录且未绑定 
+	// 		// 微信登录且未绑定
 	// 	} else {
 	// 		cacheManager.clearAll()
 	// 		uni.redirectTo({
-	// 			url: '/pages/login/index' 
+	// 			url: '/pages/login/index'
 	// 		});
 	// 	}
-	
+
 	// 	// #endif
 
 		}
@@ -84,7 +89,9 @@
 	@import '/common/styles/index.scss';
 
 	// 西文、雅黑、黑体、宋体
-	body,html,#app {
+	body,
+	html,
+	#app {
 		font-family: "Helvetica Neue", "Microsoft YaHei", "SimHei", "SimSun", "Arial", sans-serif;
 		margin: 0;
 		padding: 0;

+ 1 - 1
pages.json

@@ -137,7 +137,7 @@
 		//"animationDuration": "0",
 		//禁止滑动返回
 		"app-plus": {
-					"popGesture": "none"
+					// "popGesture": "none"
 				}
 		/* "app-plus": {
 			"background": "#efeff4"

+ 132 - 112
pages/login/index.vue

@@ -59,6 +59,13 @@
 	} from "@/utils/common";
 	import telDialog from './telDialog.vue'
 	import cacheManager from "@/utils/cacheManager.js";
+
+	import {
+		onShow,
+		onUnload,
+	} from '@dcloudio/uni-app';
+	import {useIsCanBack} from "@/store/isCanBack.js"
+
 	import {
 		error
 	} from "uview-plus";
@@ -76,24 +83,37 @@
 	const agreeWxDialog = ref(null);
 	const telDialogRef = ref(null);
 	let telDialogFlag = ref(false);
-	let showAppleLogin = ref(false);
+	let showAppleLogin = ref(false);
 	let wxFlag = ref(true);
+	
+	const store = useIsCanBack();
+	onUnload(() => {
+		console.log('unload')
+		store.setIsCanBack(false)
+	})
+	
+	onShow(() => {
+		setTimeout(() => {
+			console.log('onShow')
+			store.setIsCanBack(true)
+		},500)
+	})
 
 	onLoad((options) => {
-		showAppleLogin.value = isIOS13OrAbove();
-		if(plus.runtime.isApplicationExist({ pname: 'com.tencent.mm', action: 'weixin://' })) {
-				console.log('111',"已安装微信");
-					wxFlag.value = true
-		}else{
-			wxFlag.value = false
-		}
+		showAppleLogin.value = isIOS13OrAbove();
+		if(plus.runtime.isApplicationExist({ pname: 'com.tencent.mm', action: 'weixin://' })) {
+				console.log('111',"已安装微信");
+					wxFlag.value = true
+		}else{
+			wxFlag.value = false
+		}
 		console.log('showAppleLogin.value',showAppleLogin.value);
 	})
 
 	const getYzmBtn = () => {
 		if (indexData.telStatus === 'tel-btn-normal') {
 			if (indexData.isAgreed === true) {
-				uni.navigateTo({
+				uni.redirectTo({
 					url: `/pages/login/login?telNum=${indexData.phoneNumber}`
 				})
 			} else {
@@ -132,15 +152,15 @@
 	}
 
 	const ykConfirmBtn = () => {
-		uni.navigateTo({
+		uni.redirectTo({
 			url: `/pages/selectGradesTerms/index`
 		})
 	}
-	
+
 	const wxConfirmBtn= () => {
 		wxLoginFun();
 	}
-	
+
 	// 手机号校验规则
 	const validatePhoneNumber = (value) => {
 		const phoneRegex = /^1[3-9]\d{9}$/;
@@ -202,41 +222,41 @@
 					"code": loginRes.appleInfo.user
 				}
 				console.log(req);
-			console.log(req);
-			wxLogin(req).then(res => {
-				console.log(res);
-				if (!res.data.bind) {
-					console.log('未绑定');
-					cacheManager.set('wxLogin', {
-						bind: res.data.bing
-					})
-					telDialogFlag.value = true;
-					nextTick(() => {
-						telDialogRef.value.getOpenId(res.data.openId);
-					})
-				} else {
-					uni.showLoading({
-						title: '登录中'
-					});
-					setTimeout(() => {
-						cacheManager.set('auth', res.data.loginVo)
-						if (res.data.loginVo.cardId == 0) {
-			
-							uni.redirectTo({
-								url: `/pages/selectGradesTerms/index`
-							})
-							uni.hideLoading();
-						} else {
-			
-							uni.redirectTo({
-								url: `/pages/study/index`
-							})
-							uni.hideLoading();
-						}
-					}, 1000)
-				}
-			}).catch((error) => {
-				console.log(error);
+			console.log(req);
+			wxLogin(req).then(res => {
+				console.log(res);
+				if (!res.data.bind) {
+					console.log('未绑定');
+					cacheManager.set('wxLogin', {
+						bind: res.data.bing
+					})
+					telDialogFlag.value = true;
+					nextTick(() => {
+						telDialogRef.value.getOpenId(res.data.openId);
+					})
+				} else {
+					uni.showLoading({
+						title: '登录中'
+					});
+					setTimeout(() => {
+						cacheManager.set('auth', res.data.loginVo)
+						if (res.data.loginVo.cardId == 0) {
+
+							uni.redirectTo({
+								url: `/pages/selectGradesTerms/index`
+							})
+							uni.hideLoading();
+						} else {
+
+							uni.redirectTo({
+								url: `/pages/study/index`
+							})
+							uni.hideLoading();
+						}
+					}, 1000)
+				}
+			}).catch((error) => {
+				console.log(error);
 			})
 			},
 			fail: function(err) {
@@ -246,8 +266,8 @@
 			}
 		});
 	}
-	
-	
+
+
 	// 游客登录
 	const wxLoginClick = () => {
 		if (indexData.isAgreed === true) {
@@ -256,7 +276,7 @@
 			agreeWxDialog.value.handleShow();
 		}
 	}
-	
+
 	const wxLoginFun= () => {
 		//获取服务商信息判断手机端是否安装了app
 		// uni.getProvider({
@@ -274,68 +294,68 @@
 		// 	  });
 		//    }
 		// });
-		
-		if(plus.runtime.isApplicationExist({ pname: 'com.tencent.mm', action: 'weixin://' })) {
-			console.log('111',"已安装微信");
-		uni.login({
-			"provider": "weixin",
-			"onlyAuthorize": true, // 微信登录仅请求授权认证
-			success: function(event) {
-				console.log(event);
-				const {
-					code
-				} = event
-				//客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
-				let req = {
-					"apple": false,
-					"code": code
-				}
-				console.log(req);
-				wxLogin(req).then(res => {
-					console.log(res);
-					if (!res.data.bind) {
-						console.log('未绑定');
-						cacheManager.set('wxLogin', {
-							bind: res.data.bing
-						})
-						telDialogFlag.value = true;
-						nextTick(() => {
-							telDialogRef.value.getOpenId(res.data.openId);
-						})
-					} else {
-						uni.showLoading({
-							title: '登录中'
-						});
-						setTimeout(() => {
-							cacheManager.set('auth', res.data.loginVo)
-							if (res.data.loginVo.cardId == 0) {
-		
-								uni.redirectTo({
-									url: `/pages/selectGradesTerms/index`
-								})
-								uni.hideLoading();
-							} else {
-		
-								uni.redirectTo({
-									url: `/pages/study/index`
-								})
-								uni.hideLoading();
-							}
-						}, 1000)
-					}
-				}).catch((error) => {
-					console.log(error);
-				})
-			},
-			fail: function(err) {
-				console.log(err);
-				// 登录授权失败
-				// err.code是错误码
-			}
-		})
-		} else {
-			toast("请重启应用重试")
-			return false
+
+		if(plus.runtime.isApplicationExist({ pname: 'com.tencent.mm', action: 'weixin://' })) {
+			console.log('111',"已安装微信");
+		uni.login({
+			"provider": "weixin",
+			"onlyAuthorize": true, // 微信登录仅请求授权认证
+			success: function(event) {
+				console.log(event);
+				const {
+					code
+				} = event
+				//客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
+				let req = {
+					"apple": false,
+					"code": code
+				}
+				console.log(req);
+				wxLogin(req).then(res => {
+					console.log(res);
+					if (!res.data.bind) {
+						console.log('未绑定');
+						cacheManager.set('wxLogin', {
+							bind: res.data.bing
+						})
+						telDialogFlag.value = true;
+						nextTick(() => {
+							telDialogRef.value.getOpenId(res.data.openId);
+						})
+					} else {
+						uni.showLoading({
+							title: '登录中'
+						});
+						setTimeout(() => {
+							cacheManager.set('auth', res.data.loginVo)
+							if (res.data.loginVo.cardId == 0) {
+
+								uni.redirectTo({
+									url: `/pages/selectGradesTerms/index`
+								})
+								uni.hideLoading();
+							} else {
+
+								uni.redirectTo({
+									url: `/pages/study/index`
+								})
+								uni.hideLoading();
+							}
+						}, 1000)
+					}
+				}).catch((error) => {
+					console.log(error);
+				})
+			},
+			fail: function(err) {
+				console.log(err);
+				// 登录授权失败
+				// err.code是错误码
+			}
+		})
+		} else {
+			toast("请重启应用重试")
+			return false
 		}
 	}
 </script>

+ 2 - 2
pages/my/index.vue

@@ -118,14 +118,14 @@
 			logout().then(res => {
 					toast('退出登录成功')
 				cacheManager.clearAll();
-				uni.redirectTo({
+				uni.reLaunch({
 					url: '/pages/login/index'
 				});
 			}).catch(err => {
 				toast('退出登录失败,请稍后重试')
 			})
 		}else{
-			uni.redirectTo({
+			uni.reLaunch({
 				url: '/pages/login/index'
 			});
 		}

+ 12 - 0
store/isCanBack.js

@@ -0,0 +1,12 @@
+import { defineStore } from 'pinia';
+
+export const useIsCanBack = defineStore('isCanBack', {
+	state: () => {
+		return { isCanBack: true };
+	},
+	actions: {
+		setIsCanBack(val) {
+			this.isCanBack = val;
+		},
+	},
+});