tang-ui-x 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/components/TActionSheet/index.uvue +170 -0
- package/components/TActionSheet/type.uts +29 -0
- package/components/TAvatar/index.uvue +156 -0
- package/components/TAvatar/type.uts +54 -0
- package/components/TBadge/index.uvue +152 -0
- package/components/TBadge/type.uts +48 -0
- package/components/TButton/README.md +111 -0
- package/components/TButton/index.uvue +380 -0
- package/components/TButton/type.uts +95 -0
- package/components/TCard/index.uvue +174 -0
- package/components/TCard/type.uts +50 -0
- package/components/TCell/index.uvue +49 -0
- package/components/TCheckbox/index.uvue +187 -0
- package/components/TCheckboxGroup/index.uvue +139 -0
- package/components/TCheckboxGroup/type.uts +26 -0
- package/components/TCol/index.uvue +82 -0
- package/components/TCol/type.uts +30 -0
- package/components/TCollapse/index.uvue +93 -0
- package/components/TCollapse/type.uts +36 -0
- package/components/TCollapseItem/index.uvue +194 -0
- package/components/TCollapseItem/type.uts +25 -0
- package/components/TDialog/index.uvue +386 -0
- package/components/TDialog/type.uts +84 -0
- package/components/TDivider/index.uvue +235 -0
- package/components/TDivider/type.uts +91 -0
- package/components/TEmpty/index.uvue +128 -0
- package/components/TErrorState/index.uvue +57 -0
- package/components/TGrid/index.uvue +115 -0
- package/components/TGrid/type.uts +77 -0
- package/components/TGridItem/index.uvue +243 -0
- package/components/TGridItem/type.uts +64 -0
- package/components/TIcon/index.uvue +96 -0
- package/components/TImage/index.uvue +255 -0
- package/components/TImage/type.uts +146 -0
- package/components/TInput/README.md +119 -0
- package/components/TInput/index.uvue +376 -0
- package/components/TInput/type.uts +138 -0
- package/components/TList/index.uvue +82 -0
- package/components/TList/type.uts +68 -0
- package/components/TListItem/index.uvue +161 -0
- package/components/TListItem/type.uts +49 -0
- package/components/TLoading/index.uvue +153 -0
- package/components/TLoading/type.uts +43 -0
- package/components/TNavBar/index.uvue +120 -0
- package/components/TNavBar/type.uts +22 -0
- package/components/TNoticeBar/index.uvue +106 -0
- package/components/TNoticeBar/type.uts +21 -0
- package/components/TNumberInput/index.uvue +226 -0
- package/components/TPicker/index.uvue +276 -0
- package/components/TPicker/type.uts +105 -0
- package/components/TPopup/index.uvue +442 -0
- package/components/TProgress/index.uvue +103 -0
- package/components/TProgress/type.uts +64 -0
- package/components/TRadioButton/index.uvue +232 -0
- package/components/TRadioGroup/index.uvue +117 -0
- package/components/TRadioGroup/type.uts +25 -0
- package/components/TRate/index.uvue +182 -0
- package/components/TRow/index.uvue +105 -0
- package/components/TRow/type.uts +52 -0
- package/components/TSearchBar/index.uvue +255 -0
- package/components/TSearchBar/type.uts +140 -0
- package/components/TSelect/index.uvue +655 -0
- package/components/TSelect/type.uts +57 -0
- package/components/TSlider/index.uvue +72 -0
- package/components/TSlider/type.uts +21 -0
- package/components/TSwiper/index.uvue +222 -0
- package/components/TSwiper/type.uts +77 -0
- package/components/TSwitch/index.uvue +177 -0
- package/components/TSwitch/type.uts +52 -0
- package/components/TText/README.md +124 -0
- package/components/TText/index.uvue +257 -0
- package/components/TText/type.uts +114 -0
- package/components/TTextarea/index.uvue +239 -0
- package/components/TTextarea/type.uts +106 -0
- package/components/TToast/type.uts +14 -0
- package/components/Tabs/README.md +297 -0
- package/components/Tabs/index.uvue +383 -0
- package/components/Tabs/type.uts +10 -0
- package/components/Tags/README.md +297 -0
- package/components/Tags/index.uvue +383 -0
- package/components/Tags/type.uts +10 -0
- package/components/VbenFrom/index.uvue +392 -0
- package/composables/useModal.uts +294 -0
- package/composables/useTheme.uts +235 -0
- package/composables/useToast.uts +322 -0
- package/index.js +62 -0
- package/package.json +48 -0
- package/style/colors/index.scss +157 -0
- package/style/index.scss +399 -0
- package/types/index.uts +52 -0
- package/uni.scss +79 -0
- package/utils/color.uts +92 -0
- package/utils/common.uts +245 -0
- package/utils/dom.uts +275 -0
- package/utils/index.uts +10 -0
- package/utils/validator.uts +155 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# TText 文本组件
|
|
2
|
+
|
|
3
|
+
文本组件,支持多种类型、尺寸、粗细和样式。
|
|
4
|
+
|
|
5
|
+
## 基础用法
|
|
6
|
+
|
|
7
|
+
```vue
|
|
8
|
+
<template>
|
|
9
|
+
<TText text="默认文本" />
|
|
10
|
+
<TText type="primary" text="主要文本" />
|
|
11
|
+
<TText type="success" text="成功文本" />
|
|
12
|
+
<TText type="warning" text="警告文本" />
|
|
13
|
+
<TText type="danger" text="危险文本" />
|
|
14
|
+
<TText type="info" text="信息文本" />
|
|
15
|
+
</template>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 文本尺寸
|
|
19
|
+
|
|
20
|
+
```vue
|
|
21
|
+
<template>
|
|
22
|
+
<TText size="large" text="大号文本" />
|
|
23
|
+
<TText size="medium" text="中号文本" />
|
|
24
|
+
<TText size="small" text="小号文本" />
|
|
25
|
+
<TText size="mini" text="迷你文本" />
|
|
26
|
+
</template>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 文本粗细
|
|
30
|
+
|
|
31
|
+
```vue
|
|
32
|
+
<template>
|
|
33
|
+
<TText weight="lighter" text="细体文本" />
|
|
34
|
+
<TText weight="normal" text="正常文本" />
|
|
35
|
+
<TText weight="medium" text="中粗文本" />
|
|
36
|
+
<TText weight="bold" text="粗体文本" />
|
|
37
|
+
</template>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 文本对齐
|
|
41
|
+
|
|
42
|
+
```vue
|
|
43
|
+
<template>
|
|
44
|
+
<TText align="left" text="左对齐" />
|
|
45
|
+
<TText align="center" text="居中对齐" />
|
|
46
|
+
<TText align="right" text="右对齐" />
|
|
47
|
+
<TText align="justify" text="两端对齐" />
|
|
48
|
+
</template>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 文本样式
|
|
52
|
+
|
|
53
|
+
```vue
|
|
54
|
+
<template>
|
|
55
|
+
<TText bold text="加粗文本" />
|
|
56
|
+
<TText italic text="斜体文本" />
|
|
57
|
+
<TText underline text="下划线文本" />
|
|
58
|
+
<TText strikethrough text="删除线文本" />
|
|
59
|
+
</template>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 自定义颜色
|
|
63
|
+
|
|
64
|
+
```vue
|
|
65
|
+
<template>
|
|
66
|
+
<TText color="#ff0000" text="红色文本" />
|
|
67
|
+
<TText color="#00ff00" text="绿色文本" />
|
|
68
|
+
<TText color="#0000ff" text="蓝色文本" />
|
|
69
|
+
</template>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 文本省略
|
|
73
|
+
|
|
74
|
+
```vue
|
|
75
|
+
<template>
|
|
76
|
+
<TText ellipsis text="这是一段很长的文本,超出部分会显示省略号" />
|
|
77
|
+
<TText :max-lines="2" text="这是一段很长的文本,最多显示两行,超出部分会被隐藏" />
|
|
78
|
+
</template>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 自定义行高
|
|
82
|
+
|
|
83
|
+
```vue
|
|
84
|
+
<template>
|
|
85
|
+
<TText :line-height="2" text="行高为2的文本" />
|
|
86
|
+
<TText line-height="30px" text="行高为30px的文本" />
|
|
87
|
+
</template>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 使用插槽
|
|
91
|
+
|
|
92
|
+
```vue
|
|
93
|
+
<template>
|
|
94
|
+
<TText type="primary">
|
|
95
|
+
这是通过插槽传入的文本内容
|
|
96
|
+
</TText>
|
|
97
|
+
</template>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Props
|
|
101
|
+
|
|
102
|
+
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
103
|
+
|------|------|------|--------|--------|
|
|
104
|
+
| text | 文本内容 | string | - | - |
|
|
105
|
+
| type | 文本类型 | string | primary / success / warning / danger / info / default | default |
|
|
106
|
+
| size | 文本尺寸 | string | large / medium / small / mini | medium |
|
|
107
|
+
| weight | 文本粗细 | string | lighter / normal / medium / bold | normal |
|
|
108
|
+
| align | 文本对齐 | string | left / center / right / justify | left |
|
|
109
|
+
| color | 自定义颜色 | string | - | - |
|
|
110
|
+
| lineHeight | 行高 | number / string | - | 1.5 |
|
|
111
|
+
| maxLines | 最大行数 | number | - | 0 |
|
|
112
|
+
| ellipsis | 是否显示省略号 | boolean | - | false |
|
|
113
|
+
| bold | 是否加粗 | boolean | - | false |
|
|
114
|
+
| italic | 是否斜体 | boolean | - | false |
|
|
115
|
+
| underline | 是否显示下划线 | boolean | - | false |
|
|
116
|
+
| strikethrough | 是否显示删除线 | boolean | - | false |
|
|
117
|
+
| customClass | 自定义类名 | string | - | - |
|
|
118
|
+
| customStyle | 自定义样式 | string | - | - |
|
|
119
|
+
|
|
120
|
+
## Slots
|
|
121
|
+
|
|
122
|
+
| 名称 | 说明 |
|
|
123
|
+
|------|------|
|
|
124
|
+
| default | 文本内容 |
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<script setup lang="uts" >
|
|
4
|
+
import { computed } from 'vue'
|
|
5
|
+
import type { TextType, TextSize, TextWeight, TextAlign } from './type.uts'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TText 文本组件
|
|
9
|
+
* @description 支持多种类型、尺寸、粗细的文本组件
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Props 定义
|
|
13
|
+
interface Props {
|
|
14
|
+
text?: string
|
|
15
|
+
type?: TextType
|
|
16
|
+
size?: TextSize
|
|
17
|
+
weight?: TextWeight
|
|
18
|
+
align?: TextAlign
|
|
19
|
+
color?: string
|
|
20
|
+
lineHeight?: number | string
|
|
21
|
+
maxLines?: number
|
|
22
|
+
ellipsis?: boolean
|
|
23
|
+
bold?: boolean
|
|
24
|
+
italic?: boolean
|
|
25
|
+
underline?: boolean
|
|
26
|
+
strikethrough?: boolean
|
|
27
|
+
customClass?: string
|
|
28
|
+
customStyle?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
32
|
+
text: '',
|
|
33
|
+
type: 'default',
|
|
34
|
+
size: 'medium',
|
|
35
|
+
weight: 'normal',
|
|
36
|
+
align: 'left',
|
|
37
|
+
color: '',
|
|
38
|
+
lineHeight: 1.5,
|
|
39
|
+
maxLines: 0,
|
|
40
|
+
ellipsis: false,
|
|
41
|
+
bold: false,
|
|
42
|
+
italic: false,
|
|
43
|
+
underline: false,
|
|
44
|
+
strikethrough: false,
|
|
45
|
+
customClass: '',
|
|
46
|
+
customStyle: ''
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 计算文本类名
|
|
51
|
+
*/
|
|
52
|
+
const textClasses = computed((): string => {
|
|
53
|
+
const classes: string[] = []
|
|
54
|
+
|
|
55
|
+
// 类型样式
|
|
56
|
+
classes.push(`t-text--${props.type}`)
|
|
57
|
+
|
|
58
|
+
// 尺寸样式
|
|
59
|
+
classes.push(`t-text--${props.size}`)
|
|
60
|
+
|
|
61
|
+
// 粗细样式
|
|
62
|
+
classes.push(`t-text--${props.weight}`)
|
|
63
|
+
|
|
64
|
+
// 对齐样式
|
|
65
|
+
classes.push(`t-text--${props.align}`)
|
|
66
|
+
|
|
67
|
+
// 加粗
|
|
68
|
+
if (props.bold) {
|
|
69
|
+
classes.push('t-text--bold')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 斜体
|
|
73
|
+
if (props.italic) {
|
|
74
|
+
classes.push('t-text--italic')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 下划线
|
|
78
|
+
if (props.underline) {
|
|
79
|
+
classes.push('t-text--underline')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 删除线
|
|
83
|
+
if (props.strikethrough) {
|
|
84
|
+
classes.push('t-text--strikethrough')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 省略号
|
|
88
|
+
if (props.ellipsis) {
|
|
89
|
+
classes.push('t-text--ellipsis')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 自定义类名
|
|
93
|
+
if (props.customClass) {
|
|
94
|
+
classes.push(props.customClass)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return classes.join(' ')
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 计算文本样式
|
|
102
|
+
*/
|
|
103
|
+
const textStyles = computed((): string => {
|
|
104
|
+
const styles: string[] = []
|
|
105
|
+
|
|
106
|
+
// 自定义颜色
|
|
107
|
+
if (props.color) {
|
|
108
|
+
styles.push(`color: ${props.color}`)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// 行高
|
|
112
|
+
if (props.lineHeight) {
|
|
113
|
+
const lineHeight = typeof props.lineHeight === 'number'
|
|
114
|
+
? props.lineHeight
|
|
115
|
+
: props.lineHeight
|
|
116
|
+
styles.push(`line-height: ${lineHeight}`)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 最大行数
|
|
120
|
+
if (props.maxLines > 0) {
|
|
121
|
+
styles.push(`-webkit-line-clamp: ${props.maxLines}`)
|
|
122
|
+
styles.push('display: -webkit-box')
|
|
123
|
+
styles.push('-webkit-box-orient: vertical')
|
|
124
|
+
styles.push('overflow: hidden')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 自定义样式
|
|
128
|
+
if (props.customStyle) {
|
|
129
|
+
styles.push(props.customStyle)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return styles.join('; ')
|
|
133
|
+
})
|
|
134
|
+
</script>
|
|
135
|
+
|
|
136
|
+
<template>
|
|
137
|
+
<text class="t-text" :class="textClasses" :style="textStyles">
|
|
138
|
+
<slot>{{ text }}</slot>
|
|
139
|
+
</text>
|
|
140
|
+
</template>
|
|
141
|
+
|
|
142
|
+
<style lang="scss" scoped>
|
|
143
|
+
// 重置 uni-text 的默认样式
|
|
144
|
+
.t-text {
|
|
145
|
+
text-align: left;
|
|
146
|
+
line-height: 1.5;
|
|
147
|
+
color: inherit;
|
|
148
|
+
font-size: 14px;
|
|
149
|
+
display: inline;
|
|
150
|
+
margin: 0;
|
|
151
|
+
padding: 0;
|
|
152
|
+
word-wrap: break-word;
|
|
153
|
+
|
|
154
|
+
// 类型样式
|
|
155
|
+
&--default {
|
|
156
|
+
color: #606266;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
&--primary {
|
|
160
|
+
color: #409eff;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
&--success {
|
|
164
|
+
color: #67c23a;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
&--warning {
|
|
168
|
+
color: #e6a23c;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
&--danger {
|
|
172
|
+
color: #f56c6c;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
&--info {
|
|
176
|
+
color: #909399;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 尺寸样式
|
|
180
|
+
&--large {
|
|
181
|
+
font-size: 18px;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
&--medium {
|
|
185
|
+
font-size: 14px;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
&--small {
|
|
189
|
+
font-size: 12px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
&--mini {
|
|
193
|
+
font-size: 10px;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 粗细样式
|
|
197
|
+
&--lighter {
|
|
198
|
+
font-weight: 300;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
&--normal {
|
|
202
|
+
font-weight: 400;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
&--medium {
|
|
206
|
+
font-weight: 500;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
&--bold {
|
|
210
|
+
font-weight: 700;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// 对齐样式
|
|
214
|
+
&--left {
|
|
215
|
+
text-align: left;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
&--center {
|
|
219
|
+
text-align: center;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
&--right {
|
|
223
|
+
text-align: right;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
&--justify {
|
|
227
|
+
text-align: justify;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 加粗
|
|
231
|
+
&--bold {
|
|
232
|
+
font-weight: bold;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// 斜体
|
|
236
|
+
&--italic {
|
|
237
|
+
font-style: italic;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// 下划线
|
|
241
|
+
&--underline {
|
|
242
|
+
text-decoration: underline;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// 删除线
|
|
246
|
+
&--strikethrough {
|
|
247
|
+
text-decoration: line-through;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// 省略号
|
|
251
|
+
&--ellipsis {
|
|
252
|
+
overflow: hidden;
|
|
253
|
+
text-overflow: ellipsis;
|
|
254
|
+
white-space: nowrap;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
</style>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TText 组件类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 文本类型
|
|
7
|
+
*/
|
|
8
|
+
export type TextType = 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'default'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 文本尺寸
|
|
12
|
+
*/
|
|
13
|
+
export type TextSize = 'large' | 'medium' | 'small' | 'mini'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 文本粗细
|
|
17
|
+
*/
|
|
18
|
+
export type TextWeight = 'lighter' | 'normal' | 'medium' | 'bold'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 文本对齐
|
|
22
|
+
*/
|
|
23
|
+
export type TextAlign = 'left' | 'center' | 'right' | 'justify'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 文本 Props 接口
|
|
27
|
+
*/
|
|
28
|
+
export interface TTextProps {
|
|
29
|
+
/**
|
|
30
|
+
* 文本内容
|
|
31
|
+
*/
|
|
32
|
+
text?: string
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 文本类型
|
|
36
|
+
* @default 'default'
|
|
37
|
+
*/
|
|
38
|
+
type?: TextType
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 文本尺寸
|
|
42
|
+
* @default 'medium'
|
|
43
|
+
*/
|
|
44
|
+
size?: TextSize
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 文本粗细
|
|
48
|
+
* @default 'normal'
|
|
49
|
+
*/
|
|
50
|
+
weight?: TextWeight
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 文本对齐
|
|
54
|
+
* @default 'left'
|
|
55
|
+
*/
|
|
56
|
+
align?: TextAlign
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 自定义颜色
|
|
60
|
+
*/
|
|
61
|
+
color?: string
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 行高
|
|
65
|
+
* @default 1.5
|
|
66
|
+
*/
|
|
67
|
+
lineHeight?: number | string
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 最大行数
|
|
71
|
+
* @default 0
|
|
72
|
+
*/
|
|
73
|
+
maxLines?: number
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 是否显示省略号
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
ellipsis?: boolean
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 是否加粗
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
bold?: boolean
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 是否斜体
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
91
|
+
italic?: boolean
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 是否显示下划线
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
underline?: boolean
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 是否显示删除线
|
|
101
|
+
* @default false
|
|
102
|
+
*/
|
|
103
|
+
strikethrough?: boolean
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 自定义类名
|
|
107
|
+
*/
|
|
108
|
+
customClass?: string
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 自定义样式
|
|
112
|
+
*/
|
|
113
|
+
customStyle?: string
|
|
114
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
<script setup lang="uts">
|
|
2
|
+
import { ref, computed } from 'vue'
|
|
3
|
+
import type { TTextareaProps } from './type.uts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TTextarea 多行文本输入组件
|
|
7
|
+
* @description 支持自动高度、字数统计、清空等功能的多行文本输入框
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Props 定义 (从 type.uts 导入,排除 modelValue)
|
|
11
|
+
type Props = Omit<TTextareaProps, 'modelValue'>
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
14
|
+
placeholder: '请输入内容',
|
|
15
|
+
placeholderStyle: '',
|
|
16
|
+
disabled: false,
|
|
17
|
+
maxlength: -1,
|
|
18
|
+
showCount: false,
|
|
19
|
+
autoHeight: false,
|
|
20
|
+
rows: 3,
|
|
21
|
+
autoFocus: false,
|
|
22
|
+
clearable: false,
|
|
23
|
+
customClass: '',
|
|
24
|
+
customStyle: ''
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// 使用 defineModel 管理双向绑定
|
|
28
|
+
const modelValue = defineModel<string>({ default: '' })
|
|
29
|
+
|
|
30
|
+
// Emits 定义
|
|
31
|
+
const emit = defineEmits<{
|
|
32
|
+
input: [value: string]
|
|
33
|
+
focus: [event: Event]
|
|
34
|
+
blur: [event: Event]
|
|
35
|
+
clear: []
|
|
36
|
+
}>()
|
|
37
|
+
|
|
38
|
+
// 状态管理
|
|
39
|
+
const isFocused = ref<boolean>(false)
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 计算当前字符数
|
|
43
|
+
*/
|
|
44
|
+
const currentLength = computed((): number => {
|
|
45
|
+
return modelValue.value.length
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 计算容器类名
|
|
50
|
+
*/
|
|
51
|
+
const containerClasses = computed((): string => {
|
|
52
|
+
const classes: string[] = ['t-textarea']
|
|
53
|
+
|
|
54
|
+
if (props.disabled) {
|
|
55
|
+
classes.push('t-textarea--disabled')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (isFocused.value) {
|
|
59
|
+
classes.push('t-textarea--focused')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (props.customClass) {
|
|
63
|
+
classes.push(props.customClass)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return classes.join(' ')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 计算容器样式
|
|
71
|
+
*/
|
|
72
|
+
const containerStyle = computed((): string => {
|
|
73
|
+
const styles: string[] = []
|
|
74
|
+
|
|
75
|
+
if (props.customStyle) {
|
|
76
|
+
styles.push(props.customStyle)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return styles.join('; ')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 计算 textarea 样式
|
|
84
|
+
*/
|
|
85
|
+
const textareaStyle = computed((): string => {
|
|
86
|
+
const styles: string[] = []
|
|
87
|
+
|
|
88
|
+
if (!props.autoHeight && props.rows > 0) {
|
|
89
|
+
// 固定行数时计算高度(每行约 24px + 12px 行间距)
|
|
90
|
+
const height = props.rows * 36
|
|
91
|
+
styles.push(`height: ${height}px`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return styles.join('; ')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 输入事件处理
|
|
99
|
+
*/
|
|
100
|
+
const handleInput = (event: any): void => {
|
|
101
|
+
const value = event.detail.value as string
|
|
102
|
+
modelValue.value = value
|
|
103
|
+
emit('input', value)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 聚焦事件处理
|
|
108
|
+
*/
|
|
109
|
+
const handleFocus = (event: Event): void => {
|
|
110
|
+
isFocused.value = true
|
|
111
|
+
emit('focus', event)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 失焦事件处理
|
|
116
|
+
*/
|
|
117
|
+
const handleBlur = (event: Event): void => {
|
|
118
|
+
isFocused.value = false
|
|
119
|
+
emit('blur', event)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 清空输入
|
|
124
|
+
*/
|
|
125
|
+
const handleClear = (): void => {
|
|
126
|
+
modelValue.value = ''
|
|
127
|
+
emit('clear')
|
|
128
|
+
}
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<template>
|
|
132
|
+
<view :class="containerClasses" :style="containerStyle">
|
|
133
|
+
<!-- 文本域 -->
|
|
134
|
+
<textarea
|
|
135
|
+
class="t-textarea__input"
|
|
136
|
+
:style="textareaStyle"
|
|
137
|
+
:value="modelValue"
|
|
138
|
+
:placeholder="placeholder"
|
|
139
|
+
:placeholder-style="placeholderStyle"
|
|
140
|
+
:disabled="disabled"
|
|
141
|
+
:maxlength="maxlength"
|
|
142
|
+
:auto-height="autoHeight"
|
|
143
|
+
:focus="autoFocus"
|
|
144
|
+
@input="handleInput"
|
|
145
|
+
@focus="handleFocus"
|
|
146
|
+
@blur="handleBlur"
|
|
147
|
+
/>
|
|
148
|
+
|
|
149
|
+
<!-- 底部操作栏 -->
|
|
150
|
+
<view v-if="showCount || clearable" class="t-textarea__footer">
|
|
151
|
+
<!-- 字数统计 -->
|
|
152
|
+
<text v-if="showCount" class="t-textarea__count">
|
|
153
|
+
{{ currentLength }}{{ maxlength > 0 ? `/${maxlength}` : '' }}
|
|
154
|
+
</text>
|
|
155
|
+
|
|
156
|
+
<!-- 清空按钮 -->
|
|
157
|
+
<view
|
|
158
|
+
v-if="clearable && modelValue.length > 0 && !disabled"
|
|
159
|
+
class="t-textarea__clear"
|
|
160
|
+
@click="handleClear"
|
|
161
|
+
>
|
|
162
|
+
<text class="t-textarea__clear-icon">✕</text>
|
|
163
|
+
</view>
|
|
164
|
+
</view>
|
|
165
|
+
</view>
|
|
166
|
+
</template>
|
|
167
|
+
|
|
168
|
+
<style lang="scss" scoped>
|
|
169
|
+
.t-textarea {
|
|
170
|
+
position: relative;
|
|
171
|
+
background-color: #fff;
|
|
172
|
+
border: 1px solid #dcdfe6;
|
|
173
|
+
border-radius: 4px;
|
|
174
|
+
padding: 8px 12px;
|
|
175
|
+
transition: border-color 0.2s;
|
|
176
|
+
|
|
177
|
+
&--focused {
|
|
178
|
+
border-color: #1890ff;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
&--disabled {
|
|
182
|
+
background-color: #f5f7fa;
|
|
183
|
+
border-color: #e4e7ed;
|
|
184
|
+
cursor: not-allowed;
|
|
185
|
+
|
|
186
|
+
.t-textarea__input {
|
|
187
|
+
color: #c0c4cc;
|
|
188
|
+
cursor: not-allowed;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.t-textarea__input {
|
|
194
|
+
width: 100%;
|
|
195
|
+
font-size: 14px;
|
|
196
|
+
color: #303133;
|
|
197
|
+
line-height: 1.5;
|
|
198
|
+
box-sizing: border-box;
|
|
199
|
+
resize: none;
|
|
200
|
+
border: none;
|
|
201
|
+
outline: none;
|
|
202
|
+
background-color: transparent;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.t-textarea__footer {
|
|
206
|
+
display: flex;
|
|
207
|
+
align-items: center;
|
|
208
|
+
justify-content: space-between;
|
|
209
|
+
margin-top: 8px;
|
|
210
|
+
padding-top: 8px;
|
|
211
|
+
border-top: 1px solid #f0f0f0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.t-textarea__count {
|
|
215
|
+
font-size: 12px;
|
|
216
|
+
color: #909399;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.t-textarea__clear {
|
|
220
|
+
display: flex;
|
|
221
|
+
align-items: center;
|
|
222
|
+
justify-content: center;
|
|
223
|
+
width: 20px;
|
|
224
|
+
height: 20px;
|
|
225
|
+
cursor: pointer;
|
|
226
|
+
border-radius: 50%;
|
|
227
|
+
background-color: #c0c4cc;
|
|
228
|
+
transition: background-color 0.2s;
|
|
229
|
+
|
|
230
|
+
&:hover {
|
|
231
|
+
background-color: #909399;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.t-textarea__clear-icon {
|
|
236
|
+
font-size: 12px;
|
|
237
|
+
color: #fff;
|
|
238
|
+
}
|
|
239
|
+
</style>
|