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

W
wanganxp 已提交
4
  // #ifdef APP-ANDROID
5
  let firstBackTime = 0
W
wanganxp 已提交
6
  // #endif
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  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[],
      mySet: new Set<string>(),
      myMap: new Map<string, any>(),
      func: () : string => {
        return 'globalData func'
23 24 25 26 27 28 29
      },
      launchOptions: {
        path: '',
      } as OnLaunchOptions,
      onShowOption: {
        path: ''
      } as OnShowOptions
30
    },
31 32 33
    onLaunch: function (res : OnLaunchOptions) {
      this.globalData.launchOptions = res

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
      // 自动化测试
      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)
    },
49 50 51
    onShow: function (res : OnShowOptions) {
      this.globalData.onShowOption = res

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
      // 自动化测试
      setLifeCycleNum(state.lifeCycleNum + 100)
      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()
      }
    },
    onExit() {
      console.log('App Exit')
    },
83
    // #endif
84 85 86 87 88 89 90 91 92 93 94
    methods: {
      increasetLifeCycleNum() {
        setLifeCycleNum(state.lifeCycleNum + 100)
        console.log('App increasetLifeCycleNum')
      }
    }
  }
</script>

<style>
  /*每个页面公共css */
雪洛's avatar
雪洛 已提交
95
  @import "./common/uni.css";
96

97 98
  /* #ifdef WEB */
  .uni-top-window uni-tabbar .uni-tabbar {
99
    background-color: #fff !important;
100
  }
101

102
  .uni-app--showleftwindow .uni-page-head-btn {
103
    display: none !important;
104
  }
105

106
  /* #endif */
DCloud-WZF's avatar
DCloud-WZF 已提交
107
</style>