Skip to content

Commit 527a190

Browse files
authored
update form api of uniapp (#839)
* feat: support uniapp config-provier * chore: upadate form type * chore: remove wrong types/docs * chore: update api
1 parent 53254cb commit 527a190

30 files changed

Lines changed: 530 additions & 1279 deletions

File tree

db/TDesign.db

4 KB
Binary file not shown.

packages/products/tdesign-miniprogram/packages/uniapp-components/common/common.ts

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,149 @@ export type ExtractNonOnProps<T> = {
7070
[K in keyof T as K extends `on${string}` ? never : K]: T[K]
7171
};
7272

73+
/**
74+
* 邮箱校验选项
75+
*/
7376
export interface IsEmailOptions {
77+
/**
78+
* 是否允许显示名称格式,如 `Display Name <email>`
79+
* @default false
80+
*/
7481
allow_display_name?: boolean;
82+
/**
83+
* 是否要求必须包含显示名称格式
84+
* @default false
85+
*/
7586
require_display_name?: boolean;
87+
/**
88+
* 是否允许本地部分使用 UTF8 字符
89+
* @default true
90+
*/
7691
allow_utf8_local_part?: boolean;
92+
/**
93+
* 是否要求域名包含顶级域名
94+
* @default true
95+
*/
7796
require_tld?: boolean;
78-
allow_ip_dot?: boolean;
79-
domain_specific_validation?: boolean;
80-
host_blacklist?: string[];
97+
/**
98+
* 是否忽略邮箱最大长度限制
99+
* @default false
100+
*/
81101
ignore_max_length?: boolean;
102+
/**
103+
* 是否允许 IP 地址作为域名部分
104+
* @default false
105+
*/
106+
allow_ip_domain?: boolean;
107+
/**
108+
* 是否启用特定域名的额外校验(如 GMail 规则)
109+
* @default false
110+
*/
111+
domain_specific_validation?: boolean;
112+
/**
113+
* 是否允许下划线
114+
* @default false
115+
*/
116+
allow_underscores?: boolean;
117+
/**
118+
* 域名黑名单
119+
*/
120+
host_blacklist?: Array<string | RegExp>;
121+
/**
122+
* 域名白名单
123+
*/
124+
host_whitelist?: Array<string | RegExp>;
125+
/**
126+
* 拒绝包含指定字符的邮箱名
127+
*/
128+
blacklisted_chars?: string;
82129
}
83130

131+
/**
132+
* URL 校验选项
133+
*/
84134
export interface IsURLOptions {
135+
/**
136+
* 允许的协议
137+
* @default ['http','https','ftp']
138+
*/
85139
protocols?: string[];
140+
/**
141+
* 是否要求顶级域名
142+
* @default true
143+
*/
86144
require_tld?: boolean;
145+
/**
146+
* 是否要求协议
147+
* @default false
148+
*/
87149
require_protocol?: boolean;
150+
/**
151+
* 是否要求主机名
152+
* @default true
153+
*/
88154
require_host?: boolean;
155+
/**
156+
* 是否要求端口
157+
* @default false
158+
*/
89159
require_port?: boolean;
160+
/**
161+
* 是否要求有效协议
162+
* @default true
163+
*/
90164
require_valid_protocol?: boolean;
165+
/**
166+
* 是否允许下划线
167+
* @default false
168+
*/
91169
allow_underscores?: boolean;
92-
host_whitelist?: (string | RegExp)[];
93-
host_blacklist?: (string | RegExp)[];
170+
/**
171+
* 主机名白名单
172+
*/
173+
host_whitelist?: Array<string | RegExp>;
174+
/**
175+
* 主机名黑名单
176+
*/
177+
host_blacklist?: Array<string | RegExp>;
178+
/**
179+
* 是否允许末尾的点
180+
* @default false
181+
*/
94182
allow_trailing_dot?: boolean;
183+
/**
184+
* 是否允许协议相对 URL
185+
* @default false
186+
*/
95187
allow_protocol_relative_urls?: boolean;
188+
/**
189+
* 是否禁止认证信息
190+
* @default false
191+
*/
96192
disallow_auth?: boolean;
193+
/**
194+
* 是否允许片段(hash)
195+
* @default true
196+
*/
197+
allow_fragments?: boolean;
198+
/**
199+
* 是否允许查询参数
200+
* @default true
201+
*/
202+
allow_query_components?: boolean;
203+
/**
204+
* 是否校验长度
205+
* @default true
206+
*/
97207
validate_length?: boolean;
208+
/**
209+
* 最大允许长度
210+
* @default 2084
211+
*/
212+
max_allowed_length?: number | false;
98213
}
99214

215+
100216
/**
101217
* 通用全局类型
102218
* */

packages/scripts/packages/products/tdesign-miniprogram/packages/uniapp-components/form-item/README.en-US.md renamed to packages/products/tdesign-miniprogram/packages/uniapp-components/form-item/README.en-US.md

File renamed without changes.

packages/scripts/packages/products/tdesign-miniprogram/packages/uniapp-components/form-item/README.md renamed to packages/products/tdesign-miniprogram/packages/uniapp-components/form-item/README.md

File renamed without changes.

packages/products/tdesign-miniprogram/packages/uniapp-components/form-item/props.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ export default {
3636
},
3737
/** 是否显示必填符号(*),优先级高于 Form.requiredMark */
3838
requiredMark: {
39-
type: Boolean,
40-
default: undefined,
39+
type: [Boolean, null],
40+
default: null as TdFormItemProps['requiredMark'],
4141
},
4242
/** 表单字段校验规则 */
4343
rules: {
4444
type: Array,
4545
},
4646
/** 校验不通过时,是否显示错误提示信息,优先级高于 `Form.showErrorMessage` */
4747
showErrorMessage: {
48-
type: Boolean,
49-
default: undefined,
48+
type: [Boolean, null],
49+
default: null as TdFormItemProps['showErrorMessage'],
5050
},
5151
};

