get-system-info.uvue 1.9 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 31 32 33 34 35 36 37 38 39 40
  <!-- #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">
            <button type="primary" @tap="getSystemInfo">
              获取设备系统信息
            </button>
          </view>
        </view>
      </view>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
41
</template>
42
<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
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
type Item = {
	label : string,
	value : string,
}
export default {
	data() {
		return {
			title: 'getSystemInfo',
			items: [] as Item[],
		}
	},
	onUnload: function () {
	},
	methods: {
		getSystemInfo: function () {
			uni.getSystemInfo({
				success: (res) => {
					//类型对象暂时不支持forin或Object.keys(), 临时通过字符串进行转化。
					const json = JSON.stringify(res);
					const result = JSON.parse<Map<string, any>>(json);
					this.items = [] as Item[];
					result.forEach((value, key) => {
						const item = {
							label: key,
							value: "" + value
						} as Item;
						this.items.push(item);
					})
				},
			})
73 74
		}
	}
DCloud-WZF's avatar
DCloud-WZF 已提交
75
}
76 77 78
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
79 80 81 82
.uni-pd {
  padding-left: 30rpx;
}
</style>