Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(form): 多端适配 #2595

Closed
wants to merge 14 commits into from
Closed
1 change: 1 addition & 0 deletions scripts/rn/copy-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const childAdaptedArray = [
'hoverbuttonitem',
'avatargroup',
'icon',
'formitem',
]

// copy文件并增加css引入
Expand Down
4 changes: 2 additions & 2 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
"author": "dsj"
},
{
"version": "2.0.0",
"version": "3.0.0",
"name": "Form",
"type": "component",
"cName": "表单",
Expand All @@ -503,7 +503,7 @@
"author": "hanyuxinting"
},
{
"version": "2.0.0",
"version": "3.0.0",
"name": "FormItem",
"type": "component",
"cName": "表单项",
Expand Down
32 changes: 24 additions & 8 deletions src/packages/form/demo.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import Taro from '@tarojs/taro'
import { ScrollView, View } from '@tarojs/components'
import { ScrollView, View, Text } from '@tarojs/components'
import { useTranslate } from '@/sites/assets/locale/taro'
import Header from '@/sites/components/header'
import Demo1 from './demos/taro/demo1'
Expand All @@ -10,6 +10,7 @@ import Demo4 from './demos/taro/demo4'
import Demo5 from './demos/taro/demo5'
import Demo6 from './demos/taro/demo6'
import Demo7 from './demos/taro/demo7'
import { harmonyAndRn } from '@/utils/platform-taro'

const FormDemo = () => {
const [translated] = useTranslate({
Expand Down Expand Up @@ -37,20 +38,35 @@ const FormDemo = () => {
<>
<Header />
<ScrollView className={`demo ${Taro.getEnv() === 'WEB' ? 'web' : ''}`}>
<View className="h2">{translated.basic}</View>
<View className="h2">
<Text>{translated.basic}</Text>
</View>
<Demo1 />
<View className="h2">{translated.title2}</View>
<Demo2 />
<View className="h2">{translated.relatedDisplay}</View>
<Demo3 />
{!harmonyAndRn() ? (
<>
<View className="h2">{translated.relatedDisplay}</View>
<Demo3 />
</>
) : null}
<View className="h2">{translated.title3}</View>
<Demo4 />
<View className="h2">{translated.title4}</View>
<Demo5 />
{!harmonyAndRn() ? (
<>
<View className="h2">{translated.title4}</View>
<Demo5 />
</>
) : null}

<View className="h2">{translated.validateTrigger}</View>
<Demo6 />
<View className="h2">{translated.title5}</View>
<Demo7 />
{!harmonyAndRn() ? (
<>
<View className="h2">{translated.title5}</View>
<Demo7 />
</>
) : null}
</ScrollView>
</>
)
Expand Down
23 changes: 7 additions & 16 deletions src/packages/form/demos/taro/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import React from 'react'
import {
Button,
Form,
Input,
InputNumber,
TextArea,
} from '@nutui/nutui-react-taro'
import { Button, Form, Input, TextArea } from '@nutui/nutui-react-taro'
import { FormItemRuleWithoutValidator } from '@/packages/formitem/types'

const Demo1 = () => {
Expand All @@ -27,7 +21,7 @@ const Demo1 = () => {
label="字段A"
name="username"
rules={[
{ max: 5, message: '字段A不能超过5个字' },
{ max: 7, message: '字段A不能超过5个字' },
oasis-cloud marked this conversation as resolved.
Show resolved Hide resolved
{ required: true, message: '请输入字段A' },
{
validator: (
Expand All @@ -53,14 +47,11 @@ const Demo1 = () => {
{ required: true, message: '请输入字段D' },
]}
>
<TextArea placeholder="请输入字段D" maxLength={100} />
</Form.Item>
<Form.Item
label="数量"
name="num"
getValueFromEvent={(...args) => args[0]}
>
<InputNumber />
<TextArea
placeholder="请输入字段D"
maxLength={100}
style={{ paddingTop: 0, paddingBottom: 0 }}
/>
</Form.Item>
</Form>
</>
Expand Down
9 changes: 6 additions & 3 deletions src/packages/form/demos/taro/demo2.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react'
import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import {
Form,
Button,
Input,
type FormItemRuleWithoutValidator,
} from '@nutui/nutui-react-taro'
import pxTransform from '@/utils/px-transform'

const Demo2 = () => {
const submitFailed = (error: any) => {
Expand Down Expand Up @@ -38,20 +40,21 @@ const Demo2 = () => {
onFinish={(values) => submitSucceed(values)}
onFinishFailed={(values, errors) => submitFailed(errors)}
footer={
<div
<View
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
width: '100%',
}}
>
<Button nativeType="submit" type="primary">
提交
</Button>
<Button nativeType="reset" style={{ marginLeft: '20px' }}>
<Button nativeType="reset" style={{ marginLeft: pxTransform(20) }}>
重置
</Button>
</div>
</View>
}
>
<Form.Item
Expand Down
4 changes: 3 additions & 1 deletion src/packages/form/demos/taro/demo4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type FormItemRuleWithoutValidator,
} from '@nutui/nutui-react-taro'
import { View } from '@tarojs/components'
import pxTransform from '@/utils/px-transform'

const Demo4 = () => {
const submitFailed = (error: any) => {
Expand Down Expand Up @@ -41,13 +42,14 @@ const Demo4 = () => {
style={{
display: 'flex',
justifyContent: 'center',
flexDirection: 'row',
width: '100%',
}}
>
<Button nativeType="submit" type="primary">
提交
</Button>
<Button nativeType="reset" style={{ marginLeft: '20px' }}>
<Button nativeType="reset" style={{ marginLeft: pxTransform(20) }}>
重置
</Button>
</View>
Expand Down
3 changes: 2 additions & 1 deletion src/packages/form/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ Form.useForm() creates a Form instance, which is used to manage all data states.
| --- | --- | --- |
| getFieldValue | Get the value of the corresponding field name | `(name: NamePath) => any` |
| getFieldsValue | Get values by a set of field names. Return according to the corresponding structure. Default return mounted field value, but you can use getFieldsValue(true) to get all values | `(name: NamePath \| boolean) => any` |
| setFieldsValue | set field values | `(values) => void` |
| setFieldsValue | Set the value of the form (the value will be passed directly to the form store. If you do not want the object passed in to be modified, please copy it and pass it in) | `(values) => void` |
| setFieldValue | Set the value of the corresponding field name | `<T>(name: NamePath, value: T) => void` |
| resetFields | Reset form prompt state | `() => void` |
| submit | method to submit a form for validation | `Promise` |

Expand Down
3 changes: 2 additions & 1 deletion src/packages/form/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ Form.useForm()创建 Form 实例,用于管理所有数据状态。
| --- | --- | --- |
| getFieldValue | 获取对应字段名的值 | `(name: NamePath) => any` |
| getFieldsValue | 获取一组字段名对应的值,会按照对应结构返回。默认返回现存字段值,当调用 getFieldsValue(true) 时返回所有值 | `(name: NamePath \| boolean) => any` |
| setFieldsValue | 设置表单的值 | `(values) => void` |
| setFieldsValue | 设置表单的值(该值将直接传入 form store 中。如果你不希望传入对象被修改,请克隆后传入) | `(values) => void` |
| setFieldValue | 设置对应字段名的值 | `<T>(name: NamePath, value: T) => void` |
| resetFields | 重置表单提示状态 | `() => void` |
| submit | 提交表单进行校验的方法 | `Promise` |

Expand Down
3 changes: 2 additions & 1 deletion src/packages/form/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ Form.useForm()创建 Form 实例,用于管理所有数据状态。
| --- | --- | --- |
| getFieldValue | 获取对应字段名的值 | `(name: NamePath) => any` |
| getFieldsValue | 获取一组字段名对应的值,会按照对应结构返回。默认返回现存字段值,当调用 getFieldsValue(true) 时返回所有值 | `(name: NamePath \| boolean) => any` |
| setFieldsValue | 设置表单的值 | `(values) => void` |
| setFieldsValue | 设置表单的值(该值将直接传入 form store 中。如果你不希望传入对象被修改,请克隆后传入) | `(values) => void` |
| setFieldValue | 设置对应字段名的值 | `<T>(name: NamePath, value: T) => void` |
| resetFields | 重置表单提示状态 | `() => void` |
| submit | 提交表单进行校验的方法 | `Promise` |

Expand Down
3 changes: 2 additions & 1 deletion src/packages/form/doc.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ Form.useForm()創建 Form 實例,用於管理所有數據狀態。
| --- | --- | --- |
| getFieldValue | 獲取對應字段名的值 | `(name: NamePath) => any` |
| getFieldsValue | 获取一组字段名对应的值,会按照对应结构返回。默认返回现存字段值,当调用 getFieldsValue(true) 时返回所有值 | `(name: NamePath \| boolean) => any` |
| setFieldsValue | 設置錶單的值 | `(values) => void` |
| setFieldsValue | 設定表單的值(該值將直接傳入 form store 中。如果你不希望傳入物件被修改,請複製後傳入) | `(values) => void` |
| setFieldValue | 設定對應欄位名的值 | `<T>(name: NamePath, value: T) => void` |
| resetFields | 重置錶單提示狀態 | `() => void` |
| submit | 提交錶單進行校驗的方法 | `Promise` |

Expand Down
Loading
Loading