@quansitech/antd-admin 1.1.0 → 1.1.2

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 (119) hide show
  1. package/dist/components/Column/Cascader.d.ts +3 -0
  2. package/dist/components/Column/Cascader.js +110 -0
  3. package/dist/components/Column/File.d.ts +18 -0
  4. package/dist/components/Column/File.js +176 -0
  5. package/dist/components/Column/Image.d.ts +10 -0
  6. package/dist/components/Column/Image.js +104 -0
  7. package/dist/components/Column/Readonly/Action/Link.d.ts +11 -0
  8. package/dist/components/Column/Readonly/Action/Link.js +114 -0
  9. package/dist/components/Column/Readonly/Action/index.d.ts +4 -0
  10. package/dist/components/Column/Readonly/Action/index.js +3 -0
  11. package/dist/components/Column/Readonly/Action.d.ts +12 -0
  12. package/dist/components/Column/Readonly/Action.js +96 -0
  13. package/dist/components/Column/Readonly/Cascader.d.ts +9 -0
  14. package/dist/components/Column/Readonly/Cascader.js +52 -0
  15. package/dist/components/Column/Readonly/File.d.ts +8 -0
  16. package/dist/components/Column/Readonly/File.js +54 -0
  17. package/dist/components/Column/Readonly/Image.d.ts +3 -0
  18. package/dist/components/Column/Readonly/Image.js +69 -0
  19. package/dist/components/Column/Readonly/Ueditor.d.ts +3 -0
  20. package/dist/components/Column/Readonly/Ueditor.js +24 -0
  21. package/dist/components/Column/Readonly/index.d.ts +8 -0
  22. package/dist/components/Column/Readonly/index.js +7 -0
  23. package/dist/components/Column/Ueditor.d.ts +27 -0
  24. package/dist/components/Column/Ueditor.js +333 -0
  25. package/dist/components/Column/index.d.ts +7 -0
  26. package/dist/components/Column/index.js +6 -0
  27. package/dist/components/Form/Action/Button.d.ts +15 -0
  28. package/dist/components/Form/Action/Button.js +194 -0
  29. package/dist/components/Form/Action/index.d.ts +4 -0
  30. package/dist/components/Form/Action/index.js +3 -0
  31. package/dist/components/Form/Actions.d.ts +6 -0
  32. package/dist/components/Form/Actions.js +48 -0
  33. package/dist/components/Form.d.ts +20 -0
  34. package/dist/components/Form.js +217 -0
  35. package/dist/components/FormContext.d.ts +7 -0
  36. package/dist/components/FormContext.js +2 -0
  37. package/dist/components/Layout/New.d.ts +7 -0
  38. package/dist/components/Layout/New.js +257 -0
  39. package/dist/components/Layout.d.ts +4 -0
  40. package/dist/components/Layout.js +67 -0
  41. package/dist/components/LayoutContext.d.ts +26 -0
  42. package/dist/components/LayoutContext.js +2 -0
  43. package/dist/components/ModalContext.d.ts +8 -0
  44. package/dist/components/ModalContext.js +6 -0
  45. package/dist/components/Table/Action/Button.d.ts +10 -0
  46. package/dist/components/Table/Action/Button.js +166 -0
  47. package/dist/components/Table/Action/StartEditable.d.ts +10 -0
  48. package/dist/components/Table/Action/StartEditable.js +79 -0
  49. package/dist/components/Table/Action/index.d.ts +5 -0
  50. package/dist/components/Table/Action/index.js +4 -0
  51. package/dist/components/Table/ToolbarActions.d.ts +6 -0
  52. package/dist/components/Table/ToolbarActions.js +52 -0
  53. package/dist/components/Table.d.ts +19 -0
  54. package/dist/components/Table.js +322 -0
  55. package/dist/components/TableContext.d.ts +14 -0
  56. package/dist/components/TableContext.js +2 -0
  57. package/dist/components/Tabs.d.ts +15 -0
  58. package/dist/components/Tabs.js +62 -0
  59. package/dist/env.d.ts +1 -0
  60. package/dist/global.d.ts +6 -0
  61. package/dist/index.d.ts +7 -0
  62. package/dist/index.js +7 -0
  63. package/dist/lib/container.d.ts +9 -0
  64. package/dist/lib/container.js +93 -0
  65. package/dist/lib/customRule.d.ts +3 -0
  66. package/dist/lib/customRule.js +7 -0
  67. package/dist/lib/global.d.ts +9 -0
  68. package/dist/lib/global.js +2 -0
  69. package/dist/lib/helpers.d.ts +14 -0
  70. package/dist/lib/helpers.js +183 -0
  71. package/dist/lib/http.d.ts +5 -0
  72. package/dist/lib/http.js +72 -0
  73. package/dist/lib/schemaHandler.d.ts +5 -0
  74. package/dist/lib/schemaHandler.js +133 -0
  75. package/dist/lib/upload.d.ts +20 -0
  76. package/dist/lib/upload.js +215 -0
  77. package/dist/lib/writeExtra.d.ts +1 -0
  78. package/dist/lib/writeExtra.js +28 -0
  79. package/dist/types.d.ts +25 -0
  80. package/package.json +14 -8
  81. package/components/Column/Cascader.tsx +0 -79
  82. package/components/Column/File.tsx +0 -166
  83. package/components/Column/Image.tsx +0 -77
  84. package/components/Column/Readonly/Action/Link.tsx +0 -78
  85. package/components/Column/Readonly/Action.tsx +0 -80
  86. package/components/Column/Readonly/Cascader.tsx +0 -51
  87. package/components/Column/Readonly/File.tsx +0 -53
  88. package/components/Column/Readonly/Image.tsx +0 -39
  89. package/components/Column/Readonly/Ueditor.tsx +0 -18
  90. package/components/Column/Ueditor.tsx +0 -314
  91. package/components/Form/Action/Button.tsx +0 -129
  92. package/components/Form/Actions.tsx +0 -39
  93. package/components/Form.tsx +0 -177
  94. package/components/FormContext.ts +0 -9
  95. package/components/Layout/New.tsx +0 -252
  96. package/components/Layout.tsx +0 -52
  97. package/components/LayoutContext.ts +0 -26
  98. package/components/ModalContext.ts +0 -16
  99. package/components/Table/Action/Button.tsx +0 -89
  100. package/components/Table/Action/StartEditable.tsx +0 -59
  101. package/components/Table/ToolbarActions.tsx +0 -44
  102. package/components/Table.tsx +0 -280
  103. package/components/TableContext.ts +0 -15
  104. package/components/Tabs.tsx +0 -72
  105. package/lib/container.ts +0 -84
  106. package/lib/customRule.ts +0 -10
  107. package/lib/global.ts +0 -11
  108. package/lib/helpers.tsx +0 -146
  109. package/lib/http.ts +0 -74
  110. package/lib/schemaHandler.ts +0 -122
  111. package/lib/upload.ts +0 -177
  112. package/lib/writeExtra.js +0 -31
  113. /package/{components → dist/components}/Column/Readonly/Action/types.d.ts +0 -0
  114. /package/{components → dist/components}/Column/Readonly/types.d.ts +0 -0
  115. /package/{components → dist/components}/Column/types.d.ts +0 -0
  116. /package/{components → dist/components}/Form/Action/types.d.ts +0 -0
  117. /package/{components → dist/components}/Table/Action/types.d.ts +0 -0
  118. /package/{components → dist/components}/Table.scss +0 -0
  119. /package/{components → dist/components}/types.d.ts +0 -0
