get-system-info.uvue 2.5 KB
Newer Older
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
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
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <view>
      <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>
            </view>
            <view class="uni-list-cell-db">
              <textarea
                :auto-height="true"
                :disabled="true"
                placeholder="未获取"
                :value="item.value"
              />
            </view>
          </view>
        </view>
        <view class="uni-padding-wrap">
          <view class="uni-btn-v">
31 32 33 34 35
            <button type="primary" @tap="getSystemInfoSync">
              同步获取设备系统信息
            </button>
            <button type="primary" @tap="getSystemInfo" style="margin-top: 20px;">
              异步获取设备系统信息
DCloud-WZF's avatar
DCloud-WZF 已提交
36 37 38 39 40 41 42 43
            </button>
          </view>
        </view>
      </view>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
44
</template>
45
<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59
type Item = {
	label : string,
	value : string,
}
export default {
	data() {
		return {
			title: 'getSystemInfo',
			items: [] as Item[],
		}
	},
	onUnload: function () {
	},
	methods: {
60
		getSystemInfo: function () {
DCloud-WZF's avatar
DCloud-WZF 已提交
61
			uni.getSystemInfo({
62
				success: (res) => {
63
          this.items = [] as Item[];
64 65 66 67 68 69 70 71 72 73
          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);
            }
          }
DCloud-WZF's avatar
DCloud-WZF 已提交
74 75
				},
			})
76
		},
77 78 79 80 81 82 83 84 85 86 87 88 89 90
    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);
    	  }
    	}
    },
91 92 93 94
    //自动化测试例专用
    jest_getSystemInfo():GetSystemInfoResult{
      return uni.getSystemInfoSync();
    },
95
	}
DCloud-WZF's avatar
DCloud-WZF 已提交
96
}
97 98 99
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
100 101 102 103
.uni-pd {
  padding-left: 30rpx;
}
</style>