recordDetail.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div class="container">
  3. <Breadcrumb :items="['乐跑记录', '记录详情']" />
  4. <a-card title="记录详情">
  5. <a-skeleton animation :loading="loading">
  6. <a-space direction="vertical" :style="{ width: '100%' }" size="large">
  7. <a-skeleton-shape size="large" />
  8. <a-skeleton-line :rows="5" />
  9. </a-space>
  10. </a-skeleton>
  11. <a-descriptions :data="info" :column="2" />
  12. <MapContainer v-if="showMap" :point_list="data.result.point_list" :pathData="data.data" threeD
  13. style="margin-top: 10px;" />
  14. </a-card>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { ref, onMounted } from 'vue'
  19. import { GetRecordDetail } from '@/api/lepao'
  20. import { Notification } from '@arco-design/web-vue'
  21. import { useRoute } from 'vue-router'
  22. import MapContainer from '@/components/Map/MapContainer.vue'
  23. const route = useRoute()
  24. const loading = ref(false)
  25. const showMap = ref(false)
  26. const data = ref({})
  27. const info = ref([])
  28. const getRecordDetail = async (id) => {
  29. try {
  30. loading.value = true
  31. showMap.value = false
  32. const res = await GetRecordDetail({ id })
  33. if (!res || res.code !== 0)
  34. return Notification.error({
  35. title: '获取路径数据失败!',
  36. content: res?.msg ?? '请稍后再试'
  37. })
  38. data.value = res.data
  39. showMap.value = true
  40. info.value = [
  41. { label: '账号名称', value: res.data.name },
  42. { label: '乐跑账号', value: res.data.lepao_account },
  43. { label: '跑区名称', value: res.data.result.pass_tit },
  44. { label: '记录时间', value: stramptoTime(res.data.time) },
  45. { label: '开始时间', value: stramptoTime(res.data.result.start_time * 1000) },
  46. { label: '打卡点数量', value: res.data.result.point_list.length },
  47. { label: '跑步距离', value: res.data.result.distance + ' Km' },
  48. { label: '跑步时长', value: formatSecondsToMinSec(res.data.result.time) },
  49. { label: '平均配速', value: calculatePace(res.data.result.time, res.data.result.distance) }
  50. ]
  51. } catch (error) {
  52. Notification.error({
  53. title: '获取路径数据失败!',
  54. content: error.message || '请稍后再试'
  55. })
  56. } finally {
  57. loading.value = false
  58. }
  59. }
  60. onMounted(() => {
  61. getRecordDetail(route.params.id)
  62. })
  63. const stramptoTime = (time) => {
  64. return new Date(time).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })
  65. }
  66. function calculatePace(seconds, kilometers) {
  67. const paceInSeconds = seconds / kilometers;
  68. const minutes = Math.floor(paceInSeconds / 60);
  69. const remainingSeconds = Math.round(paceInSeconds % 60);
  70. return `${minutes}'${remainingSeconds.toString().padStart(2, '0')}''`;
  71. }
  72. function formatSecondsToMinSec(totalSeconds) {
  73. const minutes = Math.floor(totalSeconds / 60);
  74. const seconds = totalSeconds % 60;
  75. return `${minutes}分${seconds.toString().padStart(2, '0')}秒`;
  76. }
  77. </script>
  78. <style scoped lang="less">
  79. .container {
  80. padding: 0 20px 20px 20px;
  81. }
  82. </style>