@rainte/ant 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.editorconfig +9 -0
  2. package/.fatherrc.ts +15 -0
  3. package/.gitattributes +1 -0
  4. package/.prettierignore +7 -0
  5. package/.prettierrc +13 -0
  6. package/.umirc.ts +24 -0
  7. package/LICENSE +21 -0
  8. package/README.md +27 -0
  9. package/docs/index.md +9 -0
  10. package/es/components/Editor/index.d.ts +8 -0
  11. package/es/components/Editor/index.js +35 -0
  12. package/es/components/Editor/props.d.ts +13 -0
  13. package/es/components/Editor/props.js +12 -0
  14. package/es/components/Form/index.d.ts +8 -0
  15. package/es/components/Form/index.js +53 -0
  16. package/es/components/Image/index.d.ts +5 -0
  17. package/es/components/Image/index.js +14 -0
  18. package/es/components/Table/index.d.ts +9 -0
  19. package/es/components/Table/index.js +35 -0
  20. package/es/components/Tabs/index.d.ts +9 -0
  21. package/es/components/Tabs/index.js +22 -0
  22. package/es/components/ValueType/components/Cascader.d.ts +3 -0
  23. package/es/components/ValueType/components/Cascader.js +89 -0
  24. package/es/components/ValueType/components/Editor.d.ts +3 -0
  25. package/es/components/ValueType/components/Editor.js +18 -0
  26. package/es/components/ValueType/components/TreeSelect.d.ts +3 -0
  27. package/es/components/ValueType/components/TreeSelect.js +87 -0
  28. package/es/components/ValueType/components/Upload.d.ts +4 -0
  29. package/es/components/ValueType/components/Upload.js +73 -0
  30. package/es/components/ValueType/index.d.ts +15 -0
  31. package/es/components/ValueType/index.js +10 -0
  32. package/es/index.d.ts +11 -0
  33. package/es/index.js +6 -0
  34. package/es/utils/Swr.d.ts +1 -0
  35. package/es/utils/Swr.js +58 -0
  36. package/es/utils/Tree.d.ts +2 -0
  37. package/es/utils/Tree.js +65 -0
  38. package/lib/components/Editor/index.d.ts +8 -0
  39. package/lib/components/Editor/index.js +43 -0
  40. package/lib/components/Editor/props.d.ts +13 -0
  41. package/lib/components/Editor/props.js +19 -0
  42. package/lib/components/Form/index.d.ts +8 -0
  43. package/lib/components/Form/index.js +64 -0
  44. package/lib/components/Image/index.d.ts +5 -0
  45. package/lib/components/Image/index.js +22 -0
  46. package/lib/components/Table/index.d.ts +9 -0
  47. package/lib/components/Table/index.js +46 -0
  48. package/lib/components/Tabs/index.d.ts +9 -0
  49. package/lib/components/Tabs/index.js +30 -0
  50. package/lib/components/ValueType/components/Cascader.d.ts +3 -0
  51. package/lib/components/ValueType/components/Cascader.js +97 -0
  52. package/lib/components/ValueType/components/Editor.d.ts +3 -0
  53. package/lib/components/ValueType/components/Editor.js +26 -0
  54. package/lib/components/ValueType/components/TreeSelect.d.ts +3 -0
  55. package/lib/components/ValueType/components/TreeSelect.js +95 -0
  56. package/lib/components/ValueType/components/Upload.d.ts +4 -0
  57. package/lib/components/ValueType/components/Upload.js +82 -0
  58. package/lib/components/ValueType/index.d.ts +15 -0
  59. package/lib/components/ValueType/index.js +18 -0
  60. package/lib/index.d.ts +11 -0
  61. package/lib/index.js +41 -0
  62. package/lib/utils/Swr.d.ts +1 -0
  63. package/lib/utils/Swr.js +66 -0
  64. package/lib/utils/Tree.d.ts +2 -0
  65. package/lib/utils/Tree.js +73 -0
  66. package/package.json +52 -0
  67. package/src/components/Editor/index.md +8 -0
  68. package/src/components/Editor/index.tsx +20 -0
  69. package/src/components/Editor/props.ts +50 -0
  70. package/src/components/Form/index.md +132 -0
  71. package/src/components/Form/index.tsx +48 -0
  72. package/src/components/Image/index.md +8 -0
  73. package/src/components/Image/index.tsx +16 -0
  74. package/src/components/Table/index.md +80 -0
  75. package/src/components/Table/index.tsx +45 -0
  76. package/src/components/Tabs/index.md +24 -0
  77. package/src/components/Tabs/index.tsx +21 -0
  78. package/src/components/ValueType/components/Cascader.tsx +79 -0
  79. package/src/components/ValueType/components/Editor.tsx +18 -0
  80. package/src/components/ValueType/components/TreeSelect.tsx +74 -0
  81. package/src/components/ValueType/components/Upload.tsx +74 -0
  82. package/src/components/ValueType/index.ts +33 -0
  83. package/src/index.ts +12 -0
  84. package/src/utils/Swr.ts +29 -0
  85. package/src/utils/Tree.ts +51 -0
  86. package/tsconfig.json +31 -0
  87. package/typings.d.ts +4 -0
