mapList.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view class="container" :style="{ height: windowHeight + 'px' }">
  3. <uni-section v-if="mapList.length > 0" title="地图列表" type="line">
  4. <uni-list>
  5. <uni-list-item v-for="item in mapList" :key="item.id" showArrow :title="item.name" :rightText="'活跃人数 ' + item.usernum" :clickable="true"
  6. @click="handleItemClick(item.id)" />
  7. </uni-list>
  8. </uni-section>
  9. </view>
  10. </template>
  11. <script>
  12. import {
  13. mapState,
  14. mapGetters
  15. } from 'vuex'
  16. import {
  17. DefaultRequest,
  18. IdRequest
  19. } from "@/grpc/base_pb.js"
  20. export default {
  21. components: {},
  22. data() {
  23. return {
  24. interval_loadData: null,
  25. windowHeight: 0,
  26. mapList: [],
  27. }
  28. },
  29. computed: {
  30. ...mapState([
  31. 'username', // 映射 this.username 为 store.state.username
  32. ]),
  33. ...mapGetters([
  34. 'metadata'
  35. ]),
  36. },
  37. mounted() {
  38. // this.$global.getWindowInfo()
  39. // this.windowHeight = this.$global.windowHeight
  40. // uni.$on('windowResize', this.layoutInit)
  41. },
  42. onLoad() {
  43. },
  44. onShow() {
  45. console.log('[onShow]')
  46. this.$global.getWindowInfo()
  47. this.windowHeight = this.$global.windowHeight
  48. uni.$on('windowResize', this.layoutInit)
  49. this.loadData()
  50. },
  51. onHide() {
  52. console.log('[onHide]')
  53. clearInterval(this.interval_loadData)
  54. uni.$off('windowResize', this.layoutInit)
  55. },
  56. beforeDestroy() {
  57. console.log("[beforeDestroy]")
  58. clearInterval(this.interval_loadData)
  59. uni.$off('windowResize', this.layoutInit)
  60. },
  61. methods: {
  62. layoutInit() {
  63. console.log('[layoutInit]')
  64. this.windowHeight = this.$global.windowHeight
  65. },
  66. async loadData() {
  67. this.mapList = await this.getToMapList()
  68. if (this.interval_loadData != null) {
  69. clearInterval(this.interval_loadData)
  70. }
  71. let that = this
  72. this.interval_loadData = setInterval(async function() {
  73. that.mapList = await that.getToMapList()
  74. }, 3000);
  75. },
  76. async getToMapList() {
  77. try {
  78. return new Promise((resolve, reject) => {
  79. // 创建请求参数并赋值
  80. var request = new DefaultRequest()
  81. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  82. this.$client.toMapList(request, this.metadata, (err,
  83. response) => {
  84. if (err) {
  85. console.warn(`[toMapList] err: code = ${err.code}` +
  86. `, message = "${err.message}"`)
  87. reject(err)
  88. } else {
  89. let res = response.toObject()
  90. // console.log('[toMapList]', res)
  91. resolve(res.listList)
  92. }
  93. })
  94. });
  95. } catch (e) {
  96. console.log('[getToMapList] err', e)
  97. reject(e)
  98. }
  99. },
  100. // handleShopChange(mapId) {
  101. // console.log("mapId:" + mapId)
  102. // this.getControlInfoList(mapId)
  103. // this.getShopMap(mapId)
  104. // },
  105. handleItemClick(mapId) {
  106. console.log("mapId:" + mapId)
  107. uni.navigateTo({
  108. // url: '/pages/checkPoint/checkPointDetail',
  109. url: './mapShow?mapId=' + mapId
  110. })
  111. },
  112. }
  113. }
  114. </script>
  115. <style lang="scss">
  116. .container {
  117. // height: 100vh;
  118. // height: 100%;
  119. // overflow: hidden;
  120. }
  121. .padding {
  122. padding: 0 20rpx;
  123. }
  124. </style>