|
|
@@ -0,0 +1,62 @@
|
|
|
+<template>
|
|
|
+ <div v-bind="getProps">{{ props.text }}</div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import { computed } from 'vue'
|
|
|
+import defaultStyle from './style.json'
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
+ width: number
|
|
|
+ height: number
|
|
|
+ text?: string
|
|
|
+ styles: any
|
|
|
+ state?: string
|
|
|
+}>()
|
|
|
+
|
|
|
+const getProps = computed(() => {
|
|
|
+ const styles = props.styles
|
|
|
+ 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 {
|
|
|
+ class: 'button',
|
|
|
+ style: {
|
|
|
+ width: `${props.width}px`,
|
|
|
+ height: `${props.height}px`,
|
|
|
+
|
|
|
+ backgroundColor: stateStyles?.background.color,
|
|
|
+
|
|
|
+ fontSize: `${stateStyles?.text.size}px`,
|
|
|
+ color: stateStyles?.text?.color,
|
|
|
+ display: 'flex',
|
|
|
+ justifyContent: stateStyles?.text?.align || 'center',
|
|
|
+ alignItems: 'center',
|
|
|
+
|
|
|
+ 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>
|