get-app-base-info.uvue 1.7 KB
Newer Older
1
<template>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
2 3
  <page-head :title="title"></page-head>
  <view class="uni-common-mt">
DCloud-WZF's avatar
DCloud-WZF 已提交
4 5 6 7 8 9 10 11
    <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">
          <text style="width: 100%;">{{ item.value == '' ? '未获取' : item.value }}</text>
        </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
12 13 14 15 16 17 18 19
      </view>
    </view>
    <view class="uni-padding-wrap">
      <view class="uni-btn-v">
        <button type="primary" @tap="getAppBaseInfo">获取App基础信息</button>
      </view>
    </view>
  </view>
20
</template>
DCloud-WZF's avatar
DCloud-WZF 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
<script>
  type Item = {
    label : string,
    value : string,
  }
  export default {
    data() {
      return {
        title: 'getAppBaseInfo',
        items: [] as Item[],
      }
    },
    onUnload: function () {
    },
    methods: {
      getAppBaseInfo: function () {
        const res = uni.getAppBaseInfo();
        const res_str = JSON.stringify(res);
        const res_obj = JSON.parseObject(res_str);
        const res_map = res_obj!.toMap();
        let keys = [] as string[]
        res_map.forEach((_, key) => {
          keys.push(key);
        });

        this.items = [] as Item[];
        keys.sort().forEach(key => {
          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);
          }
        });

      }
    }
  }
61 62 63
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
64 65 66 67
  .uni-pd {
    padding-left: 15px;
  }
</style>