App.uvue 3.7 KB
Newer Older
1
<script lang="uts">
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6
  import { state, setLifeCycleNum, setAppLaunchPath, setAppShowPath } from './store/index.uts'

  let firstBackTime = 0
  export default {
    onLaunch: function (options) {
雪洛's avatar
雪洛 已提交
7
      console.log(options)
DCloud-WZF's avatar
DCloud-WZF 已提交
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 58
      // 自动化测试
      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 {
雪洛's avatar
雪洛 已提交
59
        // #ifdef APP
60
        const HOME_PATH = '/pages/tab-bar/options-api'
雪洛's avatar
雪洛 已提交
61 62 63 64
        // #endif
        // #ifdef WEB
        const HOME_PATH = 'pages/tab-bar/options-api'
        // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
65 66 67 68 69 70 71 72 73 74
        if (state.appLaunchPath != HOME_PATH) {
          return false
        }
        if (state.appShowPath != HOME_PATH) {
          return false
        }
        return true
      }
    }
  }
75 76 77
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
78 79
  @import "./common/uni.css";
  /* @font-face {
80 81 82 83 84 85
    font-family: uniicons;
    font-weight: normal;
    font-style: normal;
    src: url('./static/fonts/uni.ttf') format('truetype');
  } */

DCloud-WZF's avatar
DCloud-WZF 已提交
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 157 158 159 160 161 162
  .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;
  }
163
</style>