App.uvue 3.0 KB
Newer Older
1 2
<script lang="uts">
import { state, setLifeCycleNum, setAppLaunchPath, setAppShowPath } from './store/index.uts'
3 4

let firstBackTime = 0
DCloud-WZF's avatar
DCloud-WZF 已提交
5
export default {
6
  onLaunch: function (options) {
DCloud-WZF's avatar
DCloud-WZF 已提交
7 8
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum + 1000)
9
    setAppLaunchPath(options.path)
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11
    console.log('App Launch')

H
hdx 已提交
12
    const performance = uni.getPerformance()
13 14 15
    const observer: PerformanceObserver = performance.createObserver((entryList: PerformanceObserverEntryList) => {
      console.log(entryList.getEntries())
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
16 17 18 19
    observer.observe({
      entryTypes: ['render', 'navigation'],
    } as PerformanceObserverOptions)
  },
20
  onShow: function (options) {
DCloud-WZF's avatar
DCloud-WZF 已提交
21 22
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum + 100)
23
    setAppShowPath(options.path)
DCloud-WZF's avatar
DCloud-WZF 已提交
24 25 26 27 28 29 30
    console.log('App Show')
  },
  onHide: function () {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum - 100)
    console.log('App Hide')
  },
31
  onLastPageBackPress: function () {
DCloud-WZF's avatar
DCloud-WZF 已提交
32 33
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum - 1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
34
    console.log('App LastPageBackPress')
35 36 37 38 39 40 41 42 43 44 45
    if (firstBackTime == 0) {
      uni.showToast({
        title: '再按一次退出应用',
        position: 'bottom',
      })
      firstBackTime = Date.now()
      setTimeout(() => {
        firstBackTime = 0
      }, 2000)
    } else if (Date.now() - firstBackTime < 2000) {
      firstBackTime = Date.now()
DCloud-WZF's avatar
DCloud-WZF 已提交
46
      uni.exit()
47
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
48
  },
DCloud-WZF's avatar
DCloud-WZF 已提交
49 50 51
  onExit() {
    console.log('App Exit')
  },
52 53 54 55 56 57 58 59 60 61 62 63
  methods: {
    checkLaunchPath(): boolean{
      const HOME_PATH = '/pages/index'
      if(state.appLaunchPath != HOME_PATH){
        return false
      }
      if(state.appShowPath != HOME_PATH){
        return false
      }
      return true
    }
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
64
}
H
init.  
hdx 已提交
65 66 67
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
68
/* @font-face {
H
init.  
hdx 已提交
69 70 71 72 73 74
    font-family: uniicons;
    font-weight: normal;
    font-style: normal;
    src: url('./static/fonts/uni.ttf') format('truetype');
  } */

DCloud-WZF's avatar
DCloud-WZF 已提交
75 76 77 78 79 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
.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;
}
</style>