index.vue 1.44 KB
<template>
  <n-button
    :style="{ width: `${w}px`, height: `${h}px` }"
    :type="buttonType"
    @click="onClick(option.value.dataset[0],true)"
    >{{ option.value.dataset[0].label }}</n-button
  >
</template>

<script setup lang="ts">
import { PropType, toRefs, shallowReactive, watch, onMounted } from 'vue'
import cloneDeep from 'lodash/cloneDeep'
import { CreateComponentType } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { useChartInteract } from '@/hooks/external/useButtonInteract.hook'
import { InteractEventOn } from '@/enums/eventEnum'
import { ComponentInteractParamsEnum } from './interact'

const props = defineProps({
  chartConfig: {
    type: Object as PropType<CreateComponentType>,
    required: true
  }
})

const { w, h } = toRefs(props.chartConfig.attr)
const { buttonType } = toRefs(props.chartConfig.option)
const option = shallowReactive({
  value: cloneDeep(props.chartConfig.option)
})

const onClick = (v: any, s: boolean) => {
  useChartInteract(
    props.chartConfig,
    useChartEditStore,
    { [ComponentInteractParamsEnum.DATA]: v?.current },
    InteractEventOn.CHANGE,
    v?.target,
    s
  )
}

onMounted(() => {
  onClick(option.value.dataset[0], false)
})

// 手动更新
watch(
  () => props.chartConfig.option,
  (newData: any) => {
    option.value = newData
    // onClick(newData.tabValue, true)
  },
  {
    immediate: true,
    deep: true
  }
)
</script>