@@ -0,0 +1,20 @@
1
+ import 'braft-editor/dist/index.css'
2
+ import 'braft-extensions/dist/table.css'
3
+ import BraftEditor, { BraftEditorProps } from 'braft-editor'
4
+ import Table from 'braft-extensions/dist/table'
5
+ import Props from './props'
6
+
7
+ export type EditorProps = BraftEditorProps
8
+
9
+ class Editor extends BraftEditor {
10
+ static defaultProps: any
11
+ }
12
+
13
+ Editor.use(Table({ withDropdown: true, columnResizable: true }))
14
+
15
+ export default Editor
16
+
17
+ Editor.defaultProps = {
18
+ ...(BraftEditor as any).defaultProps,
19
+ ...Props,
20
+ }
@@ -0,0 +1,50 @@
1
+ export default {
2
+ controls: [
3
+ 'undo',
4
+ 'redo',
5
+ 'separator',
6
+ 'headings',
7
+ 'separator',
8
+ 'font-family',
9
+ 'font-size',
10
+ 'line-height',
11
+ 'letter-spacing',
12
+ 'separator',
13
+ 'text-indent',
14
+ 'text-align',
15
+ 'separator',
16
+ 'text-color',
17
+ 'bold',
18
+ 'italic',
19
+ 'underline',
20
+ 'strike-through',
21
+ 'separator',
22
+ 'superscript',
23
+ 'subscript',
24
+ 'remove-styles',
25
+ 'emoji',
26
+ 'hr',
27
+ 'separator',
28
+ 'list-ul',
29
+ 'list-ol',
30
+ 'blockquote',
31
+ 'code',
32
+ 'separator',
33
+ 'link',
34
+ 'separator',
35
+ 'media',
36
+ 'table',
37
+ 'clear',
38
+ 'fullscreen',
39
+ 'separator',
40
+ ],
41
+ controlBarStyle: {
42
+ border: '1px solid #d9d9d9',
43
+ borderBottom: '0',
44
+ },
45
+ contentStyle: {
46
+ height: 300,
47
+ border: '1px solid #d9d9d9',
48
+ borderTop: '0',
49
+ },
50
+ }
@@ -0,0 +1,132 @@
1
+ ## Form
2
+
3
+ ```tsx
4
+ import React, { useState } from 'react'
5
+ import { Editor, Form } from '@rainte/ant'
6
+ import { files } from '../ValueType/components/Upload'
7
+
8
+ export default () => {
9
+ const [readonly, setReadonly] = useState<boolean>(false)
10
+
11
+ const cascader = [
12
+ {
13
+ value: 'zhejiang',
14
+ label: '浙江',
15
+ children: [
16
+ {
17
+ value: 'hangzhou',
18
+ label: '杭州',
19
+ children: [
20
+ {
21
+ value: 'xihu',
22
+ label: '西湖',
23
+ },
24
+ ],
25
+ },
26
+ ],
27
+ },
28
+ {
29
+ value: 'jiangsu',
30
+ label: '江苏',
31
+ children: [
32
+ {
33
+ value: 'nanjing',
34
+ label: '南京',
35
+ children: [
36
+ {
37
+ value: 'zhonghuamen',
38
+ label: '中华门',
39
+ },
40
+ ],
41
+ },
42
+ ],
43
+ },
44
+ ]
45
+
46
+ const treeSelect = [
47
+ {
48
+ title: 'Node1',
49
+ value: '0-0',
50
+ children: [
51
+ {
52
+ title: 'Child Node1',
53
+ value: '0-0-1',
54
+ },
55
+ {
56
+ title: 'Child Node2',
57
+ value: '0-0-2',
58
+ },
59
+ ],
60
+ },
61
+ {
62
+ title: 'Node2',
63
+ value: '0-1',
64
+ },
65
+ ]
66
+
67
+ const props = {
68
+ request: () => {
69
+ return {
70
+ readonly: false,
71
+ cascader: null,
72
+ treeSelect: null,
73
+ upload: null,
74
+ editor: null,
75
+ }
76
+ },
77
+ columns: [
78
+ {
79
+ title: '只读',
80
+ dataIndex: 'readonly',
81
+ valueType: 'radio',
82
+ valueEnum: new Map([
83
+ [false, { text: '编辑', status: 'Success' }],
84
+ [true, { text: '只读', status: 'Error' }],
85
+ ]),
86
+ fieldProps: { onChange: (e: any) => setReadonly(e.target.value) },
87
+ },
88
+ {
89
+ readonly,
90
+ title: '级联选择',
91
+ dataIndex: 'cascader',
92
+ valueType: 'cascader',
93
+ request: async (params: any) => cascader,
94
+ },
95
+ {
96
+ readonly,
97
+ title: '树选择',
98
+ dataIndex: 'treeSelect',
99
+ valueType: 'treeSelect',
100
+ request: async (params: any) => treeSelect,
101
+ },
102
+ {
103
+ readonly,
104
+ title: '上传',
105
+ dataIndex: 'upload',
106
+ valueType: 'upload',
107
+ formItemProps: { getValueFromEvent: files },
108
+ fieldProps: {
109
+ customRequest: ({ file, onSuccess }: any) => {
110
+ console.log('upload.customRequest', file)
111
+ file.url = URL.createObjectURL(file)
112
+ file.status = 'done'
113
+ onSuccess?.(file.url, file)
114
+ },
115
+ },
116
+ },
117
+ {
118
+ readonly,
119
+ title: '编辑器',
120
+ dataIndex: 'editor',
121
+ valueType: 'editor',
122
+ formItemProps: { wrapperCol: { span: 16 } },
123
+ },
124
+ ],
125
+ onFinish: (values: any) => {
126
+ console.log('onFinish', values)
127
+ },
128
+ }
129
+
130
+ return <Form {...props} />
131
+ }
132
+ ```
@@ -0,0 +1,48 @@
1
+ import React, { Context, useContext } from 'react'
2
+ import { Form as AntForm, Space } from 'antd'
3
+ import ProForm, { BetaSchemaForm } from '@ant-design/pro-form'
4
+ import AntContext from '@ant-design/pro-provider'
5
+ import { FormSchema } from '@ant-design/pro-form/es/components/SchemaForm'
6
+ import ValueTypeMap, { ValueTypeEnum } from '../ValueType'
7
+
8
+ export type FormProps<
9
+ T = Record<string, any>,
10
+ ValueType = ValueTypeEnum,
11
+ > = FormSchema<T, ValueType> & { context: Context<any> }
12
+
13
+ const Form: React.FC<FormProps<any, any>> = props => {
14
+ const { context, ...attrs } = props
15
+ const values = useContext(context)
16
+ const valueTypeMap = ValueTypeMap
17
+
18
+ return (
19
+ <context.Provider value={{ ...values, valueTypeMap }}>
20
+ <BetaSchemaForm {...attrs} />
21
+ </context.Provider>
22
+ )
23
+ }
24
+
25
+ export default Form
26
+
27
+ Form.defaultProps = {
28
+ context: AntContext,
29
+ layout: 'horizontal',
30
+ labelCol: { span: 4 },
31
+ wrapperCol: { span: 8 },
32
+ submitter: {
33
+ searchConfig: {
34
+ resetText: '返回',
35
+ submitText: '保存',
36
+ },
37
+ onReset: () => history.go(-1),
38
+ render: (_: any, dom: JSX.Element[]) => {
39
+ return (
40
+ <AntForm.Item wrapperCol={{ offset: 4, span: 8 }}>
41
+ <ProForm.Group>
42
+ <Space>{dom}</Space>
43
+ </ProForm.Group>
44
+ </AntForm.Item>
45
+ )
46
+ },
47
+ },
48
+ }
@@ -0,0 +1,8 @@
1
+ ## Image
2
+
3
+ ```tsx
4
+ import React from 'react'
5
+ import { Image } from '@rainte/ant'
6
+
7
+ export default () => <Image />
8
+ ```
@@ -0,0 +1,16 @@
1
+ import React from 'react'
2
+ import { Image as AntImage, ImageProps } from 'antd'
3
+
4
+ export type { ImageProps } from 'antd'
5
+
6
+ const Image: React.FC<ImageProps> = props => {
7
+ return <AntImage {...props} />
8
+ }
9
+
10
+ export default Image
11
+
12
+ Image.defaultProps = {
13
+ src: '',
14
+ fallback:
15
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAADDCAYAAADQvc6UAAABRWlDQ1BJQ0MgUHJvZmlsZQAAKJFjYGASSSwoyGFhYGDIzSspCnJ3UoiIjFJgf8LAwSDCIMogwMCcmFxc4BgQ4ANUwgCjUcG3awyMIPqyLsis7PPOq3QdDFcvjV3jOD1boQVTPQrgSkktTgbSf4A4LbmgqISBgTEFyFYuLykAsTuAbJEioKOA7DkgdjqEvQHEToKwj4DVhAQ5A9k3gGyB5IxEoBmML4BsnSQk8XQkNtReEOBxcfXxUQg1Mjc0dyHgXNJBSWpFCYh2zi+oLMpMzyhRcASGUqqCZ16yno6CkYGRAQMDKMwhqj/fAIcloxgHQqxAjIHBEugw5sUIsSQpBobtQPdLciLEVJYzMPBHMDBsayhILEqEO4DxG0txmrERhM29nYGBddr//5/DGRjYNRkY/l7////39v///y4Dmn+LgeHANwDrkl1AuO+pmgAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAwqADAAQAAAABAAAAwwAAAAD9b/HnAAAHlklEQVR4Ae3dP3PTWBSGcbGzM6GCKqlIBRV0dHRJFarQ0eUT8LH4BnRU0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KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiECRCjUbEPNCRAhZ6NSiAARCjXbUHMCRMjZqBQiQIRCzTbUnAARcjYqhQgQoVCzDTUnQIScjUohAkQo1GxDzQkQIWejUogAEQo121BzAkTI2agUIkCEQs021JwAEXI2KoUIEKFQsw01J0CEnI1KIQJEKNRsQ80JECFno1KIABEKNdtQcwJEyNmoFCJAhELNNtScABFyNiqFCBChULMNNSdAhJyNSiEC/wGgKKC4YMA4TAAAAABJRU5ErkJggg==',
16
+ }
@@ -0,0 +1,80 @@
1
+ ## Table
2
+
3
+ ```tsx
4
+ import React from 'react'
5
+ import { Table } from '@rainte/ant'
6
+
7
+ const treeData = [
8
+ {
9
+ title: 'Node1',
10
+ value: '0-0',
11
+ children: [
12
+ {
13
+ title: 'Child Node1',
14
+ value: '0-0-1',
15
+ },
16
+ {
17
+ title: 'Child Node2',
18
+ value: '0-0-2',
19
+ },
20
+ ],
21
+ },
22
+ {
23
+ title: 'Node2',
24
+ value: '0-1',
25
+ },
26
+ ]
27
+
28
+ const props = {
29
+ columns: [
30
+ {
31
+ title: '序号',
32
+ valueType: 'index',
33
+ },
34
+ {
35
+ title: '搜索',
36
+ dataIndex: 'search',
37
+ hideInTable: true,
38
+ },
39
+ {
40
+ title: '名称',
41
+ dataIndex: 'name',
42
+ hideInSearch: true,
43
+ },
44
+ {
45
+ title: '树选择',
46
+ dataIndex: 'treeSelect',
47
+ valueType: 'treeSelect',
48
+ fieldProps: { treeData },
49
+ },
50
+ {
51
+ title: '排序',
52
+ dataIndex: 'sort',
53
+ hideInSearch: true,
54
+ },
55
+ {
56
+ title: '状态',
57
+ dataIndex: 'status',
58
+ valueEnum: new Map([
59
+ [1, { text: '显示', status: 'Success' }],
60
+ [0, { text: '隐藏', status: 'Error' }],
61
+ ]),
62
+ },
63
+ {
64
+ title: '创建时间',
65
+ dataIndex: 'created_at',
66
+ valueType: 'dateTime',
67
+ sorter: true,
68
+ hideInSearch: true,
69
+ },
70
+ {
71
+ title: '操作',
72
+ dataIndex: 'option',
73
+ valueType: 'option',
74
+ render: (_: any, row: any) => <a>查看</a>,
75
+ },
76
+ ],
77
+ }
78
+
79
+ export default () => <Table {...props} />
80
+ ```
@@ -0,0 +1,45 @@
1
+ import React, { Context, useContext } from 'react'
2
+ import ProTable, { ProTableProps } from '@ant-design/pro-table'
3
+ import AntContext from '@ant-design/pro-provider'
4
+ import { FooterToolbar } from '@ant-design/pro-layout'
5
+ import ValueTypeMap, { ValueTypeEnum } from '../ValueType'
6
+
7
+ export type TableProps<
8
+ T = any,
9
+ U = Record<string, any>,
10
+ ValueType = ValueTypeEnum,
11
+ > = ProTableProps<T, U, ValueType> & {
12
+ context: Context<any>
13
+ selection?: any[]
14
+ }
15
+
16
+ const Table: React.FC<TableProps<any, any>> = props => {
17
+ const { context, selection, ...attrs } = props
18
+ const values = useContext(context)
19
+ const valueTypeMap = ValueTypeMap
20
+
21
+ return (
22
+ <context.Provider value={{ ...values, valueTypeMap }}>
23
+ <ProTable {...attrs} />
24
+ {selection && selection.length > 0 && (
25
+ <FooterToolbar
26
+ extra={
27
+ <div>
28
+ 已选择 <a>{selection.length}</a> 项
29
+ </div>
30
+ }
31
+ >
32
+ {React.Children.map(props.children, item => item)}
33
+ </FooterToolbar>
34
+ )}
35
+ </context.Provider>
36
+ )
37
+ }
38
+
39
+ export default Table
40
+
41
+ Table.defaultProps = {
42
+ context: AntContext,
43
+ rowKey: 'id',
44
+ search: { labelWidth: 120 },
45
+ }
@@ -0,0 +1,24 @@
1
+ ## Tabs
2
+
3
+ ```tsx
4
+ import React from 'react'
5
+ import { Tabs } from '@rainte/ant'
6
+
7
+ const props = {
8
+ accessKey: 'base',
9
+ items: [
10
+ {
11
+ tab: '基本设置',
12
+ key: 'base',
13
+ children: <div>基本设置</div>,
14
+ },
15
+ {
16
+ tab: '安全设置',
17
+ key: 'security',
18
+ children: <div>安全设置</div>,
19
+ },
20
+ ],
21
+ }
22
+
23
+ export default () => <Tabs {...props} />
24
+ ```
@@ -0,0 +1,21 @@
1
+ import React from 'react'
2
+ import { Tabs as AntTabs, TabsProps as AntTabsProps, TabPaneProps } from 'antd'
3
+
4
+ export type TabsProps = AntTabsProps & {
5
+ items: (TabPaneProps & { key: any })[]
6
+ }
7
+
8
+ const Tabs: React.FC<TabsProps> = props => {
9
+ const { items, ...attrs } = props
10
+
11
+ const panes = items.map(item => <AntTabs.TabPane {...item} />)
12
+
13
+ return <AntTabs {...attrs}>{panes}</AntTabs>
14
+ }
15
+
16
+ export default Tabs
17
+
18
+ Tabs.defaultProps = {
19
+ type: 'card',
20
+ tabPosition: 'top',
21
+ }
@@ -0,0 +1,79 @@
1
+ import React from 'react'
2
+ import {
3
+ Space,
4
+ Cascader as AntCascader,
5
+ CascaderProps as AntCascaderProps,
6
+ } from 'antd'
7
+ import { RenderProps, FieldProps, RequestProps } from '../index'
8
+ import { fetch } from '../../../utils/Swr'
9
+ import { equal, intact } from '../../../utils/Tree'
10
+
11
+ type CascaderProps<T = any> = AntCascaderProps<T> & RequestProps
12
+ type TextProps = CascaderProps & { iValue: any; iDom: any }
13
+
14
+ const entire = (value: any, options: any[]) => {
15
+ if (Array.isArray(value)) {
16
+ if (value.length === 1) {
17
+ return intact(options, { value: value[0] }, 'value')
18
+ }
19
+
20
+ return value
21
+ }
22
+
23
+ return []
24
+ }
25
+
26
+ const combine = (text: any[], options: any[], dom: any) => {
27
+ return text
28
+ .map((item: any) => {
29
+ const node = equal(options, { value: item })
30
+ return node ? node.label : text ? text : dom
31
+ })
32
+ .join(' / ')
33
+ }
34
+
35
+ const Cascader: React.FC<CascaderProps> = props => {
36
+ const { iParams, iRequest, ...attrs } = props
37
+
38
+ const data = fetch(iRequest, iParams, attrs)
39
+
40
+ const options = (iRequest ? data : attrs.options) ?? []
41
+ const values = entire(attrs.value, options) ?? []
42
+
43
+ return <AntCascader {...attrs} options={options} value={values} />
44
+ }
45
+
46
+ const Text: React.FC<TextProps> = props => {
47
+ const { iValue, iDom, iParams, iRequest, ...attrs } = props
48
+
49
+ const data = fetch(iRequest, iParams, attrs)
50
+
51
+ const options = (iRequest ? data : attrs.options) ?? []
52
+ const values = entire(iValue, options) ?? []
53
+
54
+ const dom = values.length ? combine(values, options, iDom) : iDom
55
+
56
+ return <Space>{dom}</Space>
57
+ }
58
+
59
+ const Render: RenderProps = {
60
+ name: 'cascader',
61
+ render: (text, props: FieldProps, dom) => {
62
+ const { params, request, fieldProps } = props
63
+ const iParams = params
64
+ const iRequest = request
65
+ const attrs = { iValue: text, iDom: dom, iParams, iRequest }
66
+
67
+ return <Text {...fieldProps} {...attrs} />
68
+ },
69
+ renderFormItem: (_, props: FieldProps) => {
70
+ const { params, request, fieldProps } = props
71
+ const iParams = params
72
+ const iRequest = request
73
+ const attrs = { iParams, iRequest }
74
+
75
+ return <Cascader {...fieldProps} {...attrs} />
76
+ },
77
+ }
78
+
79
+ export default Render
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+ import Editor from '../../Editor'
3
+ import { RenderProps, FieldProps } from '../index'
4
+
5
+ const Render: RenderProps = {
6
+ name: 'editor',
7
+ render: (text, props, dom) => {
8
+ if (text instanceof Object) {
9
+ return <>{text.toHTML()}</>
10
+ }
11
+ return dom
12
+ },
13
+ renderFormItem: (_, props: FieldProps) => {
14
+ return <Editor {...props.fieldProps} />
15
+ },
16
+ }
17
+
18
+ export default Render
@@ -0,0 +1,74 @@
1
+ import React from 'react'
2
+ import {
3
+ Tag,
4
+ TreeSelect as AntTreeSelect,
5
+ TreeSelectProps as AntTreeSelectProps,
6
+ Space,
7
+ } from 'antd'
8
+ import { RenderProps, FieldProps, RequestProps } from '../index'
9
+ import { fetch } from '../../../utils/Swr'
10
+ import { equal } from '../../../utils/Tree'
11
+
12
+ type TreeSelectProps<T = any> = AntTreeSelectProps<T> & RequestProps
13
+ type TextProps<T = any> = TreeSelectProps<T> & { iValue: any; iDom: any }
14
+
15
+ const combine = (text: any[], options: any[], dom: any) => {
16
+ return text.map((item: any) => {
17
+ const node = equal(options, { value: item })
18
+
19
+ return <Tag>{node ? node.title : text ? text : dom}</Tag>
20
+ })
21
+ }
22
+
23
+ const TreeSelect: React.FC<TreeSelectProps> = props => {
24
+ const { iParams, iRequest, ...attrs } = props
25
+
26
+ const data = fetch(iRequest, iParams, attrs)
27
+
28
+ const options = (iRequest ? data : attrs.treeData) ?? []
29
+
30
+ return <AntTreeSelect {...attrs} treeData={options} />
31
+ }
32
+
33
+ const Text: React.FC<TextProps> = props => {
34
+ const { iValue, iDom, iParams, iRequest, ...attrs } = props
35
+
36
+ const data = fetch(iRequest, iParams, attrs)
37
+
38
+ const options = (iRequest ? data : attrs.treeData) ?? []
39
+
40
+ if (Array.isArray(iValue)) {
41
+ return <Space>{combine(iValue, options, iDom)}</Space>
42
+ }
43
+
44
+ const node = equal(options, { value: iValue })
45
+ return <>{node ? node.title : iValue ? iValue : iDom}</>
46
+ }
47
+
48
+ const Render: RenderProps = {
49
+ name: 'treeSelect',
50
+ render: (text, props: FieldProps, dom) => {
51
+ const { params, request, fieldProps } = props
52
+ const iParams = params
53
+ const iRequest = request
54
+ const attrs = { iValue: text, iDom: dom, iParams, iRequest }
55
+
56
+ return <Text {...fieldProps} {...attrs} />
57
+ },
58
+ renderFormItem: (_, props: FieldProps) => {
59
+ const { params, request, fieldProps } = props
60
+ const iParams = params
61
+ const iRequest = request
62
+ const attrs = { iParams, iRequest }
63
+
64
+ return <TreeSelect {...fieldProps} {...attrs} />
65
+ },
66
+ }
67
+
68
+ export default Render
69
+
70
+ TreeSelect.defaultProps = {
71
+ allowClear: true,
72
+ showSearch: true,
73
+ treeNodeFilterProp: 'title',
74
+ }