Commit 7384baf9927c1faca7d79588b3df633613ff0be5

Authored by 陈鑫涛
1 parent f6c45ea4

app退出

Showing 1 changed file with 28 additions and 11 deletions
src/routes/mobile/IndexMobile.js
@@ -78,7 +78,7 @@ class IndexMobile extends React.Component { @@ -78,7 +78,7 @@ class IndexMobile extends React.Component {
78 const mine = commonFunc.showLocalMessage(this.props, 'mine', '我的'); 78 const mine = commonFunc.showLocalMessage(this.props, 'mine', '我的');
79 scene 79 scene
80 const originTitle = { 80 const originTitle = {
81 - message: message , 81 + message: message,
82 scene: scene, 82 scene: scene,
83 workbench: workbench, 83 workbench: workbench,
84 device: device, 84 device: device,
@@ -94,7 +94,24 @@ class IndexMobile extends React.Component { @@ -94,7 +94,24 @@ class IndexMobile extends React.Component {
94 } 94 }
95 } 95 }
96 } 96 }
97 - 97 + componentDidMount() {
  98 + // 监听系统返回键
  99 + const { plus } = window;
  100 + plus?.key?.addEventListener('backbutton', () => {
  101 + if (location.pathname === '/indexMobile') {
  102 + // 首页双击返回
  103 + if (this.backPressedOnce) {
  104 + plus.runtime.quit();
  105 + } else {
  106 + this.backPressedOnce = true;
  107 + plus.nativeUI.toast('再按一次退出应用');
  108 + setTimeout(() => { this.backPressedOnce = false; }, 2000);
  109 + }
  110 + } else {
  111 + window.history.back(-1);
  112 + }
  113 + });
  114 + }
98 handleTouchStart = e => { 115 handleTouchStart = e => {
99 this.setState({ 116 this.setState({
100 touchStartPageX: e.changedTouches[0].pageX, 117 touchStartPageX: e.changedTouches[0].pageX,
@@ -115,7 +132,7 @@ class IndexMobile extends React.Component { @@ -115,7 +132,7 @@ class IndexMobile extends React.Component {
115 const { plus } = window; 132 const { plus } = window;
116 if (location.pathname === "/indexMobile") { 133 if (location.pathname === "/indexMobile") {
117 alert("确定退出吗?", "", [ 134 alert("确定退出吗?", "", [
118 - { text: "取消", onPress: () => {} }, 135 + { text: "取消", onPress: () => { } },
119 { text: "是", onPress: () => plus.runtime.quit() }, // 关闭app 136 { text: "是", onPress: () => plus.runtime.quit() }, // 关闭app
120 ]); 137 ]);
121 } else { 138 } else {
@@ -227,7 +244,7 @@ class IndexMobile extends React.Component { @@ -227,7 +244,7 @@ class IndexMobile extends React.Component {
227 if (location.pathname === "/indexMobile/quotationDetail") { 244 if (location.pathname === "/indexMobile/quotationDetail") {
228 return ( 245 return (
229 246
230 - <QuotationDetail {...this.props} sModelType={pageText} sModelsId="101251240115016076506222050" /> 247 + <QuotationDetail {...this.props} sModelType={pageText} sModelsId="101251240115016076506222050" />
231 ) 248 )
232 } else { 249 } else {
233 return ( 250 return (
@@ -277,12 +294,12 @@ class IndexMobile extends React.Component { @@ -277,12 +294,12 @@ class IndexMobile extends React.Component {
277 style={ 294 style={
278 this.state.fullScreen 295 this.state.fullScreen
279 ? { 296 ? {
280 - position: "fixed",  
281 - width: "100%",  
282 - top: "40px",  
283 - bottom: 0,  
284 - background: "#fff",  
285 - } 297 + position: "fixed",
  298 + width: "100%",
  299 + top: "40px",
  300 + bottom: 0,
  301 + background: "#fff",
  302 + }
286 : { height: 400 } 303 : { height: 400 }
287 } 304 }
288 onTouchStart={this.handleTouchStart.bind(this)} 305 onTouchStart={this.handleTouchStart.bind(this)}
@@ -362,7 +379,7 @@ class IndexMobile extends React.Component { @@ -362,7 +379,7 @@ class IndexMobile extends React.Component {
362 commonBusiness.clearSocketData({ token, value: {}, sModelsId: 100 }); 379 commonBusiness.clearSocketData({ token, value: {}, sModelsId: 100 });
363 this.setState({ 380 this.setState({
364 selectedTab: "scene", 381 selectedTab: "scene",
365 - title:scene, 382 + title: scene,
366 }); 383 });
367 history.push("/indexMobile"); 384 history.push("/indexMobile");
368 }} 385 }}