track.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="container">
  3. <!-- 顶部筛选区域 -->
  4. <view class="search">
  5. <uni-datetime-picker v-model="datetimerangeValue" type="datetimerange" rangeSeparator="至" :clear-icon="false" @change="changeTime" />
  6. </view>
  7. <!-- 地图区域 -->
  8. <view class="map_box">
  9. <img mode="aspectFill" class="img" src="https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20240711164230.jpg" />
  10. </view>
  11. <canvas style="width: 750rpx; height: 480rpx" canvas-id="firstCanvas"></canvas>
  12. <!-- 轨迹区域 -->
  13. <view class="track">
  14. <view class="track_title">全天状态</view>
  15. <!-- 步骤条区域 -->
  16. <uv-steps activeColor="#1E7DFB" direction="column" dot :current="list.length" v-if="list.length">
  17. <uv-steps-item v-for="item in list" :key="item.id" :customStyle="customStyle">
  18. <template v-slot:title>
  19. <view class="track_time">
  20. {{ item.type }}
  21. </view>
  22. </template>
  23. <template v-slot:desc>
  24. <view class="track_desc">地点:{{ item.location }}</view>
  25. <view class="track_desc">时间:{{ item.dateTime }}</view>
  26. <view class="track_desc" v-if="item.image">
  27. 图片:
  28. <img class="img" mode="aspectFill" :src="item.image" @click="previewImage(item.image)" />
  29. </view>
  30. </template>
  31. </uv-steps-item>
  32. </uv-steps>
  33. <NoData v-else />
  34. </view>
  35. </view>
  36. </template>
  37. <script setup>
  38. import { ref } from 'vue'
  39. import { onLoad } from '@dcloudio/uni-app'
  40. import NoData from '@/components/noData.vue'
  41. import { myRequest } from '@/utils/api.js'
  42. import { previewImage } from '@/utils/previewImage.js'
  43. import { decryptDes } from '@/utils/des.js'
  44. import dayjs from 'dayjs'
  45. onLoad((options) => {
  46. currentId.value = options.id
  47. if (options.time) {
  48. datetimerangeValue.value = [options.time, options.time.slice(0, 10) + ' 23:59:59']
  49. } else {
  50. datetimerangeValue.value = [dayjs(Date.now()).format('YYYY-MM-DD') + ' 00:00:00', dayjs(Date.now()).format('YYYY-MM-DD') + ' 23:59:59']
  51. }
  52. // 获取轨迹数组数据
  53. getData()
  54. // 绘制地点
  55. drawAddress()
  56. // 绘制轨迹
  57. setTimeout(() => {
  58. drawTrack()
  59. }, 500)
  60. })
  61. // 当前学生id
  62. const currentId = ref()
  63. // 时间筛选框绑定数据
  64. const datetimerangeValue = ref()
  65. // 学生轨迹数组
  66. const list = ref([])
  67. // 步骤条样式
  68. const customStyle = {
  69. marginBottom: '30rpx'
  70. }
  71. // 画布实例
  72. const ctx = ref()
  73. // 获取轨迹数组数据
  74. const getData = async () => {
  75. const res = await myRequest({
  76. url: '/wanzai/api/smartFaceDiscern/track',
  77. data: {
  78. id: currentId.value,
  79. startTime: datetimerangeValue.value[0],
  80. endTime: datetimerangeValue.value[1]
  81. }
  82. })
  83. // console.log(res)
  84. if (res.code == 200) {
  85. const result = JSON.parse(decryptDes(res.data))
  86. // console.log(result)
  87. list.value = result.reverse()
  88. // 获取设备宽度
  89. const system = uni.getSystemInfoSync()
  90. // 单位换算,算出1rpx = 多少px
  91. const w = system.windowWidth / 750
  92. // 处理数据
  93. list.value.forEach((ele) => {
  94. if (ele.location === '探学楼') {
  95. ele.x = 336 * w
  96. ele.y = 158 * w
  97. } else if (ele.location === '地下室出口' || ele.location === '地下室') {
  98. ele.x = 230 * w
  99. ele.y = 250 * w
  100. } else if (ele.location === '探问楼') {
  101. ele.x = 280 * w
  102. ele.y = 270 * w
  103. } else if (ele.location === '探理楼') {
  104. ele.x = 280 * w
  105. ele.y = 380 * w
  106. } else if (ele.location === '地下室入口') {
  107. ele.x = 344 * w
  108. ele.y = 356 * w
  109. } else if (ele.location === '探真楼') {
  110. ele.x = 384 * w
  111. ele.y = 276 * w
  112. } else if (ele.location === '学校大门') {
  113. ele.x = 370 * w
  114. ele.y = 396 * w
  115. } else if (ele.location === '消防通道') {
  116. ele.x = 510 * w
  117. ele.y = 380 * w
  118. } else if (ele.location === '文化连廊') {
  119. ele.x = 306 * w
  120. ele.y = 280 * w
  121. } else if (ele.location === '田径场') {
  122. ele.x = 580 * w
  123. ele.y = 218 * w
  124. }
  125. })
  126. }
  127. }
  128. // 时间筛选框切换时间回调
  129. const changeTime = (e) => {
  130. // console.log(e)
  131. if (e.length) {
  132. getData()
  133. ctx.value.clearRect(0, 0, 750, 480)
  134. drawAddress()
  135. setTimeout(() => {
  136. drawTrack()
  137. }, 1000)
  138. }
  139. }
  140. // 绘制地点
  141. const drawAddress = () => {
  142. ctx.value = uni.createCanvasContext('firstCanvas')
  143. // 获取设备宽度
  144. const system = uni.getSystemInfoSync()
  145. // 单位换算,算出1rpx = 多少px
  146. const w = system.windowWidth / 750
  147. ctx.value.beginPath()
  148. // 探学楼点位
  149. ctx.value.arc(336 * w, 158 * w, 4, 0, 2 * Math.PI)
  150. // 地下室出口
  151. ctx.value.arc(230 * w, 250 * w, 4, 0, 2 * Math.PI)
  152. ctx.value.setFillStyle('#409EFF')
  153. ctx.value.fill()
  154. ctx.value.beginPath()
  155. // 探问楼
  156. ctx.value.arc(280 * w, 270 * w, 4, 0, 2 * Math.PI)
  157. // 探理楼
  158. ctx.value.arc(280 * w, 380 * w, 4, 0, 2 * Math.PI)
  159. ctx.value.setFillStyle('#409EFF')
  160. ctx.value.fill()
  161. ctx.value.beginPath()
  162. // 地下室入口
  163. ctx.value.arc(344 * w, 356 * w, 4, 0, 2 * Math.PI)
  164. // 探真楼
  165. ctx.value.arc(384 * w, 276 * w, 4, 0, 2 * Math.PI)
  166. ctx.value.setFillStyle('#409EFF')
  167. ctx.value.fill()
  168. ctx.value.beginPath()
  169. // 学校大门
  170. ctx.value.arc(370 * w, 396 * w, 4, 0, 2 * Math.PI)
  171. // 消防通道
  172. ctx.value.arc(510 * w, 380 * w, 4, 0, 2 * Math.PI)
  173. ctx.value.setFillStyle('#409EFF')
  174. ctx.value.fill()
  175. ctx.value.beginPath()
  176. // 文化连廊
  177. ctx.value.arc(306 * w, 280 * w, 4, 0, 2 * Math.PI)
  178. // 田径场
  179. ctx.value.arc(580 * w, 218 * w, 4, 0, 2 * Math.PI)
  180. ctx.value.setFillStyle('#409EFF')
  181. ctx.value.fill()
  182. ctx.value.draw()
  183. }
  184. // 绘制轨迹
  185. const drawTrack = () => {
  186. for (let i = 0; i < list.value.length; i++) {
  187. let a = list.value[i]?.x
  188. let b = list.value[i]?.y
  189. let c = list.value[i + 1]?.x
  190. let d = list.value[i + 1]?.y
  191. drawLine(a, b, c, d, i, list.value.length)
  192. }
  193. }
  194. // 根据点之间画线
  195. const drawLine = (a, b, c, d, i, length) => {
  196. if (i == 0) {
  197. ctx.value.arc(a, b, 4, 0, 2 * Math.PI)
  198. ctx.value.setFillStyle('#fff')
  199. ctx.value.fill()
  200. }
  201. if (i === length - 1 && length > 1) {
  202. ctx.value.arc(a, b, 4, 0, 2 * Math.PI)
  203. ctx.value.setFillStyle('red')
  204. ctx.value.fill()
  205. }
  206. // 设置边框颜色
  207. ctx.value.setStrokeStyle('#00FEFE')
  208. // 把路径移动到画布中的指定点,不创建线条
  209. if (a && b) {
  210. ctx.value.moveTo(a, b)
  211. }
  212. if (c && d) {
  213. ctx.value.lineTo(c, d)
  214. }
  215. ctx.value.stroke()
  216. // 开始绘制
  217. ctx.value.draw(true)
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .container {
  222. position: relative;
  223. display: flex;
  224. flex-direction: column;
  225. min-height: 100vh;
  226. background-color: #f1f6fe;
  227. // 顶部筛选区域样式
  228. .search {
  229. display: flex;
  230. justify-content: space-evenly;
  231. padding: 0 30rpx;
  232. margin: 30rpx 0;
  233. height: 65rpx;
  234. }
  235. .map_box {
  236. position: absolute;
  237. top: 125rpx;
  238. left: 0;
  239. width: 750rpx;
  240. height: 480rpx;
  241. .img {
  242. width: 750rpx;
  243. height: 480rpx;
  244. }
  245. }
  246. // 轨迹区域样式
  247. .track {
  248. padding: 0 20rpx 20rpx 20rpx;
  249. .track_title {
  250. margin: 30rpx 0;
  251. font-size: 32rpx;
  252. font-weight: bold;
  253. }
  254. .track_time {
  255. font-size: 28rpx;
  256. font-weight: bold;
  257. }
  258. .track_desc {
  259. display: flex;
  260. margin-top: 10rpx;
  261. color: #808080;
  262. font-size: 24rpx;
  263. .img {
  264. width: 100rpx;
  265. height: 160rpx;
  266. }
  267. }
  268. }
  269. }
  270. </style>