@quansitech/antd-admin 1.0.0 → 1.1.0

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 (41) 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 +176 -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 +280 -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/lib/writeExtra.js +31 -0
  39. package/package.json +2 -6
  40. package/readme.md +151 -128
  41. package/components/Column/Readonly/Option.tsx +0 -58
@@ -1,29 +1,30 @@
1
- import type {FormInstance} from "antd/lib/form";
2
- import {ProSchema} from "@ant-design/pro-components";
3
- import {Rule} from "rc-field-form/lib/interface";
4
- import {Key} from "react";
5
-
6
- export type ColumnProps = {
7
- className: any,
8
- onChange?: <T = any>(value: T) => void;
9
- onBlur?: <T = any>(event: T) => void;
10
- schema?: ProSchema<Entity, ExtraProps, ComponentsType, ValueType>,
11
- config: {
12
- onSelect?: (value: any) => void;
13
- onChange?: <T = any>(value: T) => void;
14
- value?: any;
15
- type: ComponentsType;
16
- recordKey?: React.Key | React.Key[];
17
- record?: Entity;
18
- isEditable?: boolean;
19
- defaultRender: (newItem: ProSchema<Entity, ExtraProps, ComponentsType, ValueType>) => JSX.Element | null;
20
- options?: any[];
21
- }
22
- form: FormInstance,
23
- fieldProps: any,
24
- rules?: Rule[],
25
- dataIndex?: Key,
26
- value?: any,
27
-
28
- record?: any,
1
+ import type {FormInstance} from "antd/lib/form";
2
+ import {ProSchema} from "@ant-design/pro-components";
3
+ import {Rule} from "rc-field-form/lib/interface";
4
+ import {Key} from "react";
5
+
6
+ export type ColumnProps = {
7
+ className: any,
8
+ onChange?: <T = any>(value: T) => void;
9
+ onBlur?: <T = any>(event: T) => void;
10
+ schema?: ProSchema<Entity, ExtraProps, ComponentsType, ValueType>,
11
+ index?: number,
12
+ config: {
13
+ onSelect?: (value: any) => void;
14
+ onChange?: <T = any>(value: T) => void;
15
+ value?: any;
16
+ type: ComponentsType;
17
+ recordKey?: React.Key | React.Key[];
18
+ record?: Entity;
19
+ isEditable?: boolean;
20
+ defaultRender: (newItem: ProSchema<Entity, ExtraProps, ComponentsType, ValueType>) => JSX.Element | null;
21
+ options?: any[];
22
+ }
23
+ form: FormInstance,
24
+ fieldProps: any,
25
+ rules?: Rule[],
26
+ dataIndex?: Key,
27
+ value?: any,
28
+
29
+ record?: any,
29
30
  }
@@ -1,125 +1,129 @@
1
- import {FormActionType} from "./types";
2
- import {Button, Popconfirm} from "antd";
3
- import {useContext, useEffect, useState} from "react";
4
- import http from "../../../lib/http";
5
- import {FormContext} from "../../FormContext";
6
- import {modal, replaceParams, replaceUrl, routerNavigateTo} from "../../../lib/helpers";
7
- import {ModalContext} from "../../ModalContext";
8
- import {TableContext} from "../../TableContext";
9
-
10
- export default function (props: FormActionType & {
11
- props: any,
12
-
13
- // 操作
14
- submit?: boolean | {
15
- confirm?: string
16
- },
17
- request?: RequestOptions,
18
- link?: {
19
- url: string,
20
- }
21
- back?: boolean,
22
- reset?: boolean,
23
- modal?: ModalOptions,
24
- }) {
25
-
26
- const [loading, setLoading] = useState(false)
27
- const formContext = useContext(FormContext)
28
- const tableContext = useContext(TableContext)
29
- const modalContext = useContext(ModalContext)
30
-
31
- const onClick = async () => {
32
- try {
33
- setLoading(true)
34
- const handleAfterAction = async (req?: RequestOptions) => {
35
- if (req?.afterAction?.includes('tableReload')) {
36
- if (modalContext.contexts) {
37
- modalContext.setAfterClose(() => {
38
- modalContext.contexts?.tableContext?.actionRef.reload()
39
- })
40
- }
41
- if (tableContext.actionRef) {
42
- await tableContext.actionRef.reload()
43
- }
44
- }
45
- if (req?.afterAction?.includes('closeModal') && modalContext.inModal) {
46
- modalContext.closeModal()
47
- }
48
- }
49
-
50
- if (props.submit) {
51
- formContext.formRef?.current?.submit()
52
- return
53
- }
54
- if (props.request) {
55
- await http({
56
- method: props.request.method,
57
- url: props.request.url,
58
- headers: props.request.headers || {},
59
- data: replaceParams(props.request.data || {}, {
60
- ...(await formContext.formRef?.current?.getFieldsValue()),
61
- })
62
- })
63
-
64
- await handleAfterAction(props.request)
65
- return
66
- }
67
- if (props.modal) {
68
- await modal({
69
- ...props.modal,
70
- content: {
71
- ...props.modal.content,
72
- url: replaceUrl(props.modal.content.url as string, formContext.formRef?.current?.getFieldsValue())
73
- }
74
- })
75
- return
76
- }
77
-
78
- if (props.link) {
79
- routerNavigateTo(replaceUrl(props.link.url, await formContext.formRef?.current?.getFieldsValue()))
80
- return
81
- }
82
- if (props.reset) {
83
- formContext.formRef?.current?.resetFields()
84
- return
85
- }
86
- if (props.back) {
87
- history.back()
88
- return
89
- }
90
- } finally {
91
- setLoading(false)
92
- }
93
- }
94
-
95
- useEffect(() => {
96
- if (props.submit) {
97
- setLoading(props.loading || false)
98
- }
99
- }, [props.loading]);
100
-
101
- const MyButton = ({onClick}: {
102
- onClick?: () => void,
103
- }) => {
104
-
105
- return <>
106
- <Button {...props.props}
107
- onClick={onClick}
108
- loading={loading}
109
- >{props.title}</Button>
110
- </>
111
- }
112
-
113
- const confirm = (typeof props.submit === 'object' ? props.submit.confirm : null)
114
- || props.request?.confirm
115
-
116
- return <>
117
- {
118
- confirm ?
119
- <Popconfirm title={confirm} onConfirm={onClick}>
120
- <MyButton></MyButton>
121
- </Popconfirm>
122
- : <MyButton onClick={onClick}></MyButton>
123
- }
124
- </>
1
+ import {FormActionType} from "./types";
2
+ import {Button, Popconfirm} from "antd";
3
+ import {useContext, useEffect, useState} from "react";
4
+ import http from "../../../lib/http";
5
+ import {FormContext} from "../../FormContext";
6
+ import {modalShow, replaceParams, replaceUrl, routerNavigateTo} from "../../../lib/helpers";
7
+ import {ModalContext} from "../../ModalContext";
8
+ import {TableContext} from "../../TableContext";
9
+
10
+ export default function (props: FormActionType & {
11
+ props: any,
12
+
13
+ // 操作
14
+ submit?: boolean | {
15
+ confirm?: string
16
+ },
17
+ request?: RequestOptions,
18
+ link?: {
19
+ url: string,
20
+ }
21
+ back?: boolean,
22
+ reset?: boolean,
23
+ modal?: ModalOptions,
24
+ }) {
25
+
26
+ const [loading, setLoading] = useState(false)
27
+ const formContext = useContext(FormContext)
28
+ const tableContext = useContext(TableContext)
29
+ const modalContext = useContext(ModalContext)
30
+
31
+ const onClick = async () => {
32
+ try {
33
+ setLoading(true)
34
+ const handleAfterAction = async (req?: RequestOptions) => {
35
+ if (req?.afterAction?.includes('tableReload')) {
36
+ if (modalContext.contexts) {
37
+ modalContext.setAfterClose(() => {
38
+ modalContext.contexts?.tableContext?.actionRef.reload()
39
+ })
40
+ }
41
+ if (tableContext.actionRef) {
42
+ await tableContext.actionRef.reload()
43
+ }
44
+ }
45
+ if (req?.afterAction?.includes('closeModal') && modalContext.inModal) {
46
+ modalContext.closeModal()
47
+ }
48
+ }
49
+
50
+ if (props.submit) {
51
+ formContext.formRef?.current?.submit()
52
+ return
53
+ }
54
+ if (props.request) {
55
+ await http({
56
+ method: props.request.method,
57
+ url: props.request.url,
58
+ headers: props.request.headers || {},
59
+ data: replaceParams(props.request.data || {}, {
60
+ ...(await formContext.formRef?.current?.getFieldsValue()),
61
+ })
62
+ })
63
+
64
+ await handleAfterAction(props.request)
65
+ return
66
+ }
67
+ if (props.modal) {
68
+ await modalShow({
69
+ ...props.modal,
70
+ content: {
71
+ ...props.modal.content,
72
+ url: replaceUrl(props.modal.content.url as string, formContext.formRef?.current?.getFieldsValue())
73
+ }
74
+ })
75
+ return
76
+ }
77
+
78
+ if (props.link) {
79
+ routerNavigateTo(replaceUrl(props.link.url, await formContext.formRef?.current?.getFieldsValue()))
80
+ return
81
+ }
82
+ if (props.reset) {
83
+ formContext.formRef?.current?.resetFields()
84
+ return
85
+ }
86
+ if (props.back) {
87
+ if (modalContext.inModal) {
88
+ modalContext.closeModal()
89
+ } else {
90
+ history.back()
91
+ }
92
+ return
93
+ }
94
+ } finally {
95
+ setLoading(false)
96
+ }
97
+ }
98
+
99
+ useEffect(() => {
100
+ if (props.submit) {
101
+ setLoading(props.loading || false)
102
+ }
103
+ }, [props.loading]);
104
+
105
+ const MyButton = ({onClick}: {
106
+ onClick?: () => void,
107
+ }) => {
108
+
109
+ return <>
110
+ <Button {...props.props}
111
+ onClick={onClick}
112
+ loading={loading}
113
+ >{props.title}</Button>
114
+ </>
115
+ }
116
+
117
+ const confirm = (typeof props.submit === 'object' ? props.submit.confirm : null)
118
+ || props.request?.confirm
119
+
120
+ return <>
121
+ {
122
+ confirm ?
123
+ <Popconfirm title={confirm} onConfirm={onClick}>
124
+ <MyButton></MyButton>
125
+ </Popconfirm>
126
+ : <MyButton onClick={onClick}></MyButton>
127
+ }
128
+ </>
125
129
  }
@@ -1,5 +1,6 @@
1
- export type FormActionType = {
2
- type: string,
3
- title: string,
4
- loading?: boolean,
1
+ export type FormActionType = {
2
+ type: string,
3
+ title: string,
4
+ loading?: boolean,
5
+ badge?: string | number
5
6
  }
@@ -1,35 +1,39 @@
1
- import {FormActionType} from "./Action/types";
2
- import {lazy, useEffect, useState} from "react";
3
- import {ReactComponentLike} from "prop-types";
4
- import {Space} from "antd";
5
- import container from "../../lib/container";
6
- import upperFirst from "lodash/upperFirst";
7
-
8
- export default function (props: {
9
- actions?: FormActionType[]
10
- loading?: boolean
11
- }) {
12
- const [components, setComponents] = useState<{
13
- Component: ReactComponentLike,
14
- props: FormActionType,
15
- }[]>([])
16
-
17
- useEffect(() => {
18
- setComponents(props.actions?.map(a => {
19
- return {
20
- Component: lazy(container.get('Form.Action.' + upperFirst(a.type))),
21
- props: {
22
- ...a,
23
- },
24
- }
25
- }) || [])
26
- }, []);
27
-
28
- return <>
29
- <Space>
30
- {components.map(item => (
31
- <item.Component key={item.props.title} loading={props.loading} {...item.props}></item.Component>
32
- ))}
33
- </Space>
34
- </>
1
+ import {FormActionType} from "./Action/types";
2
+ import {lazy, useEffect, useState} from "react";
3
+ import {ReactComponentLike} from "prop-types";
4
+ import {Badge, Space} from "antd";
5
+ import container from "../../lib/container";
6
+ import {upperFirst} from "lodash";
7
+
8
+ export default function (props: {
9
+ actions?: FormActionType[]
10
+ loading?: boolean
11
+ }) {
12
+ const [components, setComponents] = useState<{
13
+ Component: ReactComponentLike,
14
+ props: FormActionType,
15
+ }[]>([])
16
+
17
+ useEffect(() => {
18
+ setComponents(props.actions?.map(a => {
19
+ return {
20
+ Component: lazy(container.get('Form.Action.' + upperFirst(a.type))),
21
+ props: {
22
+ ...a,
23
+ },
24
+ }
25
+ }) || [])
26
+ }, []);
27
+
28
+ return <>
29
+ <Space>
30
+ {components.map(item => (
31
+ item.props.badge ?
32
+ <Badge key={item.props.title} count={item.props.badge} style={{zIndex: 100}}>
33
+ <item.Component loading={props.loading} {...item.props}></item.Component>
34
+ </Badge> :
35
+ <item.Component key={item.props.title} loading={props.loading} {...item.props}></item.Component>
36
+ ))}
37
+ </Space>
38
+ </>
35
39
  }