mapShow.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <view class="page" :style="{ height: pageHeight + 'px', flexDirection: flexDirection }">
  3. <view id="map" :style="{ height: pageHeight + 'px' }" class='map' />
  4. <!-- <view class="fab">
  5. <uni-fab ref="fab" :pattern="fab.pattern" :content="fab.content" :horizontal="fab.horizontal"
  6. :vertical="fab.vertical" :direction="fab.direction" @trigger="trigger" @fabClick="fabClick" />
  7. </view> -->
  8. <view v-show="popupShow" :style="extraIcon" class="popup">
  9. <scroll-view :scroll-top="0" scroll-y="true"
  10. :style="{ height: popupHeight + 'px', width: popupWidth + 'px' }" class="scroll-Y">
  11. <uni-list v-for="(item, index) in players" :key="index" :border="true" class="list">
  12. <!-- <uni-list-item :show-extra-icon="true" :extra-icon="{color: '#4cd964', size: '22', type: 'spinner'}"
  13. :title="'(' + (index+1) + ') ' + item.name + ' 打点: ' + item.effectivenum + ' / ' + item.totalcontrolnum + ' 距离: ' + item.distance + '米 配速: ' + item.pace"
  14. :note="'平均心率: ' + item.avghr + ' 最大心率: ' + item.maxhr + ' CAL: ' + item.calorie + ' Ck: ' + item.ck + ' Ei: ' + item.ei"
  15. :clickable="true" @click="onPlayerListItemClick(item)" :class="{
  16. 'list-item': focusPlayerId != item.id,
  17. 'list-item-focus': focusPlayerId == item.id
  18. }">
  19. </uni-list-item> -->
  20. <uni-list-item :clickable="true" @click="onPlayerListItemClick(item)" class="list-item" :class="{
  21. 'list-item-focus': focusPlayerId == item.id
  22. }">
  23. <template v-slot:header>
  24. <!-- <image class="slot-image" src="/static/logo.png" mode="widthFix"></image> -->
  25. <div class="slot-image" :style="'background-color:' + getPlayerColor(item.id)"></div>
  26. </template>
  27. <template v-slot:body>
  28. <view class="slot-box">
  29. <view class="slot-title">
  30. [{{index+1}}] <span class="slot-phone" @click="onPhoneClick(item.phone)">
  31. {{item.name}} </span>
  32. 打点 {{item.effectivenum}}/{{item.totalcontrolnum}} 距离
  33. {{item.distance}}米 配速 {{item.pace}}
  34. </view>
  35. <view class="slot-note">
  36. 心率 {{item.lasthr}} 平均 {{item.avghr}} 最大 {{item.maxhr}} | CAL
  37. {{Math.round(item.calorie/1000)}} Ck {{Math.round(item.ck/1000)}} Ei {{Math.round(item.ei*100)/100}}
  38. </view>
  39. </view>
  40. </template>
  41. <!-- <template v-slot:footer>
  42. <image class="slot-image" src="/static/logo.png" mode="widthFix"></image>
  43. </template> -->
  44. </uni-list-item>
  45. </uni-list>
  46. </scroll-view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import { mapState, mapGetters } from 'vuex'
  52. import {
  53. DefaultRequest,
  54. IdRequest
  55. } from "@/grpc/base_pb.js"
  56. export default {
  57. components: {},
  58. data() {
  59. return {
  60. interval: null,
  61. systemInfo: null,
  62. deviceOrientation: 'portrait', // 设备方向(竖屏 portrait | 横屏 landscape)
  63. flexDirection: 'column',
  64. pageHeight: 0,
  65. pageWidth: 0,
  66. // mapHeight: 0,
  67. popupHeight: 0,
  68. popupWidth: 0,
  69. popupHeightPortrait: 300, // 竖屏状态下的底部弹框高度
  70. popupWidthlandscape: 390, // 横屏状态下的右侧弹框宽度
  71. popupType: 'bottom',
  72. popupShow: false,
  73. extraIcon: {
  74. color: '#4cd964',
  75. size: '22',
  76. type: 'gear-filled'
  77. },
  78. actionId: 2,
  79. actionDetail: {},
  80. mapUrl: null,
  81. mapInfo: {},
  82. map: null,
  83. checkPoints: [],
  84. players: [],
  85. players_position: [],
  86. focusPlayerId: 0,
  87. trailTime: 90000,
  88. }
  89. },
  90. computed: {
  91. ...mapState([
  92. 'username', // 映射 this.username 为 store.state.username
  93. ]),
  94. ...mapGetters([
  95. 'metadata'
  96. ]),
  97. },
  98. mounted() {},
  99. onLoad(option) {
  100. // console.log('[mapShow] onLoad')
  101. // console.log(option.actionId)
  102. if (option.actionId > 0) {
  103. this.actionId = option.actionId
  104. this.loadData(this.actionId)
  105. }
  106. // 逻辑层中触发自定义事件
  107. // uni.$emit('myEvent', {
  108. // name: 'Uniapp',
  109. // version: '2.0.0'
  110. // })
  111. },
  112. onReady() {
  113. this.layoutInit()
  114. },
  115. onShow() {
  116. // console.log('[onShow]')
  117. uni.onWindowResize(res => {
  118. // console.log('[onWindowResize]', res)
  119. this.layoutInit(res.size)
  120. });
  121. },
  122. beforeDestroy() {
  123. // console.log("beforeDestroy")
  124. clearInterval(this.interval)
  125. // leafletHelper.free()
  126. },
  127. methods: {
  128. // 全屏展示
  129. fullscreen() {
  130. if (document.fullscreenElement || document.webkitFullScreenElement || document.mozFullScreenElement ||
  131. document.msFullScreenElement) {
  132. // alert('当前是全屏')
  133. if (document.webkitCancelFullScreen) {
  134. document.webkitCancelFullScreen();
  135. } else if (document.mozCancelFullScreen) {
  136. document.mozCancelFullScreen();
  137. } else if (document.exitFullscreen) {
  138. document.exitFullscreen();
  139. } else {
  140. uni.showToast({
  141. title: '浏览器不支持全屏API或已被禁用',
  142. icon: 'none'
  143. })
  144. }
  145. } else {
  146. let elem = document.body;
  147. if (elem.webkitRequestFullScreen) {
  148. elem.webkitRequestFullScreen();
  149. } else if (elem.mozRequestFullScreen) {
  150. elem.mozRequestFullScreen();
  151. } else if (elem.requestFullScreen) {
  152. elem.requestFullscreen();
  153. } else {
  154. uni.showToast({
  155. title: '浏览器不支持全屏API或已被禁用',
  156. icon: 'none'
  157. })
  158. }
  159. }
  160. },
  161. // 布局初始化 设置地图高度
  162. layoutInit(windowSize = '') {
  163. var windowHeight, windowWidth
  164. if (windowSize == '') {
  165. this.systemInfo = uni.getSystemInfoSync()
  166. // console.log('[layoutInit] systemInfo', this.systemInfo)
  167. windowHeight = this.systemInfo.windowHeight
  168. windowWidth = this.systemInfo.windowWidth
  169. } else {
  170. windowHeight = windowSize.windowHeight
  171. windowWidth = windowSize.windowWidth
  172. }
  173. this.pageHeight = windowHeight
  174. this.pageWidth = windowWidth
  175. if (windowHeight > windowWidth) {
  176. console.log('[layoutInit] 竖屏')
  177. this.deviceOrientation = 'portrait'
  178. this.flexDirection = 'column'
  179. this.popupHeight = this.popupHeightPortrait
  180. this.popupWidth = this.pageWidth
  181. // if (this.popupShow) {
  182. // this.mapHeight = this.pageHeight - this.popupHeight
  183. // } else {
  184. // this.mapHeight = this.pageHeight
  185. // }
  186. } else { // 横屏
  187. console.log('[layoutInit] 横屏')
  188. this.deviceOrientation = 'landscape'
  189. this.flexDirection = 'row'
  190. this.popupHeight = this.pageHeight
  191. this.popupWidth = this.popupWidthlandscape
  192. // this.mapHeight = this.pageHeight
  193. }
  194. },
  195. popupToggle() {
  196. this.popupShow = !this.popupShow
  197. },
  198. fullScreenToggle() {
  199. this.fullscreen()
  200. this.layoutInit()
  201. },
  202. async loadData() {
  203. this.actionDetail = await this.getToActionDetail(this.actionId)
  204. uni.setNavigationBarTitle({
  205. title: this.actionDetail.name
  206. });
  207. // console.log(this.actionDetail)
  208. this.initMap()
  209. this.handleMapDrawRoute()
  210. if (this.interval != null) {
  211. clearInterval(this.interval)
  212. }
  213. let that = this
  214. that.players = await that.getToUsersInGameDetail(that.actionId)
  215. // console.log('players', that.players)
  216. // leafletHelper.global.setPlayers(this.players)
  217. that.players_position = await that.getToUsersInGameGpsQuery(that.actionId)
  218. // leafletHelper.global.setPlayersPosition(this.players_position)
  219. that.handleMapDrawPlayer()
  220. that.handleMapDrawTrail()
  221. this.interval = setInterval(async function() {
  222. that.players = await that.getToUsersInGameDetail(that.actionId)
  223. that.players_position = await that.getToUsersInGameGpsQuery(that.actionId)
  224. //// leaflet.leafletHelper.global.setPlayers(that.players)
  225. // leafletHelper.global.setPlayersPosition(that.players_position)
  226. that.handleMapDrawPlayer()
  227. that.handleMapDrawTrail()
  228. }, 1000);
  229. // await mapHelper.handleMapInfo(this, this.mapInfo)
  230. this.handleMapToggle()
  231. },
  232. //场控端_活动详情
  233. async getToActionDetail(actId) {
  234. try {
  235. return new Promise((resolve, reject) => {
  236. // 创建请求参数并赋值
  237. var request = new IdRequest()
  238. request.setId(actId)
  239. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  240. this.$client.toActionDetail(request, this.metadata, (err, response) => {
  241. if (err) {
  242. console.warn(`[toActionDetail] err: code = ${err.code}` +
  243. `, message = "${err.message}"`)
  244. reject(err)
  245. } else {
  246. let res = response.toObject()
  247. console.log('[toActionDetail]', res)
  248. resolve(res)
  249. }
  250. })
  251. });
  252. } catch (e) {
  253. console.log('[getToActionDetail] err', e)
  254. reject(e)
  255. }
  256. },
  257. //场控端_正在进行中所有用户实时信息
  258. async getToUsersInGameDetail(actId) {
  259. try {
  260. return new Promise((resolve, reject) => {
  261. // 创建请求参数并赋值
  262. var request = new IdRequest()
  263. request.setId(actId)
  264. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  265. this.$client.toUsersInGameDetail(request, this.metadata, (err,
  266. response) => {
  267. if (err) {
  268. console.warn(`[toUsersInGameDetail] err: code = ${err.code}` +
  269. `, message = "${err.message}"`)
  270. reject(err)
  271. } else {
  272. let res = response.toObject()
  273. // console.log('[toUsersInGameDetail]', res)
  274. resolve(res.usersList)
  275. }
  276. })
  277. });
  278. } catch (e) {
  279. console.log('[getToUsersInGameDetail] err', e)
  280. reject(e)
  281. }
  282. },
  283. //场控端_正在进行中所有用户实时gps查询
  284. async getToUsersInGameGpsQuery(actId) {
  285. try {
  286. return new Promise((resolve, reject) => {
  287. // 创建请求参数并赋值
  288. var request = new IdRequest()
  289. request.setId(actId)
  290. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  291. this.$client.toUsersInGameGpsQuery(request, this.metadata, (err,
  292. response) => {
  293. if (err) {
  294. console.warn(`[toUsersInGameGpsQuery] err: code = ${err.code}` +
  295. `, message = "${err.message}"`)
  296. reject(err)
  297. } else {
  298. let res = response.toObject()
  299. // console.log('[toUsersInGameGpsQuery]', res)
  300. resolve(res.gpsinfoList)
  301. }
  302. })
  303. });
  304. } catch (e) {
  305. console.log('[getToUsersInGameGpsQuery] err', e)
  306. reject(e)
  307. }
  308. },
  309. onPlayerListItemClick(item) {
  310. // console.log("onListItemClick", item)
  311. this.handlePlayerListItemClick(item)
  312. },
  313. onPhoneClick(phoneNumber) {
  314. if (phoneNumber.length == 11) {
  315. uni.makePhoneCall({
  316. phoneNumber: phoneNumber
  317. })
  318. } else {
  319. uni.showToast({
  320. title: '手机号码不正确',
  321. icon: 'none'
  322. })
  323. }
  324. }
  325. // trigger(e) {
  326. // console.log(e)
  327. // this.content[e.index].active = !e.item.active
  328. // uni.showModal({
  329. // title: '提示',
  330. // content: `您${this.content[e.index].active ? '选中了' : '取消了'}${e.item.text}`,
  331. // success: function(res) {
  332. // if (res.confirm) {
  333. // console.log('用户点击确定')
  334. // } else if (res.cancel) {
  335. // console.log('用户点击取消')
  336. // }
  337. // }
  338. // })
  339. // },
  340. // fabClick() {
  341. // uni.showToast({
  342. // title: '点击了悬浮按钮',
  343. // icon: 'none'
  344. // })
  345. // },
  346. }
  347. }
  348. </script>
  349. <script module="leaflet" lang="renderjs">
  350. import 'leaflet/dist/leaflet.css'
  351. import '@/utils/map/leafletHelper.css'
  352. // import mapHelper from '@/utils/mapHelper'
  353. import leafletHelper from '@/utils/map/leafletHelper'
  354. export default {
  355. components: {},
  356. // data() {
  357. // return {},
  358. // },
  359. // mounted() {
  360. // uni.$on('myEvent', this.myEventHandler);
  361. // },
  362. // destroyed() {
  363. // uni.$off('myEvent', this.myEventHandler);
  364. // },
  365. beforeDestroy() {
  366. // console.log("beforeDestroy")
  367. // clearInterval(this.interval)
  368. leafletHelper.free()
  369. },
  370. methods: {
  371. // myEventHandler(data) {
  372. // console.log('视图层接收到数据:', data);
  373. // },
  374. initMap() {
  375. // leafletHelper.init(this, 'map', [36.67175772119628, 117.12792580603369], 17)
  376. // const mapid = this.actionDetail.mapinfo.lid
  377. const mapurl = this.actionDetail.mapinfo.mapurl
  378. const centPoint = [this.actionDetail.mapinfo.centerlatitude, this.actionDetail.mapinfo.centerlongitude]
  379. const zoomNum = this.actionDetail.mapinfo.defscale
  380. leafletHelper.init(this, 'map', centPoint, zoomNum)
  381. leafletHelper.addMapLayer(mapurl)
  382. },
  383. handleMapDrawRoute() {
  384. // leafletHelper.global.setCheckPoints(this.checkPoints)
  385. leafletHelper.global.setRoutes(this.actionDetail.routesList)
  386. // leafletHelper.checkPoint.drawAllCheckPoints()
  387. // leafletHelper.checkPoint.drawPath()
  388. leafletHelper.route.drawAllRoutes()
  389. leafletHelper.route.drawAllPath()
  390. },
  391. handleMapDrawPlayer() {
  392. leafletHelper.global.setPlayers(this.players)
  393. leafletHelper.global.setPlayersPosition(this.players_position)
  394. leafletHelper.player.drawAllPlayers()
  395. // leafletHelper.player.drawOnePlayer(2)
  396. // leafletHelper.player.drawOnePlayer(3)
  397. leafletHelper.global.dealStaleData()
  398. },
  399. handleMapDrawTrail() {
  400. // leafletHelper.player.drawOneTrail(2, 10000)
  401. // leafletHelper.player.drawOneTrail(3, 10000)
  402. // leafletHelper.player.drawOneTrail(2, 0, false)
  403. leafletHelper.player.drawAllTrails(this.trailTime)
  404. },
  405. handleMapToggle() {
  406. // leafletHelper.checkPoint.toggle(true)
  407. leafletHelper.route.toggle(true)
  408. leafletHelper.player.togglePlayer(true)
  409. leafletHelper.player.toggleTooltip(true)
  410. leafletHelper.player.toggleTrail(true)
  411. },
  412. handlePlayerListItemClick(item) {
  413. this.focusPlayerId = item.id
  414. leafletHelper.player.handleFocusPlayer(this.focusPlayerId)
  415. },
  416. getPlayerColor(playerId) {
  417. if (playerId != this.focusPlayerId)
  418. return leafletHelper.player.getPlayerColor(playerId)
  419. else
  420. return leafletHelper.config.gStyle.marker.focus.fillColor
  421. }
  422. },
  423. }
  424. </script>
  425. <style lang="scss" scoped>
  426. .page {
  427. // background-color: red;
  428. display: flex;
  429. }
  430. .map {
  431. flex: 1 1 auto;
  432. background-color: white;
  433. z-index: 0;
  434. // display: flex;
  435. // justify-content: center;
  436. // align-items: center;
  437. }
  438. .popup {
  439. // height: 200px;
  440. // overflow: hidden;
  441. }
  442. .scroll-Y {
  443. // height: 100vh;
  444. }
  445. .list {}
  446. .list-item {
  447. /* #ifndef APP-NVUE */
  448. display: flex;
  449. /* #endif */
  450. flex-direction: row;
  451. align-items: center;
  452. height: 60px;
  453. }
  454. .list-item-focus {
  455. background-color: #fffaef;
  456. }
  457. .slot-box {
  458. /* #ifndef APP-NVUE */
  459. display: flex;
  460. /* #endif */
  461. flex-direction: column;
  462. align-items: flex-start;
  463. }
  464. .slot-image {
  465. /* #ifndef APP-NVUE */
  466. display: block;
  467. /* #endif */
  468. margin-right: 10px;
  469. width: 6px;
  470. height: 39px;
  471. align-self: center;
  472. }
  473. .slot-title {
  474. flex: 1;
  475. font-size: 14px;
  476. color: #424242;
  477. // margin-right: 10px;
  478. }
  479. .slot-note {
  480. flex: 1;
  481. font-size: 12px;
  482. color: #7d8da7;
  483. // margin-right: 10px;
  484. }
  485. .slot-phone {
  486. padding: 0 5px;
  487. color: #000;
  488. font-weight: bold;
  489. }
  490. // .fab {
  491. // z-index: 1000;
  492. // width: 20px;
  493. // }
  494. </style>