videoModal.vue
3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<template>
  <div>
    <BasicModal
      v-bind="$attrs"
      width="60rem"
      destroyOnClose
      :height="heightNum"
      @register="register"
      title="视频预览"
      :showOkBtn="false"
      @cancel="handleCancel"
    >
      <div
        class="flex items-center justify-center w-full h-full min-h-96 video-container bg-dark-50"
      >
        <VideoPlayer
          ref="videoInstance"
          v-if="showVideo"
          :options="(options as VideoJsPlayerOptions)"
          :withToken="withToken"
          :isGBT="isGBT"
          :GBTOption="GBTOption"
        />
      </div>
    </BasicModal>
  </div>
</template>
<script setup lang="ts">
  import { ref, reactive } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { VideoJsPlayerOptions } from 'video.js';
  import VideoPlayer from './video.vue';
  import { getVideoControlStart } from '/@/api/device/videoChannel';
  import { VideoChannelItemType } from '/@/api/device/model/videoChannelModel';
  import { getVideoTypeByUrl } from '/@/components/Video';
  import { AccessMode } from '/@/views/camera/manage/config.data';
  import { getStreamingPlayUrl } from '/@/api/camera/cameraManager';
  const emit = defineEmits(['reloadTable', 'register']);
  const heightNum = ref(800);
  const showVideo = ref(false);
  const videoInstance = ref<InstanceType<typeof VideoPlayer>>();
  const videoId = ref<string>();
  const withToken = ref(false);
  const options = reactive<VideoJsPlayerOptions>({
    width: '100%' as unknown as number,
    height: 384 as unknown as number,
    autoplay: true,
  });
  const GBTOption = ref({
    tbDeviceId: '',
    channelId: '',
  });
  const isGBT = ref<boolean>(false);
  const [register, { setModalProps }] = useModalInner(
    async (data: { record: VideoChannelItemType }) => {
      const { record, ifShowGBT = false } = data;
      const { params } = record as Recordable;
      videoId.value = record.id || '';
      isGBT.value = ifShowGBT;
      GBTOption.value.tbDeviceId = params?.deviceId ? params?.deviceId : record?.deviceId;
      GBTOption.value.channelId = params?.channelNo ? params?.channelNo : record?.channelId;
      try {
        setModalProps({ loading: true, loadingTip: '视频加载中...' });
        // getStreamingPlayUrl
        let result: any = null;
        if (record.accessMode === AccessMode.GBT28181 || ifShowGBT) {
          result = await getVideoControlStart({
            deviceId: params?.deviceId ? params?.deviceId : record?.deviceId,
            channelId: params?.channelNo ? params?.channelNo : record?.channelId,
          });
          options.sources = [{ src: result.data.flv, type: getVideoTypeByUrl(result.data.flv) }];
        } else {
          result = await getStreamingPlayUrl(record.id);
          options.sources = [
            { src: result.data.url, type: getVideoTypeByUrl(result.data.url), id: record.id },
          ];
        }
        showVideo.value = true;
      } catch (error) {
      } finally {
        setModalProps({ loading: false });
      }
    }
  );
  const handleCancel = () => {
    showVideo.value = false;
    withToken.value = false;
    emit('reloadTable');
  };
</script>
<style lang="less" scoped>
  .video-container:deep(.vben-basic-video-play) {
    min-height: 13rem;
  }
  .video-container:deep(.video-js) {
    min-height: 13rem;
  }
</style>