index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <van-dialog
  3. v-model:show="show"
  4. class="custom-dialog"
  5. title="在线点名提醒"
  6. confirmButtonText="确认点名"
  7. @confirm="handleToRollCall"
  8. >
  9. <div class="btn" @click="handleHideDialog">浮窗显示</div>
  10. <div class="line">
  11. <i class="icon-tip" />
  12. <div class="text1">{{ durationTime }}</div>
  13. </div>
  14. </van-dialog>
  15. <van-dialog
  16. v-model:show="show2"
  17. class="custom-dialog2"
  18. title="在线点名提醒"
  19. :showConfirmButton="false"
  20. >
  21. <div class="dialog-content">
  22. <div class="img-box" />
  23. <div v-show="!img" class="text1">即将通过摄像头捕捉画面</div>
  24. <div v-show="!img" class="text2">请稍等</div>
  25. <div v-show="img" class="btn" @click="handleToRollCall2">
  26. 上传视频截图
  27. </div>
  28. <div v-show="img" class="text3">已完成</div>
  29. </div>
  30. </van-dialog>
  31. <div v-if="!!rollCallData.id" class="float-box" @click="show = true" />
  32. </template>
  33. <script lang="ts" setup name="OnlineRollCall">
  34. import { ref, onUnmounted, nextTick } from "vue";
  35. import { useRouter } from "vue-router";
  36. import { hasMyCall, ackMyCall } from "@/api/onlineRollCall";
  37. const router = useRouter();
  38. // 在线点名弹窗
  39. let timer;
  40. let show = ref(false);
  41. let durationTime = ref("");
  42. let rollCallData = ref({
  43. id: 0,
  44. time1: ""
  45. });
  46. // 在线点名
  47. let show2 = ref();
  48. let img = ref("");
  49. const handleToRollCall = () => {
  50. show.value = false;
  51. show2.value = true;
  52. setTimeout(() => {
  53. img.value = "2";
  54. }, 3000);
  55. };
  56. const handleToRollCall2 = () => {
  57. ackMyCall({call_id: rollCallData.value.id}).then((res)=>{
  58. router.push({
  59. name: "rollCallRecord2",
  60. query: { id: rollCallData.value.id }
  61. });
  62. })
  63. };
  64. const calculateDuration = startTimeStr => {
  65. // 将起始时间字符串转换为日期对象
  66. const startTime = new Date(startTimeStr);
  67. // 获取当前时间作为结束时间
  68. const endTime = new Date();
  69. // 确保起始时间在结束时间之前(可选,用于验证输入)
  70. if (startTime > endTime) {
  71. return "";
  72. }
  73. // 计算时间差(以毫秒为单位)
  74. let timeDifference = endTime - startTime;
  75. // 将毫秒转换为秒、分钟和小时
  76. const seconds = Math.floor((timeDifference / 1000) % 60);
  77. const minutes = Math.floor((timeDifference / (1000 * 60)) % 60);
  78. const hours = Math.floor(timeDifference / (1000 * 60 * 60));
  79. // 格式化时间为 HH:MM:SS
  80. const formattedDuration = `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
  81. // 返回格式化的持续时间
  82. return formattedDuration;
  83. };
  84. const updateTime = () => {
  85. durationTime.value = calculateDuration(rollCallData.value.time1);
  86. };
  87. const handleHideDialog = () => {
  88. show.value = false;
  89. };
  90. nextTick(() => {
  91. const env = import.meta.env.VITE_APP_ENV
  92. if (env != 'development_') {
  93. hasMyCall({}).then((res)=>{
  94. if(res.data && res.data.length > 0) {
  95. rollCallData.value = res.data[0];
  96. show.value = true;
  97. if (!timer && !!rollCallData.value.time1) {
  98. timer = setInterval(updateTime, 1000);
  99. }
  100. }
  101. })
  102. }
  103. });
  104. onUnmounted(() => {
  105. if (!!timer) {
  106. clearInterval(timer);
  107. }
  108. });
  109. </script>
  110. <style lang="scss" scoped>
  111. .custom-dialog {
  112. position: relative;
  113. .btn {
  114. position: absolute;
  115. top: 10px;
  116. right: 6px;
  117. font-size: 12px;
  118. color: #2c81ff;
  119. }
  120. .line {
  121. display: flex;
  122. align-items: center;
  123. justify-content: center;
  124. height: 70px;
  125. .icon-tip {
  126. width: 30px;
  127. height: 31px;
  128. background: url("@/assets/images/onlineRollCall/tip.png") no-repeat;
  129. background-size: 100% 100%;
  130. }
  131. .text1 {
  132. font-size: 24px;
  133. color: #2c81ff;
  134. }
  135. }
  136. }
  137. .float-box {
  138. position: fixed;
  139. right: 10px;
  140. bottom: 70px;
  141. width: 86px;
  142. height: 77px;
  143. background: url("@/assets/images/onlineRollCall/float.png") no-repeat;
  144. background-size: 100% 100%;
  145. }
  146. .custom-dialog2 {
  147. .dialog-content {
  148. display: flex;
  149. flex-direction: column;
  150. justify-content: center;
  151. align-items: center;
  152. margin-top: 16px;
  153. }
  154. .img-box {
  155. width: 267px;
  156. height: 284px;
  157. background-color: #ededed;
  158. margin-bottom: 16px;
  159. }
  160. .text1 {
  161. font-size: 14px;
  162. color: #2c81ff;
  163. line-height: 26px;
  164. }
  165. .text2 {
  166. font-size: 12px;
  167. color: #ffaf00;
  168. line-height: 26px;
  169. }
  170. .text3 {
  171. font-size: 12px;
  172. color: #40c75f;
  173. line-height: 26px;
  174. }
  175. .btn {
  176. background: #2c81ff;
  177. border-radius: 2px;
  178. font-size: 12px;
  179. color: #ffffff;
  180. padding: 3px 14px;
  181. }
  182. }
  183. </style>