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,255 @@
|
|
|
1
|
+
<script setup lang="uts">
|
|
2
|
+
import { ref, computed } from 'vue'
|
|
3
|
+
import type { TSearchBarProps } from './type.uts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TSearchBar 搜索框组件
|
|
7
|
+
* @description 用于搜索场景的输入框组件,支持防抖、清除、取消等功能
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Props 定义 (从 type.uts 导入,排除 modelValue)
|
|
11
|
+
type Props = Omit<TSearchBarProps, 'modelValue'>
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
14
|
+
placeholder: '请输入搜索关键词',
|
|
15
|
+
shape: 'square',
|
|
16
|
+
background: '#f5f5f5',
|
|
17
|
+
maxlength: -1,
|
|
18
|
+
clearable: true,
|
|
19
|
+
showCancel: false,
|
|
20
|
+
cancelText: '取消',
|
|
21
|
+
disabled: false,
|
|
22
|
+
readonly: false,
|
|
23
|
+
autoFocus: false,
|
|
24
|
+
leftIcon: '🔍',
|
|
25
|
+
debounce: 300,
|
|
26
|
+
customClass: '',
|
|
27
|
+
customStyle: ''
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// 使用 defineModel 管理双向绑定
|
|
31
|
+
const modelValue = defineModel<string>({ default: '' })
|
|
32
|
+
|
|
33
|
+
// Emits 定义
|
|
34
|
+
const emit = defineEmits<{
|
|
35
|
+
search: [value: string]
|
|
36
|
+
input: [value: string]
|
|
37
|
+
cancel: []
|
|
38
|
+
clear: []
|
|
39
|
+
focus: [event: Event]
|
|
40
|
+
blur: [event: Event]
|
|
41
|
+
}>()
|
|
42
|
+
|
|
43
|
+
// 状态管理
|
|
44
|
+
const isFocused = ref<boolean>(false)
|
|
45
|
+
let debounceTimer: number | null = null
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 计算容器类名
|
|
49
|
+
*/
|
|
50
|
+
const containerClasses = computed((): string => {
|
|
51
|
+
const classes: string[] = ['t-search-bar']
|
|
52
|
+
|
|
53
|
+
if (props.shape === 'round') {
|
|
54
|
+
classes.push('t-search-bar--round')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (props.disabled) {
|
|
58
|
+
classes.push('t-search-bar--disabled')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (props.customClass) {
|
|
62
|
+
classes.push(props.customClass)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return classes.join(' ')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 计算输入框样式
|
|
70
|
+
*/
|
|
71
|
+
const inputStyle = computed((): string => {
|
|
72
|
+
const styles: string[] = []
|
|
73
|
+
|
|
74
|
+
styles.push(`background-color: ${props.background}`)
|
|
75
|
+
|
|
76
|
+
if (props.customStyle) {
|
|
77
|
+
styles.push(props.customStyle)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return styles.join('; ')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 输入事件处理(带防抖)
|
|
85
|
+
*/
|
|
86
|
+
const handleInput = (event: any): void => {
|
|
87
|
+
const value = event.detail.value as string
|
|
88
|
+
modelValue.value = value
|
|
89
|
+
emit('input', value)
|
|
90
|
+
|
|
91
|
+
// 防抖搜索
|
|
92
|
+
if (debounceTimer !== null) {
|
|
93
|
+
clearTimeout(debounceTimer)
|
|
94
|
+
}
|
|
95
|
+
debounceTimer = setTimeout(() => {
|
|
96
|
+
emit('search', value)
|
|
97
|
+
}, props.debounce)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 聚焦事件
|
|
102
|
+
*/
|
|
103
|
+
const handleFocus = (event: Event): void => {
|
|
104
|
+
isFocused.value = true
|
|
105
|
+
emit('focus', event)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 失焦事件
|
|
110
|
+
*/
|
|
111
|
+
const handleBlur = (event: Event): void => {
|
|
112
|
+
isFocused.value = false
|
|
113
|
+
emit('blur', event)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 清空输入
|
|
118
|
+
*/
|
|
119
|
+
const handleClear = (): void => {
|
|
120
|
+
modelValue.value = ''
|
|
121
|
+
emit('clear')
|
|
122
|
+
emit('search', '')
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 点击搜索按钮
|
|
127
|
+
*/
|
|
128
|
+
const handleSearch = (): void => {
|
|
129
|
+
emit('search', modelValue.value)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 取消搜索
|
|
134
|
+
*/
|
|
135
|
+
const handleCancel = (): void => {
|
|
136
|
+
modelValue.value = ''
|
|
137
|
+
emit('cancel')
|
|
138
|
+
}
|
|
139
|
+
</script>
|
|
140
|
+
|
|
141
|
+
<template>
|
|
142
|
+
<view :class="containerClasses">
|
|
143
|
+
<view class="t-search-bar__content" :style="inputStyle">
|
|
144
|
+
<!-- 左侧图标 -->
|
|
145
|
+
<text v-if="leftIcon" class="t-search-bar__icon">{{ leftIcon }}</text>
|
|
146
|
+
|
|
147
|
+
<!-- 输入框 -->
|
|
148
|
+
<input
|
|
149
|
+
class="t-search-bar__input"
|
|
150
|
+
type="text"
|
|
151
|
+
:value="modelValue"
|
|
152
|
+
:placeholder="placeholder"
|
|
153
|
+
:maxlength="maxlength"
|
|
154
|
+
:disabled="disabled"
|
|
155
|
+
:focus="autoFocus"
|
|
156
|
+
@input="handleInput"
|
|
157
|
+
@focus="handleFocus"
|
|
158
|
+
@blur="handleBlur"
|
|
159
|
+
@confirm="handleSearch"
|
|
160
|
+
/>
|
|
161
|
+
|
|
162
|
+
<!-- 清除按钮 -->
|
|
163
|
+
<view
|
|
164
|
+
v-if="clearable && modelValue.length > 0"
|
|
165
|
+
class="t-search-bar__clear"
|
|
166
|
+
@click="handleClear"
|
|
167
|
+
>
|
|
168
|
+
<text class="t-search-bar__clear-icon">✕</text>
|
|
169
|
+
</view>
|
|
170
|
+
</view>
|
|
171
|
+
|
|
172
|
+
<!-- 取消按钮 -->
|
|
173
|
+
<text
|
|
174
|
+
v-if="showCancel"
|
|
175
|
+
class="t-search-bar__cancel"
|
|
176
|
+
@click="handleCancel"
|
|
177
|
+
>
|
|
178
|
+
{{ cancelText }}
|
|
179
|
+
</text>
|
|
180
|
+
</view>
|
|
181
|
+
</template>
|
|
182
|
+
|
|
183
|
+
<style lang="scss" scoped>
|
|
184
|
+
.t-search-bar {
|
|
185
|
+
display: flex;
|
|
186
|
+
align-items: center;
|
|
187
|
+
padding: 8px 12px;
|
|
188
|
+
background-color: #fff;
|
|
189
|
+
|
|
190
|
+
&--round {
|
|
191
|
+
.t-search-bar__content {
|
|
192
|
+
border-radius: 18px;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
&--disabled {
|
|
197
|
+
opacity: 0.6;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.t-search-bar__content {
|
|
202
|
+
position: relative;
|
|
203
|
+
display: flex;
|
|
204
|
+
flex-direction: row;
|
|
205
|
+
align-items: center;
|
|
206
|
+
flex: 1;
|
|
207
|
+
padding: 8px 12px;
|
|
208
|
+
background-color: #f5f5f5;
|
|
209
|
+
border-radius: 4px;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.t-search-bar__icon {
|
|
213
|
+
font-size: 16px;
|
|
214
|
+
margin-right: 8px;
|
|
215
|
+
color: #969799;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.t-search-bar__input {
|
|
219
|
+
flex: 1;
|
|
220
|
+
font-size: 14px;
|
|
221
|
+
color: #323233;
|
|
222
|
+
background-color: transparent;
|
|
223
|
+
border: none;
|
|
224
|
+
outline: none;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.t-search-bar__clear {
|
|
228
|
+
display: flex;
|
|
229
|
+
align-items: center;
|
|
230
|
+
justify-content: center;
|
|
231
|
+
width: 16px;
|
|
232
|
+
height: 16px;
|
|
233
|
+
margin-left: 8px;
|
|
234
|
+
border-radius: 50%;
|
|
235
|
+
background-color: #c8c9cc;
|
|
236
|
+
cursor: pointer;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.t-search-bar__clear-icon {
|
|
240
|
+
font-size: 10px;
|
|
241
|
+
color: #fff;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.t-search-bar__cancel {
|
|
245
|
+
margin-left: 12px;
|
|
246
|
+
font-size: 14px;
|
|
247
|
+
color: #323233;
|
|
248
|
+
cursor: pointer;
|
|
249
|
+
white-space: nowrap;
|
|
250
|
+
|
|
251
|
+
&:active {
|
|
252
|
+
opacity: 0.7;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
</style>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TSearchBar 组件类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 搜索框形状
|
|
7
|
+
*/
|
|
8
|
+
export type SearchBarShape = 'square' | 'round'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* TSearchBar Props 接口
|
|
12
|
+
*/
|
|
13
|
+
export interface TSearchBarProps {
|
|
14
|
+
/**
|
|
15
|
+
* 搜索值
|
|
16
|
+
*/
|
|
17
|
+
modelValue?: string
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 占位符
|
|
21
|
+
* @default '请输入搜索关键词'
|
|
22
|
+
*/
|
|
23
|
+
placeholder?: string
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 形状
|
|
27
|
+
* @default 'square'
|
|
28
|
+
*/
|
|
29
|
+
shape?: SearchBarShape
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 背景色
|
|
33
|
+
* @default '#f5f5f5'
|
|
34
|
+
*/
|
|
35
|
+
background?: string
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 最大输入长度
|
|
39
|
+
* @default -1
|
|
40
|
+
*/
|
|
41
|
+
maxlength?: number
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 是否显示清除按钮
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
clearable?: boolean
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 是否显示取消按钮
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
showCancel?: boolean
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 取消按钮文字
|
|
57
|
+
* @default '取消'
|
|
58
|
+
*/
|
|
59
|
+
cancelText?: string
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 是否禁用
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
65
|
+
disabled?: boolean
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 是否只读
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
readonly?: boolean
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 是否自动聚焦
|
|
75
|
+
* @default false
|
|
76
|
+
*/
|
|
77
|
+
autoFocus?: boolean
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 左侧图标
|
|
81
|
+
* @default '🔍'
|
|
82
|
+
*/
|
|
83
|
+
leftIcon?: string
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 防抖延迟(毫秒)
|
|
87
|
+
* @default 300
|
|
88
|
+
*/
|
|
89
|
+
debounce?: number
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 自定义类名
|
|
93
|
+
*/
|
|
94
|
+
customClass?: string
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 自定义样式
|
|
98
|
+
*/
|
|
99
|
+
customStyle?: string
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* TSearchBar 事件接口
|
|
104
|
+
*/
|
|
105
|
+
export interface TSearchBarEmits {
|
|
106
|
+
/**
|
|
107
|
+
* 更新值
|
|
108
|
+
*/
|
|
109
|
+
'update:modelValue': (value: string) => void
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 搜索事件
|
|
113
|
+
*/
|
|
114
|
+
search: (value: string) => void
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 输入事件
|
|
118
|
+
*/
|
|
119
|
+
input: (value: string) => void
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 取消事件
|
|
123
|
+
*/
|
|
124
|
+
cancel: () => void
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 清空事件
|
|
128
|
+
*/
|
|
129
|
+
clear: () => void
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 聚焦事件
|
|
133
|
+
*/
|
|
134
|
+
focus: (event: Event) => void
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 失焦事件
|
|
138
|
+
*/
|
|
139
|
+
blur: (event: Event) => void
|
|
140
|
+
}
|