get-system-info.uvue 2.6 KB
Newer Older
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
H
hdx 已提交
4
  <!-- #endif -->
DCloud-WZF's avatar
DCloud-WZF 已提交
5 6 7 8
    <view>
      <page-head :title="title"></page-head>
      <view class="uni-common-mt">
        <view class="uni-list">
H
hdx 已提交
9
          <view class="uni-list-cell" v-for="(item, _) in items" style="align-items: center">
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11 12 13 14 15
            <view class="uni-pd">
              <view class="uni-label" style="width: 180px">{{
                item.label
              }}</view>
            </view>
            <view class="uni-list-cell-db">
16
              <textarea style="width: 100%;" :auto-height="true" :disabled="true" placeholder="未获取" :value="item.value" />
DCloud-WZF's avatar
DCloud-WZF 已提交
17 18 19 20 21
            </view>
          </view>
        </view>
        <view class="uni-padding-wrap">
          <view class="uni-btn-v">
22 23
            <button type="primary" @tap="getSystemInfoSync">
              同步获取设备系统信息
H
hdx 已提交
24 25 26
            </button>
            <button type="primary" @tap="getSystemInfo" style="margin-top: 20px;">
              异步获取设备系统信息
DCloud-WZF's avatar
DCloud-WZF 已提交
27 28 29 30 31
            </button>
          </view>
        </view>
      </view>
    </view>
H
hdx 已提交
32
  <!-- #ifdef APP -->
DCloud-WZF's avatar
DCloud-WZF 已提交
33 34
  </scroll-view>
  <!-- #endif -->
35
</template>
36
<script>
H
hdx 已提交
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 77 78 79 80 81 82 83 84 85 86 87
  type Item = {
    label : string,
    value : string,
  }
  export default {
    data() {
      return {
        title: 'getSystemInfo',
        items: [] as Item[],
      }
    },
    onUnload: function () {
    },
    methods: {
      getSystemInfo: function () {
        uni.getSystemInfo({
          success: (res) => {
            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);
              }
            }
          },
        })
      },
      getSystemInfoSync: function () {
        this.items = [] as Item[];
        const res = uni.getSystemInfoSync()
        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_getSystemInfo() : GetSystemInfoResult {
        return uni.getSystemInfoSync();
      },
    }
  }
88 89 90
</script>

<style>
H
hdx 已提交
91 92 93 94
  .uni-pd {
    padding-left: 15px;
  }
</style>