@quansitech/antd-admin 1.0.0 → 1.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 (40) hide show
  1. package/components/Column/Cascader.tsx +78 -78
  2. package/components/Column/File.tsx +165 -167
  3. package/components/Column/Image.tsx +76 -76
  4. package/components/{Table/Option → Column/Readonly/Action}/Link.tsx +77 -67
  5. package/components/{Table/Option → Column/Readonly/Action}/types.d.ts +5 -4
  6. package/components/Column/Readonly/Action.tsx +80 -0
  7. package/components/Column/Readonly/Cascader.tsx +50 -50
  8. package/components/Column/Readonly/File.tsx +52 -53
  9. package/components/Column/Readonly/Image.tsx +38 -77
  10. package/components/Column/Readonly/Ueditor.tsx +18 -0
  11. package/components/Column/Readonly/types.d.ts +9 -8
  12. package/components/Column/Ueditor.tsx +313 -313
  13. package/components/Column/types.d.ts +29 -28
  14. package/components/Form/Action/Button.tsx +128 -124
  15. package/components/Form/Action/types.d.ts +5 -4
  16. package/components/Form/Actions.tsx +38 -34
  17. package/components/Form.tsx +179 -170
  18. package/components/FormContext.ts +8 -7
  19. package/components/Layout/New.tsx +252 -0
  20. package/components/Layout.tsx +52 -237
  21. package/components/LayoutContext.ts +25 -25
  22. package/components/ModalContext.ts +15 -15
  23. package/components/Table/Action/Button.tsx +88 -88
  24. package/components/Table/Action/StartEditable.tsx +58 -58
  25. package/components/Table/Action/types.d.ts +7 -6
  26. package/components/Table/ToolbarActions.tsx +43 -38
  27. package/components/Table.scss +4 -7
  28. package/components/Table.tsx +283 -279
  29. package/components/TableContext.ts +14 -13
  30. package/components/Tabs.tsx +71 -71
  31. package/lib/container.ts +83 -81
  32. package/lib/customRule.ts +9 -9
  33. package/lib/global.ts +10 -10
  34. package/lib/helpers.tsx +145 -149
  35. package/lib/http.ts +73 -73
  36. package/lib/schemaHandler.ts +121 -121
  37. package/lib/upload.ts +177 -177
  38. package/package.json +2 -6
  39. package/readme.md +128 -128
  40. package/components/Column/Readonly/Option.tsx +0 -58
