index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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, ref, onUnmounted } from "vue";
  24. import { positionList, paths, initialPaths } from "@/store";
  25. import { sdk } from "@/sdk";
  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. // console.log(paths, 8888)
  70. let positionPaths = sdk.generateAniPathData() || []
  71. positionPaths.forEach(async(positionPath: any) => {
  72. await postAddPathInPosition(positionPath, startTime.value, endTime.value)
  73. })
  74. //获取一次列表
  75. setTimeout(async () => {
  76. await initialPaths()
  77. }, 500)
  78. // positionList.value.forEach((pos: any) => {
  79. // // 寻找当前设备对应的path
  80. // let positionPath = positionPaths.find((path: any) =>{return '00' + pos.macId == path.id})
  81. // console.log(positionPaths, pos, positionPath, 88)
  82. // if(positionPath){
  83. // postAddPathInPosition(positionPath, startTime.value, endTime.value)
  84. // }
  85. // });
  86. // enterOld(async () => {})
  87. }
  88. };
  89. // 组件卸载时清理计时器
  90. onUnmounted(() => {
  91. if (timer) {
  92. clearInterval(timer);
  93. timer = null;
  94. }
  95. });
  96. </script>
  97. <style lang="scss" scoped>
  98. .tabs {
  99. height: 60px;
  100. border-bottom: 1px solid rgba(255, 255, 255, 0.16);
  101. display: flex;
  102. justify-content: space-between;
  103. align-items: center;
  104. margin: -20px;
  105. padding: 0 20px;
  106. margin-bottom: 20px;
  107. .tabs-left {
  108. font-size: 16px;
  109. font-weight: blod;
  110. color: #fff;
  111. }
  112. .tabs-right {
  113. display: flex;
  114. align-items: center;
  115. gap: 10px;
  116. .timer-display {
  117. font-family: 'Courier New', monospace;
  118. font-weight: bold;
  119. color: #FFFFFF;
  120. font-size: 14px;
  121. min-width: 65px;
  122. text-align: center;
  123. }
  124. .tabs-right-img {
  125. display: flex;
  126. align-items: center;
  127. img {
  128. width: 20px;
  129. height: 20px;
  130. cursor: pointer;
  131. }
  132. }
  133. }
  134. }
  135. </style>