get-launch-options-sync.uvue 2.2 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1
<template>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
2 3 4 5 6 7
  <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
8 9
    </view>
  </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
10
</template>
DCloud-WZF's avatar
DCloud-WZF 已提交
11

DCloud-WZF's avatar
DCloud-WZF 已提交
12
<script lang="uts">
辛宝Otto's avatar
辛宝Otto 已提交
13 14 15 16
  type OnShowReturn = {
    appOnShow : OnShowOptions,
    onShowOption : OnShowOptions
  }
17

辛宝Otto's avatar
辛宝Otto 已提交
18 19 20 21 22 23
  type IOnLaunchOptions = {
    appOnLaunch : OnLaunchOptions,
    launchOptions : OnLaunchOptions
  }
  export default {
    data() {
24
      return {
辛宝Otto's avatar
辛宝Otto 已提交
25 26 27 28
        checked: false,
        homePagePath: 'pages/tabBar/component',
        globalPropertiesPath: 'pages/component/global-properties/global-properties',
        launchOptionsPath: '',
29
      }
辛宝Otto's avatar
辛宝Otto 已提交
30 31 32 33 34 35
    },
    methods: {
      // 自动化测试
      compareOnLaunchRes() : IOnLaunchOptions {
        const launchOptions = uni.getLaunchOptionsSync();
        const app = getApp()
36

辛宝Otto's avatar
辛宝Otto 已提交
37 38 39 40 41 42 43 44
        const appOnLaunch = app.globalData.launchOptions as OnLaunchOptions
        const res : IOnLaunchOptions = {
          appOnLaunch,
          launchOptions
        }
        return res
      },
      compareOnShowRes() : OnShowReturn {
45

辛宝Otto's avatar
辛宝Otto 已提交
46 47 48 49 50 51 52 53 54 55 56
        // #ifdef APP-ANDROID
        const res : OnShowReturn = {
          appOnShow: {
            path: ''
          } as OnShowOptions,
          onShowOption: {
            path: ''
          } as OnShowOptions
        }
        return res
        // #endif
57

辛宝Otto's avatar
辛宝Otto 已提交
58 59 60
        // #ifndef APP-ANDROID
        const onShowOption = uni.getEnterOptionsSync();
        const app = getApp()
61

辛宝Otto's avatar
辛宝Otto 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
        const appOnShow = app.globalData.onShowOption as OnShowOptions
        return {
          appOnShow,
          onShowOption
        }
        // #endif
      },
      getLaunchOptionsSync() {
        const launchOptions = uni.getLaunchOptionsSync()
        this.launchOptionsPath = launchOptions.path
        let targetLaunchPath = ''
        // #ifdef APP
        targetLaunchPath = this.homePagePath
        // #endif
        // #ifdef WEB
        targetLaunchPath = this.globalPropertiesPath
        // #endif
        if (launchOptions.path == targetLaunchPath) {
          this.checked = true
        }
      },
83
    },
辛宝Otto's avatar
辛宝Otto 已提交
84
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
85
</script>