index.vue 1.39 KB
<template>
  <div>
    <n-input :style="`width:${w}px;height:${h}px;`" type="text"
             v-model:value="option.value.dataset"
             placeholder="请输入"
             @blur="onBlur">

    </n-input>
  </div>
</template>

<script lang="ts" setup>
import { PropType, toRefs, shallowReactive, watch } from 'vue'
import { CreateComponentType } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { useChartInteract } from '@/hooks/external/useChartSelectInteract.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 option = shallowReactive({
  value: {
    inputValue: props.chartConfig.option.inputValue,
    dataset: props.chartConfig.option.dataset
  }
})

const onBlur = () => {
  // 存储到联动数据
  useChartInteract(
      props.chartConfig,
      useChartEditStore,
      { [ComponentInteractParamsEnum.DATA]: encodeURIComponent(option.value.dataset) },
      InteractEventOn.CHANGE,
      []
  )
}

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

</script>