get-app-base-info.uvue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <page-head :title="title"></page-head>
  3. <view class="uni-common-mt">
  4. <view class="uni-list">
  5. <view class="uni-list-cell" v-for="(item,_) in items" style="align-items: center;">
  6. <view class="uni-pd">
  7. <view class="uni-label" style="width:180px;">{{item.label}}</view>
  8. </view>
  9. <view class="uni-list-cell-db">
  10. <text class="uni-list-cell-db-text">{{ item.value == '' ? '未获取' : item.value }}</text>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="uni-padding-wrap">
  15. <view class="uni-btn-v">
  16. <button type="primary" @tap="getAppBaseInfo">获取App基础信息</button>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. type Item = {
  23. label : string,
  24. value : string,
  25. }
  26. export default {
  27. data() {
  28. return {
  29. title: 'getAppBaseInfo',
  30. items: [] as Item[],
  31. }
  32. },
  33. onUnload: function () {
  34. },
  35. methods: {
  36. getAppBaseInfo: function () {
  37. const res = uni.getAppBaseInfo();
  38. const res_str = JSON.stringify(res);
  39. const res_obj = JSON.parseObject(res_str);
  40. const res_map = res_obj!.toMap();
  41. let keys = [] as string[]
  42. res_map.forEach((_, key) => {
  43. keys.push(key);
  44. });
  45. this.items = [] as Item[];
  46. keys.sort().forEach(key => {
  47. const value = res[key];
  48. if (value != null) {
  49. const item = {
  50. label: key,
  51. value: "" + ((typeof value == "object") ? JSON.stringify(value) : value)
  52. } as Item;
  53. this.items.push(item);
  54. }
  55. });
  56. }
  57. }
  58. }
  59. </script>
  60. <style>
  61. .uni-pd {
  62. padding-left: 15px;
  63. }
  64. </style>