|
|
@@ -1,10 +1,9 @@
|
|
|
<template>
|
|
|
- <div :style="getStyle"></div>
|
|
|
+ <div :style="styleMap?.mainStyle"></div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { computed, CSSProperties } from 'vue'
|
|
|
-import defaultStyle from './style.json'
|
|
|
+import { useWidgetStyle } from '../hooks/useWidgetStyle'
|
|
|
|
|
|
const props = defineProps<{
|
|
|
width: number
|
|
|
@@ -13,49 +12,9 @@ const props = defineProps<{
|
|
|
state: string
|
|
|
}>()
|
|
|
|
|
|
-const getStyle = computed((): CSSProperties => {
|
|
|
- const { width, height, styles } = props
|
|
|
-
|
|
|
- let stateStyles = styles.find((item) => item.part.state === props.state)
|
|
|
-
|
|
|
- // 从默认样式获取样式
|
|
|
- if (!stateStyles && props.state) {
|
|
|
- stateStyles = defaultStyle.part[0].state.find((item) => item.state === props.state)?.style
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- width: `${width}px`,
|
|
|
- height: `${height}px`,
|
|
|
-
|
|
|
- backgroundColor: stateStyles?.background.color,
|
|
|
-
|
|
|
- boxSizing: 'border-box',
|
|
|
- borderRadius: `${stateStyles?.border.radius}px`,
|
|
|
- borderStyle: 'solid',
|
|
|
- borderColor: 'transparent',
|
|
|
- borderWidth: `${stateStyles?.border.width}px`,
|
|
|
- borderTopColor:
|
|
|
- stateStyles?.border?.side?.includes('all') || stateStyles?.border?.side?.includes('top')
|
|
|
- ? stateStyles?.border?.color
|
|
|
- : 'transparent',
|
|
|
- borderRightColor:
|
|
|
- stateStyles?.border?.side?.includes('all') || stateStyles?.border?.side?.includes('right')
|
|
|
- ? stateStyles?.border?.color
|
|
|
- : 'transparent',
|
|
|
- borderBottomColor:
|
|
|
- stateStyles?.border?.side?.includes('all') || stateStyles?.border?.side?.includes('bottom')
|
|
|
- ? stateStyles?.border?.color
|
|
|
- : 'transparent',
|
|
|
- borderLeftColor:
|
|
|
- stateStyles?.border?.side?.includes('all') || stateStyles?.border?.side?.includes('left')
|
|
|
- ? stateStyles?.border?.color
|
|
|
- : 'transparent',
|
|
|
- padding: `${stateStyles?.padding.top}px ${stateStyles?.padding.right}px ${stateStyles?.padding.bottom}px ${stateStyles?.padding.left}px`,
|
|
|
- /* x 偏移量 | y 偏移量 | 阴影模糊半径 | 阴影扩散半径 | 阴影颜色 */
|
|
|
- boxShadow: stateStyles?.shadow
|
|
|
- ? `${stateStyles?.shadow?.x}px ${stateStyles?.shadow?.y}px ${stateStyles?.shadow?.width}px ${stateStyles?.shadow?.spread}px ${stateStyles?.shadow?.color}`
|
|
|
- : 'none'
|
|
|
- }
|
|
|
+const styleMap = useWidgetStyle({
|
|
|
+ widget: 'lv_obj',
|
|
|
+ props
|
|
|
})
|
|
|
</script>
|
|
|
|