get-launch-options-sync.uvue 2.0 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
<template>
  <page-head title="getLaunchOptionsSync"></page-head>
  <view class="uni-padding-wrap">
    <button @click="getLaunchOptionsSync">getLaunchOptionsSync</button>
    <view v-if="launchOptionsPath.length > 0" class="uni-common-mt">
      <text>应用启动路径:</text>
      <text style="margin-top: 5px">{{ launchOptionsPath }}</text>
    </view>
  </view>
</template>

<script lang="uts">
  type OnShowReturn = {
    appOnShow : OnShowOptions,
    onShowOption : OnShowOptions
  }

  type IOnLaunchOptions = {
    appOnLaunch : OnLaunchOptions,
    launchOptions : OnLaunchOptions
  }
  export default {
    data() {
      return {
        checked: false,
        homePagePath: 'pages/tabBar/component',
        launchOptionsPath: '',
      }
    },
    methods: {
      // 自动化测试
      compareOnLaunchRes() : IOnLaunchOptions {
        const launchOptions = uni.getLaunchOptionsSync();
        const app = getApp()

        const appOnLaunch = app.globalData.launchOptions as OnLaunchOptions
        const res : IOnLaunchOptions = {
          appOnLaunch,
          launchOptions
        }
        return res
      },
      compareOnShowRes() : OnShowReturn {

        // #ifdef APP-ANDROID
        const res : OnShowReturn = {
          appOnShow: {
            path: ''
          } as OnShowOptions,
          onShowOption: {
            path: ''
          } as OnShowOptions
        }
        return res
        // #endif

        // #ifndef APP-ANDROID
        const onShowOption = uni.getEnterOptionsSync();
        const app = getApp()

        const appOnShow = app.globalData.onShowOption as OnShowOptions
        return {
          appOnShow,
          onShowOption
        }
        // #endif
      },
      getLaunchOptionsSync() {
        const launchOptions = uni.getLaunchOptionsSync()
        this.launchOptionsPath = launchOptions.path
        if (launchOptions.path == this.homePagePath) {
          this.checked = true
        }
      },
    },
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
77
</script>