|
|
@@ -1,9 +1,13 @@
|
|
|
<template>
|
|
|
- <div v-bind="getProps">{{ props.text }}</div>
|
|
|
+ <div :style="getProps.mainStyle">
|
|
|
+ <span :style="{ color: !text ? '#ccc' : '' }">{{ getContent }}</span>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { computed } from 'vue'
|
|
|
+import { computed, type CSSProperties } from 'vue'
|
|
|
+import defaultStyle from './style.json'
|
|
|
+
|
|
|
const props = defineProps<{
|
|
|
width: number
|
|
|
height: number
|
|
|
@@ -17,48 +21,75 @@ const props = defineProps<{
|
|
|
nowrap: boolean
|
|
|
}>()
|
|
|
|
|
|
-const getProps = computed(() => {
|
|
|
+// 文本内容
|
|
|
+const getContent = computed(() => {
|
|
|
+ const { text, placeholder, passwordMode } = props
|
|
|
+
|
|
|
+ return passwordMode ? '*'.repeat(text.length) : text || placeholder
|
|
|
+})
|
|
|
+
|
|
|
+const getProps = computed((): Record<string, CSSProperties> => {
|
|
|
const styles = props.styles
|
|
|
- const stateStyles = styles.find((item) => item.state === props.state)
|
|
|
+ let mainStyle = styles.find((item) => item.state === props.state && item.part.name === 'main')
|
|
|
+ let scrollbarStyle = styles.find(
|
|
|
+ (item) => item.state === props.state && item.part.name === 'scrollbar'
|
|
|
+ )
|
|
|
|
|
|
+ // 从默认样式获取样式
|
|
|
+ if (!mainStyle && props.state) {
|
|
|
+ mainStyle = defaultStyle.part
|
|
|
+ ?.find((item) => item.partName === 'main')
|
|
|
+ ?.state.find((item) => item.state === props.state)?.style
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!scrollbarStyle && props.state) {
|
|
|
+ scrollbarStyle = defaultStyle.part
|
|
|
+ ?.find((item) => item.partName === 'scrollbar')
|
|
|
+ ?.state.find((item) => item.state === props.state)?.style
|
|
|
+ }
|
|
|
+ console.log(mainStyle, scrollbarStyle)
|
|
|
return {
|
|
|
- class: 'button',
|
|
|
- style: {
|
|
|
+ mainStyle: {
|
|
|
width: `${props.width}px`,
|
|
|
height: `${props.height}px`,
|
|
|
+ boxSizing: 'border-box',
|
|
|
+ display: 'flex',
|
|
|
|
|
|
- backgroundColor: stateStyles?.background.color,
|
|
|
+ backgroundColor: mainStyle?.background.color,
|
|
|
|
|
|
- fontSize: `${stateStyles?.text.size}px`,
|
|
|
- color: stateStyles?.text?.color,
|
|
|
- display: 'flex',
|
|
|
- justifyContent: stateStyles?.text?.align || 'center',
|
|
|
- alignItems: 'center',
|
|
|
+ fontSize: `${mainStyle?.text.size}px`,
|
|
|
+ color: mainStyle?.text?.color,
|
|
|
+ justifyContent: mainStyle?.text?.align || 'center',
|
|
|
+ fontWeight: mainStyle?.text.bold ? 'bold' : 'normal',
|
|
|
|
|
|
- borderRadius: `${stateStyles?.border.radius}px`,
|
|
|
+ borderRadius: `${mainStyle?.border.radius}px`,
|
|
|
borderStyle: 'solid',
|
|
|
borderColor: 'transparent',
|
|
|
- borderWidth: `${stateStyles?.border.width}px`,
|
|
|
+ borderWidth: `${mainStyle?.border.width}px`,
|
|
|
borderTopColor:
|
|
|
- stateStyles?.border?.side?.includes('all') || stateStyles?.border?.side?.includes('top')
|
|
|
- ? stateStyles?.border?.color
|
|
|
+ mainStyle?.border?.side?.includes('all') || mainStyle?.border?.side?.includes('top')
|
|
|
+ ? mainStyle?.border?.color
|
|
|
: 'transparent',
|
|
|
borderRightColor:
|
|
|
- stateStyles?.border?.side?.includes('all') || stateStyles?.border?.side?.includes('right')
|
|
|
- ? stateStyles?.border?.color
|
|
|
+ mainStyle?.border?.side?.includes('all') || mainStyle?.border?.side?.includes('right')
|
|
|
+ ? mainStyle?.border?.color
|
|
|
: 'transparent',
|
|
|
borderBottomColor:
|
|
|
- stateStyles?.border?.side?.includes('all') || stateStyles?.border?.side?.includes('bottom')
|
|
|
- ? stateStyles?.border?.color
|
|
|
+ mainStyle?.border?.side?.includes('all') || mainStyle?.border?.side?.includes('bottom')
|
|
|
+ ? mainStyle?.border?.color
|
|
|
: 'transparent',
|
|
|
borderLeftColor:
|
|
|
- stateStyles?.border?.side?.includes('all') || stateStyles?.border?.side?.includes('left')
|
|
|
- ? stateStyles?.border?.color
|
|
|
+ mainStyle?.border?.side?.includes('all') || mainStyle?.border?.side?.includes('left')
|
|
|
+ ? mainStyle?.border?.color
|
|
|
: 'transparent',
|
|
|
+ // 内边距
|
|
|
+ padding: `${mainStyle?.padding.top}px ${mainStyle?.padding.right}px ${mainStyle?.padding.bottom}px ${mainStyle?.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'
|
|
|
+ boxShadow: mainStyle?.shadow
|
|
|
+ ? `${mainStyle?.shadow?.x}px ${mainStyle?.shadow?.y}px ${mainStyle?.shadow?.width}px ${mainStyle?.shadow?.spread}px ${mainStyle?.shadow?.color}`
|
|
|
+ : 'none',
|
|
|
+ // 字间距
|
|
|
+ letterSpacing: `${mainStyle?.gap?.column}px`
|
|
|
}
|
|
|
}
|
|
|
})
|