SelectBackgroundImage.vue
1.59 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
<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>