index.vue
2.07 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
<template>
<div class="banner-box" ref="root">
<n-grid x-gap="12" :y-gap="12" :cols="computedCols">
<n-gi v-for="(item, index) in option.dataset" :key="index + item">
<div class="camera-container">
<CameraItem
ref="cameraRef"
:name="item.name"
:avatar="item.avatar"
:key="item + index"
:sourceSrc="item.url"
:index="index"
:autoplay="autoplay"
/>
</div>
</n-gi>
</n-grid>
</div>
</template>
<script setup lang="ts">
import { PropType, toRefs, watch, shallowReactive, ref, computed } from 'vue'
import { CreateComponentType } from '@/packages/index.d'
import 'video.js/dist/video-js.min.css'
import { option as configOption } from './config'
import { CameraItem } from './components'
const props = defineProps({
chartConfig: {
type: Object as PropType<CreateComponentType>,
required: true
}
})
const { h } = toRefs(props.chartConfig.attr)
const { autoplay } = toRefs(props.chartConfig.option)
const responsiveComputeValue = ref(0)
const option = shallowReactive({
dataset: configOption.dataset
})
const computedCols = computed(() => {
if (option.dataset.length <= 1) return 1
if (option.dataset.length <= 4) return 2
return 3
})
const cameraRef = ref<InstanceType<typeof CameraItem>>()
const responsive = (value: number) => {
responsiveComputeValue.value = value
if (option.dataset.length <= 2) responsiveComputeValue.value = value
if (option.dataset.length > 2 && option.dataset.length <= 4) responsiveComputeValue.value = value / 2.03
if (option.dataset.length > 4 && option.dataset.length <= 9) responsiveComputeValue.value = value / 3.1
}
watch(
() => props.chartConfig.option.dataset,
newData => {
option.dataset = newData
responsive(h.value)
},
{
immediate: true,
deep: true
}
)
watch(
() => h.value,
newData => responsive(newData),
{
immediate: true
}
)
</script>
<style lang="scss" scoped>
.banner-box {
.camera-container {
height: v-bind('`${responsiveComputeValue}px`');
}
}
</style>