|
|
@@ -1,6 +1,10 @@
|
|
|
<template>
|
|
|
<div :style="boxStyle" class="overflow-hidden flex items-center justify-center">
|
|
|
- <img :style="imgStyle" :src="src || defaultImg" alt="img" />
|
|
|
+ <ImageBg
|
|
|
+ :src="src || defaultImg"
|
|
|
+ :image-style="styleMap?.mainStyle?.imageStyle"
|
|
|
+ :image-props="imageProps"
|
|
|
+ />
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -9,22 +13,53 @@ import { computed, watch, ref } from 'vue'
|
|
|
import { getImageByPath } from '@/utils'
|
|
|
import { useProjectStore } from '@/store/modules/project'
|
|
|
import defaultImg from '@/assets/default.png'
|
|
|
+import ImageBg from '../ImageBg.vue'
|
|
|
+import { useWidgetStyle } from '../hooks/useWidgetStyle'
|
|
|
|
|
|
const props = defineProps<{
|
|
|
width: number
|
|
|
height: number
|
|
|
image: string
|
|
|
+ styles: any
|
|
|
+ part?: string
|
|
|
+ state?: string
|
|
|
rotate: {
|
|
|
x: number
|
|
|
y: number
|
|
|
angle: number
|
|
|
}
|
|
|
- styles: any
|
|
|
- state?: string
|
|
|
+ openScale: boolean
|
|
|
+ scale: number
|
|
|
+ antiAliasing: boolean
|
|
|
}>()
|
|
|
|
|
|
const src = ref('')
|
|
|
const projectStore = useProjectStore()
|
|
|
+const width = ref(props.width)
|
|
|
+const height = ref(props.height)
|
|
|
+
|
|
|
+const styleMap = useWidgetStyle({
|
|
|
+ widget: 'lv_image',
|
|
|
+ props
|
|
|
+})
|
|
|
+
|
|
|
+const imageProps = computed(() => {
|
|
|
+ const { openScale, scale = 256, image } = props
|
|
|
+ const s = scale / 256
|
|
|
+ if (openScale) {
|
|
|
+ return {
|
|
|
+ width: `${width.value * s}px`,
|
|
|
+ height: `${height.value * s}px`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!image) {
|
|
|
+ return {
|
|
|
+ height: '100%',
|
|
|
+ width: '100%'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {}
|
|
|
+})
|
|
|
|
|
|
watch(
|
|
|
() => props.image,
|
|
|
@@ -34,14 +69,15 @@ watch(
|
|
|
const basePath = projectStore.project.meta.path
|
|
|
const imagePath = projectStore.project.resources.images.find((item) => item.id === val)?.path
|
|
|
const result = await getImageByPath(basePath + imagePath)
|
|
|
- if (result?.base64) {
|
|
|
- src.value = result.base64
|
|
|
- } else {
|
|
|
- src.value = ''
|
|
|
- }
|
|
|
+ src.value = result?.src!
|
|
|
+ width.value = result?.dimensions.width!
|
|
|
+ height.value = result?.dimensions.height!
|
|
|
} else {
|
|
|
src.value = ''
|
|
|
}
|
|
|
+ },
|
|
|
+ {
|
|
|
+ immediate: true
|
|
|
}
|
|
|
)
|
|
|
|
|
|
@@ -57,13 +93,4 @@ const boxStyle = computed(() => {
|
|
|
alignItems: 'center'
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
-const imgStyle = computed(() => {
|
|
|
- const { rotate = { x: 50, y: 0, angle: 0 } } = props
|
|
|
-
|
|
|
- return {
|
|
|
- // transform: `rotate(${rotate.angle}deg)`,
|
|
|
- transformOrigin: `${rotate.x}px ${rotate.y}px`
|
|
|
- }
|
|
|
-})
|
|
|
</script>
|