Commit 9369133db8ff306b9e5e29e60c00683e625722eb
1 parent
11b68377
perf(src/views/chart): 优化多个摄像头,可以自动切换也可以手动切换
Showing
3 changed files
with
18 additions
and
5 deletions
| ... | ... | @@ -9,6 +9,7 @@ export enum sourceTypeEnum { | 
| 9 | 9 | } | 
| 10 | 10 | |
| 11 | 11 | export const option = { | 
| 12 | + autoSwitch: false, | |
| 12 | 13 | dataset: [ | 
| 13 | 14 | { | 
| 14 | 15 | byIdUrl: '', //通过接口获取的url | 
| ... | ... | @@ -18,7 +19,7 @@ export const option = { | 
| 18 | 19 | } | 
| 19 | 20 | ] as any, | 
| 20 | 21 | // 自动播放的间隔(ms) | 
| 21 | - interval: 5000, | |
| 22 | + interval: 2000, | |
| 22 | 23 | autoplay: true, | 
| 23 | 24 | effect: 'slide', | 
| 24 | 25 | displayMode: 'singleGrid' | ... | ... | 
| 1 | 1 | <template> | 
| 2 | 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 | 13 | <template v-for="(item, index) in optionData.dataset" :key="index"> | 
| 4 | 14 | <setting-item-box name="源类型" :alone="true"> | 
| 5 | 15 | <setting-item> | ... | ... | 
| ... | ... | @@ -37,6 +37,8 @@ const isShowSvg = ref(false) | 
| 37 | 37 | |
| 38 | 38 | const { w, h } = toRefs(props.chartConfig.attr) | 
| 39 | 39 | |
| 40 | +const { autoSwitch, interval } = toRefs(props.chartConfig.option) | |
| 41 | + | |
| 40 | 42 | const option = shallowReactive({ | 
| 41 | 43 | dataset: configOption.dataset | 
| 42 | 44 | }) | 
| ... | ... | @@ -45,8 +47,6 @@ const cameraRef = ref<InstanceType<typeof CameraItem>>() | 
| 45 | 47 | |
| 46 | 48 | let initial = ref(0) | 
| 47 | 49 | |
| 48 | -let interval = ref(2500) | |
| 49 | - | |
| 50 | 50 | const computedFunc = (initial: number, source: any) => { | 
| 51 | 51 | if (initial < 0) initial = 0 | 
| 52 | 52 | if (Array.isArray(source)) { | 
| ... | ... | @@ -130,10 +130,12 @@ let root = ref(null) | 
| 130 | 130 | |
| 131 | 131 | onMounted(() => { | 
| 132 | 132 | clearInterval(timer) | 
| 133 | - autoPlay() | |
| 134 | 133 | const box: any = root.value | 
| 135 | 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 | // 点击左右按钮切换图片 | ... | ... |