UNPKG

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