wangxy 1 month ago
parent
commit
32695dff8e
2 changed files with 76 additions and 40 deletions
  1. 26 40
      pages/login/index.vue
  2. 50 0
      utils/useExitApp.js

+ 26 - 40
pages/login/index.vue

@@ -1,24 +1,24 @@
 <template>
 <template>
 	<view class="ezy-login-page">
 	<view class="ezy-login-page">
-			<icon class="login-img"></icon>
-			<!-- 手机号 -->
-			<view class="login-body-box">
-				<view class="phone-input-box">
-					<view class="phone-prefix">+86</view>
-					<input class="phone-input" type="text" v-model="indexData.phoneNumber" placeholder="请输入手机号"
-						maxlength="11" @input="clearTelInput" />
-					<view class="close-btn" v-if="indexData.clearTelIcon" @click="clearTel"></view>
+		<icon class="login-img"></icon>
+		<!-- 手机号 -->
+		<view class="login-body-box">
+			<view class="phone-input-box">
+				<view class="phone-prefix">+86</view>
+				<input class="phone-input" type="text" v-model="indexData.phoneNumber" placeholder="请输入手机号"
+					maxlength="11" @input="clearTelInput" />
+				<view class="close-btn" v-if="indexData.clearTelIcon" @click="clearTel"></view>
+			</view>
+			<!-- 协议勾选框和按钮 -->
+			<view class="agreement-checkbox-box">
+				<checkbox-group @change="handleAgreementChange">
+					<checkbox class="agreement-checkbox-input" color="#FFFFFF" value="agree"
+						:checked="indexData.isAgreed" />
+				</checkbox-group>
+				<view class="agreement-text-box">
+					我已阅读并同意<view class="agreement-text" @click="agreeBtn('yhxy')">《用户协议》</view>和<view
+						@click="agreeBtn('ystk')" class="agreement-text">《隐私政策》</view>
 				</view>
 				</view>
-				<!-- 协议勾选框和按钮 -->
-				<view class="agreement-checkbox-box">
-					<checkbox-group @change="handleAgreementChange">
-						<checkbox class="agreement-checkbox-input" color="#FFFFFF" value="agree"
-							:checked="indexData.isAgreed" />
-					</checkbox-group>
-					<view class="agreement-text-box"> 
-						我已阅读并同意<view class="agreement-text" @click="agreeBtn('yhxy')">《用户协议》</view>和<view
-							@click="agreeBtn('ystk')" class="agreement-text">《隐私政策》</view>
-					</view>
 			</view>
 			</view>
 			<view class="login-btn" @click="getYzmBtn" :class="indexData.telStatus">发送验证码</view>
 			<view class="login-btn" @click="getYzmBtn" :class="indexData.telStatus">发送验证码</view>
 			<view class="bottom-btn-box">
 			<view class="bottom-btn-box">
@@ -28,7 +28,7 @@
 						<icon></icon>
 						<icon></icon>
 						<view>微信登录</view>
 						<view>微信登录</view>
 					</view>
 					</view>
-		<!-- 			<view class="yk-btn" @click="ykBtn">
+					<!-- 			<view class="yk-btn" @click="ykBtn">
 						<icon></icon>
 						<icon></icon>
 						<view>游客登录</view>
 						<view>游客登录</view>
 					</view> -->
 					</view> -->
@@ -56,7 +56,8 @@
 	} from "vue"
 	} from "vue"
 	import {
 	import {
 		onLoad,
 		onLoad,
-		onReady
+		onReady,
+		onBackPress
 	} from '@dcloudio/uni-app';
 	} from '@dcloudio/uni-app';
 	import agreeContentDialog from './agreeContentDialog.vue';
 	import agreeContentDialog from './agreeContentDialog.vue';
 	import agreeDialog from './agreeDialog.vue'
 	import agreeDialog from './agreeDialog.vue'
@@ -70,19 +71,14 @@
 	} from "@/utils/common";
 	} from "@/utils/common";
 	import telDialog from './telDialog.vue'
 	import telDialog from './telDialog.vue'
 	import cacheManager from "@/utils/cacheManager.js";
 	import cacheManager from "@/utils/cacheManager.js";
-
-	import {
-		onShow,
-		onUnload,
-	} from '@dcloudio/uni-app';
-	import {
-		useIsCanBack
-	} from "@/store/isCanBack.js"
 	import tipDialog from '@/components/dialog/tipDialog.vue';
 	import tipDialog from '@/components/dialog/tipDialog.vue';
 	import config from '../../config.js'
 	import config from '../../config.js'
 	import {
 	import {
 		error
 		error
 	} from "uview-plus";
 	} from "uview-plus";
+	import {useExitApp} from "@/utils/useExitApp.js"
+	
+	
 	let indexData = reactive({
 	let indexData = reactive({
 		phoneNumber: null,
 		phoneNumber: null,
 		clearTelIcon: false,
 		clearTelIcon: false,
@@ -105,18 +101,8 @@
 	const tipTitle = '升级提醒';
 	const tipTitle = '升级提醒';
 	const tipContent = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!';
 	const tipContent = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!';
 
 
-	const store = useIsCanBack();
-	onUnload(() => {
-		console.log('unload')
-		store.setIsCanBack(false)
-	})
-
-	onShow(() => {
-		setTimeout(() => {
-			console.log('onShow')
-			store.setIsCanBack(true)
-		}, 500)
-	})
+	// 初始化退出逻辑
+	useExitApp();
 
 
 	onLoad((options) => {
 	onLoad((options) => {
 		showAppleLogin.value = isIOS13OrAbove();
 		showAppleLogin.value = isIOS13OrAbove();

+ 50 - 0
utils/useExitApp.js

@@ -0,0 +1,50 @@
+	
+	import {ref} from "vue";
+	import {
+		onBackPress
+	} from '@dcloudio/uni-app';
+
+	export function useExitApp() {
+		const canExitApp = ref(false);
+		
+		onBackPress((options) => {
+			if (options.from === 'backbutton') {
+				// 鸿蒙返回键处理
+				return handleHarmonyOSBack()
+			}
+			return false
+		})
+		
+		function handleHarmonyOSBack() {
+			// 双击返回键退出应用
+			if (!canExitApp.value) {
+				canExitApp.value = true
+		
+				// 显示提示
+				uni.showToast({
+					title: '再按一次退出应用',
+					icon: 'none',
+					duration: 2000
+				})
+		
+				// 2秒后重置状态
+				setTimeout(() => {
+					canExitApp.value = false
+				}, 2000)
+		
+				return true // 拦截返回事件
+			} else {
+				// 退出应用
+				exitApp()
+				return true
+			}
+		}
+		
+		function exitApp() {
+			// #ifdef APP-PLUS || APP-PLUS-NVUE
+			// 鸿蒙系统退出应用
+			plus.runtime.quit()
+			// #endif
+		}
+		
+	}