Commit 9369133db8ff306b9e5e29e60c00683e625722eb

Authored by fengwotao
1 parent 11b68377

perf(src/views/chart): 优化多个摄像头,可以自动切换也可以手动切换

@@ -9,6 +9,7 @@ export enum sourceTypeEnum { @@ -9,6 +9,7 @@ export enum sourceTypeEnum {
9 } 9 }
10 10
11 export const option = { 11 export const option = {
  12 + autoSwitch: false,
12 dataset: [ 13 dataset: [
13 { 14 {
14 byIdUrl: '', //通过接口获取的url 15 byIdUrl: '', //通过接口获取的url
@@ -18,7 +19,7 @@ export const option = { @@ -18,7 +19,7 @@ export const option = {
18 } 19 }
19 ] as any, 20 ] as any,
20 // 自动播放的间隔(ms) 21 // 自动播放的间隔(ms)
21 - interval: 5000, 22 + interval: 2000,
22 autoplay: true, 23 autoplay: true,
23 effect: 'slide', 24 effect: 'slide',
24 displayMode: 'singleGrid' 25 displayMode: 'singleGrid'
1 <template> 1 <template>
2 <CollapseItem name="播放器配置" :expanded="true"> 2 <CollapseItem name="播放器配置" :expanded="true">
  3 + <setting-item-box name="开启切换" :alone="true">
  4 + <setting-item>
  5 + <n-switch v-model:value="optionData.autoSwitch" size="small"></n-switch>
  6 + </setting-item>
  7 + </setting-item-box>
  8 + <setting-item-box name="间隔时长" :alone="true">
  9 + <setting-item>
  10 + <n-input-number v-model:value="optionData.interval" size="small"></n-input-number>
  11 + </setting-item>
  12 + </setting-item-box>
3 <template v-for="(item, index) in optionData.dataset" :key="index"> 13 <template v-for="(item, index) in optionData.dataset" :key="index">
4 <setting-item-box name="源类型" :alone="true"> 14 <setting-item-box name="源类型" :alone="true">
5 <setting-item> 15 <setting-item>
@@ -37,6 +37,8 @@ const isShowSvg = ref(false) @@ -37,6 +37,8 @@ const isShowSvg = ref(false)
37 37
38 const { w, h } = toRefs(props.chartConfig.attr) 38 const { w, h } = toRefs(props.chartConfig.attr)
39 39
  40 +const { autoSwitch, interval } = toRefs(props.chartConfig.option)
  41 +
40 const option = shallowReactive({ 42 const option = shallowReactive({
41 dataset: configOption.dataset 43 dataset: configOption.dataset
42 }) 44 })
@@ -45,8 +47,6 @@ const cameraRef = ref<InstanceType<typeof CameraItem>>() @@ -45,8 +47,6 @@ const cameraRef = ref<InstanceType<typeof CameraItem>>()
45 47
46 let initial = ref(0) 48 let initial = ref(0)
47 49
48 -let interval = ref(2500)  
49 -  
50 const computedFunc = (initial: number, source: any) => { 50 const computedFunc = (initial: number, source: any) => {
51 if (initial < 0) initial = 0 51 if (initial < 0) initial = 0
52 if (Array.isArray(source)) { 52 if (Array.isArray(source)) {
@@ -130,10 +130,12 @@ let root = ref(null) @@ -130,10 +130,12 @@ let root = ref(null)
130 130
131 onMounted(() => { 131 onMounted(() => {
132 clearInterval(timer) 132 clearInterval(timer)
133 - autoPlay()  
134 const box: any = root.value 133 const box: any = root.value
135 box.onmouseenter = () => clearInterval(timer) 134 box.onmouseenter = () => clearInterval(timer)
136 - box.onmouseleave = () => autoPlay() 135 + if (autoSwitch.value) {
  136 + autoPlay()
  137 + box.onmouseleave = () => autoPlay()
  138 + }
137 }) 139 })
138 140
139 // 点击左右按钮切换图片 141 // 点击左右按钮切换图片