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
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/nutui-taro-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@tarojs/shared": "4.0.2",
"@tarojs/taro": "4.0.2",
"@tarojs/taro-h5": "4.0.2",
"async-validator": "^4.2.5",
"babel-plugin-import": "^1.13.8",
"lodash.isequal": "^4.5.0",
"lodash.kebabcase": "^4.1.1",
Expand Down Expand Up @@ -111,6 +112,6 @@
},
"resolutions": {
"react-native-webview": "13.6.3",
"sass":"1.77.6"
"sass": "1.77.6"
}
}
36 changes: 33 additions & 3 deletions packages/nutui-taro-demo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4656,6 +4656,11 @@ async-limiter@~1.0.0:
resolved "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==

async-validator@^4.2.5:
version "4.2.5"
resolved "https://registry.yarnpkg.com/async-validator/-/async-validator-4.2.5.tgz#c96ea3332a521699d0afaaceed510a54656c6339"
integrity sha512-7HhHjtERjqlNbZtqNqy2rckN/SpOOlmDliet+lP7k+eKZEjPk3DgyeU9lIXLdeLz0uBbbVp+9Qdow9wJWgwwfg==

async@^3.2.2, async@^3.2.4:
version "3.2.5"
resolved "https://registry.npmjs.org/async/-/async-3.2.5.tgz#ebd52a8fdaf7a2289a24df399f8d8485c8a46b66"
Expand Down Expand Up @@ -13249,7 +13254,16 @@ string-hash@^1.1.1:
resolved "https://registry.npmjs.org/string-hash/-/string-hash-1.1.3.tgz#e8aafc0ac1855b4666929ed7dd1275df5d6c811b"
integrity sha512-kJUvRUFK49aub+a7T1nNE66EJbZBMnBgoC1UbCZ5n6bsZKBRga4KgBRTMn/pFkeCZSYtNeSyMxPDM0AXWELk2A==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -13340,7 +13354,7 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand All @@ -13354,6 +13368,13 @@ strip-ansi@^5.0.0, strip-ansi@^5.2.0:
dependencies:
ansi-regex "^4.1.0"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1, strip-ansi@^7.1.0:
version "7.1.0"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
Expand Down Expand Up @@ -14531,7 +14552,7 @@ word-wrap@^1.2.5:
resolved "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -14549,6 +14570,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down
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
Loading