|
|
@@ -0,0 +1,89 @@
|
|
|
+<template>
|
|
|
+ <div v-bind="getProps">
|
|
|
+ <span v-for="(item, index) in items" :key="index" :style="getSpanStyle(item)">{{
|
|
|
+ item.text
|
|
|
+ }}</span>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import { computed, CSSProperties } from 'vue'
|
|
|
+import { LineEnum } from './data'
|
|
|
+
|
|
|
+type Item = {
|
|
|
+ text: string
|
|
|
+ text_color: string
|
|
|
+ font_family: string
|
|
|
+ font_size: number
|
|
|
+ text_decor: LineEnum
|
|
|
+}
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
+ width: number
|
|
|
+ height: number
|
|
|
+ styles: any
|
|
|
+ state?: string
|
|
|
+ mode: 'break' | 'fixed' | 'Expand'
|
|
|
+ items: Item[]
|
|
|
+}>()
|
|
|
+
|
|
|
+const getProps = computed(() => {
|
|
|
+ const styles = props.styles
|
|
|
+ const stateStyles = styles.find((item) => item.state === props.state)
|
|
|
+
|
|
|
+ return {
|
|
|
+ class: 'button',
|
|
|
+ style: {
|
|
|
+ width: `${props.width}px`,
|
|
|
+ height: `${props.height}px`,
|
|
|
+ boxSizing: 'border-box',
|
|
|
+ // 背景
|
|
|
+ backgroundColor: stateStyles?.background.color,
|
|
|
+
|
|
|
+ // 边框
|
|
|
+ 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?.shadow
|
|
|
+ ? `${stateStyles?.shadow?.offsetX}px ${stateStyles?.shadow?.offsetY}px ${stateStyles?.shadow?.width}px ${stateStyles?.shadow?.spread}px ${stateStyles?.shadow?.color}`
|
|
|
+ : 'none',
|
|
|
+ // 内边距
|
|
|
+ padding: `${stateStyles?.padding.top}px ${stateStyles?.padding.right}px ${stateStyles?.padding.bottom}px ${stateStyles?.padding.left}px`
|
|
|
+ } as CSSProperties
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+// 获取子项样式
|
|
|
+const getSpanStyle = (item: Item) => {
|
|
|
+ const lineStyle =
|
|
|
+ item.text_decor === LineEnum['LV_TEXT_DECOR_UNDERLINE | LV_TEXT_DECOR_STRIKETHROUGH']
|
|
|
+ ? 'underline line-through'
|
|
|
+ : item.text_decor === LineEnum.LV_TEXT_DECOR_UNDERLINE
|
|
|
+ ? 'underline'
|
|
|
+ : item.text_decor === LineEnum.LV_TEXT_DECOR_STRIKETHROUGH
|
|
|
+ ? 'line-through'
|
|
|
+ : 'none'
|
|
|
+
|
|
|
+ return {
|
|
|
+ color: item.text_color,
|
|
|
+ fontSize: `${item.font_size}px`,
|
|
|
+ textDecoration: lineStyle
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped></style>
|