get-window-info.uvue 1.8 KB
Newer Older
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
1
<template>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
2 3 4 5 6 7
  <page-head :title="title"></page-head>
  <view class="uni-common-mt">
    <view class="uni-list">
      <view class="uni-list-cell" v-for="(item, _) in items" style="align-items: center">
        <view class="uni-pd">
          <view class="uni-label" style="width: 180px">{{ item.label }}</view>
DCloud-WZF's avatar
DCloud-WZF 已提交
8
        </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
9
        <view class="uni-list-cell-db">
10
          <text style="width: 100%;" :value="item.value == '' ? '未获取' : item.value " />
DCloud-WZF's avatar
DCloud-WZF 已提交
11 12 13
        </view>
      </view>
    </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
14 15 16 17 18
    <view class="uni-padding-wrap">
      <view class="uni-btn-v">
        <button type="primary" @tap="getWindowInfo">获取窗口信息</button>
      </view>
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
19
  </view>
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
20 21
</template>
<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
22
  import { setStatusBarHeight } from '@/store/index.uts'
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35

  type Item = {
    label : string,
    value : string,
  }
  export default {
    data() {
      return {
        title: 'getWindowInfo',
        items: [] as Item[],
      }
    },
    onUnload: function () {
36 37 38
    },
    onReady() {
      this.getWindowInfo()
DCloud-WZF's avatar
DCloud-WZF 已提交
39 40 41 42 43
    },
    methods: {
      getWindowInfo: function () {
        const res = uni.getWindowInfo();
        // 获取状态栏+导航栏高度, 供截图对比使用
44
        setStatusBarHeight(res.statusBarHeight);
DCloud-WZF's avatar
DCloud-WZF 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
        this.items = [] as Item[];
        for (const key in res) {
          const value = res[key];
          if (value != null) {
            const item = {
              label: key,
              value: "" + ((typeof value == "object") ? JSON.stringify(value) : value)
            } as Item;
            this.items.push(item);
          }
        }
      },
      //自动化测试例专用
      jest_getWindowInfo() : GetWindowInfoResult {
        return uni.getWindowInfo();
60
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
61 62
    }
  }
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
63 64 65
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
66
  .uni-pd {
H
hdx 已提交
67
    padding-left: 15px;
DCloud-WZF's avatar
DCloud-WZF 已提交
68 69
  }
</style>