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

4
let firstBackTime = 0
5 6
export default {
  onLaunch: function () {
7
    // 自动化测试
DCloud-WZF's avatar
DCloud-WZF 已提交
8
    setLifeCycleNum(state.lifeCycleNum + 1000)
9
    console.log('App Launch')
H
hdx 已提交
10 11 12 13 14 15 16 17 18 19 20

    // 页面性能分析
    // const performance = uni.getPerformance()
    // const observer1: PerformanceObserver = performance.createObserver(
    //   (entryList: PerformanceObserverEntryList) => {
    //     console.log('observer1:entryList.getEntries()' +JSON.stringify(entryList.getEntries()))
    //   }
    // )
    // observer1.observe({
    //   entryTypes: ['render', 'navigation'],
    // } as PerformanceObserverOptions)
21 22
  },
  onShow: function () {
23
    // 自动化测试
DCloud-WZF's avatar
DCloud-WZF 已提交
24
    setLifeCycleNum(state.lifeCycleNum + 100)
25
    console.log('App Show')
26 27
  },
  onHide: function () {
28
    // 自动化测试
DCloud-WZF's avatar
DCloud-WZF 已提交
29
    setLifeCycleNum(state.lifeCycleNum - 100)
30
    console.log('App Hide')
31
  },
M
mehaotian 已提交
32
  onLastPageBackPress: function () {
33
    // 自动化测试
DCloud-WZF's avatar
DCloud-WZF 已提交
34
    setLifeCycleNum(state.lifeCycleNum - 1000)
DCloud-WZF's avatar
DCloud-WZF 已提交
35
    console.log('App LastPageBackPress')
36 37 38 39 40 41 42 43 44 45 46
    if (firstBackTime == 0) {
      uni.showToast({
        title: '再按一次退出应用',
        position: 'bottom',
      })
      firstBackTime = Date.now()
      setTimeout(() => {
        firstBackTime = 0
      }, 2000)
    } else if (Date.now() - firstBackTime < 2000) {
      firstBackTime = Date.now()
47
      uni.exit()
48
    }
49
  },
DCloud-WZF's avatar
DCloud-WZF 已提交
50 51 52
  onExit(){
		console.log('App Exit')
	},
DCloud-WZF's avatar
DCloud-WZF 已提交
53 54 55 56 57 58
  methods: {
    increasetLifeCycleNum() {
      setLifeCycleNum(state.lifeCycleNum + 100)
      console.log('App increasetLifeCycleNum')
    }
  }
59
}
Y
init  
yurj26 已提交
60 61 62
</script>

<style>
63
/*每个页面公共css */
DCloud-WZF's avatar
DCloud-WZF 已提交
64
@import "./common/uni.css";
65 66 67 68 69 70 71 72 73 74

/* #ifdef H5 */
@media screen and (min-width: 768px) {
  body {
    overflow-y: scroll;
  }
}

/* 顶栏通栏样式 */
/* .uni-top-window {
Y
yurj26 已提交
75 76 77 78
  	    left: 0;
  	    right: 0;
  	} */

79 80 81 82 83
uni-page-body {
  background-color: #f5f5f5 !important;
  min-height: 100% !important;
  height: auto !important;
}
Y
yurj26 已提交
84

85 86 87
.uni-top-window uni-tabbar .uni-tabbar {
  background-color: #fff !important;
}
Y
yurj26 已提交
88

89 90 91
.uni-app--showleftwindow .hideOnPc {
  display: none !important;
}
Y
yurj26 已提交
92

93 94
.uni-row {
  flex-direction: row;
95
}
96 97
.uni-column {
  flex-direction: column;
98 99
}

100 101
/* #endif */
</style>