|
|
@@ -1,15 +1,53 @@
|
|
|
<template>
|
|
|
- <div></div>
|
|
|
+ <div :style="getStyle"></div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-defineProps<{
|
|
|
+import { computed } from 'vue'
|
|
|
+import defaultStyle from './style.json'
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
width: number
|
|
|
height: number
|
|
|
- text: string
|
|
|
styles: any
|
|
|
state: string
|
|
|
}>()
|
|
|
+
|
|
|
+const getStyle = computed(() => {
|
|
|
+ const { width, height, styles } = props
|
|
|
+
|
|
|
+ let stateStyles = styles.find((item) => item.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`,
|
|
|
+
|
|
|
+ borderRadius: `${stateStyles?.border.radius}px`,
|
|
|
+ borderColor: 'transparent',
|
|
|
+ borderWidth: `${stateStyles?.border.width}px`,
|
|
|
+ borderTopColor: ['all', 'top'].includes(stateStyles?.border?.side)
|
|
|
+ ? stateStyles?.border?.color
|
|
|
+ : 'transparent',
|
|
|
+ borderRightColor: ['all', 'right'].includes(stateStyles?.border?.side)
|
|
|
+ ? stateStyles?.border?.color
|
|
|
+ : 'transparent',
|
|
|
+ borderBottomColor: ['all', 'bottom'].includes(stateStyles?.border?.side)
|
|
|
+ ? stateStyles?.border?.color
|
|
|
+ : 'transparent',
|
|
|
+ borderLeftColor: ['all', 'left'].includes(stateStyles?.border?.side)
|
|
|
+ ? stateStyles?.border?.color
|
|
|
+ : 'transparent',
|
|
|
+ /* x 偏移量 | y 偏移量 | 阴影模糊半径 | 阴影扩散半径 | 阴影颜色 */
|
|
|
+ boxShodow: stateStyles?.boxShadow
|
|
|
+ ? `${stateStyles?.boxShadow?.offsetX}px ${stateStyles?.boxShadow?.offsetY}px ${stateStyles?.boxShadow?.width}px ${stateStyles?.boxShadow?.spread}px ${stateStyles?.boxShadow?.color}`
|
|
|
+ : 'none'
|
|
|
+ }
|
|
|
+})
|
|
|
</script>
|
|
|
|
|
|
<style scoped></style>
|