@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.
- package/components/Column/Cascader.tsx +78 -78
- package/components/Column/File.tsx +165 -167
- package/components/Column/Image.tsx +76 -76
- package/components/{Table/Option → Column/Readonly/Action}/Link.tsx +77 -67
- package/components/{Table/Option → Column/Readonly/Action}/types.d.ts +5 -4
- package/components/Column/Readonly/Action.tsx +80 -0
- package/components/Column/Readonly/Cascader.tsx +50 -50
- package/components/Column/Readonly/File.tsx +52 -53
- package/components/Column/Readonly/Image.tsx +38 -77
- package/components/Column/Readonly/Ueditor.tsx +18 -0
- package/components/Column/Readonly/types.d.ts +9 -8
- package/components/Column/Ueditor.tsx +313 -313
- package/components/Column/types.d.ts +29 -28
- package/components/Form/Action/Button.tsx +128 -124
- package/components/Form/Action/types.d.ts +5 -4
- package/components/Form/Actions.tsx +38 -34
- package/components/Form.tsx +179 -170
- package/components/FormContext.ts +8 -7
- package/components/Layout/New.tsx +252 -0
- package/components/Layout.tsx +52 -237
- package/components/LayoutContext.ts +25 -25
- package/components/ModalContext.ts +15 -15
- package/components/Table/Action/Button.tsx +88 -88
- package/components/Table/Action/StartEditable.tsx +58 -58
- package/components/Table/Action/types.d.ts +7 -6
- package/components/Table/ToolbarActions.tsx +43 -38
- package/components/Table.scss +4 -7
- package/components/Table.tsx +283 -279
- package/components/TableContext.ts +14 -13
- package/components/Tabs.tsx +71 -71
- package/lib/container.ts +83 -81
- package/lib/customRule.ts +9 -9
- package/lib/global.ts +10 -10
- package/lib/helpers.tsx +145 -149
- package/lib/http.ts +73 -73
- package/lib/schemaHandler.ts +121 -121
- package/lib/upload.ts +177 -177
- package/package.json +2 -6
- package/readme.md +128 -128
- package/components/Column/Readonly/Option.tsx +0 -58
package/components/Form.tsx
CHANGED
|
@@ -1,171 +1,180 @@
|
|
|
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 upperFirst from "lodash/upperFirst";
|
|
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 {RuleObject} from "rc-field-form/lib/interface";
|
|
12
|
-
import customRule from "../lib/customRule";
|
|
13
|
-
import cloneDeep from "lodash/cloneDeep";
|
|
14
|
-
import {ModalContext} from "./ModalContext";
|
|
15
|
-
import {TableContext} from "./TableContext";
|
|
16
|
-
import {commonHandler} from "../lib/schemaHandler";
|
|
17
|
-
|
|
18
|
-
type SubmitRequestType = {
|
|
19
|
-
url: string,
|
|
20
|
-
method?: string,
|
|
21
|
-
data?: any,
|
|
22
|
-
afterSubmit?: () => void,
|
|
23
|
-
headers?: Record<string, string>
|
|
24
|
-
afterAction?: string[],
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export default function (props: FormSchema & {
|
|
29
|
-
actions?: FormActionType[]
|
|
30
|
-
metaTitle?: string,
|
|
31
|
-
columns?: ProFormColumnsType[],
|
|
32
|
-
submitRequest?: SubmitRequestType
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
c.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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 upperFirst from "lodash/upperFirst";
|
|
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 {RuleObject} from "rc-field-form/lib/interface";
|
|
12
|
+
import customRule from "../lib/customRule";
|
|
13
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
14
|
+
import {ModalContext} from "./ModalContext";
|
|
15
|
+
import {TableContext} from "./TableContext";
|
|
16
|
+
import {commonHandler} from "../lib/schemaHandler";
|
|
17
|
+
|
|
18
|
+
type SubmitRequestType = {
|
|
19
|
+
url: string,
|
|
20
|
+
method?: string,
|
|
21
|
+
data?: any,
|
|
22
|
+
afterSubmit?: () => void,
|
|
23
|
+
headers?: Record<string, string>
|
|
24
|
+
afterAction?: string[],
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
export default function (props: FormSchema & {
|
|
29
|
+
actions?: FormActionType[]
|
|
30
|
+
metaTitle?: string,
|
|
31
|
+
columns?: ProFormColumnsType[],
|
|
32
|
+
submitRequest?: SubmitRequestType,
|
|
33
|
+
extraRenderValues?: Record<string, any>,
|
|
34
|
+
}) {
|
|
35
|
+
|
|
36
|
+
const [columns, setColumns] = useState<ProFormColumnsType[]>([])
|
|
37
|
+
const formRef = useRef<ProFormInstance>()
|
|
38
|
+
const [initialized, setInitialized] = useState(false)
|
|
39
|
+
const [loading, setLoading] = useState(false)
|
|
40
|
+
const hiddenField = useRef<Record<string, any>>({})
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
setColumns((cloneDeep(props.columns)?.map((c: ProFormColumnsType & {
|
|
44
|
+
formItemProps?: {
|
|
45
|
+
rules?: (RuleObject & {
|
|
46
|
+
customType?: string
|
|
47
|
+
})[]
|
|
48
|
+
}
|
|
49
|
+
}) => {
|
|
50
|
+
// rules
|
|
51
|
+
if (!c.formItemProps) {
|
|
52
|
+
c.formItemProps = {}
|
|
53
|
+
}
|
|
54
|
+
if (!c.formItemProps?.rules) {
|
|
55
|
+
c.formItemProps.rules = []
|
|
56
|
+
}
|
|
57
|
+
c.formItemProps.rules = c.formItemProps.rules.map(rule => {
|
|
58
|
+
if (rule.customType) {
|
|
59
|
+
if (customRule[rule.customType]) {
|
|
60
|
+
rule.validator = customRule[rule.customType]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return rule
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
// hideInForm时增加
|
|
67
|
+
if (c.hideInForm) {
|
|
68
|
+
hiddenField.current[c.dataIndex as string] = props.initialValues?.[c.dataIndex as string]
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// item render
|
|
73
|
+
const formItemComponent = 'Column.' + upperFirst(c.valueType as string)
|
|
74
|
+
if (container.check(formItemComponent)) {
|
|
75
|
+
const Component = lazy(container.get(formItemComponent))
|
|
76
|
+
c.renderFormItem = (schema, config, form) =>
|
|
77
|
+
<Suspense fallback={<Spin/>}>
|
|
78
|
+
<Component config={config}
|
|
79
|
+
form={form}
|
|
80
|
+
fieldProps={c.fieldProps}
|
|
81
|
+
key={c.title as string}
|
|
82
|
+
rules={c.formItemProps?.rules}
|
|
83
|
+
dataIndex={c.dataIndex}
|
|
84
|
+
></Component>
|
|
85
|
+
</Suspense>
|
|
86
|
+
}
|
|
87
|
+
// readonly render
|
|
88
|
+
const readonlyComponent = 'Column.Readonly.' + upperFirst(c.valueType as string)
|
|
89
|
+
if (container.check(readonlyComponent)) {
|
|
90
|
+
const Component = lazy(container.get(readonlyComponent))
|
|
91
|
+
c.render = (dom, entity, index, action, schema) =>
|
|
92
|
+
<Suspense fallback={<Spin/>}>
|
|
93
|
+
<Component key={c.title as string}
|
|
94
|
+
entity={entity}
|
|
95
|
+
index={index}
|
|
96
|
+
action={action}
|
|
97
|
+
schema={schema}
|
|
98
|
+
dom={dom}
|
|
99
|
+
></Component>
|
|
100
|
+
</Suspense>
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
commonHandler(c)
|
|
104
|
+
if (container.schemaHandler[c.valueType as string]) {
|
|
105
|
+
return container.schemaHandler[c.valueType as string](c)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return c
|
|
109
|
+
}).filter(c => !!c) || []) as ProFormColumnsType[])
|
|
110
|
+
|
|
111
|
+
setInitialized(true)
|
|
112
|
+
}, []);
|
|
113
|
+
|
|
114
|
+
const modalContext = useContext(ModalContext)
|
|
115
|
+
const tableContext = useContext(TableContext)
|
|
116
|
+
|
|
117
|
+
const handleAfterAction = async (req?: SubmitRequestType) => {
|
|
118
|
+
if (req?.afterAction?.includes('tableReload')) {
|
|
119
|
+
if (modalContext.contexts) {
|
|
120
|
+
modalContext.setAfterClose(() => {
|
|
121
|
+
modalContext.contexts?.tableContext?.actionRef.reload()
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
if (tableContext.actionRef) {
|
|
125
|
+
await tableContext.actionRef.reload()
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (req?.afterAction?.includes('closeModal') && modalContext.inModal) {
|
|
129
|
+
modalContext.closeModal()
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const onFinish = async (values: any) => {
|
|
134
|
+
if (props.submitRequest) {
|
|
135
|
+
setLoading(true)
|
|
136
|
+
try {
|
|
137
|
+
await http({
|
|
138
|
+
method: props.submitRequest.method,
|
|
139
|
+
url: props.submitRequest.url,
|
|
140
|
+
data: Object.assign({}, hiddenField.current, props.submitRequest.data, values),
|
|
141
|
+
headers: props.submitRequest.headers,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
handleAfterAction(props.submitRequest)
|
|
145
|
+
} finally {
|
|
146
|
+
setLoading(false)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return <>
|
|
152
|
+
<Row justify={'center'}>
|
|
153
|
+
<Col sm={24} md={22} lg={20}>
|
|
154
|
+
<FormContext.Provider value={{
|
|
155
|
+
formRef: formRef,
|
|
156
|
+
extraRenderValues: props.extraRenderValues,
|
|
157
|
+
}}>
|
|
158
|
+
{!initialized
|
|
159
|
+
? <ProSkeleton type={"list"} list={2}></ProSkeleton>
|
|
160
|
+
: <BetaSchemaForm columns={columns}
|
|
161
|
+
colProps={props.colProps}
|
|
162
|
+
readonly={props.readonly}
|
|
163
|
+
grid={true}
|
|
164
|
+
loading={loading}
|
|
165
|
+
formRef={formRef}
|
|
166
|
+
initialValues={props.initialValues}
|
|
167
|
+
onFinish={onFinish}
|
|
168
|
+
submitter={{
|
|
169
|
+
render: () => [
|
|
170
|
+
<Actions key={'actions'} loading={loading}
|
|
171
|
+
actions={props.actions}></Actions>
|
|
172
|
+
]
|
|
173
|
+
}}
|
|
174
|
+
></BetaSchemaForm>
|
|
175
|
+
}
|
|
176
|
+
</FormContext.Provider>
|
|
177
|
+
</Col>
|
|
178
|
+
</Row>
|
|
179
|
+
</>
|
|
171
180
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
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
|
+
|
|
8
9
|
export const FormContext = createContext<FormContextProps>({})
|
|
@@ -0,0 +1,252 @@
|
|
|
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/assign";
|
|
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
|
+
}
|