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