wangxy 1 месяц назад
Родитель
Сommit
b1f1382c7f
4 измененных файлов с 53 добавлено и 2 удалено
  1. 4 0
      pages/chanpinMy/my.vue
  2. 5 0
      pages/chanpinXuanze/index.vue
  3. 42 0
      pages/chanpinneirong/index.vue
  4. 2 2
      utils/useExitApp.js

+ 4 - 0
pages/chanpinMy/my.vue

@@ -49,6 +49,10 @@
 		ref
 	} from "vue";
 	
+	import {useExitApp} from "@/utils/useExitApp.js"
+	// 初始化退出逻辑
+	useExitApp();
+	
 	let currentTabIndex = ref(3)
 	let myInfoData = reactive({
 		userImg: '',

+ 5 - 0
pages/chanpinXuanze/index.vue

@@ -43,6 +43,11 @@
 	} from "@dcloudio/uni-app"
 	import * as shuxueHttp from "@/api/chanpinShuxue.js"
 	import CustomTabBar from "@/components/custom-tabbar/index.vue";
+	
+	import {useExitApp} from "@/utils/useExitApp.js"
+	// 初始化退出逻辑
+	useExitApp();
+	
 	let currentTabIndex = ref(0)
 	const data = reactive({
 		list: [{

+ 42 - 0
pages/chanpinneirong/index.vue

@@ -80,6 +80,8 @@
 	export default {
 		data() {
 			return {
+				canExitApp: false,
+				
 				danyuanList: [],
 				currentUnitName: "",
 				isShow: true,
@@ -138,7 +140,47 @@
 				this.loadDataFromApi();
 			}
 		},
+		// 返回处理
+		onBackPress(options) {
+			if (options.from === 'backbutton') {
+				// 返回键处理
+				return this.handleHarmonyOSBack()
+			}
+			return false
+		}),
 		methods: {
+			handleHarmonyOSBack() {
+				// 双击返回键退出应用
+				if (!this.canExitApp) {
+					this.canExitApp = true
+			
+					// 显示提示
+					uni.showToast({
+						title: '再按一次退出应用',
+						icon: 'none',
+						duration: 2000
+					})
+			
+					// 2秒后重置状态
+					setTimeout(() => {
+						this.canExitApp = false
+					}, 2000)
+			
+					return true // 拦截返回事件
+				} else {
+					// 退出应用
+					this.exitApp()
+					return true
+				}
+			}
+			exitApp() {
+				// #ifdef APP-PLUS || APP-PLUS-NVUE
+				// 系统退出应用
+				plus.runtime.quit()
+				// #endif
+			},
+			
+			
 			// 从缓存初始化方法
 			initFromCache(cacheData) {
 				this.banbenInfo = cacheData;

+ 2 - 2
utils/useExitApp.js

@@ -9,7 +9,7 @@
 		
 		onBackPress((options) => {
 			if (options.from === 'backbutton') {
-				// 鸿蒙返回键处理
+				// 返回键处理
 				return handleHarmonyOSBack()
 			}
 			return false
@@ -42,7 +42,7 @@
 		
 		function exitApp() {
 			// #ifdef APP-PLUS || APP-PLUS-NVUE
-			// 鸿蒙系统退出应用
+			// 系统退出应用
 			plus.runtime.quit()
 			// #endif
 		}