chronography.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { defineComponent, onBeforeUnmount, onMounted, reactive } from 'vue'
  2. import dayjs from 'dayjs'
  3. import duration from 'dayjs/plugin/duration'
  4. import 'loaders.css/loaders.min.css'
  5. import runtime, { START_LIVE_TIME } from '../../components/live-broadcast/runtime'
  6. import styles from './chronography.module.less'
  7. dayjs.extend(duration)
  8. export default defineComponent({
  9. setup() {
  10. const data = reactive({
  11. duration: ''
  12. })
  13. const starttimestr = sessionStorage.getItem(START_LIVE_TIME)
  14. const starttime = Number(starttimestr)
  15. let timer: NodeJS.Timer | null = null
  16. onMounted(() => {
  17. timer = setInterval(() => {
  18. const nowtime = dayjs().valueOf()
  19. if (starttime && nowtime - starttime) {
  20. data.duration = dayjs.duration((nowtime - starttime)).format('HH:mm:ss')
  21. }
  22. })
  23. })
  24. onBeforeUnmount(() => {
  25. if (timer) {
  26. clearInterval(timer)
  27. }
  28. })
  29. return () => runtime.videoStatus === 'liveing' && starttime ? (
  30. <div class={styles.time}>
  31. <div class={styles.status}>
  32. <div class="line-scale-pulse-out">
  33. <div></div>
  34. <div></div>
  35. <div></div>
  36. </div>
  37. <span>直播中</span>
  38. </div>
  39. <span class={styles.text}>{data.duration}</span>
  40. </div>
  41. ) : null
  42. }
  43. })