@@ -1,16 +0,0 @@
1
- import {createContext} from "react";
2
-
3
- export type ModalContextProps = {
4
- inModal: boolean,
5
- closeModal: () => void,
6
- contexts?: Record<string, any>
7
- setAfterClose(callback: () => void): void
8
- }
9
-
10
- export const ModalContext = createContext<ModalContextProps>({
11
- inModal: false,
12
- closeModal: () => {
13
- },
14
- setAfterClose: (fn: Function) => {
15
- },
16
- })
@@ -1,89 +0,0 @@
1
- import {Button, Popconfirm} from "antd";
2
- import {useContext, useEffect, useState} from "react";
3
- import {TableContext} from "../../TableContext";
4
- import http from "../../../lib/http";
5
- import {modalShow, routerNavigateTo} from "../../../lib/helpers";
6
- import {TableActionProps} from "./types";
7
-
8
- export default function (props: TableActionProps & {
9
- props: Record<string, any>,
10
- link?: {
11
- url: string,
12
- },
13
- request?: RequestOptions,
14
- modal?: ModalOptions,
15
- }) {
16
- const tableContext = useContext(TableContext)
17
-
18
- const onClick = async () => {
19
- const rowKey = tableContext.getTableProps().rowKey
20
- if (props.link) {
21
- routerNavigateTo(props.link.url)
22
- return
23
- }
24
-
25
- if (props.request) {
26
- setLoading(true)
27
- const data = props.request.data || {}
28
- if (props.relateSelection) {
29
- data.selection = props.selectedRows?.map(item => item[rowKey])
30
- for (const key in data) {
31
- if (typeof data[key] !== 'string') {
32
- continue
33
- }
34
- const matches = data[key].match(/^__(\w+)__$/)
35
- if (!matches) {
36
- continue
37
- }
38
- data[key] = props.selectedRows?.map(item => item[matches[1]])
39
- }
40
- }
41
- try {
42
- await http({
43
- url: props.request.url,
44
- method: props.request.method,
45
- headers: props.request.headers || {},
46
- data: data,
47
- })
48
- } finally {
49
- setLoading(false)
50
- }
51
- return
52
- }
53
-
54
- if (props.modal) {
55
- await modalShow(props.modal)
56
- return
57
- }
58
-
59
- await tableContext.actionRef?.reload()
60
- }
61
-
62
- const [loading, setLoading] = useState(false)
63
-
64
- const [disabled, setDisabled] = useState(props.props.disabled)
65
-
66
- useEffect(() => {
67
- if (!props.relateSelection) {
68
- return
69
- }
70
- setDisabled(props.selectedRows?.length === 0)
71
-
72
- }, [props.selectedRows]);
73
-
74
-
75
- const ButtonComponent = () => {
76
- if (props.request?.confirm) {
77
- return <Popconfirm title={props.request.confirm} onConfirm={onClick}>
78
- <Button loading={loading} {...props.props} disabled={disabled}>{props.title}</Button>
79
- </Popconfirm>
80
- } else {
81
- return <Button loading={loading} onClick={onClick} {...props.props}
82
- disabled={disabled}>{props.title}</Button>
83
- }
84
- }
85
-
86
- return <>
87
- <ButtonComponent></ButtonComponent>
88
- </>
89
- }
@@ -1,59 +0,0 @@
1
- import {Button, ButtonProps, Space} from "antd";
2
- import {TableContext} from "../../TableContext";
3
- import {useContext, useState} from "react";
4
- import http from "../../../lib/http";
5
- import {TableActionProps} from "./types";
6
-
7
- export default function (props: TableActionProps & {
8
- props: ButtonProps,
9
- saveRequest: {
10
- url: string,
11
- method: string,
12
- },
13
- }) {
14
- const tableContext = useContext(TableContext)
15
-
16
- const onStartClick = () => {
17
- const rowKey = tableContext.getTableProps().rowKey
18
- tableContext.getTableProps().dataSource.map(item => {
19
- tableContext.actionRef?.startEditable(item[rowKey], item)
20
- })
21
- }
22
-
23
- const onCancelClick = () => {
24
- const rowKey = tableContext.getTableProps().rowKey
25
- tableContext.getTableProps().dataSource.map(item => {
26
- tableContext.actionRef?.cancelEditable(item[rowKey])
27
- })
28
- }
29
-
30
- const [loading, setLoading] = useState(false)
31
-
32
- const onSaveClick = async () => {
33
- setLoading(true)
34
-
35
- try {
36
- await http({
37
- method: props.saveRequest.method,
38
- url: props.saveRequest.url,
39
- data: tableContext.getEditedValues(),
40
- })
41
-
42
- await tableContext.actionRef?.reload()
43
- } finally {
44
- setLoading(false)
45
- }
46
- onCancelClick()
47
- }
48
-
49
- return <>
50
- {tableContext.editableKeys.length > 0
51
- ?
52
- <Space>
53
- <Button loading={loading} type={'primary'} onClick={onSaveClick}>保存</Button>
54
- <Button danger={true} onClick={onCancelClick}>取消</Button>
55
- </Space>
56
- : <Button {...props.props} onClick={onStartClick}>{props.title}</Button>
57
- }
58
- </>
59
- }
@@ -1,44 +0,0 @@
1
- import {lazy, useEffect, useState} from "react";
2
- import container from "../../lib/container";
3
- import {ReactComponentLike} from "prop-types";
4
- import {Badge, Space} from "antd";
5
- import {TableActionProps} from "./Action/types";
6
- import {upperFirst} from "lodash";
7
-
8
- export default function ({
9
- actions,
10
- selectedRows,
11
- }: {
12
- actions: TableActionProps[],
13
- selectedRows?: any[]
14
- }) {
15
- const [components, setComponents] = useState<{
16
- Component: ReactComponentLike,
17
- props: TableActionProps,
18
- }[]>([])
19
-
20
- useEffect(() => {
21
- setComponents(actions.map(a => {
22
- return {
23
- Component: lazy(container.get('Table.Action.' + upperFirst(a.type))),
24
- props: {
25
- ...a,
26
- },
27
- }
28
- }))
29
-
30
- }, []);
31
-
32
-
33
- return <>
34
- <Space wrap={true}>
35
- {components.map(c => (
36
- c.props.badge ?
37
- <Badge key={c.props.title} count={c.props.badge} style={{zIndex: 100}}>
38
- <c.Component {...c.props} selectedRows={selectedRows}></c.Component>
39
- </Badge> :
40
- <c.Component key={c.props.title} {...c.props} selectedRows={selectedRows}></c.Component>
41
- ))}
42
- </Space>
43
- </>
44
- }
@@ -1,280 +0,0 @@
1
- import React, {lazy, Suspense, useContext, useEffect, useRef, useState} from "react";
2
- import {
3
- ActionType,
4
- FormInstance,
5
- ProColumnType,
6
- ProSkeleton,
7
- ProTable,
8
- ProTableProps
9
- } from "@ant-design/pro-components";
10
- import type {SortOrder} from "antd/lib/table/interface";
11
- import {TablePaginationConfig} from "antd/es/table";
12
- import {cloneDeep, isArray, uniqueId, upperFirst} from "lodash"
13
- import {TableContext} from "./TableContext";
14
- import ToolbarActions from "./Table/ToolbarActions";
15
- import container from "../lib/container";
16
- import {TableActionProps} from "./Table/Action/types";
17
- import http from "../lib/http";
18
- import {Spin} from "antd";
19
- import "./Table.scss"
20
- import {ModalContext} from "./ModalContext";
21
- import {commonHandler} from "../lib/schemaHandler";
22
-
23
- export type TableProps = ProTableProps<any, any> & {
24
- columns: ProColumnType[],
25
- dataSource: any[],
26
- pagination: TablePaginationConfig & {
27
- paramName?: string,
28
- },
29
- rowKey: string,
30
- defaultSearchValue?: Record<string, any>,
31
- actions: TableActionProps[],
32
- searchUrl: string,
33
- search?: boolean,
34
- extraRenderValues?: Record<string, any>[],
35
- }
36
-
37
- export default function (props: TableProps) {
38
-
39
- const request = async (params: Record<string, any> & {
40
- pageSize: number,
41
- current: number
42
- }, sort: Record<string, SortOrder>, filter: Record<string, (string | number)[] | null>) => {
43
- setLoading(true)
44
- const data: Record<string, any> = {
45
- ...params,
46
- ...filter,
47
- sort,
48
- }
49
- if (props.pagination) {
50
- data[props.pagination.paramName || 'page'] = data.current
51
- delete data.current
52
- delete data.pageSize
53
- }
54
-
55
- setEditableKeys([])
56
- setEditableValues([])
57
-
58
- try {
59
- const res = await http.get(props.searchUrl, {
60
- params: data,
61
- headers: {
62
- 'X-Table-Search': '1'
63
- }
64
- })
65
-
66
- if (res.data.pagination) {
67
- setPagination({
68
- ...res.data.pagination,
69
- current: params.current,
70
- })
71
- }
72
- return {
73
- data: res.data.dataSource || [],
74
- success: true,
75
- }
76
- } finally {
77
- setLoading(false)
78
- }
79
- }
80
-
81
- const formRef = useRef<FormInstance>()
82
- const actionRef = useRef<ActionType>()
83
- const [editableKeys, setEditableKeys] = useState<React.Key[]>(() => [])
84
- const [columns, setColumns] = useState<ProColumnType[]>([])
85
- const [selectedRows, setSelectedRows] = useState<any[]>([])
86
- const [editableValues, setEditableValues] = useState<Record<string, any>[]>([])
87
- const [loading, setLoading] = useState(false)
88
- const [initialized, setInitialized] = useState(false)
89
- const [pagination, setPagination] = useState<TablePaginationConfig>()
90
- const [dataSource, setDataSource] = useState<any[]>([])
91
- const [sticky, setSticky] = useState<TableProps['sticky']>(true)
92
-
93
- const modalContext = useContext(ModalContext)
94
-
95
- useEffect(() => {
96
- setPagination(props.pagination as TablePaginationConfig || false)
97
- setDataSource(postData(props.dataSource))
98
-
99
- // 重新定义列
100
- setColumns(cloneDeep(props.columns)?.map((c: ProColumnType) => {
101
- c.key = c.dataIndex as string
102
-
103
- // 列render
104
- const renderComponent = 'Column.Readonly.' + upperFirst(c.valueType as string)
105
- if (container.check(renderComponent)) {
106
- const Component = lazy(container.get(renderComponent))
107
- c.render = (dom, record, index, action) =>
108
- <Suspense fallback={<Spin/>}>
109
- <Component {...c}
110
- schema={c}
111
- key={c.title as string}
112
- index={index}
113
- record={record}
114
- ></Component>
115
- </Suspense>
116
- }
117
-
118
- // 列查询及编辑render
119
- const formItemComponent = 'Column.' + upperFirst(c.valueType as string)
120
- if (container.check(formItemComponent)) {
121
- const Component = lazy(container.get(formItemComponent))
122
- c.renderFormItem = (schema, config, form) => (
123
- <Suspense fallback={<Spin/>}>
124
- <Component config={config}
125
- form={form}
126
- index={schema.index}
127
- schema={schema}
128
- fieldProps={c.fieldProps}
129
- key={c.title as string}
130
- ></Component>
131
- </Suspense>
132
- )
133
- }
134
-
135
- if (props.defaultSearchValue?.[c.dataIndex as string] !== undefined) {
136
- c.initialValue = props.defaultSearchValue[c.dataIndex as string]
137
- }
138
-
139
- commonHandler(c)
140
- if (container.schemaHandler[c.valueType as string]) {
141
- return container.schemaHandler[c.valueType as string](c) as ProColumnType
142
- }
143
-
144
- return c
145
- }))
146
-
147
- setLoading(false)
148
- setInitialized(true)
149
-
150
- if (!modalContext.inModal) {
151
- setSticky({
152
- offsetHeader: document.querySelector('.ant-layout-header')?.clientHeight || 56,
153
- })
154
- }
155
-
156
- }, []);
157
-
158
- const postData = (data: any[]) => {
159
- if (!isArray(data)) {
160
- return data
161
- }
162
-
163
- props.columns.map(column => {
164
- switch (column.valueType) {
165
- case 'dateTime':
166
- data = data.map(row => {
167
- const v = row[column.dataIndex]
168
- if (parseInt(v) == v && v < 4102444800) {
169
- row[column.dataIndex] *= 1000
170
- }
171
- return row
172
- })
173
- break;
174
- }
175
- })
176
-
177
- return data.map(row => {
178
- if (typeof row[props.rowKey] === 'undefined') {
179
- row[props.rowKey] = uniqueId('row_')
180
- }
181
- return row
182
- })
183
- }
184
-
185
-
186
- return <>
187
- <TableContext.Provider value={{
188
- getTableProps: () => props,
189
- getEditedValues: () => editableValues,
190
- editableKeys: editableKeys,
191
- actionRef: actionRef.current,
192
- formRef: formRef.current,
193
- extraRenderValues: props.extraRenderValues,
194
- }}>
195
- {!initialized && <ProSkeleton type={"list"} list={2}></ProSkeleton>}
196
- <ProTable rowKey={props.rowKey}
197
- style={{display: initialized ? 'block' : 'none'}}
198
- tableClassName={'qs-antd-table'}
199
- columns={columns}
200
- onDataSourceChange={setDataSource}
201
- dataSource={dataSource}
202
- pagination={pagination}
203
- loading={loading}
204
- scroll={{x: true}}
205
- postData={postData}
206
- sticky={sticky}
207
- form={{
208
- onValuesChange(changedValues) {
209
- const key = Object.keys(changedValues)[0]
210
- const c = columns.find(c => c.dataIndex === key) as ProColumnType & {
211
- searchOnChange: boolean
212
- }
213
- if (!c) {
214
- return
215
- }
216
- // 是否立即搜索
217
- if (c.searchOnChange) {
218
- formRef.current?.submit()
219
- }
220
- }
221
- }}
222
- rowSelection={props.rowSelection && {
223
- alwaysShowAlert: false,
224
- selectedRowKeys: selectedRows.map(item => item[props.rowKey]),
225
- onSelect(record, selected) {
226
- if (selected) {
227
- setSelectedRows([...selectedRows, record])
228
- } else {
229
- setSelectedRows(selectedRows.filter(item => item[props.rowKey] !== record[props.rowKey]))
230
- }
231
- },
232
- onChange(selectedRowKeys, newSelectedRows, info) {
233
- switch (info.type) {
234
- case 'all':
235
- if (newSelectedRows.length) {
236
- setSelectedRows([
237
- ...selectedRows,
238
- ...newSelectedRows.filter(item => !selectedRows.find(s => s[props.rowKey] == item[props.rowKey]))
239
- ])
240
- } else {
241
- setSelectedRows(selectedRows.filter(item => !dataSource.find(dr => dr[props.rowKey] == item[props.rowKey])))
242
- }
243
- break;
244
- case 'none':
245
- setSelectedRows([])
246
- break;
247
- }
248
- },
249
- }}
250
- toolbar={{
251
- filter: true,
252
- }}
253
- toolBarRender={(action) => [
254
- <ToolbarActions key={'actions'} actions={props.actions}
255
- selectedRows={selectedRows}></ToolbarActions>
256
- ]}
257
- editable={{
258
- type: 'multiple',
259
- editableKeys: editableKeys,
260
- onChange: setEditableKeys,
261
- onValuesChange(record) {
262
- setEditableValues([
263
- ...editableValues.filter(item => item[props.rowKey] !== record[props.rowKey]),
264
- record
265
- ])
266
- }
267
- }}
268
- cardBordered
269
- manualRequest={true}
270
- request={request}
271
- formRef={formRef}
272
- actionRef={actionRef}
273
- search={props.search}
274
- dateFormatter={props.dateFormatter}
275
- ></ProTable>
276
-
277
- </TableContext.Provider>
278
- </>
279
- }
280
-
@@ -1,15 +0,0 @@
1
- import React, {createContext} from "react";
2
- import {ActionType} from "@ant-design/pro-components";
3
- import {TableProps} from "./Table";
4
- import {FormInstance} from "antd/lib/form";
5
-
6
- type TableContextValue = {
7
- getTableProps: () => TableProps,
8
- getEditedValues: () => Record<string, any>[],
9
- editableKeys: React.Key[],
10
- actionRef?: ActionType,
11
- formRef?: FormInstance,
12
- extraRenderValues?: Record<string, any>[],
13
- }
14
-
15
- export const TableContext = createContext({} as TableContextValue)
@@ -1,72 +0,0 @@
1
- import {Tabs} from "antd";
2
- import {lazy, Suspense, useEffect, useState} from "react";
3
- import type {Tab} from 'rc-tabs/lib/interface';
4
- import container from "../lib/container";
5
- import {routerNavigateTo} from "../lib/helpers";
6
- import {upperFirst} from "lodash";
7
- import {ProSkeleton} from "@ant-design/pro-components";
8
-
9
- type TabProps = {
10
- title: string,
11
- url?: string,
12
- pane?: {
13
- component: 'form' | 'table',
14
- props: any,
15
- }
16
- }
17
-
18
- export type TabsPageType = {
19
- tabs: Record<string, TabProps>,
20
- defaultActiveKey?: string,
21
- }
22
-
23
- export default function (props: TabsPageType) {
24
- const [items, setItems] = useState<Tab[]>([]);
25
- const [activeKey, setActiveKey] = useState<string>();
26
-
27
- useEffect(() => {
28
- setActiveKey(props.defaultActiveKey || Object.keys(props.tabs)[0])
29
-
30
- setItems(Object.keys(props.tabs).map(key => {
31
- const t = props.tabs[key]
32
-
33
- if (!t.pane) {
34
- return {
35
- key,
36
- label: t.title,
37
- children: <>
38
- <ProSkeleton list={2}></ProSkeleton>
39
- </>
40
- }
41
- }
42
-
43
- const Component = lazy(() => container.get('Tab.Pane.' + upperFirst(t.pane?.component)))
44
-
45
- return {
46
- key,
47
- label: t.title,
48
- children: <>
49
- <Suspense>
50
- <Component {...t.pane.props}></Component>
51
- </Suspense>
52
- </>
53
- }
54
- }))
55
- }, []);
56
-
57
- const onChange = (key: string) => {
58
- setActiveKey(key)
59
-
60
- const tab = props.tabs[key]
61
- if (tab.url) {
62
- routerNavigateTo(tab.url)
63
- }
64
- }
65
-
66
- return <>
67
- <Tabs items={items}
68
- onChange={onChange}
69
- activeKey={activeKey}
70
- ></Tabs>
71
- </>
72
- }
package/lib/container.ts DELETED
@@ -1,84 +0,0 @@
1
- import {schemaHandler} from "./schemaHandler";
2
- import {routerNavigateTo} from "./helpers";
3
-
4
- const components: Record<string, any> = {}
5
-
6
- const container = {
7
- register(name: string, componentLoader: any) {
8
- if (this.check(name)) {
9
- throw new Error(`Component ${name} already registered`)
10
- }
11
- components[name] = componentLoader
12
- },
13
- get(name: string) {
14
- if (!this.check(name)) {
15
- throw new Error(`Component ${name} is not registered`)
16
- }
17
- return components[name]
18
- },
19
- check(name: string) {
20
- return !!components[name]
21
- },
22
- schemaHandler,
23
- routerNavigateTo,
24
- };
25
-
26
- function autoRegister(prefix: string, components: Record<string, () => Promise<any>>) {
27
- for (const [key, value] of Object.entries(components)) {
28
- const name = key.split('/').pop()?.split('.').shift()
29
- container.register(prefix + name, value)
30
- }
31
- }
32
-
33
- // -------- 通用 -----------
34
- {
35
- const columnRender = import.meta.glob('../components/Column/*.tsx')
36
- autoRegister('Column.', columnRender)
37
-
38
- // readonly render
39
- const columnReadonlyRender = import.meta.glob('../components/Column/Readonly/*.tsx')
40
- autoRegister('Column.Readonly.', columnReadonlyRender)
41
- }
42
-
43
- // -------- 弹窗 -----------
44
- {
45
- container.register('Modal.Table', import('../components/Table'))
46
- container.register('Modal.Form', import('../components/Form'))
47
- }
48
-
49
- // -------- Tabs -----------
50
- {
51
- container.register('Tab.Pane.Table', import('../components/Table'))
52
- container.register('Tab.Pane.Form', import('../components/Form'))
53
- }
54
-
55
- // -------- 表格 -----------
56
- {
57
- // column.action render
58
- const optionsRender = import.meta.glob('../components/Column/Readonly/Action/*.tsx')
59
- autoRegister('Column.Readonly.Action.', optionsRender)
60
-
61
- // action render
62
- const actionRender = import.meta.glob('../components/Table/Action/*.tsx')
63
- autoRegister('Table.Action.', actionRender)
64
- }
65
-
66
- // -------- 表单 -----------
67
- {
68
-
69
- // formAction render
70
- const formActionRender = import.meta.glob('../components/Form/Action/*.tsx')
71
- autoRegister('Form.Action.', formActionRender)
72
- }
73
-
74
-
75
- ;((globalThis: any) => {
76
- if (globalThis.$qsContainer) {
77
- return;
78
- }
79
-
80
- globalThis.$qsContainer = container
81
-
82
- })(window)
83
-
84
- export default container
package/lib/customRule.ts DELETED
@@ -1,10 +0,0 @@
1
- import {RuleObject, StoreValue} from "rc-field-form/lib/interface";
2
-
3
- const customRule: Record<string, (rule: RuleObject, value: StoreValue, callback: (error?: string) => void) => any> = {
4
- notInEnum(rule, value) {
5
- return !rule.enum?.includes(value);
6
-
7
- }
8
- }
9
-
10
- export default customRule
package/lib/global.ts DELETED
@@ -1,11 +0,0 @@
1
- import {MessageInstance} from "antd/es/message/interface";
2
- import {ModalStaticFunctions} from "antd/es/modal/confirm";
3
- import {NotificationInstance} from "antd/es/notification/interface";
4
-
5
- const global = {} as {
6
- message: MessageInstance,
7
- modal: Omit<ModalStaticFunctions, 'warn'>,
8
- notification: NotificationInstance,
9
- }
10
-
11
- export default global