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,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 验证工具函数
|
|
3
|
+
* @module utils/validator
|
|
4
|
+
* @description 提供各种数据验证功能
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 验证是否为空
|
|
9
|
+
* @param {any} value - 待验证值
|
|
10
|
+
* @returns {boolean} 是否为空
|
|
11
|
+
*/
|
|
12
|
+
export function isEmpty(value: any): boolean {
|
|
13
|
+
if (value === null || value === undefined) {
|
|
14
|
+
return true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (typeof value === 'string') {
|
|
18
|
+
return value.trim().length === 0
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
return value.length === 0
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (typeof value === 'object') {
|
|
26
|
+
return Object.keys(value).length === 0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 验证手机号
|
|
34
|
+
* @param {string} phone - 手机号
|
|
35
|
+
* @returns {boolean} 是否为有效手机号
|
|
36
|
+
*/
|
|
37
|
+
export function isPhone(phone: string): boolean {
|
|
38
|
+
return /^1[3-9]\d{9}$/.test(phone)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 验证邮箱
|
|
43
|
+
* @param email 邮箱地址
|
|
44
|
+
* @returns 是否为有效邮箱
|
|
45
|
+
*/
|
|
46
|
+
export function isEmail(email: string): boolean {
|
|
47
|
+
return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 验证身份证号
|
|
52
|
+
* @param idCard 身份证号
|
|
53
|
+
* @returns 是否为有效身份证号
|
|
54
|
+
*/
|
|
55
|
+
export function isIdCard(idCard: string): boolean {
|
|
56
|
+
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idCard)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 验证 URL
|
|
61
|
+
* @param url URL 地址
|
|
62
|
+
* @returns 是否为有效 URL
|
|
63
|
+
*/
|
|
64
|
+
export function isUrl(url: string): boolean {
|
|
65
|
+
return /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/.test(url)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 验证中文
|
|
70
|
+
* @param str 字符串
|
|
71
|
+
* @returns 是否为中文
|
|
72
|
+
*/
|
|
73
|
+
export function isChinese(str: string): boolean {
|
|
74
|
+
return /^[\u4e00-\u9fa5]+$/.test(str)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 验证数字
|
|
79
|
+
* @param value 值
|
|
80
|
+
* @returns 是否为数字
|
|
81
|
+
*/
|
|
82
|
+
export function isNumber(value: any): boolean {
|
|
83
|
+
return !isNaN(parseFloat(value)) && isFinite(value)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 验证整数
|
|
88
|
+
* @param value 值
|
|
89
|
+
* @returns 是否为整数
|
|
90
|
+
*/
|
|
91
|
+
export function isInteger(value: any): boolean {
|
|
92
|
+
return /^-?\d+$/.test(String(value))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 验证正整数
|
|
97
|
+
* @param value 值
|
|
98
|
+
* @returns 是否为正整数
|
|
99
|
+
*/
|
|
100
|
+
export function isPositiveInteger(value: any): boolean {
|
|
101
|
+
return /^\d+$/.test(String(value))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 验证小数
|
|
106
|
+
* @param value 值
|
|
107
|
+
* @param decimal 小数位数,默认不限制
|
|
108
|
+
* @returns 是否为小数
|
|
109
|
+
*/
|
|
110
|
+
export function isDecimal(value: any, decimal?: number): boolean {
|
|
111
|
+
if (decimal !== undefined) {
|
|
112
|
+
const reg = new RegExp(`^-?\\d+\\.\\d{${decimal}}$`)
|
|
113
|
+
return reg.test(String(value))
|
|
114
|
+
}
|
|
115
|
+
return /^-?\d+\.\d+$/.test(String(value))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 验证密码强度
|
|
120
|
+
* @param password 密码
|
|
121
|
+
* @param level 强度等级:1-弱(至少6位),2-中(包含数字和字母),3-强(包含数字、字母和特殊字符)
|
|
122
|
+
* @returns 是否符合强度要求
|
|
123
|
+
*/
|
|
124
|
+
export function isPasswordStrong(password: string, level: number = 2): boolean {
|
|
125
|
+
switch (level) {
|
|
126
|
+
case 1:
|
|
127
|
+
return password.length >= 6
|
|
128
|
+
case 2:
|
|
129
|
+
return /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/.test(password)
|
|
130
|
+
case 3:
|
|
131
|
+
return /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/.test(password)
|
|
132
|
+
default:
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 验证银行卡号
|
|
139
|
+
* @param cardNo 银行卡号
|
|
140
|
+
* @returns 是否为有效银行卡号
|
|
141
|
+
*/
|
|
142
|
+
export function isBankCard(cardNo: string): boolean {
|
|
143
|
+
return /^[1-9]\d{9,29}$/.test(cardNo)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 验证车牌号
|
|
148
|
+
* @param plateNo 车牌号
|
|
149
|
+
* @returns 是否为有效车牌号
|
|
150
|
+
*/
|
|
151
|
+
export function isPlateNo(plateNo: string): boolean {
|
|
152
|
+
return /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-Z0-9]{4,5}[A-Z0-9挂学警港澳]$/.test(
|
|
153
|
+
plateNo
|
|
154
|
+
)
|
|
155
|
+
}
|