index.vue
1.51 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
<!-- eslint-disable vue/multi-word-component-names -->
<template>
<!-- 重要:需要设置 crossOrigin="anonymous",否则保存画板缩略图会失败 -->
<video
ref="vVideoRef"
class="go-video"
preload="auto"
crossOrigin="anonymous"
playsinline
autoplay
:loop="option.loop"
:muted="option.muted"
:width="w"
:height="h"
:src="option.dataset"
controls
></video>
</template>
<script setup lang="ts">
import { PropType, toRefs, shallowReactive, watch, ref } from 'vue'
import { useChartDataFetch } from '@/hooks'
import { CreateComponentType } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { option as configOption } from './config'
const props = defineProps({
chartConfig: {
type: Object as PropType<CreateComponentType>,
required: true
}
})
const { w, h } = toRefs(props.chartConfig.attr)
let option = shallowReactive({ ...configOption })
// 预览更新
const vVideoRef = ref(null)
useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
option = newData
})
// 编辑更新
watch(
() => props.chartConfig.option,
(newData: any) => {
option = newData
if (!vVideoRef.value) return
const video: any = vVideoRef.value
video.loop = option.loop
video.muted = option.muted
video.play()
},
{
immediate: true,
deep: true
}
)
</script>
<style lang="scss" scoped>
@include go('video') {
display: block;
object-fit: v-bind('option.fit');
}
</style>