From 7384baf9927c1faca7d79588b3df633613ff0be5 Mon Sep 17 00:00:00 2001 From: 陈鑫涛 <10125295+chen-xintao97@user.noreply.gitee.com> Date: Fri, 29 Aug 2025 09:00:15 +0800 Subject: [PATCH] app退出 --- src/routes/mobile/IndexMobile.js | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/routes/mobile/IndexMobile.js b/src/routes/mobile/IndexMobile.js index fb6423e..b683d36 100644 --- a/src/routes/mobile/IndexMobile.js +++ b/src/routes/mobile/IndexMobile.js @@ -78,7 +78,7 @@ class IndexMobile extends React.Component { const mine = commonFunc.showLocalMessage(this.props, 'mine', '我的'); scene const originTitle = { - message: message , + message: message, scene: scene, workbench: workbench, device: device, @@ -94,7 +94,24 @@ class IndexMobile extends React.Component { } } } - + componentDidMount() { + // 监听系统返回键 + const { plus } = window; + plus?.key?.addEventListener('backbutton', () => { + if (location.pathname === '/indexMobile') { + // 首页双击返回 + if (this.backPressedOnce) { + plus.runtime.quit(); + } else { + this.backPressedOnce = true; + plus.nativeUI.toast('再按一次退出应用'); + setTimeout(() => { this.backPressedOnce = false; }, 2000); + } + } else { + window.history.back(-1); + } + }); + } handleTouchStart = e => { this.setState({ touchStartPageX: e.changedTouches[0].pageX, @@ -115,7 +132,7 @@ class IndexMobile extends React.Component { const { plus } = window; if (location.pathname === "/indexMobile") { alert("确定退出吗?", "", [ - { text: "取消", onPress: () => {} }, + { text: "取消", onPress: () => { } }, { text: "是", onPress: () => plus.runtime.quit() }, // 关闭app ]); } else { @@ -227,7 +244,7 @@ class IndexMobile extends React.Component { if (location.pathname === "/indexMobile/quotationDetail") { return ( - + ) } else { return ( @@ -277,12 +294,12 @@ class IndexMobile extends React.Component { style={ this.state.fullScreen ? { - position: "fixed", - width: "100%", - top: "40px", - bottom: 0, - background: "#fff", - } + position: "fixed", + width: "100%", + top: "40px", + bottom: 0, + background: "#fff", + } : { height: 400 } } onTouchStart={this.handleTouchStart.bind(this)} @@ -362,7 +379,7 @@ class IndexMobile extends React.Component { commonBusiness.clearSocketData({ token, value: {}, sModelsId: 100 }); this.setState({ selectedTab: "scene", - title:scene, + title: scene, }); history.push("/indexMobile"); }} -- libgit2 0.22.2