|
|
@@ -1,63 +1,24 @@
|
|
|
<template>
|
|
|
- <div class="relative" :style="getProps.rootStyle">
|
|
|
- <img
|
|
|
- v-if="bgImage"
|
|
|
- width="100%"
|
|
|
- height="100%"
|
|
|
- class="absolute z-0"
|
|
|
- :src="bgImage"
|
|
|
- alt="bg image"
|
|
|
- />
|
|
|
- <div v-if="bgImage" class="z-1 absolute w-full h-full" :style="getProps.imageColor"></div>
|
|
|
+ <div class="relative box-border overflow-hidden" :style="styleMap?.mainStyle">
|
|
|
+ <ImageBg :src="styleMap?.mainStyle?.imageSrc" :imageStyle="styleMap?.mainStyle?.imageStyle" />
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, computed, type CSSProperties } from 'vue'
|
|
|
-import { getImageByPath } from '@/utils'
|
|
|
-import { useProjectStore } from '@/store/modules/project'
|
|
|
+import ImageBg from '../ImageBg.vue'
|
|
|
+import { useWidgetStyle } from '../hooks/useWidgetStyle'
|
|
|
|
|
|
const props = defineProps<{
|
|
|
width?: number
|
|
|
height?: number
|
|
|
styles: any
|
|
|
state?: string
|
|
|
+ part?: string
|
|
|
}>()
|
|
|
|
|
|
-const projectStore = useProjectStore()
|
|
|
-
|
|
|
-const bgImage = ref('')
|
|
|
-
|
|
|
-const getProps = computed(() => {
|
|
|
- const styles = props.styles
|
|
|
- let stateStyles = styles[0]
|
|
|
-
|
|
|
- const imageId = stateStyles?.background?.image?.imgId
|
|
|
- if (imageId && projectStore.project) {
|
|
|
- // 加载图片
|
|
|
- const basePath = projectStore.project.meta.path
|
|
|
- const imagePath = projectStore.project.resources.images.find(
|
|
|
- (item) => item.id === imageId
|
|
|
- )?.path
|
|
|
- getImageByPath(basePath + imagePath).then((res) => {
|
|
|
- bgImage.value = res?.base64 || ''
|
|
|
- })
|
|
|
- } else {
|
|
|
- bgImage.value = ''
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- rootStyle: {
|
|
|
- width: `${props.width}px`,
|
|
|
- height: `${props.height}px`,
|
|
|
- boxSizing: 'border-box',
|
|
|
-
|
|
|
- backgroundColor: stateStyles?.background.color
|
|
|
- } as CSSProperties,
|
|
|
- imageColor: {
|
|
|
- background: stateStyles?.background?.image?.color
|
|
|
- } as CSSProperties
|
|
|
- }
|
|
|
+const styleMap = useWidgetStyle({
|
|
|
+ widget: 'page',
|
|
|
+ props
|
|
|
})
|
|
|
</script>
|
|
|
<
|