@@ -1,279 +1,283 @@
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 isArray from "lodash/isArray"
13
- import upperFirst from "lodash/upperFirst"
14
- import {TableContext} from "./TableContext";
15
- import ToolbarActions from "./Table/ToolbarActions";
16
- import container from "../lib/container";
17
- import {TableActionProps} from "./Table/Action/types";
18
- import http from "../lib/http";
19
- import {Spin} from "antd";
20
- import "./Table.scss"
21
- import {ModalContext} from "./ModalContext";
22
- import cloneDeep from "lodash/cloneDeep";
23
- import uniqueId from "lodash/uniqueId";
24
- import {commonHandler} from "../lib/schemaHandler";
25
-
26
- export type TableProps = ProTableProps<any, any> & {
27
- columns: ProColumnType[],
28
- dataSource: any[],
29
- pagination: TablePaginationConfig & {
30
- paramName?: string,
31
- },
32
- rowKey: string,
33
- defaultSearchValue?: Record<string, any>,
34
- actions: TableActionProps[],
35
- searchUrl: string,
36
- search?: boolean,
37
- }
38
-
39
- export default function (props: TableProps) {
40
-
41
-
42
- const request = async (params: Record<string, any> & {
43
- pageSize: number,
44
- current: number
45
- }, sort: Record<string, SortOrder>, filter: Record<string, (string | number)[] | null>) => {
46
- setLoading(true)
47
- const data: Record<string, any> = {
48
- ...params,
49
- ...filter,
50
- sort,
51
- }
52
- if (props.pagination) {
53
- data[props.pagination.paramName || 'page'] = data.current
54
- delete data.current
55
- delete data.pageSize
56
- }
57
-
58
- setEditableKeys([])
59
- setEditableValues([])
60
-
61
- try {
62
- const res = await http.get(props.searchUrl, {
63
- params: data,
64
- headers: {
65
- 'X-Table-Search': '1'
66
- }
67
- })
68
-
69
- if (res.data.pagination) {
70
- setPagination({
71
- ...res.data.pagination,
72
- current: params.current,
73
- })
74
- }
75
- return {
76
- data: res.data.dataSource || [],
77
- success: true,
78
- }
79
- } finally {
80
- setLoading(false)
81
- }
82
- }
83
-
84
- const formRef = useRef<FormInstance>()
85
- const actionRef = useRef<ActionType>()
86
- const [editableKeys, setEditableKeys] = useState<React.Key[]>(() => [])
87
- const [columns, setColumns] = useState<ProColumnType[]>([])
88
- const [selectedRows, setSelectedRows] = useState<any[]>([])
89
- const [editableValues, setEditableValues] = useState<Record<string, any>[]>([])
90
- const [loading, setLoading] = useState(false)
91
- const [initialized, setInitialized] = useState(false)
92
- const [pagination, setPagination] = useState<TablePaginationConfig>()
93
- const [dataSource, setDataSource] = useState<any[]>([])
94
- const [sticky, setSticky] = useState<TableProps['sticky']>(true)
95
-
96
- const modalContext = useContext(ModalContext)
97
-
98
- useEffect(() => {
99
- setPagination(props.pagination as TablePaginationConfig || false)
100
- setDataSource(postData(props.dataSource))
101
-
102
- // 重新定义列
103
- setColumns(cloneDeep(props.columns)?.map((c: ProColumnType) => {
104
- c.key = c.dataIndex as string
105
-
106
- // 列render
107
- const renderComponent = 'Column.Readonly.' + upperFirst(c.valueType as string)
108
- if (container.check(renderComponent)) {
109
- const Component = lazy(container.get(renderComponent))
110
- c.render = (dom, record, _, action) =>
111
- <Suspense fallback={<Spin/>}>
112
- <Component {...c}
113
- key={c.title as string}
114
- record={record}
115
- ></Component>
116
- </Suspense>
117
- }
118
-
119
- // 列查询及编辑render
120
- const formItemComponent = 'Column.' + upperFirst(c.valueType as string)
121
- if (container.check(formItemComponent)) {
122
- const Component = lazy(container.get(formItemComponent))
123
- c.renderFormItem = (schema, config, form) => (
124
- <Suspense fallback={<Spin/>}>
125
- <Component config={config}
126
- form={form}
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
- }}>
194
- {!initialized && <ProSkeleton type={"list"} list={2}></ProSkeleton>}
195
- <ProTable rowKey={props.rowKey}
196
- style={{display: initialized ? 'block' : 'none'}}
197
- tableClassName={'qs-antd-table'}
198
- columns={columns}
199
- onDataSourceChange={setDataSource}
200
- dataSource={dataSource}
201
- pagination={pagination}
202
- loading={loading}
203
- scroll={{x: true}}
204
- postData={postData}
205
- sticky={sticky}
206
- form={{
207
- onValuesChange(changedValues) {
208
- const key = Object.keys(changedValues)[0]
209
- const c = columns.find(c => c.dataIndex === key) as ProColumnType & {
210
- searchOnChange: boolean
211
- }
212
- if (!c) {
213
- return
214
- }
215
- // 是否立即搜索
216
- if (c.searchOnChange) {
217
- formRef.current?.submit()
218
- }
219
- }
220
- }}
221
- rowSelection={props.rowSelection && {
222
- alwaysShowAlert: false,
223
- selectedRowKeys: selectedRows.map(item => item[props.rowKey]),
224
- onSelect(record, selected) {
225
- if (selected) {
226
- setSelectedRows([...selectedRows, record])
227
- } else {
228
- setSelectedRows(selectedRows.filter(item => item[props.rowKey] !== record[props.rowKey]))
229
- }
230
- },
231
- onChange(selectedRowKeys, newSelectedRows, info) {
232
- switch (info.type) {
233
- case 'all':
234
- if (newSelectedRows.length) {
235
- setSelectedRows([
236
- ...selectedRows,
237
- ...newSelectedRows.filter(item => !selectedRows.find(s => s[props.rowKey] == item[props.rowKey]))
238
- ])
239
- } else {
240
- setSelectedRows(selectedRows.filter(item => !props.dataSource.find(dr => dr[props.rowKey] == item[props.rowKey])))
241
- }
242
- break;
243
- case 'none':
244
- setSelectedRows([])
245
- break;
246
- }
247
- },
248
- }}
249
- toolbar={{
250
- filter: true,
251
- }}
252
- toolBarRender={(action) => [
253
- <ToolbarActions key={'actions'} actions={props.actions}
254
- selectedRows={selectedRows}></ToolbarActions>
255
- ]}
256
- editable={{
257
- type: 'multiple',
258
- editableKeys: editableKeys,
259
- onChange: setEditableKeys,
260
- onValuesChange(record) {
261
- setEditableValues([
262
- ...editableValues.filter(item => item[props.rowKey] !== record[props.rowKey]),
263
- record
264
- ])
265
- }
266
- }}
267
- cardBordered
268
- manualRequest={true}
269
- request={request}
270
- formRef={formRef}
271
- actionRef={actionRef}
272
- search={props.search}
273
- dateFormatter={props.dateFormatter}
274
- ></ProTable>
275
-
276
- </TableContext.Provider>
277
- </>
278
- }
279
-
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 isArray from "lodash/isArray"
13
+ import upperFirst from "lodash/upperFirst"
14
+ import {TableContext} from "./TableContext";
15
+ import ToolbarActions from "./Table/ToolbarActions";
16
+ import container from "../lib/container";
17
+ import {TableActionProps} from "./Table/Action/types";
18
+ import http from "../lib/http";
19
+ import {Spin} from "antd";
20
+ import "./Table.scss"
21
+ import {ModalContext} from "./ModalContext";
22
+ import cloneDeep from "lodash/cloneDeep";
23
+ import uniqueId from "lodash/uniqueId";
24
+ import {commonHandler} from "../lib/schemaHandler";
25
+
26
+ export type TableProps = ProTableProps<any, any> & {
27
+ columns: ProColumnType[],
28
+ dataSource: any[],
29
+ pagination: TablePaginationConfig & {
30
+ paramName?: string,
31
+ },
32
+ rowKey: string,
33
+ defaultSearchValue?: Record<string, any>,
34
+ actions: TableActionProps[],
35
+ searchUrl: string,
36
+ search?: boolean,
37
+ extraRenderValues?: Record<string, any>[],
38
+ }
39
+
40
+ export default function (props: TableProps) {
41
+
42
+ const request = async (params: Record<string, any> & {
43
+ pageSize: number,
44
+ current: number
45
+ }, sort: Record<string, SortOrder>, filter: Record<string, (string | number)[] | null>) => {
46
+ setLoading(true)
47
+ const data: Record<string, any> = {
48
+ ...params,
49
+ ...filter,
50
+ sort,
51
+ }
52
+ if (props.pagination) {
53
+ data[props.pagination.paramName || 'page'] = data.current
54
+ delete data.current
55
+ delete data.pageSize
56
+ }
57
+
58
+ setEditableKeys([])
59
+ setEditableValues([])
60
+
61
+ try {
62
+ const res = await http.get(props.searchUrl, {
63
+ params: data,
64
+ headers: {
65
+ 'X-Table-Search': '1'
66
+ }
67
+ })
68
+
69
+ if (res.data.pagination) {
70
+ setPagination({
71
+ ...res.data.pagination,
72
+ current: params.current,
73
+ })
74
+ }
75
+ return {
76
+ data: res.data.dataSource || [],
77
+ success: true,
78
+ }
79
+ } finally {
80
+ setLoading(false)
81
+ }
82
+ }
83
+
84
+ const formRef = useRef<FormInstance>()
85
+ const actionRef = useRef<ActionType>()
86
+ const [editableKeys, setEditableKeys] = useState<React.Key[]>(() => [])
87
+ const [columns, setColumns] = useState<ProColumnType[]>([])
88
+ const [selectedRows, setSelectedRows] = useState<any[]>([])
89
+ const [editableValues, setEditableValues] = useState<Record<string, any>[]>([])
90
+ const [loading, setLoading] = useState(false)
91
+ const [initialized, setInitialized] = useState(false)
92
+ const [pagination, setPagination] = useState<TablePaginationConfig>()
93
+ const [dataSource, setDataSource] = useState<any[]>([])
94
+ const [sticky, setSticky] = useState<TableProps['sticky']>(true)
95
+
96
+ const modalContext = useContext(ModalContext)
97
+
98
+ useEffect(() => {
99
+ setPagination(props.pagination as TablePaginationConfig || false)
100
+ setDataSource(postData(props.dataSource))
101
+
102
+ // 重新定义列
103
+ setColumns(cloneDeep(props.columns)?.map((c: ProColumnType) => {
104
+ c.key = c.dataIndex as string
105
+
106
+ // 列render
107
+ const renderComponent = 'Column.Readonly.' + upperFirst(c.valueType as string)
108
+ if (container.check(renderComponent)) {
109
+ const Component = lazy(container.get(renderComponent))
110
+ c.render = (dom, record, index, action) =>
111
+ <Suspense fallback={<Spin/>}>
112
+ <Component {...c}
113
+ schema={c}
114
+ key={c.title as string}
115
+ index={index}
116
+ record={record}
117
+ ></Component>
118
+ </Suspense>
119
+ }
120
+
121
+ // 列查询及编辑render
122
+ const formItemComponent = 'Column.' + upperFirst(c.valueType as string)
123
+ if (container.check(formItemComponent)) {
124
+ const Component = lazy(container.get(formItemComponent))
125
+ c.renderFormItem = (schema, config, form) => (
126
+ <Suspense fallback={<Spin/>}>
127
+ <Component config={config}
128
+ form={form}
129
+ index={schema.index}
130
+ schema={schema}
131
+ fieldProps={c.fieldProps}
132
+ key={c.title as string}
133
+ ></Component>
134
+ </Suspense>
135
+ )
136
+ }
137
+
138
+ if (props.defaultSearchValue?.[c.dataIndex as string] !== undefined) {
139
+ c.initialValue = props.defaultSearchValue[c.dataIndex as string]
140
+ }
141
+
142
+ commonHandler(c)
143
+ if (container.schemaHandler[c.valueType as string]) {
144
+ return container.schemaHandler[c.valueType as string](c) as ProColumnType
145
+ }
146
+
147
+ return c
148
+ }))
149
+
150
+ setLoading(false)
151
+ setInitialized(true)
152
+
153
+ if (!modalContext.inModal) {
154
+ setSticky({
155
+ offsetHeader: document.querySelector('.ant-layout-header')?.clientHeight || 56,
156
+ })
157
+ }
158
+
159
+ }, []);
160
+
161
+ const postData = (data: any[]) => {
162
+ if (!isArray(data)) {
163
+ return data
164
+ }
165
+
166
+ props.columns.map(column => {
167
+ switch (column.valueType) {
168
+ case 'dateTime':
169
+ data = data.map(row => {
170
+ const v = row[column.dataIndex]
171
+ if (parseInt(v) == v && v < 4102444800) {
172
+ row[column.dataIndex] *= 1000
173
+ }
174
+ return row
175
+ })
176
+ break;
177
+ }
178
+ })
179
+
180
+ return data.map(row => {
181
+ if (typeof row[props.rowKey] === 'undefined') {
182
+ row[props.rowKey] = uniqueId('row_')
183
+ }
184
+ return row
185
+ })
186
+ }
187
+
188
+
189
+ return <>
190
+ <TableContext.Provider value={{
191
+ getTableProps: () => props,
192
+ getEditedValues: () => editableValues,
193
+ editableKeys: editableKeys,
194
+ actionRef: actionRef.current,
195
+ formRef: formRef.current,
196
+ extraRenderValues: props.extraRenderValues,
197
+ }}>
198
+ {!initialized && <ProSkeleton type={"list"} list={2}></ProSkeleton>}
199
+ <ProTable rowKey={props.rowKey}
200
+ style={{display: initialized ? 'block' : 'none'}}
201
+ tableClassName={'qs-antd-table'}
202
+ columns={columns}
203
+ onDataSourceChange={setDataSource}
204
+ dataSource={dataSource}
205
+ pagination={pagination}
206
+ loading={loading}
207
+ scroll={{x: true}}
208
+ postData={postData}
209
+ sticky={sticky}
210
+ form={{
211
+ onValuesChange(changedValues) {
212
+ const key = Object.keys(changedValues)[0]
213
+ const c = columns.find(c => c.dataIndex === key) as ProColumnType & {
214
+ searchOnChange: boolean
215
+ }
216
+ if (!c) {
217
+ return
218
+ }
219
+ // 是否立即搜索
220
+ if (c.searchOnChange) {
221
+ formRef.current?.submit()
222
+ }
223
+ }
224
+ }}
225
+ rowSelection={props.rowSelection && {
226
+ alwaysShowAlert: false,
227
+ selectedRowKeys: selectedRows.map(item => item[props.rowKey]),
228
+ onSelect(record, selected) {
229
+ if (selected) {
230
+ setSelectedRows([...selectedRows, record])
231
+ } else {
232
+ setSelectedRows(selectedRows.filter(item => item[props.rowKey] !== record[props.rowKey]))
233
+ }
234
+ },
235
+ onChange(selectedRowKeys, newSelectedRows, info) {
236
+ switch (info.type) {
237
+ case 'all':
238
+ if (newSelectedRows.length) {
239
+ setSelectedRows([
240
+ ...selectedRows,
241
+ ...newSelectedRows.filter(item => !selectedRows.find(s => s[props.rowKey] == item[props.rowKey]))
242
+ ])
243
+ } else {
244
+ setSelectedRows(selectedRows.filter(item => !dataSource.find(dr => dr[props.rowKey] == item[props.rowKey])))
245
+ }
246
+ break;
247
+ case 'none':
248
+ setSelectedRows([])
249
+ break;
250
+ }
251
+ },
252
+ }}
253
+ toolbar={{
254
+ filter: true,
255
+ }}
256
+ toolBarRender={(action) => [
257
+ <ToolbarActions key={'actions'} actions={props.actions}
258
+ selectedRows={selectedRows}></ToolbarActions>
259
+ ]}
260
+ editable={{
261
+ type: 'multiple',
262
+ editableKeys: editableKeys,
263
+ onChange: setEditableKeys,
264
+ onValuesChange(record) {
265
+ setEditableValues([
266
+ ...editableValues.filter(item => item[props.rowKey] !== record[props.rowKey]),
267
+ record
268
+ ])
269
+ }
270
+ }}
271
+ cardBordered
272
+ manualRequest={true}
273
+ request={request}
274
+ formRef={formRef}
275
+ actionRef={actionRef}
276
+ search={props.search}
277
+ dateFormatter={props.dateFormatter}
278
+ ></ProTable>
279
+
280
+ </TableContext.Provider>
281
+ </>
282
+ }
283
+
@@ -1,14 +1,15 @@
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
- }
13
-
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
+
14
15
  export const TableContext = createContext({} as TableContextValue)