get-device-info.uvue 1.4 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 7 8 9 10 11 12 13
				<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>
14 15 16 17 18 19 20 21 22 23 24 25
					</view>
				</view>
			</view>
			<view class="uni-padding-wrap">
				<view class="uni-btn-v">
					<button type="primary" @tap="getDeviceInfo">获取设备信息</button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
26 27 28 29
	type Item = {
		label : string,
		value : string,
	}
30 31 32 33
	export default {
		data() {
			return {
				title: 'getDeviceInfo',
34
				items: [] as Item[],
35 36 37 38 39 40 41
			}
		},
		onUnload:function(){
		},
		methods: {
			getDeviceInfo: function () {
				const res = uni.getDeviceInfo();
42 43
				const json = JSON.stringify(res);
				const result = JSON.parse<Map<string, any>>(json);
44
				this.items = [] as Item[];
45 46 47 48 49 50 51
				result.forEach((value, key) => {
					const item = {
						label: key,
						value: "" + value
					} as Item;
					this.items.push(item);
				})
52 53 54 55 56 57 58 59 60 61
			}
		}
	}
</script>

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