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

Y
yurj26 已提交
4
  let firstBackTime = 0
DCloud-WZF's avatar
DCloud-WZF 已提交
5 6 7 8 9 10 11 12 13 14 15 16
  export default {
    globalData: {
      str: 'default globalData str',
      num: 0,
      bool: false,
      obj: {
        str: 'default globalData obj str',
        num: 0,
        bool: false,
      },
      null: null as string | null,
      arr: [] as number[],
DCloud-WZF's avatar
DCloud-WZF 已提交
17 18
      mySet: new Set<string>(),
      myMap: new Map<string, any>(),
19 20
      func: () : string => {
        return 'globalData func'
DCloud-WZF's avatar
DCloud-WZF 已提交
21
      }
22
    },
Y
yurj26 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    onLaunch: function () {
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum + 1000)
      console.log('App Launch')

      // 页面性能分析
      // 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)
    },
    onShow: function () {
      // 自动化测试
DCloud-WZF's avatar
DCloud-WZF 已提交
41
      setLifeCycleNum(state.lifeCycleNum + 100)
Y
yurj26 已提交
42 43 44 45 46 47 48 49
      console.log('App Show')
    },
    onHide: function () {
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum - 100)
      console.log('App Hide')
    },
    onLastPageBackPress: function () {
50
      // #ifdef APP-ANDROID
Y
yurj26 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
      // 自动化测试
      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()
      }
67
      // #endif
Y
yurj26 已提交
68 69 70 71 72 73 74 75 76
    },
    onExit() {
      console.log('App Exit')
    },
    methods: {
      increasetLifeCycleNum() {
        setLifeCycleNum(state.lifeCycleNum + 100)
        console.log('App increasetLifeCycleNum')
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
77 78
    }
  }
Y
init  
yurj26 已提交
79 80 81
</script>

<style>
Y
yurj26 已提交
82 83
  /*每个页面公共css */
  @import "./common/uni.css";
DCloud-WZF's avatar
DCloud-WZF 已提交
84
</style>