index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <RightFillPano>
  3. <template #header>
  4. <div class="tabs">
  5. <span class="tabs-left">行动录制</span>
  6. <div class="tabs-right">
  7. <span v-if="!isRecord"></span>
  8. <span v-else class="timer-display">{{ formatTime(recordingTime) }}</span>
  9. <span class="tabs-right-img">
  10. <img v-show="!isRecord" src="@/assets/record_n.svg" alt="" @click="startRecord('start')">
  11. <img v-show="isRecord" src="@/assets/record_s.svg" alt="" @click="startRecord('stop')">
  12. </span>
  13. </div>
  14. </div>
  15. </template>
  16. <mediaList />
  17. </RightFillPano>
  18. </template>
  19. <script lang="ts" setup>
  20. import { RightFillPano } from "@/layout";
  21. import { postAddPathInPosition } from '@/api'
  22. import mediaList from "./components/mediaList.vue";
  23. import { nextTick, reactive, ref, watchEffect, onUnmounted } from "vue";
  24. import { positionList, enterOld, enterEdit } from "@/store";
  25. import { loadPack } from '@/utils'
  26. const isRecord = ref(false);
  27. const startTime = ref<number>(0);
  28. const endTime = ref<number>(0);
  29. const recordingTime = ref<number>(0);
  30. let timer: NodeJS.Timeout | null = null;
  31. nextTick(() => {
  32. // enterEdit();
  33. });
  34. // 格式化时间为 HH:MM:SS 格式
  35. const formatTime = (seconds: number): string => {
  36. const hours = Math.floor(seconds / 3600);
  37. const minutes = Math.floor((seconds % 3600) / 60);
  38. const secs = seconds % 60;
  39. return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
  40. };
  41. const startRecord = (type: string) => {
  42. if (type === 'start') {
  43. // 开始录制
  44. isRecord.value = true;
  45. startTime.value = Date.now(); // 记录开始时间戳
  46. recordingTime.value = 0;
  47. // 启动计时器,每秒更新一次
  48. timer = setInterval(() => {
  49. recordingTime.value = Math.floor((Date.now() - startTime.value) / 1000);
  50. }, 1000);
  51. let isSave = false;
  52. } else {
  53. // 停止录制
  54. isRecord.value = false;
  55. endTime.value = Date.now(); // 记录结束时间戳
  56. // 清除计时器
  57. if (timer) {
  58. clearInterval(timer);
  59. timer = null;
  60. }
  61. // 重置录制时间
  62. recordingTime.value = 0;
  63. console.log('录制时间段:', {
  64. startTime: startTime.value,
  65. endTime: endTime.value,
  66. duration: endTime.value - startTime.value
  67. });
  68. // 这里调path接口传路线数据过去,有几个设备就生成几个path
  69. positionList.value.forEach((pos: any) => {
  70. postAddPathInPosition({}, startTime.value, endTime.value)
  71. });
  72. // enterOld(async () => {})
  73. }
  74. };
  75. // 组件卸载时清理计时器
  76. onUnmounted(() => {
  77. if (timer) {
  78. clearInterval(timer);
  79. timer = null;
  80. }
  81. });
  82. </script>
  83. <style lang="scss" scoped>
  84. .tabs {
  85. height: 60px;
  86. border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  87. display: flex;
  88. justify-content: space-between;
  89. align-items: center;
  90. margin: -20px;
  91. padding: 0 20px;
  92. margin-bottom: 20px;
  93. .tabs-left {
  94. font-size: 16px;
  95. font-weight: blod;
  96. color: #fff;
  97. }
  98. .tabs-right {
  99. display: flex;
  100. align-items: center;
  101. gap: 10px;
  102. .timer-display {
  103. font-family: 'Courier New', monospace;
  104. font-weight: bold;
  105. color: #FFFFFF;
  106. font-size: 14px;
  107. min-width: 65px;
  108. text-align: center;
  109. }
  110. .tabs-right-img {
  111. display: flex;
  112. align-items: center;
  113. img {
  114. width: 20px;
  115. height: 20px;
  116. cursor: pointer;
  117. }
  118. }
  119. }
  120. }
  121. </style>