get-window-info.uvue 1.5 KB
Newer Older
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
1 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
<template>
	<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="getWindowInfo">获取窗口信息</button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	type Item = {
		label : string,
		value : string,
	}
	export default {
		data() {
			return {
				title: 'getWindowInfo',
				items: [] as Item[],
			}
		},
		onUnload: function () {
		},
		methods: {
			getWindowInfo: function () {
				const res = uni.getWindowInfo();
40 41 42 43 44 45 46 47 48 49
				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);
          }
				}
50 51 52 53 54
			},
      //自动化测试例专用
      jest_getWindowInfo():GetWindowInfoResult{
        return uni.getWindowInfo();
      },
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
55 56 57 58 59 60 61 62 63
		}
	}
</script>

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