feat: 补充提交

develop
donghao 11 months ago
parent d6950afaea
commit 8c79571e1b

@ -1,8 +1,11 @@
<!--
* @Author: donghao donghao@supervision.ltd
* @Date: 2023-11-01 13:56:33
* @LastEditors: donghao donghao@supervision.ltd
* @LastEditTime: 2024-03-29 17:59:03
* @FilePath: \general-ai-platform-web\.eslintrc.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
module.exports = { module.exports = {
extends: [require.resolve('@umijs/lint/dist/config/eslint')],
globals: {
page: true,
REACT_APP_ENV: true,
SERVER_HOST: true,
},
}; };

@ -44,12 +44,9 @@ export default [
}, },
], ],
}, },
{ {
path: '/system', path: '/system',
name: 'system', name: 'system',
routes: [ routes: [
{ {
name: 'api-list', name: 'api-list',

@ -8,4 +8,4 @@
"@/*": ["./src/*"] "@/*": ["./src/*"]
} }
} }
} }

@ -46,6 +46,8 @@ export async function getInitialState(): Promise<{
if (location.pathname !== loginPath && localStorage.getItem('access')) { if (location.pathname !== loginPath && localStorage.getItem('access')) {
const currentUser = await fetchUserInfo(); const currentUser = await fetchUserInfo();
const menus = await postMenuGetMenu(); const menus = await postMenuGetMenu();
console.log('app_menus', menus.data.routes);
if (getLocale() === 'zh-CN') { if (getLocale() === 'zh-CN') {
let localData = getAllRouteNameTile(menus.data.routes, ''); let localData = getAllRouteNameTile(menus.data.routes, '');
let localRes: any = {}; let localRes: any = {};
@ -88,7 +90,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
src: SERVER_HOST + initialState?.currentUser?.avatarUrl, src: SERVER_HOST + initialState?.currentUser?.avatarUrl,
title: <AvatarName />, title: <AvatarName />,
render: (_, avatarChildren) => { render: (_, avatarChildren) => {
console.log(avatarChildren,'111111111') console.log(avatarChildren,'avatarProps')
return <AvatarDropdown menu={true}>{avatarChildren}</AvatarDropdown>; return <AvatarDropdown menu={true}>{avatarChildren}</AvatarDropdown>;
}, },
}, },
@ -118,14 +120,18 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
userId: initialState?.currentUser?.id, userId: initialState?.currentUser?.id,
}, },
request: async () => { request: async () => {
// console.log(initialState?.menuData,'initialState_menuData') console.log(initialState?.menuData,'initialState_menuData')
return initialState?.menuData || []; return initialState?.menuData || [];
}, },
}, },
// headerRender: () => <>导航栏</>,
// menuRender: () => <></>,
footerRender: () => <Footer />, footerRender: () => <Footer />,
onPageChange: () => { onPageChange: () => {
const { location } = history; const { location } = history;
// 如果没有登录,重定向到 login // 如果没有登录,重定向到 login
console.log(location.pathname,'location_pathname')
if (!initialState?.currentUser && location.pathname !== loginPath) { if (!initialState?.currentUser && location.pathname !== loginPath) {
history.push(loginPath); history.push(loginPath);
} }

@ -1,8 +1,8 @@
/* /*
* @Author: zhoux zhouxia@supervision.ltd * @Author: zhoux zhouxia@supervision.ltd
* @Date: 2023-11-14 15:49:36 * @Date: 2023-11-14 15:49:36
* @LastEditors: zhoux zhouxia@supervision.ltd * @LastEditors: donghao donghao@supervision.ltd
* @LastEditTime: 2023-12-11 10:30:54 * @LastEditTime: 2024-04-10 11:21:37
* @FilePath: \general-ai-platform-web\src\components\TableActionCard\index.tsx * @FilePath: \general-ai-platform-web\src\components\TableActionCard\index.tsx
* @Description: ,`customMade`, koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: ,`customMade`, koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
@ -12,7 +12,7 @@ import { Dropdown } from 'antd';
import React from 'react'; import React from 'react';
//TODO 表单的操作按钮集合 key的报错未解决 //TODO 表单的操作按钮集合 key的报错未解决
type actionsProps = { export type actionsProps = {
key: string; key: string;
renderDom: any; renderDom: any;
} }

@ -1,21 +1,18 @@
import { history } from '@umijs/max';
import { Dropdown, Tabs } from 'antd'; import { Dropdown, Tabs } from 'antd';
import { useCallback, useMemo } from 'react'; import { useCallback, useMemo } from 'react';
import { history } from '@umijs/max';
import { KeepAliveTab, useKeepAliveTabs } from './useKeepAliveTabs';
import type { ItemType, MenuInfo } from 'rc-menu/lib/interface'; import type { ItemType, MenuInfo } from 'rc-menu/lib/interface';
import { KeepAliveTabContext } from './context'; import { KeepAliveTab, useKeepAliveTabs } from './useKeepAliveTabs';
enum OperationType { enum OperationType {
REFRESH = 'refresh', REFRESH = 'refresh',
CLOSE = 'close', CLOSE = 'close',
CLOSEOTHER = 'close-other', CLOSEOTHER = 'close-other',
} }
type MenuItemType = (ItemType & { key: OperationType }) | null;
type MenuItemType = ItemType & { key: OperationType } | null;
const KeepAliveLayout = () => { const KeepAliveLayout = () => {
const { const {
keepAliveTabs, keepAliveTabs,
activeTabRoutePath, activeTabRoutePath,
@ -26,78 +23,91 @@ const KeepAliveLayout = () => {
onShow, onShow,
} = useKeepAliveTabs(); } = useKeepAliveTabs();
const menuItems: MenuItemType[] = useMemo(() => [ const menuItems: MenuItemType[] = useMemo(
{ () =>
label: '刷新', [
key: OperationType.REFRESH, {
}, label: '刷新',
keepAliveTabs.length <= 1 ? null : { key: OperationType.REFRESH,
label: '关闭', },
key: OperationType.CLOSE, keepAliveTabs.length <= 1
}, ? null
keepAliveTabs.length <= 1 ? null : { : {
label: '关闭其他', label: '关闭',
key: OperationType.CLOSEOTHER, key: OperationType.CLOSE,
}, },
].filter(o => o), [keepAliveTabs]); keepAliveTabs.length <= 1
? null
const menuClick = useCallback(({ key, domEvent }: MenuInfo, tab: KeepAliveTab) => { : {
domEvent.stopPropagation(); label: '关闭其他',
key: OperationType.CLOSEOTHER,
},
].filter((o) => o),
[keepAliveTabs],
);
if (key === OperationType.REFRESH) { const menuClick = useCallback(
refreshTab(tab.routePath); ({ key, domEvent }: MenuInfo, tab: KeepAliveTab) => {
} else if (key === OperationType.CLOSE) { domEvent.stopPropagation();
closeTab(tab.routePath);
} else if (key === OperationType.CLOSEOTHER) {
closeOtherTab(tab.routePath);
}
}, [closeOtherTab, closeTab, refreshTab]);
if (key === OperationType.REFRESH) {
refreshTab(tab.routePath);
} else if (key === OperationType.CLOSE) {
closeTab(tab.routePath);
} else if (key === OperationType.CLOSEOTHER) {
closeOtherTab(tab.routePath);
}
},
[closeOtherTab, closeTab, refreshTab],
);
const renderTabTitle = useCallback((tab: KeepAliveTab) => { const renderTabTitle = useCallback(
return ( (tab: KeepAliveTab) => {
<Dropdown return (
menu={{ items: menuItems, onClick: (e) => menuClick(e, tab) }} <Dropdown
trigger={['contextMenu']} menu={{ items: menuItems, onClick: (e) => menuClick(e, tab) }}
> trigger={['contextMenu']}
<div style={{ margin: '-12px 0', padding: '12px 0' }}> >
{/*{tab.icon}*/} <div style={{ margin: '-12px 0', padding: '12px 0' }}>
{tab.title} {/*{tab.icon}*/}
</div> {tab.title}
</Dropdown> </div>
) </Dropdown>
}, [menuItems]); );
},
[menuItems],
);
const tabItems = useMemo(() => { const tabItems = useMemo(() => {
let finalKeepAliveTabs = keepAliveTabs let finalKeepAliveTabs = keepAliveTabs;
// .filter(item => !item?.isHideTab) // .filter(item => !item?.isHideTab)
return finalKeepAliveTabs.map(tab => { return finalKeepAliveTabs.map((tab) => {
console.log(tab,'tabItems') console.log(tab, 'tabItems');
// TODO 未找到合适办法只去除tab标题栏位保留页面内容 // TODO 未找到合适办法只去除tab标题栏位保留页面内容
return { return {
key: tab.routePath, key: tab.routePath,
label: renderTabTitle(tab), label: renderTabTitle(tab),
children: ( children: (
<div <div key={tab.key} style={{ height: 'calc(100vh - 112px)', overflow: 'auto' }}>
key={tab.key}
style={{ height: 'calc(100vh - 112px)', overflow: 'auto' }}
>
{tab.children} {tab.children}
</div> </div>
), ),
// style: {display: 'none'}, // style: {display: 'none'},
closable: keepAliveTabs.length > 1, closable: keepAliveTabs.length > 1,
forceRender: true forceRender: true,
} };
}) });
}, [keepAliveTabs]); }, [keepAliveTabs]);
const onTabsChange = useCallback((tabRoutePath: string) => { const onTabsChange = useCallback(
const curTab = keepAliveTabs.find(o => o.routePath === tabRoutePath); (tabRoutePath: string) => {
if (curTab) { const curTab = keepAliveTabs.find((o) => o.routePath === tabRoutePath);
history.push(curTab?.pathname); if (curTab) {
} history.push(curTab?.pathname);
}, [keepAliveTabs]); }
},
[keepAliveTabs],
);
const onTabEdit = ( const onTabEdit = (
targetKey: React.MouseEvent | React.KeyboardEvent | string, targetKey: React.MouseEvent | React.KeyboardEvent | string,
@ -116,23 +126,23 @@ const KeepAliveLayout = () => {
onHidden, onHidden,
onShow, onShow,
}), }),
[closeTab, closeOtherTab, refreshTab, onHidden, onShow] [closeTab, closeOtherTab, refreshTab, onHidden, onShow],
); );
return ( return (
<KeepAliveTabContext.Provider value={keepAliveContextValue}> <div>
<Tabs <Tabs
type="editable-card" type="editable-card"
items={tabItems} items={tabItems}
activeKey={activeTabRoutePath} activeKey={activeTabRoutePath}
onChange={onTabsChange} onChange={onTabsChange}
className='keep-alive-tabs' className="keep-alive-tabs"
hideAdd hideAdd
animated={false} animated={false}
onEdit={onTabEdit} onEdit={onTabEdit}
/> />
</KeepAliveTabContext.Provider> </div>
) );
} };
export default KeepAliveLayout; export default KeepAliveLayout;