packages/products/tdesign-miniprogram/packages/uniapp-components/form-item/type.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
55
* */
66

7+
import type { FormRule } from '../form/type';
8+
79
export interface TdFormItemProps {
810
/**
911
* 是否显示右侧箭头
@@ -35,13 +37,13 @@ export interface TdFormItemProps {
3537
/**
3638
* 是否显示必填符号(*),优先级高于 Form.requiredMark
3739
*/
38-
requiredMark?: boolean;
40+
requiredMark?: boolean | null;
3941
/**
4042
* 表单字段校验规则
4143
*/
4244
rules?: Array<FormRule>;
4345
/**
4446
* 校验不通过时,是否显示错误提示信息,优先级高于 `Form.showErrorMessage`
4547
*/
46-
showErrorMessage?: boolean;
48+
showErrorMessage?: boolean | null;
4749
}

packages/products/tdesign-miniprogram/packages/uniapp-components/form/README.en-US.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ reset | `(params?: FormResetParams<FormData>)` | \- | required。[see more ts de
3737
set-validate-message | `(message: FormValidateMessage<FormData>)` | \- | required。[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form/type.ts)。<br/>`type FormValidateMessage<FormData> = { [field in keyof FormData]: FormItemValidateMessage[] }`<br/><br/>`interface FormItemValidateMessage { type: 'warning' \| 'error'; message: string }`<br/>
3838
submit | `(params?: { showErrorMessage?: boolean })` | \- | required
3939
validate | `(params?: FormValidateParams)` | `Promise<FormValidateResult<FormData>> ` | required。[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form/type.ts)。<br/>`interface FormValidateParams { fields?: Array<string>; showErrorMessage?: boolean; trigger?: ValidateTriggerType }`<br/><br/>`type ValidateTriggerType = 'blur' \| 'change' \| 'submit' \| 'all'`<br/><br/>`type FormValidateResult<T> = boolean \| ValidateResultObj<T>`<br/><br/>`type ValidateResultObj<T> = { [key in keyof T]: boolean \| ValidateResultList }`<br/><br/>`type ValidateResultList = Array<AllValidateResult>`<br/><br/>`type AllValidateResult = CustomValidateObj \| ValidateResultType`<br/><br/>`interface ValidateResultType extends FormRule { result: boolean }`<br/>
40-
validate | `(params?: FormValidateParams)` | `Promise<FormValidateResult<FormData>>` | required。[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form/type.ts)。<br/>`interface FormValidateParams { fields?: Array<string>; showErrorMessage?: boolean; trigger?: ValidateTriggerType }`<br/><br/>`type ValidateTriggerType = 'blur' \| 'change' \| 'submit' \| 'all'`<br/>
4140

4241

4342
### FormItem Props
@@ -52,7 +51,7 @@ label-align | String | - | options: left/right/top | N
5251
label-width | String / Number | - | \- | N
5352
name | String | - | \- | N
5453
required-mark | Boolean | undefined | \- | N
55-
rules | Array | - | Typescript: `Array<FormRule>` | N
54+
rules | Array | - | Typescript: `Array<FormRule> `[Form API Documents](./form?tab=api)[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form-item/type.ts) | N
5655
show-error-message | Boolean | undefined | \- | N
5756

5857
### FormItem Slots
@@ -67,8 +66,8 @@ label | \-
6766
name | type | default | description | required
6867
-- | -- | -- | -- | --
6968
boolean | Boolean | - | \- | N
70-
date | Boolean / Object | - | Typescript: `boolean \| IsDateOptions` `interface IsDateOptions { format: string; strictMode: boolean; delimiters: string[] }`[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form-rule/type.ts) | N
71-
email | Boolean / Object | - | Typescript: `boolean \| IsEmailOptions` `import { IsEmailOptions } from 'validator/es/lib/isEmail'`[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form-rule/type.ts) | N
69+
date | Boolean / Object | - | Typescript: `boolean \| IsDateOptions` `interface IsDateOptions { format: string; strictMode: boolean; delimiters: string[] }`[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form/type.ts) | N
70+
email | Boolean / Object | - | Typescript: `boolean \| IsEmailOptions`[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form/type.ts) | N
7271
enum | Array | - | Typescript: `Array<string>` | N
7372
idcard | Boolean | - | \- | N
7473
len | Number / Boolean | - | \- | N
@@ -81,8 +80,8 @@ required | Boolean | - | \- | N
8180
telnumber | Boolean | - | \- | N
8281
trigger | String | change | Typescript: `ValidateTriggerType` | N
8382
type | String | error | options: error/warning | N
84-
url | Boolean / Object | - | Typescript: `boolean \| IsURLOptions` `import { IsURLOptions } from 'validator/es/lib/isURL'`[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form-rule/type.ts) | N
85-
validator | Function | - | Typescript: `CustomValidator` `type CustomValidator = (val: ValueType, context?: { formData: Data , name: string }) => CustomValidateResolveType \| Promise<CustomValidateResolveType>` `type CustomValidateResolveType = boolean \| CustomValidateObj` `interface CustomValidateObj { result: boolean; message: string; type?: 'error' \| 'warning' \| 'success' }` `type ValueType = any`[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form-rule/type.ts) | N
83+
url | Boolean / Object | - | Typescript: `boolean \| IsURLOptions`[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form/type.ts) | N
84+
validator | Function | - | Typescript: `CustomValidator` `type CustomValidator = (val: ValueType, context?: { formData: Data , name: string }) => CustomValidateResolveType \| Promise<CustomValidateResolveType>` `type CustomValidateResolveType = boolean \| CustomValidateObj` `interface CustomValidateObj { result: boolean; message: string; type?: 'error' \| 'warning' \| 'success' }` `type ValueType = any`[see more ts definition](https://github.com/tencent/tdesign-miniprogram/blob/develop/packages/uniapp-components/form/type.ts) | N
8685
whitespace | Boolean | - | \- | N
8786

8887
### FormErrorMessage

0 commit comments

Comments
 (0)