2021-07-10 19:35:06 +08:00
|
|
|
/*
|
|
|
|
* @Author: yehuozhili
|
|
|
|
* @Date: 2021-07-07 14:51:17
|
|
|
|
* @LastEditors: yehuozhili
|
2021-09-28 22:36:03 +08:00
|
|
|
* @LastEditTime: 2021-09-28 16:33:32
|
2021-07-10 19:35:06 +08:00
|
|
|
* @FilePath: \dooringx\packages\dooringx-example\src\layouts\index.tsx
|
|
|
|
*/
|
|
|
|
import { Button } from 'antd';
|
2021-07-13 20:15:38 +08:00
|
|
|
import { UserConfig } from 'dooringx-lib';
|
2021-07-10 19:35:06 +08:00
|
|
|
import 'dooringx-lib/dist/dooringx-lib.esm.css';
|
2021-07-13 20:15:38 +08:00
|
|
|
import { createContext, useState } from 'react';
|
2021-07-10 19:35:06 +08:00
|
|
|
import { IRouteComponentProps } from 'umi';
|
|
|
|
import plugin from '../plugin';
|
|
|
|
import 'antd/dist/antd.css';
|
|
|
|
import '../global.less';
|
|
|
|
import 'animate.css';
|
2021-08-27 16:28:19 +08:00
|
|
|
import { IntlProvider } from 'react-intl';
|
|
|
|
import { locale } from 'dooringx-lib';
|
|
|
|
import { localeKey } from '../../../dooringx-lib/dist/locale';
|
2021-07-10 19:35:06 +08:00
|
|
|
export const config = new UserConfig(plugin);
|
|
|
|
export const configContext = createContext<UserConfig>(config);
|
2021-09-28 22:36:03 +08:00
|
|
|
//config.i18n = false;
|
2021-07-10 19:35:06 +08:00
|
|
|
// 自定义右键
|
|
|
|
const contextMenuState = config.getContextMenuState();
|
|
|
|
const unmountContextMenu = contextMenuState.unmountContextMenu;
|
|
|
|
const commander = config.getCommanderRegister();
|
|
|
|
const ContextMenu = () => {
|
|
|
|
const handleclick = () => {
|
|
|
|
unmountContextMenu();
|
|
|
|
};
|
2021-07-13 20:15:38 +08:00
|
|
|
const forceUpdate = useState(0)[1];
|
|
|
|
contextMenuState.forceUpdate = () => {
|
|
|
|
forceUpdate((pre) => pre + 1);
|
|
|
|
};
|
2021-07-10 19:35:06 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
left: contextMenuState.left,
|
|
|
|
top: contextMenuState.top,
|
|
|
|
position: 'fixed',
|
|
|
|
background: 'rgb(24, 23, 23)',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
onClick={() => {
|
|
|
|
commander.exec('redo');
|
|
|
|
handleclick();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Button>自定义</Button>
|
|
|
|
</div>
|
2021-07-27 16:35:09 +08:00
|
|
|
<div
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
onClick={() => {
|
|
|
|
commander.exec('lock');
|
|
|
|
handleclick();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Button style={{ width: '100%' }}>锁定</Button>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
onClick={() => {
|
|
|
|
commander.exec('unlock');
|
|
|
|
handleclick();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Button style={{ width: '100%' }}>解锁</Button>
|
|
|
|
</div>
|
2021-07-10 19:35:06 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
contextMenuState.contextMenu = <ContextMenu></ContextMenu>;
|
|
|
|
|
2021-08-27 16:28:19 +08:00
|
|
|
interface LocaleContextType {
|
|
|
|
change: Function;
|
|
|
|
current: localeKey;
|
|
|
|
}
|
|
|
|
export const LocaleContext = createContext<LocaleContextType>({
|
|
|
|
change: () => {},
|
|
|
|
current: 'zh-CN',
|
|
|
|
});
|
|
|
|
|
2021-07-10 19:35:06 +08:00
|
|
|
export default function Layout({ children }: IRouteComponentProps) {
|
2021-08-27 16:28:19 +08:00
|
|
|
const [l, setLocale] = useState<localeKey>('zh-CN');
|
2021-09-28 22:36:03 +08:00
|
|
|
return (
|
|
|
|
<LocaleContext.Provider value={{ change: setLocale, current: l }}>
|
|
|
|
<IntlProvider messages={locale.localeMap[l]} locale={l} defaultLocale={l}>
|
|
|
|
<configContext.Provider value={config}>{children}</configContext.Provider>
|
|
|
|
</IntlProvider>
|
|
|
|
</LocaleContext.Provider>
|
|
|
|
);
|
2021-09-27 21:52:16 +08:00
|
|
|
return <configContext.Provider value={config}>{children}</configContext.Provider>;
|
2021-07-10 19:35:06 +08:00
|
|
|
}
|