App.uvue 3.5 KB
Newer Older
1
<script lang="uts">
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
  import { state, setLifeCycleNum, setAppLaunchPath, setAppShowPath } from './store/index.uts'

  let firstBackTime = 0
  export default {
    onLaunch: function (options) {
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum + 1000)
      setAppLaunchPath(options.path)
      console.log('App Launch')
      // #ifdef UNI-APP-X && APP-ANDROID
      const performance = uni.getPerformance()
      const observer : PerformanceObserver = performance.createObserver((entryList : PerformanceObserverEntryList) => {
        console.log('observer:entryList.getEntries()')
        console.log(entryList.getEntries())
      })
      observer.observe({
        entryTypes: ['render', 'navigation'],
      } as PerformanceObserverOptions)
      // #endif
    },
    onShow: function (options) {
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum + 100)
      setAppShowPath(options.path)
      console.log('App Show')
    },
    onHide: function () {
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum - 100)
      console.log('App Hide')
    },
    // #ifdef APP-ANDROID
    onLastPageBackPress: function () {
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum - 1000)
      console.log('App LastPageBackPress')
      if (firstBackTime == 0) {
        uni.showToast({
          title: '再按一次退出应用',
          position: 'bottom',
        })
        firstBackTime = Date.now()
        setTimeout(() => {
          firstBackTime = 0
        }, 2000)
      } else if (Date.now() - firstBackTime < 2000) {
        firstBackTime = Date.now()
        uni.exit()
      }
    },
    // #endif
    onExit() {
      console.log('App Exit')
    },
    methods: {
      checkLaunchPath() : boolean {
58
        const HOME_PATH = '/pages/tab-bar/options-api'
DCloud-WZF's avatar
DCloud-WZF 已提交
59 60 61 62 63 64 65 66 67 68
        if (state.appLaunchPath != HOME_PATH) {
          return false
        }
        if (state.appShowPath != HOME_PATH) {
          return false
        }
        return true
      }
    }
  }
69 70 71
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
72 73
  @import "./common/uni.css";
  /* @font-face {
74 75 76 77 78 79
    font-family: uniicons;
    font-weight: normal;
    font-style: normal;
    src: url('./static/fonts/uni.ttf') format('truetype');
  } */

DCloud-WZF's avatar
DCloud-WZF 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
  .page {
    padding: 15px;
  }

  .uni-panel {
    margin-bottom: 12px;
  }

  .uni-panel-h {
    background-color: #ffffff;
    flex-direction: row;
    align-items: center;
    padding: 12px;
  }

  .uni-panel-h-on {
    background-color: #f0f0f0;
  }

  .uni-panel-text {
    color: #000000;
    font-size: 14px;
    font-weight: normal;
  }

  .uni-panel-icon-on {
    transform: rotate(180deg);
  }

  .uni-navigate-item {
    flex-direction: row;
    align-items: center;
    background-color: #ffffff;
    border-top-style: solid;
    border-top-color: #f0f0f0;
    border-top-width: 1px;
    padding: 12px;
    justify-content: space-between;
  }

  .uni-navigate-item:active {
    background-color: #f8f8f8;
  }

  .uni-navigate-text {
    color: #000000;
    font-size: 12px;
    opacity: 0.8;
  }

  .uni-navigate-icon {
    margin-left: 15px;
    color: #999999;
    font-size: 14px;
    font-weight: normal;
  }

  .text-disabled {
    color: #a0a0a0;
  }

  .list-item-text {
    line-height: 36px;
  }

  .split-title {
    margin: 20px 0 5px;
    padding: 5px 0;
    border-bottom: 1px solid #dfdfdf;
  }

  .btn-view {
    margin: 10px 0;
    padding: 10px;
    border: 1px solid #dfdfdf;
    border-radius: 3px;
  }
157
</style>