Commit 0ff759504b82562e136598cf08d3c0c49aaf069c

Authored by ww
1 parent 4ae77c09

fix: 视频组件视频流为必选&&视频新增loading加载

@@ -66,9 +66,13 @@ const [register, { getFieldsValue, validate, setFieldsValue }] = useForm({ @@ -66,9 +66,13 @@ const [register, { getFieldsValue, validate, setFieldsValue }] = useForm({
66 field: VideoFormFieldsEnum.VIDEO_ID, 66 field: VideoFormFieldsEnum.VIDEO_ID,
67 label: VideoFormFieldsNameEnum.VIDEO_ID, 67 label: VideoFormFieldsNameEnum.VIDEO_ID,
68 component: ComponentEnum.API_SELECT, 68 component: ComponentEnum.API_SELECT,
  69 + required: true,
69 componentProps: ({ formModel }) => { 70 componentProps: ({ formModel }) => {
70 return { 71 return {
71 - api: getCameraList, 72 + api: async (params: Record<'organizationId', string>) => {
  73 + if (!params.organizationId) return []
  74 + return await getCameraList(params)
  75 + },
72 params: { 76 params: {
73 organizationId: formModel[ContentDataFieldsEnum.ORG_ID], 77 organizationId: formModel[ContentDataFieldsEnum.ORG_ID],
74 }, 78 },
@@ -167,9 +171,10 @@ createPublicFormContext(nodeDataActinType) @@ -167,9 +171,10 @@ createPublicFormContext(nodeDataActinType)
167 171
168 <style lang="less" scoped> 172 <style lang="less" scoped>
169 .form-container { 173 .form-container {
  174 + @apply text-sm;
  175 +
  176 + :deep(.ant-divider) {
170 @apply text-sm; 177 @apply text-sm;
171 - :deep(.ant-divider) {  
172 - @apply text-sm;  
173 - }  
174 } 178 }
  179 +}
175 </style> 180 </style>
1 <script setup lang="ts"> 1 <script setup lang="ts">
  2 +import { Spin } from 'ant-design-vue'
2 import { computed, nextTick, onMounted, onUnmounted, ref, toRaw, unref } from 'vue' 3 import { computed, nextTick, onMounted, onUnmounted, ref, toRaw, unref } from 'vue'
3 import 'video.js/dist/video-js.css' 4 import 'video.js/dist/video-js.css'
4 5
@@ -21,6 +22,7 @@ const props = defineProps<{ @@ -21,6 +22,7 @@ const props = defineProps<{
21 // 获取节点数据 22 // 获取节点数据
22 const contentDataStore = useContentDataStore() 23 const contentDataStore = useContentDataStore()
23 const { getResult } = useFingerprint() 24 const { getResult } = useFingerprint()
  25 +const loading = ref(false)
24 26
25 const getOptions = computed<VideoJsPlayerOptions>(() => { 27 const getOptions = computed<VideoJsPlayerOptions>(() => {
26 const { config } = props || {} 28 const { config } = props || {}
@@ -47,53 +49,58 @@ const playSource = ref<Record<'src' | 'type', string>>( @@ -47,53 +49,58 @@ const playSource = ref<Record<'src' | 'type', string>>(
47 49
48 // 数据绑定获取的url 50 // 数据绑定获取的url
49 const handleGetVideoPlay = async () => { 51 const handleGetVideoPlay = async () => {
50 - const { dataSourceJson } = unref(videoConfig)[0] || {}  
51 - const { videoOption } = dataSourceJson || {}  
52 - const { id, accessMode, videoUrl, deviceId, channelId } = videoOption || {}  
53 - let type = getVideoTypeByUrl(videoUrl!)  
54 - let playUrl = videoUrl  
55 -  
56 - // 判断是否是流媒体播放  
57 - if (accessMode === VideoAccessModeEnum.Streaming && id) {  
58 - const { data: { url } = { url: '' } } = await getStreamingPlayUrl(id!)  
59 - playUrl = url  
60 - playUrl && (type = getVideoTypeByUrl(playUrl!))  
61 - }  
62 - else if (accessMode === VideoAccessModeEnum.GBT28181 && deviceId && channelId) {  
63 - const {  
64 - data: { flv },  
65 - } = await getVideoControlStart({ channelId, deviceId }) 52 + try {
  53 + loading.value = true
  54 + const { dataSourceJson } = unref(videoConfig)[0] || {}
  55 + const { videoOption } = dataSourceJson || {}
  56 + const { id, accessMode, videoUrl, deviceId, channelId } = videoOption || {}
  57 + let type = getVideoTypeByUrl(videoUrl!)
  58 + let playUrl = videoUrl
  59 + // 判断是否是流媒体播放
  60 + if (accessMode === VideoAccessModeEnum.Streaming && id) {
  61 + const { data: { url } = { url: '' } } = await getStreamingPlayUrl(id!)
  62 + playUrl = url
  63 + playUrl && (type = getVideoTypeByUrl(playUrl!))
  64 + }
  65 + else if (accessMode === VideoAccessModeEnum.GBT28181 && deviceId && channelId) {
  66 + const {
  67 + data: { flv },
  68 + } = await getVideoControlStart({ channelId, deviceId })
66 69
67 - playUrl = flv  
68 - type = VideoPlayerType.flv  
69 - } 70 + playUrl = flv
  71 + type = VideoPlayerType.flv
  72 + }
70 73
71 - // 判断是否是rtsp播放  
72 - if (isRtspProtocol(videoUrl!)) {  
73 - const result = await getResult()  
74 - const { visitorId } = result  
75 - playUrl = getFlvPlayUrl(playUrl!, visitorId)  
76 - withToken.value = true  
77 - } 74 + // 判断是否是rtsp播放
  75 + if (isRtspProtocol(videoUrl!)) {
  76 + const result = await getResult()
  77 + const { visitorId } = result
  78 + playUrl = getFlvPlayUrl(playUrl!, visitorId)
  79 + withToken.value = true
  80 + }
78 81
79 - playSource.value = {  
80 - src: playUrl!,  
81 - type,  
82 - } 82 + playSource.value = {
  83 + src: playUrl!,
  84 + type,
  85 + }
83 86
84 - const instance = unref(basicVideoPlayEl)?.customInit((options) => {  
85 - if (unref(withToken)) {  
86 - (options as any).flvjs.config.headers = {  
87 - 'X-Authorization': `Bearer ${isShareMode() ? getShareJwtToken() : getJwtToken()}`, 87 + const instance = unref(basicVideoPlayEl)?.customInit((options) => {
  88 + if (unref(withToken)) {
  89 + (options as any).flvjs.config.headers = {
  90 + 'X-Authorization': `Bearer ${isShareMode() ? getShareJwtToken() : getJwtToken()}`,
  91 + }
88 } 92 }
89 - }  
90 - return {  
91 - ...options,  
92 - sources: [toRaw(unref(playSource))],  
93 - } as VideoJsPlayerOptions  
94 - }) 93 + return {
  94 + ...options,
  95 + sources: [toRaw(unref(playSource))],
  96 + } as VideoJsPlayerOptions
  97 + })
95 98
96 - instance?.play() 99 + instance?.play()
  100 + }
  101 + finally {
  102 + loading.value = false
  103 + }
97 } 104 }
98 105
99 // 默认播放 106 // 默认播放
@@ -135,12 +142,12 @@ onUnmounted(async () => { @@ -135,12 +142,12 @@ onUnmounted(async () => {
135 142
136 <template> 143 <template>
137 <div class="w-full h-full flex justify-center items-center"> 144 <div class="w-full h-full flex justify-center items-center">
138 - <!-- <Spin :spinning="loading" wrapper-class-name="video-spin" class="w-full h-full"> -->  
139 - <BasicVideoPlay  
140 - ref="basicVideoPlayEl" :options="getOptions" :with-token="withToken"  
141 - :immediate-init-on-mounted="false"  
142 - />  
143 - <!-- </Spin> --> 145 + <Spin :spinning="loading">
  146 + <BasicVideoPlay
  147 + ref="basicVideoPlayEl" :options="getOptions" :with-token="withToken"
  148 + :immediate-init-on-mounted="false"
  149 + />
  150 + </Spin>
144 </div> 151 </div>
145 </template> 152 </template>
146 153