index.vue
1.22 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
<template>
  <div>
    <n-image
      preview-disabled
      :fallback-src="requireErrorImg()"
      :src="!dataset ? logo : dataset"
      :width="w"
      :height="h"
    ></n-image>
  </div>
</template>
<script setup lang="ts">
import { PropType, toRefs, watch } from 'vue'
import { requireErrorImg } from '@/utils'
import { useChartDataFetch } from '@/hooks'
import { CreateComponentType } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { option } from './config'
import logo from '@/assets/logo.png'
const props = defineProps({
  chartConfig: {
    type: Object as PropType<CreateComponentType>,
    required: true
  }
})
const { w, h } = toRefs(props.chartConfig.attr)
const { dataset, valueConfig } = toRefs(props.chartConfig.option as unknown as typeof option)
watch(
  () => dataset?.value,
  newValue => {
    const findImageUrl = valueConfig?.value.find(
      (valueConfigItem: typeof option['valueConfig'][0]) => String(valueConfigItem.value) === String(newValue)
    )
    if (findImageUrl) {
      dataset.value = findImageUrl?.imageUrl
    }
  },
  {
    immediate: true
  }
)
// 预览更新
useChartDataFetch(props.chartConfig, useChartEditStore)
</script>