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,386 @@
|
|
|
1
|
+
<script setup lang="uts" >
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import type { TDialogProps } from './type.uts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TDialog 对话框组件
|
|
7
|
+
* @description 模态对话框组件
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Props 定义 (从 type.uts 导入,排除 visible)
|
|
11
|
+
type Props = Omit<TDialogProps, 'visible'>
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
14
|
+
title: '',
|
|
15
|
+
content: '',
|
|
16
|
+
width: '80%',
|
|
17
|
+
mask: true,
|
|
18
|
+
maskClosable: true,
|
|
19
|
+
showClose: true,
|
|
20
|
+
showCancel: true,
|
|
21
|
+
confirmText: '确定',
|
|
22
|
+
cancelText: '取消',
|
|
23
|
+
confirmType: 'primary'
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// 使用 defineModel 管理显示状态 (v-model)
|
|
27
|
+
const modelValue = defineModel<boolean>({ default: false })
|
|
28
|
+
|
|
29
|
+
// 定义 emits
|
|
30
|
+
const emit = defineEmits<{
|
|
31
|
+
confirm: []
|
|
32
|
+
cancel: []
|
|
33
|
+
close: []
|
|
34
|
+
}>()
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 计算对话框样式
|
|
38
|
+
*/
|
|
39
|
+
const dialogStyle = computed<string>(() => {
|
|
40
|
+
const styles: string[] = []
|
|
41
|
+
|
|
42
|
+
if (props.width != '') {
|
|
43
|
+
styles.push(`width: ${props.width}`)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return styles.join('; ')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 计算确认按钮样式类
|
|
51
|
+
*/
|
|
52
|
+
const confirmBtnClass = computed<string>(() => {
|
|
53
|
+
const classes: string[] = ['t-dialog__btn', 't-dialog__btn--confirm']
|
|
54
|
+
|
|
55
|
+
classes.push(`t-dialog__btn--${props.confirmType}`)
|
|
56
|
+
|
|
57
|
+
return classes.join(' ')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 处理遮罩层点击
|
|
62
|
+
*/
|
|
63
|
+
const handleMaskClick = (): void => {
|
|
64
|
+
if (props.maskClosable) {
|
|
65
|
+
handleClose()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 处理确认
|
|
71
|
+
*/
|
|
72
|
+
const handleConfirm = (): void => {
|
|
73
|
+
emit('confirm')
|
|
74
|
+
handleClose()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 处理取消
|
|
79
|
+
*/
|
|
80
|
+
const handleCancel = (): void => {
|
|
81
|
+
emit('cancel')
|
|
82
|
+
handleClose()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 处理关闭
|
|
87
|
+
*/
|
|
88
|
+
const handleClose = (): void => {
|
|
89
|
+
modelValue.value = false
|
|
90
|
+
emit('close')
|
|
91
|
+
}
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<template>
|
|
95
|
+
<transition name="t-dialog-fade" appear>
|
|
96
|
+
<view v-if="modelValue" class="t-dialog">
|
|
97
|
+
<!-- 遮罩层 -->
|
|
98
|
+
<transition name="t-dialog-mask" appear>
|
|
99
|
+
<view v-if="mask" class="t-dialog__mask" @click="handleMaskClick"></view>
|
|
100
|
+
</transition>
|
|
101
|
+
|
|
102
|
+
<!-- 对话框主体 -->
|
|
103
|
+
<view class="t-dialog__wrapper">
|
|
104
|
+
<transition name="t-dialog-zoom" appear>
|
|
105
|
+
<view class="t-dialog__content" :style="dialogStyle">
|
|
106
|
+
<!-- 头部 -->
|
|
107
|
+
<view v-if="title || showClose" class="t-dialog__header">
|
|
108
|
+
<!-- 关闭按钮(定位方式,不占用文档流) -->
|
|
109
|
+
<view v-if="showClose" class="t-dialog__close" @click="handleClose">
|
|
110
|
+
<text class="t-dialog__close-icon">×</text>
|
|
111
|
+
</view>
|
|
112
|
+
|
|
113
|
+
<!-- 标题(居中,支持插槽) -->
|
|
114
|
+
<view class="t-dialog__title">
|
|
115
|
+
<slot name="title">
|
|
116
|
+
<text v-if="title" class="t-dialog__title-text">{{ title }}</text>
|
|
117
|
+
</slot>
|
|
118
|
+
</view>
|
|
119
|
+
</view>
|
|
120
|
+
|
|
121
|
+
<!-- 内容 -->
|
|
122
|
+
<view class="t-dialog__body">
|
|
123
|
+
<slot>
|
|
124
|
+
<text class="t-dialog__text">{{ content }}</text>
|
|
125
|
+
</slot>
|
|
126
|
+
</view>
|
|
127
|
+
|
|
128
|
+
<!-- 底部按钮 -->
|
|
129
|
+
<view class="t-dialog__footer">
|
|
130
|
+
<slot name="footer">
|
|
131
|
+
<view v-if="showCancel" class="t-dialog__btn t-dialog__btn--cancel" @click="handleCancel">
|
|
132
|
+
<text class="t-dialog__btn-text">{{ cancelText }}</text>
|
|
133
|
+
</view>
|
|
134
|
+
<view :class="confirmBtnClass" @click="handleConfirm">
|
|
135
|
+
<text class="t-dialog__btn-text t-dialog__btn-text--confirm">{{ confirmText }}</text>
|
|
136
|
+
</view>
|
|
137
|
+
</slot>
|
|
138
|
+
</view>
|
|
139
|
+
</view>
|
|
140
|
+
</transition>
|
|
141
|
+
</view>
|
|
142
|
+
</view>
|
|
143
|
+
</transition>
|
|
144
|
+
</template>
|
|
145
|
+
|
|
146
|
+
<style lang="scss" scoped>
|
|
147
|
+
.t-dialog {
|
|
148
|
+
position: fixed;
|
|
149
|
+
top: 0;
|
|
150
|
+
left: 0;
|
|
151
|
+
right: 0;
|
|
152
|
+
bottom: 0;
|
|
153
|
+
z-index: 9999;
|
|
154
|
+
|
|
155
|
+
&__mask {
|
|
156
|
+
position: absolute;
|
|
157
|
+
top: 0;
|
|
158
|
+
left: 0;
|
|
159
|
+
right: 0;
|
|
160
|
+
bottom: 0;
|
|
161
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
&__wrapper {
|
|
165
|
+
position: absolute;
|
|
166
|
+
top: 50%;
|
|
167
|
+
left: 50%;
|
|
168
|
+
transform: translate(-50%, -50%);
|
|
169
|
+
z-index: 1;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
&__content {
|
|
173
|
+
background-color: #ffffff;
|
|
174
|
+
border-radius: 8px;
|
|
175
|
+
overflow: hidden;
|
|
176
|
+
min-width: 280px;
|
|
177
|
+
max-width: 90%;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* 头部:使用定位布局 */
|
|
181
|
+
&__header {
|
|
182
|
+
position: relative;
|
|
183
|
+
padding: 16px 20px;
|
|
184
|
+
border-bottom: 1px solid #ebeef5;
|
|
185
|
+
min-height: 48px;
|
|
186
|
+
display: flex;
|
|
187
|
+
align-items: center;
|
|
188
|
+
justify-content: center;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* 关闭按钮:绝对定位 */
|
|
192
|
+
&__close {
|
|
193
|
+
position: absolute;
|
|
194
|
+
top: 50%;
|
|
195
|
+
right: 20px;
|
|
196
|
+
transform: translateY(-50%);
|
|
197
|
+
cursor: pointer;
|
|
198
|
+
padding: 4px;
|
|
199
|
+
z-index: 1;
|
|
200
|
+
width: 32px;
|
|
201
|
+
height: 32px;
|
|
202
|
+
display: flex;
|
|
203
|
+
align-items: center;
|
|
204
|
+
justify-content: center;
|
|
205
|
+
border-radius: 4px;
|
|
206
|
+
transition: all 0.2s;
|
|
207
|
+
|
|
208
|
+
&:hover {
|
|
209
|
+
background-color: #f5f5f5;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
&:active {
|
|
213
|
+
background-color: #e4e7ed;
|
|
214
|
+
transform: translateY(-50%) scale(0.95);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
&-icon {
|
|
218
|
+
font-size: 24px;
|
|
219
|
+
color: #909399;
|
|
220
|
+
font-weight: bold;
|
|
221
|
+
line-height: 1;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* 标题容器:居中 */
|
|
226
|
+
&__title {
|
|
227
|
+
position: relative;
|
|
228
|
+
width: 100%;
|
|
229
|
+
display: flex;
|
|
230
|
+
align-items: center;
|
|
231
|
+
justify-content: center;
|
|
232
|
+
|
|
233
|
+
&-text {
|
|
234
|
+
font-size: 18px;
|
|
235
|
+
font-weight: 600;
|
|
236
|
+
color: #303133;
|
|
237
|
+
line-height: 1.4;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
&__body {
|
|
242
|
+
padding: 20px;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
&__text {
|
|
246
|
+
font-size: 14px;
|
|
247
|
+
color: #606266;
|
|
248
|
+
line-height: 1.5;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
&__footer {
|
|
252
|
+
display: flex;
|
|
253
|
+
flex-direction: row;
|
|
254
|
+
justify-content: space-around;
|
|
255
|
+
padding: 12px 20px;
|
|
256
|
+
border-top: 1px solid #ebeef5;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
&__btn {
|
|
260
|
+
padding: 8px 20px;
|
|
261
|
+
border-radius: 4px;
|
|
262
|
+
cursor: pointer;
|
|
263
|
+
margin-left: 12px;
|
|
264
|
+
transition: all 0.3s;
|
|
265
|
+
|
|
266
|
+
&--cancel {
|
|
267
|
+
background-color: #ffffff;
|
|
268
|
+
border: 1px solid #dcdfe6;
|
|
269
|
+
color: #606266;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
&--primary {
|
|
273
|
+
background-color: #409eff;
|
|
274
|
+
color: #ffffff;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
&--success {
|
|
278
|
+
background-color: #67c23a;
|
|
279
|
+
color: #ffffff;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
&--warning {
|
|
283
|
+
background-color: #e6a23c;
|
|
284
|
+
color: #ffffff;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
&--danger {
|
|
288
|
+
background-color: #f56c6c;
|
|
289
|
+
color: #ffffff;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
&-text {
|
|
293
|
+
font-size: 14px;
|
|
294
|
+
|
|
295
|
+
&--confirm {
|
|
296
|
+
color: #ffffff;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/* 渐隐动画 - 对话框整体 */
|
|
303
|
+
.t-dialog-fade-enter-active {
|
|
304
|
+
animation: dialog-fade-in 0.3s ease-out;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.t-dialog-fade-leave-active {
|
|
308
|
+
animation: dialog-fade-out 0.3s ease-in;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@keyframes dialog-fade-in {
|
|
312
|
+
from {
|
|
313
|
+
opacity: 0;
|
|
314
|
+
}
|
|
315
|
+
to {
|
|
316
|
+
opacity: 1;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
@keyframes dialog-fade-out {
|
|
321
|
+
from {
|
|
322
|
+
opacity: 1;
|
|
323
|
+
}
|
|
324
|
+
to {
|
|
325
|
+
opacity: 0;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/* 遮罩层渐隐动画 */
|
|
330
|
+
.t-dialog-mask-enter-active {
|
|
331
|
+
animation: mask-fade-in 0.3s ease-out;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.t-dialog-mask-leave-active {
|
|
335
|
+
animation: mask-fade-out 0.3s ease-in;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
@keyframes mask-fade-in {
|
|
339
|
+
from {
|
|
340
|
+
opacity: 0;
|
|
341
|
+
}
|
|
342
|
+
to {
|
|
343
|
+
opacity: 1;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
@keyframes mask-fade-out {
|
|
348
|
+
from {
|
|
349
|
+
opacity: 1;
|
|
350
|
+
}
|
|
351
|
+
to {
|
|
352
|
+
opacity: 0;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/* 内容区域缩放动画 */
|
|
357
|
+
.t-dialog-zoom-enter-active {
|
|
358
|
+
animation: content-zoom-in 0.3s cubic-bezier(0.12, 0.8, 0.32, 1);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.t-dialog-zoom-leave-active {
|
|
362
|
+
animation: content-zoom-out 0.25s cubic-bezier(0.4, 0, 1, 1);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
@keyframes content-zoom-in {
|
|
366
|
+
from {
|
|
367
|
+
opacity: 0;
|
|
368
|
+
transform: scale(0.7);
|
|
369
|
+
}
|
|
370
|
+
to {
|
|
371
|
+
opacity: 1;
|
|
372
|
+
transform: scale(1);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
@keyframes content-zoom-out {
|
|
377
|
+
from {
|
|
378
|
+
opacity: 1;
|
|
379
|
+
transform: scale(1);
|
|
380
|
+
}
|
|
381
|
+
to {
|
|
382
|
+
opacity: 0;
|
|
383
|
+
transform: scale(0.7);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
</style>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TDialog 对话框组件属性类型定义
|
|
3
|
+
*/
|
|
4
|
+
export type TDialogProps = {
|
|
5
|
+
/**
|
|
6
|
+
* 是否显示对话框
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
visible?: boolean
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 对话框标题
|
|
13
|
+
*/
|
|
14
|
+
title?: string
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 对话框内容
|
|
18
|
+
*/
|
|
19
|
+
content?: string
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 对话框宽度
|
|
23
|
+
*/
|
|
24
|
+
width?: string
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 是否显示遮罩层
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
mask?: boolean
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 是否点击遮罩关闭
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
maskClosable?: boolean
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 是否显示关闭按钮
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
showClose?: boolean
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 是否显示取消按钮
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
showCancel?: boolean
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 确认按钮文字
|
|
52
|
+
* @default "确定"
|
|
53
|
+
*/
|
|
54
|
+
confirmText?: string
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 取消按钮文字
|
|
58
|
+
* @default "取消"
|
|
59
|
+
*/
|
|
60
|
+
cancelText?: string
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 确认按钮类型
|
|
64
|
+
* @default "primary"
|
|
65
|
+
*/
|
|
66
|
+
confirmType?: 'primary' | 'success' | 'warning' | 'danger'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type TDialogEmits = {
|
|
70
|
+
/**
|
|
71
|
+
* 确认时触发
|
|
72
|
+
*/
|
|
73
|
+
confirm: () => void
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 取消时触发
|
|
77
|
+
*/
|
|
78
|
+
cancel: () => void
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 关闭时触发
|
|
82
|
+
*/
|
|
83
|
+
close: () => void
|
|
84
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
<script setup lang="uts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import type { DividerDirection, DividerType, DividerContentPosition } from './type.uts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TDivider 分割线组件
|
|
7
|
+
* @description 用于分隔内容的分割线,支持水平、垂直、虚线、文字等多种形式
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Props 定义
|
|
11
|
+
interface Props {
|
|
12
|
+
direction?: DividerDirection
|
|
13
|
+
type?: DividerType
|
|
14
|
+
color?: string
|
|
15
|
+
thickness?: number
|
|
16
|
+
hairline?: boolean
|
|
17
|
+
content?: string
|
|
18
|
+
contentPosition?: DividerContentPosition
|
|
19
|
+
contentStyle?: string
|
|
20
|
+
padding?: string | number
|
|
21
|
+
margin?: string | number
|
|
22
|
+
customClass?: string
|
|
23
|
+
customStyle?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
27
|
+
direction: 'horizontal',
|
|
28
|
+
type: 'solid',
|
|
29
|
+
color: '#e0e0e0',
|
|
30
|
+
thickness: 1,
|
|
31
|
+
hairline: true,
|
|
32
|
+
content: '',
|
|
33
|
+
contentPosition: 'center',
|
|
34
|
+
contentStyle: '',
|
|
35
|
+
padding: '16px',
|
|
36
|
+
margin: '16px',
|
|
37
|
+
customClass: '',
|
|
38
|
+
customStyle: ''
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 计算容器样式
|
|
43
|
+
*/
|
|
44
|
+
const containerStyle = computed((): string => {
|
|
45
|
+
const styles: string[] = []
|
|
46
|
+
|
|
47
|
+
// 外边距
|
|
48
|
+
if (props.direction === 'horizontal') {
|
|
49
|
+
if (typeof props.margin === 'number') {
|
|
50
|
+
styles.push(`margin: ${props.margin}px 0`)
|
|
51
|
+
} else {
|
|
52
|
+
styles.push(`margin: ${props.margin} 0`)
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
if (typeof props.margin === 'number') {
|
|
56
|
+
styles.push(`margin: 0 ${props.margin}px`)
|
|
57
|
+
} else {
|
|
58
|
+
styles.push(`margin: 0 ${props.margin}`)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 自定义样式
|
|
63
|
+
if (props.customStyle) {
|
|
64
|
+
styles.push(props.customStyle)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return styles.join('; ')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 计算分割线样式
|
|
72
|
+
*/
|
|
73
|
+
const lineStyle = computed((): string => {
|
|
74
|
+
const styles: string[] = []
|
|
75
|
+
|
|
76
|
+
// 颜色
|
|
77
|
+
if (props.direction === 'horizontal') {
|
|
78
|
+
styles.push(`border-top-color: ${props.color}`)
|
|
79
|
+
} else {
|
|
80
|
+
styles.push(`border-left-color: ${props.color}`)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 粗细
|
|
84
|
+
const thickness = props.hairline ? '1px' : `${props.thickness}px`
|
|
85
|
+
if (props.direction === 'horizontal') {
|
|
86
|
+
styles.push(`border-top-width: ${thickness}`)
|
|
87
|
+
} else {
|
|
88
|
+
styles.push(`border-left-width: ${thickness}`)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 类型
|
|
92
|
+
if (props.direction === 'horizontal') {
|
|
93
|
+
styles.push(`border-top-style: ${props.type}`)
|
|
94
|
+
} else {
|
|
95
|
+
styles.push(`border-left-style: ${props.type}`)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return styles.join('; ')
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 计算文字样式
|
|
103
|
+
*/
|
|
104
|
+
const textStyle = computed((): string => {
|
|
105
|
+
const styles: string[] = []
|
|
106
|
+
|
|
107
|
+
// 内边距
|
|
108
|
+
if (typeof props.padding === 'number') {
|
|
109
|
+
styles.push(`padding: 0 ${props.padding}px`)
|
|
110
|
+
} else {
|
|
111
|
+
styles.push(`padding: 0 ${props.padding}`)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 自定义文字样式
|
|
115
|
+
if (props.contentStyle) {
|
|
116
|
+
styles.push(props.contentStyle)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return styles.join('; ')
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 计算容器类名
|
|
124
|
+
*/
|
|
125
|
+
const containerClasses = computed((): string => {
|
|
126
|
+
const classes: string[] = ['t-divider']
|
|
127
|
+
|
|
128
|
+
// 方向
|
|
129
|
+
classes.push(`t-divider--${props.direction}`)
|
|
130
|
+
|
|
131
|
+
// 文字位置
|
|
132
|
+
if (props.content && props.direction === 'horizontal') {
|
|
133
|
+
classes.push(`t-divider--${props.contentPosition}`)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 自定义类名
|
|
137
|
+
if (props.customClass) {
|
|
138
|
+
classes.push(props.customClass)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return classes.join(' ')
|
|
142
|
+
})
|
|
143
|
+
</script>
|
|
144
|
+
|
|
145
|
+
<template>
|
|
146
|
+
<view :class="containerClasses" :style="containerStyle">
|
|
147
|
+
<!-- 水平分割线 -->
|
|
148
|
+
<template v-if="direction === 'horizontal'">
|
|
149
|
+
<!-- 无文字 -->
|
|
150
|
+
<view v-if="!content" class="t-divider__line" :style="lineStyle"></view>
|
|
151
|
+
|
|
152
|
+
<!-- 有文字 -->
|
|
153
|
+
<template v-else>
|
|
154
|
+
<view class="t-divider__line" :style="lineStyle"></view>
|
|
155
|
+
<text class="t-divider__text" :style="textStyle">
|
|
156
|
+
<slot>{{ content }}</slot>
|
|
157
|
+
</text>
|
|
158
|
+
<view class="t-divider__line" :style="lineStyle"></view>
|
|
159
|
+
</template>
|
|
160
|
+
</template>
|
|
161
|
+
|
|
162
|
+
<!-- 垂直分割线 -->
|
|
163
|
+
<view v-else class="t-divider__line" :style="lineStyle"></view>
|
|
164
|
+
</view>
|
|
165
|
+
</template>
|
|
166
|
+
|
|
167
|
+
<style lang="scss" scoped>
|
|
168
|
+
.t-divider {
|
|
169
|
+
position: relative;
|
|
170
|
+
display: flex;
|
|
171
|
+
align-items: center;
|
|
172
|
+
|
|
173
|
+
&--horizontal {
|
|
174
|
+
width: 100%;
|
|
175
|
+
flex-direction: row;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
&--vertical {
|
|
179
|
+
height: 100%;
|
|
180
|
+
flex-direction: column;
|
|
181
|
+
display: inline-flex;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
&--left {
|
|
185
|
+
.t-divider__line:first-child {
|
|
186
|
+
flex: 0.3;
|
|
187
|
+
max-width: 80px;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.t-divider__line:last-child {
|
|
191
|
+
flex: 1;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
&--center {
|
|
196
|
+
.t-divider__line {
|
|
197
|
+
flex: 1;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
&--right {
|
|
202
|
+
.t-divider__line:first-child {
|
|
203
|
+
flex: 1;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.t-divider__line:last-child {
|
|
207
|
+
flex: 0.3;
|
|
208
|
+
max-width: 80px;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.t-divider__line {
|
|
214
|
+
border: none;
|
|
215
|
+
|
|
216
|
+
.t-divider--horizontal & {
|
|
217
|
+
border-top-width: 1px;
|
|
218
|
+
border-top-style: solid;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.t-divider--vertical & {
|
|
222
|
+
width: 0;
|
|
223
|
+
height: 100%;
|
|
224
|
+
border-left-width: 1px;
|
|
225
|
+
border-left-style: solid;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.t-divider__text {
|
|
230
|
+
white-space: nowrap;
|
|
231
|
+
font-size: 14px;
|
|
232
|
+
color: #909399;
|
|
233
|
+
padding: 0 16px;
|
|
234
|
+
}
|
|
235
|
+
</style>
|