get-system-info.uvue 1.5 KB
Newer Older
1 2 3 4 5
<template>
	<view>
		<page-head :title="title"></page-head>
		<view class="uni-common-mt">
			<view class="uni-list">
6
				<view class="uni-list-cell" v-for="(item,_) in items" style="align-items: center;">
7
					<view class="uni-pd">
8
						<view class="uni-label" style="width:180px;">{{item.label}}</view>
9 10
					</view>
					<view class="uni-list-cell-db">
11
						<textarea :auto-height="true" :disabled="true" placeholder="未获取" :value="item.value" />
12 13 14 15 16 17 18 19 20 21 22
					</view>
				</view>
			</view>
			<view class="uni-padding-wrap">
				<view class="uni-btn-v">
					<button type="primary" @tap="getSystemInfo">获取设备系统信息</button>
				</view>
			</view>
		</view>
	</view>
</template>
23 24 25 26 27
<script>
	type Item = {
		label : string,
		value : string,
	}
28 29 30 31
	export default {
		data() {
			return {
				title: 'getSystemInfo',
32
				items: [] as Item[],
33 34
			}
		},
35
		onUnload: function () {
36 37
		},
		methods: {
38
			getSystemInfo: function () {
39
				uni.getSystemInfo({
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
40 41
					success: (res) => {
						//类型对象暂时不支持forin或Object.keys(), 临时通过字符串进行转化。
42
						const json = JSON.stringify(res);
43 44
						const result = JSON.parse<Map<string, any>>(json);
						this.items = [] as Item[];
45 46 47 48 49 50 51 52
						result.forEach((value, key) => {
							const item = {
								label: key,
								value: "" + value
							} as Item;
							this.items.push(item);
						})
					},
53 54 55 56 57 58 59 60 61 62
				})
			}
		}
	}
</script>

<style>
	.uni-pd {
		padding-left: 30rpx;
	}
63
</style>