8
src/typings.d.ts vendored

@ -1,3 +1,11 @@
/*
* @Author: donghao donghao@supervision.ltd
* @Date: 2023-11-01 13:56:33
* @LastEditors: donghao donghao@supervision.ltd
* @LastEditTime: 2024-03-29 16:51:11
* @FilePath: \general-ai-platform-web\src\typings.d.ts
* @Description: ,`customMade`, koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
declare module 'slash2'; declare module 'slash2';
declare module '*.css'; declare module '*.css';
declare module '*.less'; declare module '*.less';

@ -1,7 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"forceConsistentCasingInFileNames": false, "forceConsistentCasingInFileNames": false,
"target": "esnext", "target": "esnext",
"module": "esnext", "module": "esnext",
"moduleResolution": "node", "moduleResolution": "node",
@ -20,7 +19,6 @@
"@@/*": ["./src/.umi/*"], "@@/*": ["./src/.umi/*"],
"@@test/*": ["./src/.umi-test/*"], "@@test/*": ["./src/.umi-test/*"],
"@umijs/max": ["./src/.umijs/max"], "@umijs/max": ["./src/.umijs/max"],
} }
}, },
"include": ["./**/*.d.ts", "./**/*.ts", "./**/*.tsx", "src/utils/storage.js"] "include": ["./**/*.d.ts", "./**/*.ts", "./**/*.tsx", "src/utils/storage.js"]

Loading…
Cancel
Save