SelectBackgroundImage.vue 1.59 KB
<script lang="ts" setup>
import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditStore.d';
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore';
import { NEllipsis, NImage, NSelect, NSpace, NText, SelectOption } from 'naive-ui';
import { computed, h } from 'vue';
import { useBackgroundSelect } from '@/utils/external/useBackgroundImageSelect';

const emit = defineEmits(['bgChange'])
const chartEditStore = useChartEditStore()
const canvasConfig = computed(() => chartEditStore.getEditCanvasConfig)

const { getAllBackgroundImageList, getBackgroundImagePath } = useBackgroundSelect()

const renderOption = (option: SelectOption) => {
  return h(NSpace, { justify: 'space-between', style: 'padding: 0 15px; height: 28px; line-height: 28px;' }, () => [
    h(NImage, { width: 50, src: getBackgroundImagePath(option.value as string), previewDisabled: true, style: { height: '28px' } } as Recordable),
    h(NEllipsis, null, () => option.label)
  ])
}

const handleUpdateValue = (value: string) => {
  chartEditStore.setEditCanvasConfig(EditCanvasConfigEnum.BACKGROUND_IMAGE, value)
  emit('bgChange',value)
}

const removeBg = ()=> canvasConfig.value.backgroundImage = null
defineExpose({
  removeBg
})
</script>


<template>
  <NSpace>
    <NText>背景选择</NText>
    <NSelect size="small" placeholder="请选择您要使用的背景" clearable style="width: 250px" :value="canvasConfig.backgroundImage"
      :options="getAllBackgroundImageList" :render-label="renderOption" @update-value="handleUpdateValue" />
  </NSpace>
</template>

<style lang="scss" scoped>
</style>