Commit 7384baf9927c1faca7d79588b3df633613ff0be5
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 | 78 | const mine = commonFunc.showLocalMessage(this.props, 'mine', '我的'); |
| 79 | 79 | scene |
| 80 | 80 | const originTitle = { |
| 81 | - message: message , | |
| 81 | + message: message, | |
| 82 | 82 | scene: scene, |
| 83 | 83 | workbench: workbench, |
| 84 | 84 | device: device, |
| ... | ... | @@ -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 | 115 | handleTouchStart = e => { |
| 99 | 116 | this.setState({ |
| 100 | 117 | touchStartPageX: e.changedTouches[0].pageX, |
| ... | ... | @@ -115,7 +132,7 @@ class IndexMobile extends React.Component { |
| 115 | 132 | const { plus } = window; |
| 116 | 133 | if (location.pathname === "/indexMobile") { |
| 117 | 134 | alert("确定退出吗?", "", [ |
| 118 | - { text: "取消", onPress: () => {} }, | |
| 135 | + { text: "取消", onPress: () => { } }, | |
| 119 | 136 | { text: "是", onPress: () => plus.runtime.quit() }, // 关闭app |
| 120 | 137 | ]); |
| 121 | 138 | } else { |
| ... | ... | @@ -227,7 +244,7 @@ class IndexMobile extends React.Component { |
| 227 | 244 | if (location.pathname === "/indexMobile/quotationDetail") { |
| 228 | 245 | return ( |
| 229 | 246 | |
| 230 | - <QuotationDetail {...this.props} sModelType={pageText} sModelsId="101251240115016076506222050" /> | |
| 247 | + <QuotationDetail {...this.props} sModelType={pageText} sModelsId="101251240115016076506222050" /> | |
| 231 | 248 | ) |
| 232 | 249 | } else { |
| 233 | 250 | return ( |
| ... | ... | @@ -277,12 +294,12 @@ class IndexMobile extends React.Component { |
| 277 | 294 | style={ |
| 278 | 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 | 303 | : { height: 400 } |
| 287 | 304 | } |
| 288 | 305 | onTouchStart={this.handleTouchStart.bind(this)} |
| ... | ... | @@ -362,7 +379,7 @@ class IndexMobile extends React.Component { |
| 362 | 379 | commonBusiness.clearSocketData({ token, value: {}, sModelsId: 100 }); |
| 363 | 380 | this.setState({ |
| 364 | 381 | selectedTab: "scene", |
| 365 | - title:scene, | |
| 382 | + title: scene, | |
| 366 | 383 | }); |
| 367 | 384 | history.push("/indexMobile"); |
| 368 | 385 | }} | ... | ... |