点我去Gitee
点我去Gitee

退出app操作

退出app操作


componentDidMount() {
    //plusPredy准备工作  用于监听首页退出事件
    if (window.plus) {//当有plus时,直接plusPredy
      this.plusready.bind(this)()
    } else {//当没有plus时,要先创造plusready事件
      document.addEventListener('plusready', this.plusready.bind(this), false)
    }
  }

plusready() {
// 监听首页退出
    let first = null
    plus.key.addEventListener('backbutton', function () {
      if (!first) {//若2s内没有连续点击返回按钮 则只弹出提示 不退出
        first = new Date().getTime()
        plus.nativeUI.toast("再按一次退出应用", {
          background: 'rgba(255, 255, 255, 0.6)',
        })
        setTimeout(function () {
          first = null
        }, 2000)
      } else {//若2s内连续点击返回键 则退出
        if (new Date().getTime() - first < 2000) {
          plus.storage.clear()//清空缓存
          plus.runtime.quit()//退出app
        }
      }
    }, false)
}
posted @ 2021-10-19 11:00  biuo  阅读(156)  评论(0编辑  收藏  举报