UNPKG

4.59 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3interface FormProps extends StandardProps {
4 /** 是否返回 `formId` 用于发送模板消息。
5 * @default false
6 * @supported weapp, alipay, swan, qq, jd, h5, harmony_hybrid
7 */
8 reportSubmit?: boolean
9 /** 等待一段时间(毫秒数)以确认 `formId` 是否生效。
10 * 如果未指定这个参数,`formId` 有很小的概率是无效的(如遇到网络失败的情况)。
11 * 指定这个参数将可以检测 `formId` 是否有效,
12 * 以这个参数的时间作为这项检测的超时时间。
13 * 如果失败,将返回 `requestFormId:fail` 开头的 `formId`。
14 * @default 0
15 * @supported weapp
16 */
17 reportSubmitTimeout?: number
18 /** 模板消息的类型,report-submit 为 true 时填写有效
19 * 取值:default / subscribe
20 * @default 'default'
21 * @supported swan
22 */
23 reportType?: string
24 /** 发送订阅类模板消息所用的模板库标题 ID ,可通过 getTemplateLibraryList 获取
25 * 当参数类型为 Array 时,可传递 1~3 个模板库标题 ID (注:此处填写模板库id。示例:BD0001)
26 * @supported swan
27 */
28 templateId?: string | Array<string>
29 /** 发送订阅类模板消息时所使用的唯一标识符,内容由开发者自定义,用来标识订阅场景
30 * 注意:同一用户在同一 subscribe-id 下的多次授权不累积下发权限,只能下发一条。若要订阅多条,需要不同 subscribe-id
31 * @supported swan
32 */
33 subscribeId?: string
34 /** 用于分发目的。取值:0 或 1,其中 0 表示默认,1 表示留资目标,需要和留资分发配置一起使用,详情见留资分发配置
35 * @supported tt
36 * @default 0
37 */
38 conversionTarget?: number
39 /** 用于分发目的。开发者在【小程序开发者后台 -> 进入目标小程序 -> 运营 -> 流量配置 -> 抖音 -> 留资分发配置】复制创建的配置 ID,需要和留资分发配置一起使用,详情见留资分发配置
40 *
41 * @supported tt
42 * @default ""
43 */
44 clueComponentId?: string
45 /** 携带 form 中的数据触发 submit 事件
46 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
47 */
48 onSubmit?: CommonEventFunction<FormProps.onSubmitEventDetail>
49 /** 表单重置时会触发 reset 事件
50 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony_hybrid
51 */
52 onReset?: CommonEventFunction
53}
54declare namespace FormProps {
55 interface onSubmitEventDetail {
56 /** 当点击 `<form>` 表单中 `form-type` 为 `submit` 的 `<button>` 组件时,
57 * 会将表单组件中的 `value` 值进行提交,
58 * 需要在表单组件中加上 `name` 来作为 `key`。
59 */
60 value?: {
61 [formItemName: string]: any
62 }
63 /** 当 `reportSubmit` 为 `true` 时,返回 `formId` 用于发送模板消息。
64 */
65 formId?: string
66 }
67}
68/** 表单。将组件内的用户输入的 switch input checkbox slider radio picker 提交。
69 *
70 * 当点击 form 表单中 form-type 为 submit 的 button 组件时,会将表单组件中的 value 值进行提交,需要在表单组件中加上 name 来作为 key。
71 * @classification forms
72 * @supported weapp, alipay, swan, tt, qq, jd, h5, rn, harmony, harmony_hybrid
73 * @example_react
74 * ```tsx
75 * class App extends Component {
76 *
77 * formSubmit = e => {
78 * console.log(e)
79 * }
80 *
81 * formReset = e => {
82 * console.log(e)
83 * }
84 *
85 * render () {
86 * return (
87 * <Form onSubmit={this.formSubmit} onReset={this.formReset} >
88 * <View className='example-body'>
89 * <Switch name='switch' className='form-switch'></Switch>
90 * </View>
91 * </Form>
92 * )
93 * }
94 * }
95 * ```
96 * @example_vue
97 * ```html
98 * <template>
99 * <form `@submit="formSubmit" `@reset="formReset" >
100 * <view class="taro-example-body">
101 * <switch name="switch" class="form-switch"></Switch>
102 * </view>
103 * <view class="taro-example-btns">
104 * <button form-type="submit">Submit</button>
105 * <button type="default" form-type="reset">Reset</button>
106 * </view>
107 * </form>
108 * </template>
109 *
110 * <script>
111 * export default {
112 * data() {
113 * return {}
114 * },
115 * methods: {
116 * formSubmit (e) {
117 * console.log(e)
118 * },
119 *
120 * formReset (e) {
121 * console.log(e)
122 * }
123 * }
124 * }
125 * </script>
126 * ```
127 * @see https://developers.weixin.qq.com/miniprogram/dev/component/form.html
128 */
129declare const Form: ComponentType<FormProps>
130export { Form, FormProps }