@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.
- package/dist/components/Column/Cascader.d.ts +3 -0
- package/dist/components/Column/Cascader.js +110 -0
- package/dist/components/Column/File.d.ts +18 -0
- package/dist/components/Column/File.js +176 -0
- package/dist/components/Column/Image.d.ts +10 -0
- package/dist/components/Column/Image.js +104 -0
- package/dist/components/Column/Readonly/Action/Link.d.ts +11 -0
- package/dist/components/Column/Readonly/Action/Link.js +114 -0
- package/dist/components/Column/Readonly/Action/index.d.ts +4 -0
- package/dist/components/Column/Readonly/Action/index.js +3 -0
- package/dist/components/Column/Readonly/Action.d.ts +12 -0
- package/dist/components/Column/Readonly/Action.js +96 -0
- package/dist/components/Column/Readonly/Cascader.d.ts +9 -0
- package/dist/components/Column/Readonly/Cascader.js +52 -0
- package/dist/components/Column/Readonly/File.d.ts +8 -0
- package/dist/components/Column/Readonly/File.js +54 -0
- package/dist/components/Column/Readonly/Image.d.ts +3 -0
- package/dist/components/Column/Readonly/Image.js +69 -0
- package/dist/components/Column/Readonly/Ueditor.d.ts +3 -0
- package/dist/components/Column/Readonly/Ueditor.js +24 -0
- package/dist/components/Column/Readonly/index.d.ts +8 -0
- package/dist/components/Column/Readonly/index.js +7 -0
- package/dist/components/Column/Ueditor.d.ts +27 -0
- package/dist/components/Column/Ueditor.js +333 -0
- package/dist/components/Column/index.d.ts +7 -0
- package/dist/components/Column/index.js +6 -0
- package/dist/components/Form/Action/Button.d.ts +15 -0
- package/dist/components/Form/Action/Button.js +194 -0
- package/dist/components/Form/Action/index.d.ts +4 -0
- package/dist/components/Form/Action/index.js +3 -0
- package/dist/components/Form/Actions.d.ts +6 -0
- package/dist/components/Form/Actions.js +48 -0
- package/dist/components/Form.d.ts +20 -0
- package/dist/components/Form.js +217 -0
- package/dist/components/FormContext.d.ts +7 -0
- package/dist/components/FormContext.js +2 -0
- package/dist/components/Layout/New.d.ts +7 -0
- package/dist/components/Layout/New.js +257 -0
- package/dist/components/Layout.d.ts +4 -0
- package/dist/components/Layout.js +67 -0
- package/dist/components/LayoutContext.d.ts +26 -0
- package/dist/components/LayoutContext.js +2 -0
- package/dist/components/ModalContext.d.ts +8 -0
- package/dist/components/ModalContext.js +6 -0
- package/dist/components/Table/Action/Button.d.ts +10 -0
- package/dist/components/Table/Action/Button.js +166 -0
- package/dist/components/Table/Action/StartEditable.d.ts +10 -0
- package/dist/components/Table/Action/StartEditable.js +79 -0
- package/dist/components/Table/Action/index.d.ts +5 -0
- package/dist/components/Table/Action/index.js +4 -0
- package/dist/components/Table/ToolbarActions.d.ts +6 -0
- package/dist/components/Table/ToolbarActions.js +52 -0
- package/dist/components/Table.d.ts +19 -0
- package/dist/components/Table.js +322 -0
- package/dist/components/TableContext.d.ts +14 -0
- package/dist/components/TableContext.js +2 -0
- package/dist/components/Tabs.d.ts +15 -0
- package/dist/components/Tabs.js +62 -0
- package/dist/env.d.ts +1 -0
- package/dist/global.d.ts +6 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/lib/container.d.ts +9 -0
- package/dist/lib/container.js +93 -0
- package/dist/lib/customRule.d.ts +3 -0
- package/dist/lib/customRule.js +7 -0
- package/dist/lib/global.d.ts +9 -0
- package/dist/lib/global.js +2 -0
- package/dist/lib/helpers.d.ts +14 -0
- package/dist/lib/helpers.js +183 -0
- package/dist/lib/http.d.ts +5 -0
- package/dist/lib/http.js +72 -0
- package/dist/lib/schemaHandler.d.ts +5 -0
- package/dist/lib/schemaHandler.js +133 -0
- package/dist/lib/upload.d.ts +20 -0
- package/dist/lib/upload.js +215 -0
- package/dist/lib/writeExtra.d.ts +1 -0
- package/dist/lib/writeExtra.js +28 -0
- package/dist/types.d.ts +25 -0
- package/package.json +14 -8
- package/components/Column/Cascader.tsx +0 -79
- package/components/Column/File.tsx +0 -166
- package/components/Column/Image.tsx +0 -77
- package/components/Column/Readonly/Action/Link.tsx +0 -78
- package/components/Column/Readonly/Action.tsx +0 -80
- package/components/Column/Readonly/Cascader.tsx +0 -51
- package/components/Column/Readonly/File.tsx +0 -53
- package/components/Column/Readonly/Image.tsx +0 -39
- package/components/Column/Readonly/Ueditor.tsx +0 -18
- package/components/Column/Ueditor.tsx +0 -314
- package/components/Form/Action/Button.tsx +0 -129
- package/components/Form/Actions.tsx +0 -39
- package/components/Form.tsx +0 -177
- package/components/FormContext.ts +0 -9
- package/components/Layout/New.tsx +0 -252
- package/components/Layout.tsx +0 -52
- package/components/LayoutContext.ts +0 -26
- package/components/ModalContext.ts +0 -16
- package/components/Table/Action/Button.tsx +0 -89
- package/components/Table/Action/StartEditable.tsx +0 -59
- package/components/Table/ToolbarActions.tsx +0 -44
- package/components/Table.tsx +0 -280
- package/components/TableContext.ts +0 -15
- package/components/Tabs.tsx +0 -72
- package/lib/container.ts +0 -84
- package/lib/customRule.ts +0 -10
- package/lib/global.ts +0 -11
- package/lib/helpers.tsx +0 -146
- package/lib/http.ts +0 -74
- package/lib/schemaHandler.ts +0 -122
- package/lib/upload.ts +0 -177
- package/lib/writeExtra.js +0 -31
- /package/{components → dist/components}/Column/Readonly/Action/types.d.ts +0 -0
- /package/{components → dist/components}/Column/Readonly/types.d.ts +0 -0
- /package/{components → dist/components}/Column/types.d.ts +0 -0
- /package/{components → dist/components}/Form/Action/types.d.ts +0 -0
- /package/{components → dist/components}/Table/Action/types.d.ts +0 -0
- /package/{components → dist/components}/Table.scss +0 -0
- /package/{components → dist/components}/types.d.ts +0 -0
|
@@ -1,129 +0,0 @@
|
|
|
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
|
-
</>
|
|
129
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
</>
|
|
39
|
-
}
|
package/components/Form.tsx
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import {BetaSchemaForm, ProFormColumnsType, ProFormInstance, ProSkeleton} from "@ant-design/pro-components";
|
|
2
|
-
import type {FormSchema} from "@ant-design/pro-form/es/components/SchemaForm/typing";
|
|
3
|
-
import React, {lazy, Suspense, useContext, useEffect, useRef, useState} from "react";
|
|
4
|
-
import {cloneDeep, upperFirst} from "lodash";
|
|
5
|
-
import container from "../lib/container";
|
|
6
|
-
import {FormActionType} from "./Form/Action/types";
|
|
7
|
-
import Actions from "./Form/Actions";
|
|
8
|
-
import {FormContext} from "./FormContext";
|
|
9
|
-
import {Col, Row, Spin} from "antd";
|
|
10
|
-
import http from "../lib/http";
|
|
11
|
-
import customRule from "../lib/customRule";
|
|
12
|
-
import {ModalContext} from "./ModalContext";
|
|
13
|
-
import {TableContext} from "./TableContext";
|
|
14
|
-
import {commonHandler} from "../lib/schemaHandler";
|
|
15
|
-
import {Rule} from "antd/es/form";
|
|
16
|
-
|
|
17
|
-
type SubmitRequestType = {
|
|
18
|
-
url: string,
|
|
19
|
-
method?: string,
|
|
20
|
-
data?: any,
|
|
21
|
-
afterSubmit?: () => void,
|
|
22
|
-
headers?: Record<string, string>
|
|
23
|
-
afterAction?: string[],
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export default function (props: FormSchema & {
|
|
28
|
-
actions?: FormActionType[]
|
|
29
|
-
metaTitle?: string,
|
|
30
|
-
columns?: ProFormColumnsType[],
|
|
31
|
-
submitRequest?: SubmitRequestType,
|
|
32
|
-
extraRenderValues?: Record<string, any>,
|
|
33
|
-
}) {
|
|
34
|
-
|
|
35
|
-
const [columns, setColumns] = useState<ProFormColumnsType[]>([])
|
|
36
|
-
const formRef = useRef<ProFormInstance>()
|
|
37
|
-
const [initialized, setInitialized] = useState(false)
|
|
38
|
-
const [loading, setLoading] = useState(false)
|
|
39
|
-
const hiddenField = useRef<Record<string, any>>({})
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
setColumns((cloneDeep(props.columns)?.map((c: ProFormColumnsType & {
|
|
43
|
-
formItemProps?: {
|
|
44
|
-
rules?: (Rule & {
|
|
45
|
-
customType?: string
|
|
46
|
-
})[]
|
|
47
|
-
}
|
|
48
|
-
}) => {
|
|
49
|
-
// rules
|
|
50
|
-
if (!c.formItemProps) {
|
|
51
|
-
c.formItemProps = {}
|
|
52
|
-
}
|
|
53
|
-
if (!c.formItemProps?.rules) {
|
|
54
|
-
c.formItemProps.rules = []
|
|
55
|
-
}
|
|
56
|
-
c.formItemProps.rules = c.formItemProps.rules.map(rule => {
|
|
57
|
-
if (rule.customType && customRule[rule.customType]) {
|
|
58
|
-
rule.validator = customRule[rule.customType]
|
|
59
|
-
}
|
|
60
|
-
return rule
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
// hideInForm时增加
|
|
64
|
-
if (c.hideInForm) {
|
|
65
|
-
hiddenField.current[c.dataIndex as string] = props.initialValues?.[c.dataIndex as string]
|
|
66
|
-
return null
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// item render
|
|
70
|
-
const formItemComponent = 'Column.' + upperFirst(c.valueType as string)
|
|
71
|
-
if (container.check(formItemComponent)) {
|
|
72
|
-
const Component = lazy(container.get(formItemComponent))
|
|
73
|
-
c.renderFormItem = (schema, config, form) =>
|
|
74
|
-
<Suspense fallback={<Spin/>}>
|
|
75
|
-
<Component config={config}
|
|
76
|
-
form={form}
|
|
77
|
-
fieldProps={c.fieldProps}
|
|
78
|
-
key={c.title as string}
|
|
79
|
-
rules={c.formItemProps?.rules}
|
|
80
|
-
dataIndex={c.dataIndex}
|
|
81
|
-
></Component>
|
|
82
|
-
</Suspense>
|
|
83
|
-
}
|
|
84
|
-
// readonly render
|
|
85
|
-
const readonlyComponent = 'Column.Readonly.' + upperFirst(c.valueType as string)
|
|
86
|
-
if (container.check(readonlyComponent)) {
|
|
87
|
-
const Component = lazy(container.get(readonlyComponent))
|
|
88
|
-
c.render = (dom, entity, index, action, schema) =>
|
|
89
|
-
<Suspense fallback={<Spin/>}>
|
|
90
|
-
<Component key={c.title as string}
|
|
91
|
-
entity={entity}
|
|
92
|
-
index={index}
|
|
93
|
-
action={action}
|
|
94
|
-
schema={schema}
|
|
95
|
-
dom={dom}
|
|
96
|
-
></Component>
|
|
97
|
-
</Suspense>
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
commonHandler(c)
|
|
101
|
-
if (container.schemaHandler[c.valueType as string]) {
|
|
102
|
-
return container.schemaHandler[c.valueType as string](c)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return c
|
|
106
|
-
}).filter(c => !!c) || []) as ProFormColumnsType[])
|
|
107
|
-
|
|
108
|
-
setInitialized(true)
|
|
109
|
-
}, []);
|
|
110
|
-
|
|
111
|
-
const modalContext = useContext(ModalContext)
|
|
112
|
-
const tableContext = useContext(TableContext)
|
|
113
|
-
|
|
114
|
-
const handleAfterAction = async (req?: SubmitRequestType) => {
|
|
115
|
-
if (req?.afterAction?.includes('tableReload')) {
|
|
116
|
-
if (modalContext.contexts) {
|
|
117
|
-
modalContext.setAfterClose(() => {
|
|
118
|
-
modalContext.contexts?.tableContext?.actionRef.reload()
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
if (tableContext.actionRef) {
|
|
122
|
-
await tableContext.actionRef.reload()
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (req?.afterAction?.includes('closeModal') && modalContext.inModal) {
|
|
126
|
-
modalContext.closeModal()
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const onFinish = async (values: any) => {
|
|
131
|
-
if (props.submitRequest) {
|
|
132
|
-
setLoading(true)
|
|
133
|
-
try {
|
|
134
|
-
await http({
|
|
135
|
-
method: props.submitRequest.method,
|
|
136
|
-
url: props.submitRequest.url,
|
|
137
|
-
data: Object.assign({}, hiddenField.current, props.submitRequest.data, values),
|
|
138
|
-
headers: props.submitRequest.headers,
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
handleAfterAction(props.submitRequest)
|
|
142
|
-
} finally {
|
|
143
|
-
setLoading(false)
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return <>
|
|
149
|
-
<Row justify={'center'}>
|
|
150
|
-
<Col sm={24} md={22} lg={20}>
|
|
151
|
-
<FormContext.Provider value={{
|
|
152
|
-
formRef: formRef,
|
|
153
|
-
extraRenderValues: props.extraRenderValues,
|
|
154
|
-
}}>
|
|
155
|
-
{!initialized
|
|
156
|
-
? <ProSkeleton type={"list"} list={2}></ProSkeleton>
|
|
157
|
-
: <BetaSchemaForm columns={columns}
|
|
158
|
-
colProps={props.colProps}
|
|
159
|
-
readonly={props.readonly}
|
|
160
|
-
grid={true}
|
|
161
|
-
loading={loading}
|
|
162
|
-
formRef={formRef}
|
|
163
|
-
initialValues={props.initialValues}
|
|
164
|
-
onFinish={onFinish}
|
|
165
|
-
submitter={{
|
|
166
|
-
render: () => [
|
|
167
|
-
<Actions key={'actions'} loading={loading}
|
|
168
|
-
actions={props.actions}></Actions>
|
|
169
|
-
]
|
|
170
|
-
}}
|
|
171
|
-
></BetaSchemaForm>
|
|
172
|
-
}
|
|
173
|
-
</FormContext.Provider>
|
|
174
|
-
</Col>
|
|
175
|
-
</Row>
|
|
176
|
-
</>
|
|
177
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ProFormInstance} from "@ant-design/pro-components";
|
|
2
|
-
import {createContext, MutableRefObject} from "react";
|
|
3
|
-
|
|
4
|
-
export type FormContextProps = {
|
|
5
|
-
formRef?: MutableRefObject<ProFormInstance | undefined>,
|
|
6
|
-
extraRenderValues?: Record<string, any>
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const FormContext = createContext<FormContextProps>({})
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import {MenuDataItem, PageContainer, ProConfigProvider, ProLayout} from "@ant-design/pro-components";
|
|
2
|
-
import {Button, Dropdown, Menu, Space} from "antd";
|
|
3
|
-
import type {LayoutProps} from "../LayoutContext";
|
|
4
|
-
import {LayoutContext} from "../LayoutContext";
|
|
5
|
-
import {useEffect, useRef, useState} from "react";
|
|
6
|
-
import {usePage} from "@inertiajs/react";
|
|
7
|
-
import {routerNavigateTo} from "../../lib/helpers";
|
|
8
|
-
import {MenuInfo} from "rc-menu/lib/interface";
|
|
9
|
-
import http from "../../lib/http";
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
import {Route} from '@ant-design/pro-layout/lib/typing';
|
|
12
|
-
import {assign} from "lodash";
|
|
13
|
-
import {MoonOutlined, SunOutlined} from "@ant-design/icons";
|
|
14
|
-
|
|
15
|
-
export default function ({children, pageTitle, siteTitle}: {
|
|
16
|
-
children: React.ReactNode,
|
|
17
|
-
pageTitle: string,
|
|
18
|
-
siteTitle: string,
|
|
19
|
-
}) {
|
|
20
|
-
|
|
21
|
-
const pageProps = usePage<{
|
|
22
|
-
layoutProps: LayoutProps,
|
|
23
|
-
}>().props
|
|
24
|
-
|
|
25
|
-
const layoutProps = pageProps.layoutProps
|
|
26
|
-
const contentRef = useRef<HTMLDivElement>(null)
|
|
27
|
-
|
|
28
|
-
const [props, setProps] = useState<LayoutProps>({
|
|
29
|
-
title: '',
|
|
30
|
-
metaTitle: '',
|
|
31
|
-
topMenuActiveKey: '',
|
|
32
|
-
menuActiveKey: '',
|
|
33
|
-
loading: false,
|
|
34
|
-
topMenu: [],
|
|
35
|
-
menuList: [],
|
|
36
|
-
logo: '',
|
|
37
|
-
userMenu: [],
|
|
38
|
-
})
|
|
39
|
-
const [theme, setTheme] = useState<'light' | 'realDark'>('light')
|
|
40
|
-
|
|
41
|
-
const assignProps = (newProps: LayoutProps) => {
|
|
42
|
-
setProps(assign(props, newProps))
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const headerContentRender = () => {
|
|
46
|
-
return <>
|
|
47
|
-
<Menu items={props.topMenu}
|
|
48
|
-
mode={'horizontal'}
|
|
49
|
-
activeKey={props.topMenuActiveKey}
|
|
50
|
-
/>
|
|
51
|
-
</>
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const [openKeys, setOpenKeys] = useState<string[]>([])
|
|
55
|
-
const [route, setRoute] = useState<Route>()
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
function findKeyPath(key: string, list: MenuDataItem[]): string[] {
|
|
59
|
-
for (let i = 0; i < list.length; i++) {
|
|
60
|
-
const item = list[i];
|
|
61
|
-
if (item.key === key) {
|
|
62
|
-
return [item.key]
|
|
63
|
-
} else if (item.children?.length) {
|
|
64
|
-
const path = findKeyPath(key, item.children)
|
|
65
|
-
if (path?.length) {
|
|
66
|
-
return [item.key as string, ...path]
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return []
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!props.menuActiveKey) {
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
setOpenKeys(findKeyPath(props.menuActiveKey, props.menuList || []))
|
|
77
|
-
|
|
78
|
-
}, [props.menuActiveKey]);
|
|
79
|
-
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
if (pageProps.layoutProps?.menuActiveKey) {
|
|
82
|
-
assignProps({
|
|
83
|
-
menuActiveKey: pageProps.layoutProps.menuActiveKey
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const title = props.title || layoutProps.title
|
|
88
|
-
if (pageProps.layoutProps?.metaTitle) {
|
|
89
|
-
assignProps({
|
|
90
|
-
metaTitle: pageProps.layoutProps.metaTitle + ' | ' + title
|
|
91
|
-
})
|
|
92
|
-
} else {
|
|
93
|
-
assignProps({
|
|
94
|
-
metaTitle: title
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
}, [pageProps.layoutProps]);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
|
|
102
|
-
setProps({
|
|
103
|
-
title: layoutProps.title || '',
|
|
104
|
-
metaTitle: '',
|
|
105
|
-
topMenuActiveKey: layoutProps.topMenuActiveKey,
|
|
106
|
-
menuActiveKey: layoutProps.menuActiveKey,
|
|
107
|
-
loading: false,
|
|
108
|
-
topMenu: layoutProps.topMenu,
|
|
109
|
-
menuList: layoutProps.menuList,
|
|
110
|
-
logo: layoutProps.logo,
|
|
111
|
-
userMenu: layoutProps.userMenu,
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
const r = {
|
|
115
|
-
key: '/',
|
|
116
|
-
routes: layoutProps.menuList?.map(menu => {
|
|
117
|
-
return {
|
|
118
|
-
name: menu.name,
|
|
119
|
-
key: menu.key,
|
|
120
|
-
children: menu.children?.map(child => {
|
|
121
|
-
return {
|
|
122
|
-
name: child.name,
|
|
123
|
-
key: child.key
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
setRoute(r)
|
|
131
|
-
|
|
132
|
-
// 设置内容高度
|
|
133
|
-
function onResize() {
|
|
134
|
-
if (contentRef.current) {
|
|
135
|
-
contentRef.current.style.minHeight = Math.max(window.innerHeight - 200, 200) + 'px'
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
onResize()
|
|
140
|
-
window.addEventListener('resize', onResize)
|
|
141
|
-
return () => {
|
|
142
|
-
window.removeEventListener('resize', onResize)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
}, [])
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const onMenuClick = (info: MenuInfo) => {
|
|
149
|
-
const keyPath = info.keyPath.reverse()
|
|
150
|
-
let menu: MenuDataItem | undefined = props.menuList?.find(menu => menu.key === keyPath[0]);
|
|
151
|
-
for (let i = 1; i < keyPath.length; i++) {
|
|
152
|
-
menu = menu?.children?.find(m => m.key === keyPath[i])
|
|
153
|
-
}
|
|
154
|
-
if (menu?.path) {
|
|
155
|
-
assignProps({
|
|
156
|
-
loading: true
|
|
157
|
-
})
|
|
158
|
-
routerNavigateTo(menu.path, {
|
|
159
|
-
onSuccess() {
|
|
160
|
-
assignProps({
|
|
161
|
-
menuActiveKey: info.key
|
|
162
|
-
})
|
|
163
|
-
},
|
|
164
|
-
onFinish() {
|
|
165
|
-
assignProps({
|
|
166
|
-
loading: false
|
|
167
|
-
})
|
|
168
|
-
}
|
|
169
|
-
})
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const actionsRender = () => <>
|
|
174
|
-
<Space>
|
|
175
|
-
<Button type={'text'} onClick={() => {
|
|
176
|
-
setTheme(theme === 'light' ? 'realDark' : 'light')
|
|
177
|
-
}}>
|
|
178
|
-
{theme === 'realDark' ? <MoonOutlined/> : <SunOutlined/>}
|
|
179
|
-
</Button>
|
|
180
|
-
</Space>
|
|
181
|
-
</>
|
|
182
|
-
|
|
183
|
-
return <>
|
|
184
|
-
<LayoutContext.Provider value={{
|
|
185
|
-
assignProps,
|
|
186
|
-
props,
|
|
187
|
-
}}>
|
|
188
|
-
<ProConfigProvider dark={theme === 'realDark'}>
|
|
189
|
-
<ProLayout title={siteTitle}
|
|
190
|
-
loading={props.loading}
|
|
191
|
-
layout="mix"
|
|
192
|
-
actionsRender={actionsRender}
|
|
193
|
-
route={route}
|
|
194
|
-
fixSiderbar={true}
|
|
195
|
-
logo={props.logo}
|
|
196
|
-
headerContentRender={headerContentRender}
|
|
197
|
-
pageTitleRender={p => `${pageTitle} | ${siteTitle} 后台管理`}
|
|
198
|
-
footerRender={() => <>
|
|
199
|
-
<Space>
|
|
200
|
-
<a href="https://www.quansitech.com/" target={'_blank'}>全思科技</a>
|
|
201
|
-
<a href="https://github.com/quansitech/" target={'_blank'}>Github</a>
|
|
202
|
-
</Space>
|
|
203
|
-
</>}
|
|
204
|
-
avatarProps={{
|
|
205
|
-
title: 'admin',
|
|
206
|
-
render(p, dom) {
|
|
207
|
-
return <>
|
|
208
|
-
<Dropdown menu={{
|
|
209
|
-
items: props.userMenu?.map(menu => {
|
|
210
|
-
return {
|
|
211
|
-
label: menu.title,
|
|
212
|
-
key: menu.url,
|
|
213
|
-
onClick() {
|
|
214
|
-
switch (menu.type) {
|
|
215
|
-
case 'open':
|
|
216
|
-
window.open(menu.url)
|
|
217
|
-
break;
|
|
218
|
-
case 'nav':
|
|
219
|
-
routerNavigateTo(menu.url)
|
|
220
|
-
break
|
|
221
|
-
case 'ajax':
|
|
222
|
-
http.get(menu.url).then(() => {
|
|
223
|
-
window.location.reload()
|
|
224
|
-
})
|
|
225
|
-
break
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}) || [],
|
|
230
|
-
}}>
|
|
231
|
-
{dom}
|
|
232
|
-
</Dropdown>
|
|
233
|
-
</>
|
|
234
|
-
}
|
|
235
|
-
}}
|
|
236
|
-
menuProps={{
|
|
237
|
-
activeKey: props.menuActiveKey as string,
|
|
238
|
-
selectedKeys: [props.menuActiveKey as string],
|
|
239
|
-
openKeys: openKeys,
|
|
240
|
-
onClick: onMenuClick,
|
|
241
|
-
onOpenChange: setOpenKeys
|
|
242
|
-
}}
|
|
243
|
-
>
|
|
244
|
-
|
|
245
|
-
<PageContainer title={pageTitle}>
|
|
246
|
-
<div ref={contentRef}>{children}</div>
|
|
247
|
-
</PageContainer>
|
|
248
|
-
</ProLayout>
|
|
249
|
-
</ProConfigProvider>
|
|
250
|
-
</LayoutContext.Provider>
|
|
251
|
-
</>
|
|
252
|
-
}
|
package/components/Layout.tsx
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {Head, usePage} from "@inertiajs/react";
|
|
2
|
-
import {useEffect, useState} from "react";
|
|
3
|
-
import {PageProps} from "@inertiajs/core/types/types";
|
|
4
|
-
import New from "./Layout/New";
|
|
5
|
-
import {PageContainer} from "@ant-design/pro-components"
|
|
6
|
-
import {App} from "antd";
|
|
7
|
-
import global from "../lib/global";
|
|
8
|
-
|
|
9
|
-
export default function ({children}: {
|
|
10
|
-
children: React.ReactNode
|
|
11
|
-
}) {
|
|
12
|
-
const pageProps: PageProps & {
|
|
13
|
-
layoutProps?: {
|
|
14
|
-
metaTitle?: string,
|
|
15
|
-
enableNewLayout?: boolean
|
|
16
|
-
title?: string,
|
|
17
|
-
}
|
|
18
|
-
} = usePage().props
|
|
19
|
-
const {modal, notification, message} = App.useApp()
|
|
20
|
-
const [enableNewLayout, setEnableNewLayout] = useState(false)
|
|
21
|
-
const [pageTitle, setPageTitle] = useState('')
|
|
22
|
-
const [siteTitle, setSiteTitle] = useState('')
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
console.log(pageProps)
|
|
26
|
-
|
|
27
|
-
if (pageProps.layoutProps?.enableNewLayout) {
|
|
28
|
-
setEnableNewLayout(true)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
global.modal = modal
|
|
32
|
-
global.notification = notification
|
|
33
|
-
global.message = message
|
|
34
|
-
}, [])
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
setPageTitle(pageProps.layoutProps?.metaTitle || '')
|
|
38
|
-
pageProps.layoutProps?.title && setSiteTitle(pageProps.layoutProps?.title + '')
|
|
39
|
-
}, [pageProps.layoutProps]);
|
|
40
|
-
|
|
41
|
-
return <>
|
|
42
|
-
{enableNewLayout
|
|
43
|
-
? <New pageTitle={pageTitle} siteTitle={siteTitle} children={children}></New>
|
|
44
|
-
: <>
|
|
45
|
-
<Head title={pageTitle + ' | ' + siteTitle + ' 后台管理'}></Head>
|
|
46
|
-
<PageContainer title={pageTitle}>
|
|
47
|
-
{children}
|
|
48
|
-
</PageContainer>
|
|
49
|
-
</>
|
|
50
|
-
}
|
|
51
|
-
</>
|
|
52
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {createContext} from "react";
|
|
2
|
-
import {MenuDataItem} from "@ant-design/pro-components";
|
|
3
|
-
|
|
4
|
-
declare type LayoutContextValue = {
|
|
5
|
-
assignProps: (props: LayoutProps) => void,
|
|
6
|
-
props: LayoutProps,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export declare type LayoutProps = {
|
|
10
|
-
title?: string,
|
|
11
|
-
metaTitle?: string,
|
|
12
|
-
topMenuActiveKey?: string,
|
|
13
|
-
menuActiveKey?: string,
|
|
14
|
-
loading?: boolean,
|
|
15
|
-
topMenu?: { name: string, key: string }[],
|
|
16
|
-
menuList?: MenuDataItem[],
|
|
17
|
-
logo?: string,
|
|
18
|
-
userMenu?: {
|
|
19
|
-
title: string,
|
|
20
|
-
url: string,
|
|
21
|
-
type: string,
|
|
22
|
-
|
|
23
|
-
}[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const LayoutContext = createContext<LayoutContextValue>({} as LayoutContextValue)
|