Commit e6ffb67e797452c2b74f0a7c7db33b2f38ec4371

Authored by fengwotao
1 parent bee12495

perf(src/packages): 多个摄像头切换箭头显示

1 -<template>  
2 - <video  
3 - crossOrigin="anonymous"  
4 - :id="`my-player${index}`"  
5 - ref="videoRef"  
6 - class="video-js my-video vjs-theme-city vjs-big-play-centered"  
7 - >  
8 - <source :src="sourceSrc" />  
9 - </video>  
10 -</template>  
11 -<script setup lang="ts">  
12 -import { onMounted, ref, onUnmounted, watch } from 'vue'  
13 -import videojs from 'video.js'  
14 -import type { VideoJsPlayerOptions } from 'video.js'  
15 -import 'video.js/dist/video-js.min.css'  
16 -  
17 -const props = defineProps({  
18 - sourceSrc: {  
19 - type: String  
20 - },  
21 - name: {  
22 - type: String  
23 - },  
24 - avatar: {  
25 - type: String  
26 - },  
27 - w: {  
28 - type: Number,  
29 - default: 300  
30 - },  
31 - h: {  
32 - type: Number,  
33 - default: 300  
34 - },  
35 - index: {  
36 - type: Number  
37 - }  
38 -})  
39 -  
40 -// video标签  
41 -const videoRef = ref<HTMLElement | null>(null)  
42 -  
43 -// video实例对象  
44 -let videoPlayer: videojs.Player | null = null  
45 -  
46 -//options配置  
47 -const options: VideoJsPlayerOptions = {  
48 - language: 'zh-CN', // 设置语言  
49 - controls: true, // 是否显示控制条  
50 - preload: 'auto', // 预加载  
51 - autoplay: true, // 是否自动播放  
52 - fluid: false, // 自适应宽高  
53 - poster: props?.avatar || '',  
54 - src: props?.sourceSrc || '', // 要嵌入的视频源的源 URL  
55 - muted: true,  
56 - userActions: {  
57 - hotkeys: true  
58 - }  
59 -}  
60 -  
61 -// 初始化videojs  
62 -const initVideo = () => {  
63 - if (videoRef.value) {  
64 - // 创建 video 实例  
65 - videoPlayer = videojs(videoRef.value, options)  
66 - }  
67 -}  
68 -  
69 -watch(  
70 - () => props.sourceSrc,  
71 - (newData: any) => {  
72 - // props.sourceSrc = newData  
73 - videoPlayer?.src(newData) as any  
74 - videoPlayer?.play()  
75 - },  
76 - {  
77 - immediate: true  
78 - }  
79 -)  
80 -  
81 -onMounted(() => {  
82 - initVideo()  
83 -})  
84 -  
85 -onUnmounted(() => {  
86 - handleVideoDispose()  
87 -})  
88 -  
89 -//播放  
90 -const handleVideoPlay = () => videoPlayer?.play()  
91 -  
92 -const handleVideoDispose = () => videoPlayer?.dispose() && videoPlayer?.pause()  
93 -//暂停  
94 -defineExpose({  
95 - handleVideoPlay,  
96 - handleVideoDispose  
97 -})  
98 -</script>  
99 -  
100 -<style lang="scss" scoped>  
101 -.my-video {  
102 - width: 100%;  
103 - height: 100%;  
104 -}  
105 -</style>  
1 <template> 1 <template>
2 <div class="banner-box" ref="root"> 2 <div class="banner-box" ref="root">
3 <div class="wrapper"> 3 <div class="wrapper">
4 - <div  
5 - v-for="(item, index) in option.dataset"  
6 - :key="index + item"  
7 - :class="item.className"  
8 - :style="item.sty"  
9 - > 4 + <div v-for="(item, index) in option.dataset" :key="index + item" :class="item.className" :style="item.sty">
10 <CameraItem 5 <CameraItem
11 ref="cameraRef" 6 ref="cameraRef"
12 :name="item.name" 7 :name="item.name"
@@ -24,7 +19,7 @@ @@ -24,7 +19,7 @@
24 <a href="javascript:;" class="right" @click="changeSlide('right')"></a> 19 <a href="javascript:;" class="right" @click="changeSlide('right')"></a>
25 </div> 20 </div>
26 </template> 21 </template>
27 -<script setup lang="ts"> 22 +<script setup lang="ts" name="index">
28 import { PropType, watch, toRefs, shallowReactive, onMounted, ref } from 'vue' 23 import { PropType, watch, toRefs, shallowReactive, onMounted, ref } from 'vue'
29 import { CreateComponentType } from '@/packages/index.d' 24 import { CreateComponentType } from '@/packages/index.d'
30 import 'video.js/dist/video-js.min.css' 25 import 'video.js/dist/video-js.min.css'
@@ -186,7 +181,7 @@ function changeSlide(dir: string) { @@ -186,7 +181,7 @@ function changeSlide(dir: string) {
186 position: absolute; 181 position: absolute;
187 top: 50%; 182 top: 50%;
188 transform: translateY(-50%); 183 transform: translateY(-50%);
189 - z-index: 9; 184 + z-index: 90000000;
190 width: 50px; 185 width: 50px;
191 height: 50px; 186 height: 50px;
192 background-size: contain; 187 background-size: contain;
@@ -195,12 +190,12 @@ function changeSlide(dir: string) { @@ -195,12 +190,12 @@ function changeSlide(dir: string) {
195 } 190 }
196 a.left { 191 a.left {
197 @extend .arrow; 192 @extend .arrow;
198 - background-image: url(./static/left.svg); 193 + background-image: url('./static/left.svg');
199 left: 0px; 194 left: 0px;
200 } 195 }
201 a.right { 196 a.right {
202 @extend .arrow; 197 @extend .arrow;
203 - background-image: url(./static/right.svg); 198 + background-image: url('./static/right.svg');
204 right: 0px; 199 right: 0px;
205 } 200 }
206 } 201 }
1 -<template>  
2 - <div class="banner-box" ref="root">  
3 - <n-grid x-gap="12" :y-gap="12" :cols="computedCols">  
4 - <n-gi v-for="(item, index) in option.dataset" :key="index + item">  
5 - <div class="camera-container">  
6 - <CameraItem  
7 - ref="cameraRef"  
8 - :name="item.name"  
9 - :avatar="item.avatar"  
10 - :key="item + index"  
11 - :sourceSrc="item.url"  
12 - :index="index"  
13 - />  
14 - </div>  
15 - </n-gi>  
16 - </n-grid>  
17 - </div>  
18 -</template>  
19 -<script setup lang="ts">  
20 -import { PropType, toRefs, watch, shallowReactive, ref, computed } from 'vue'  
21 -import { CreateComponentType } from '@/packages/index.d'  
22 -import 'video.js/dist/video-js.min.css'  
23 -import { option as configOption } from './config'  
24 -import { CameraItem } from './components'  
25 -  
26 -const props = defineProps({  
27 - chartConfig: {  
28 - type: Object as PropType<CreateComponentType>,  
29 - required: true  
30 - }  
31 -})  
32 -  
33 -const { h } = toRefs(props.chartConfig.attr)  
34 -  
35 -const responsiveComputeValue = ref(0)  
36 -  
37 -const option = shallowReactive({  
38 - dataset: configOption.dataset  
39 -})  
40 -  
41 -const computedCols = computed(() => {  
42 - if (option.dataset.length <= 1) return 1  
43 - if (option.dataset.length <= 4) return 2  
44 - return 3  
45 -})  
46 -  
47 -const cameraRef = ref<InstanceType<typeof CameraItem>>()  
48 -  
49 -const responsive = (value: number) => {  
50 - responsiveComputeValue.value = value  
51 - if (option.dataset.length <= 2) responsiveComputeValue.value = value  
52 - if (option.dataset.length > 2 && option.dataset.length <= 4) responsiveComputeValue.value = value / 2.03  
53 - if (option.dataset.length > 4 && option.dataset.length <= 9) responsiveComputeValue.value = value / 3.1  
54 -}  
55 -  
56 -watch(  
57 - () => props.chartConfig.option.dataset,  
58 - newData => {  
59 - option.dataset = newData  
60 - responsive(h.value)  
61 - },  
62 - {  
63 - immediate: true,  
64 - deep: true  
65 - }  
66 -)  
67 -  
68 -watch(  
69 - () => h.value,  
70 - newData => responsive(newData),  
71 - {  
72 - immediate: true  
73 - }  
74 -)  
75 -</script>  
76 -  
77 -<style lang="scss" scoped>  
78 -.banner-box {  
79 - .camera-container {  
80 - height: v-bind('`${responsiveComputeValue}px`');  
81 - }  
82 -}  
83 -</style>