| @@ -110,6 +110,7 @@ export default defineConfig({ | |||||
| */ | */ | ||||
| antd: { | antd: { | ||||
| configProvider: {}, | configProvider: {}, | ||||
| appConfig: {}, | |||||
| }, | }, | ||||
| /** | /** | ||||
| * @name 网络请求配置 | * @name 网络请求配置 | ||||
| @@ -1,8 +1,7 @@ | |||||
| import RightContent from '@/components/RightContent'; | import RightContent from '@/components/RightContent'; | ||||
| import themes from '@/styles/theme.less'; | import themes from '@/styles/theme.less'; | ||||
| import type { Settings as LayoutSettings } from '@ant-design/pro-components'; | import type { Settings as LayoutSettings } from '@ant-design/pro-components'; | ||||
| import type { RunTimeLayoutConfig } from '@umijs/max'; | |||||
| import { history } from '@umijs/max'; | |||||
| import { RuntimeConfig, history } from '@umijs/max'; | |||||
| import { RuntimeAntdConfig } from 'umi'; | import { RuntimeAntdConfig } from 'umi'; | ||||
| import defaultSettings from '../config/defaultSettings'; | import defaultSettings from '../config/defaultSettings'; | ||||
| import '../public/fonts/font.css'; | import '../public/fonts/font.css'; | ||||
| @@ -10,6 +9,7 @@ import { getAccessToken } from './access'; | |||||
| import './dayjsConfig'; | import './dayjsConfig'; | ||||
| import { PageEnum } from './enums/pagesEnums'; | import { PageEnum } from './enums/pagesEnums'; | ||||
| import './global.less'; | import './global.less'; | ||||
| import { removeAllPageCacheState } from './hooks/pageCacheState'; | |||||
| import { | import { | ||||
| getRemoteMenu, | getRemoteMenu, | ||||
| getRoutersInfo, | getRoutersInfo, | ||||
| @@ -29,8 +29,7 @@ export async function getInitialState(): Promise<{ | |||||
| loading?: boolean; | loading?: boolean; | ||||
| fetchUserInfo?: () => Promise<API.CurrentUser | undefined>; | fetchUserInfo?: () => Promise<API.CurrentUser | undefined>; | ||||
| }> { | }> { | ||||
| console.log('getInitialState'); | |||||
| // console.log('getInitialState'); | |||||
| const fetchUserInfo = async () => { | const fetchUserInfo = async () => { | ||||
| try { | try { | ||||
| const response = await getUserInfo({ | const response = await getUserInfo({ | ||||
| @@ -67,7 +66,7 @@ export async function getInitialState(): Promise<{ | |||||
| } | } | ||||
| // ProLayout 支持的api https://procomponents.ant.design/components/layout | // ProLayout 支持的api https://procomponents.ant.design/components/layout | ||||
| export const layout: RunTimeLayoutConfig = ({ initialState }) => { | |||||
| export const layout: RuntimeConfig['layout'] = ({ initialState }) => { | |||||
| return { | return { | ||||
| rightContentRender: () => <RightContent />, | rightContentRender: () => <RightContent />, | ||||
| waterMarkProps: { | waterMarkProps: { | ||||
| @@ -137,30 +136,36 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => { | |||||
| // if (initialState?.loading) return <PageLoading />; | // if (initialState?.loading) return <PageLoading />; | ||||
| return <>{children}</>; | return <>{children}</>; | ||||
| }, | }, | ||||
| menuProps: { | |||||
| onClick: () => { | |||||
| removeAllPageCacheState(); | |||||
| }, | |||||
| }, | |||||
| ...initialState?.settings, | ...initialState?.settings, | ||||
| }; | }; | ||||
| }; | }; | ||||
| export async function onRouteChange({ clientRoutes, location }: any) { | |||||
| export const onRouteChange: RuntimeConfig['onRouteChange'] = async (e) => { | |||||
| const { location } = e; | |||||
| const menus = getRemoteMenu(); | const menus = getRemoteMenu(); | ||||
| // console.log('onRouteChange', clientRoutes, location, menus); | |||||
| console.log('onRouteChange', e); | |||||
| if (menus === null && location.pathname !== PageEnum.LOGIN) { | if (menus === null && location.pathname !== PageEnum.LOGIN) { | ||||
| console.log('refresh'); | console.log('refresh'); | ||||
| history.go(0); | history.go(0); | ||||
| } | } | ||||
| } | |||||
| }; | |||||
| export function patchRoutes({ routes, routeComponents }: any) { | |||||
| //console.log('patchRoutes', routes, routeComponents); | |||||
| } | |||||
| export const patchRoutes: RuntimeConfig['patchRoutes'] = (e) => { | |||||
| console.log('patchRoutes', e); | |||||
| }; | |||||
| export async function patchClientRoutes({ routes }: any) { | |||||
| // console.log('patchClientRoutes', routes); | |||||
| patchRouteWithRemoteMenus(routes); | |||||
| } | |||||
| export const patchClientRoutes: RuntimeConfig['patchClientRoutes'] = (e) => { | |||||
| console.log('patchClientRoutes', e); | |||||
| patchRouteWithRemoteMenus(e.routes); | |||||
| }; | |||||
| export function render(oldRender: () => void) { | export function render(oldRender: () => void) { | ||||
| // console.log('render get routers', oldRender); | |||||
| console.log('render'); | |||||
| const token = getAccessToken(); | const token = getAccessToken(); | ||||
| if (!token || token?.length === 0) { | if (!token || token?.length === 0) { | ||||
| oldRender(); | oldRender(); | ||||
| @@ -0,0 +1,42 @@ | |||||
| /* | |||||
| * @Author: 赵伟 | |||||
| * @Date: 2024-04-28 11:49:48 | |||||
| * @Description: 页面状态缓存,pop 回到这个页面的时候,重新构建之前的状态 | |||||
| */ | |||||
| const pageKeys: string[] = []; | |||||
| export const useCacheState = () => { | |||||
| const { pathname } = window.location; | |||||
| const key = 'pagecache:' + pathname; | |||||
| const getState = () => { | |||||
| const jsonStr = sessionStorage.getItem(key); | |||||
| if (jsonStr) { | |||||
| removeState(); | |||||
| return JSON.parse(jsonStr); | |||||
| } | |||||
| return undefined; | |||||
| }; | |||||
| const setState = (state: any) => { | |||||
| pageKeys.push(key); | |||||
| sessionStorage.setItem(key, JSON.stringify(state)); | |||||
| }; | |||||
| const removeState = () => { | |||||
| sessionStorage.removeItem(key); | |||||
| const index = pageKeys.indexOf(key); | |||||
| if (index !== -1) { | |||||
| pageKeys.splice(index, 1); | |||||
| } | |||||
| }; | |||||
| return [getState(), setState] as const; | |||||
| }; | |||||
| export const removeAllPageCacheState = () => { | |||||
| pageKeys.forEach((key) => { | |||||
| sessionStorage.removeItem(key); | |||||
| }); | |||||
| }; | |||||
| @@ -9,6 +9,7 @@ import KFIcon from '@/components/KFIcon'; | |||||
| import PageTitle from '@/components/PageTitle'; | import PageTitle from '@/components/PageTitle'; | ||||
| import SubAreaTitle from '@/components/SubAreaTitle'; | import SubAreaTitle from '@/components/SubAreaTitle'; | ||||
| import { useDomSize } from '@/hooks'; | import { useDomSize } from '@/hooks'; | ||||
| import { useCacheState } from '@/hooks/pageCacheState'; | |||||
| import { | import { | ||||
| deleteMirrorVersionReq, | deleteMirrorVersionReq, | ||||
| getMirrorInfoReq, | getMirrorInfoReq, | ||||
| @@ -20,13 +21,13 @@ import { mirrorNameKey } from '@/utils/sessionKeys'; | |||||
| import { modalConfirm } from '@/utils/ui'; | import { modalConfirm } from '@/utils/ui'; | ||||
| import { useNavigate, useParams, useSearchParams } from '@umijs/max'; | import { useNavigate, useParams, useSearchParams } from '@umijs/max'; | ||||
| import { | import { | ||||
| App, | |||||
| Button, | Button, | ||||
| Col, | Col, | ||||
| ConfigProvider, | ConfigProvider, | ||||
| Flex, | Flex, | ||||
| Row, | Row, | ||||
| Table, | Table, | ||||
| message, | |||||
| type TablePaginationConfig, | type TablePaginationConfig, | ||||
| type TableProps, | type TableProps, | ||||
| } from 'antd'; | } from 'antd'; | ||||
| @@ -56,17 +57,19 @@ function MirrorInfo() { | |||||
| const navigate = useNavigate(); | const navigate = useNavigate(); | ||||
| const urlParams = useParams(); | const urlParams = useParams(); | ||||
| const [searchParams] = useSearchParams(); | const [searchParams] = useSearchParams(); | ||||
| const [cacheState, setCacheState] = useCacheState(); | |||||
| const [mirrorInfo, setMirrorInfo] = useState<MirrorInfoData>({}); | const [mirrorInfo, setMirrorInfo] = useState<MirrorInfoData>({}); | ||||
| const [tableData, setTableData] = useState<MirrorVersionData[]>([]); | const [tableData, setTableData] = useState<MirrorVersionData[]>([]); | ||||
| const [topRef, { height: topHeight }] = useDomSize<HTMLDivElement>(0, 0, [mirrorInfo]); | const [topRef, { height: topHeight }] = useDomSize<HTMLDivElement>(0, 0, [mirrorInfo]); | ||||
| const [total, setTotal] = useState(0); | const [total, setTotal] = useState(0); | ||||
| const [pagination, setPagination] = useState<TablePaginationConfig>({ | |||||
| showSizeChanger: true, | |||||
| showQuickJumper: true, | |||||
| current: 1, | |||||
| pageSize: 10, | |||||
| }); | |||||
| const [pagination, setPagination] = useState<TablePaginationConfig>( | |||||
| cacheState?.pagination ?? { | |||||
| current: 1, | |||||
| pageSize: 10, | |||||
| }, | |||||
| ); | |||||
| const isPublic = searchParams.get('isPublic') === 'true'; | const isPublic = searchParams.get('isPublic') === 'true'; | ||||
| const { message } = App.useApp(); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| getMirrorInfo(); | getMirrorInfo(); | ||||
| }, []); | }, []); | ||||
| @@ -115,7 +118,7 @@ function MirrorInfo() { | |||||
| // 如果是一页的唯一数据,删除时,请求第一页的数据 | // 如果是一页的唯一数据,删除时,请求第一页的数据 | ||||
| // 否则直接刷新这一页的数据 | // 否则直接刷新这一页的数据 | ||||
| // 避免回到第一页 | // 避免回到第一页 | ||||
| if (tableData.length > 1) { | |||||
| if (tableData.length === 1) { | |||||
| setPagination((prev) => ({ | setPagination((prev) => ({ | ||||
| ...prev, | ...prev, | ||||
| current: 1, | current: 1, | ||||
| @@ -147,6 +150,9 @@ function MirrorInfo() { | |||||
| const createMirrorVersion = () => { | const createMirrorVersion = () => { | ||||
| navigate(`/dataset/mirror/create`); | navigate(`/dataset/mirror/create`); | ||||
| sessionStorage.setItem(mirrorNameKey, mirrorInfo.name || ''); | sessionStorage.setItem(mirrorNameKey, mirrorInfo.name || ''); | ||||
| setCacheState({ | |||||
| pagination, | |||||
| }); | |||||
| }; | }; | ||||
| const columns: TableProps<MirrorVersionData>['columns'] = [ | const columns: TableProps<MirrorVersionData>['columns'] = [ | ||||
| @@ -256,13 +262,14 @@ function MirrorInfo() { | |||||
| </Col> | </Col> | ||||
| </Row> | </Row> | ||||
| </div> | </div> | ||||
| <Flex justify="space-between" align="center" style={{ marginTop: '40px' }}> | |||||
| <Flex justify="flex-start" align="center" style={{ marginTop: '40px' }}> | |||||
| <SubAreaTitle | <SubAreaTitle | ||||
| title="镜像版本" | title="镜像版本" | ||||
| image={require('@/assets/img/mirror-version.png')} | image={require('@/assets/img/mirror-version.png')} | ||||
| ></SubAreaTitle> | ></SubAreaTitle> | ||||
| {!isPublic && ( | {!isPublic && ( | ||||
| <Button | <Button | ||||
| style={{ marginRight: 0, marginLeft: 'auto' }} | |||||
| type="default" | type="default" | ||||
| onClick={createMirrorVersion} | onClick={createMirrorVersion} | ||||
| icon={<KFIcon type="icon-xinjian2" />} | icon={<KFIcon type="icon-xinjian2" />} | ||||
| @@ -270,6 +277,14 @@ function MirrorInfo() { | |||||
| 新增镜像版本 | 新增镜像版本 | ||||
| </Button> | </Button> | ||||
| )} | )} | ||||
| <Button | |||||
| style={{ marginLeft: '20px' }} | |||||
| type="default" | |||||
| onClick={getMirrorVersionList} | |||||
| icon={<KFIcon type="icon-shuaxin" />} | |||||
| > | |||||
| 刷新 | |||||
| </Button> | |||||
| </Flex> | </Flex> | ||||
| </div> | </div> | ||||
| <div | <div | ||||
| @@ -280,7 +295,7 @@ function MirrorInfo() { | |||||
| dataSource={tableData} | dataSource={tableData} | ||||
| columns={columns} | columns={columns} | ||||
| scroll={{ y: 'calc(100% - 55px)' }} | scroll={{ y: 'calc(100% - 55px)' }} | ||||
| pagination={{ ...pagination, total }} | |||||
| pagination={{ ...pagination, total, showSizeChanger: true, showQuickJumper: true }} | |||||
| onChange={handleTableChange} | onChange={handleTableChange} | ||||
| rowKey="id" | rowKey="id" | ||||
| /> | /> | ||||
| @@ -7,11 +7,12 @@ import CommonTableCell from '@/components/CommonTableCell'; | |||||
| import DateTableCell from '@/components/DateTableCell'; | import DateTableCell from '@/components/DateTableCell'; | ||||
| import KFIcon from '@/components/KFIcon'; | import KFIcon from '@/components/KFIcon'; | ||||
| import { CommonTabKeys } from '@/enums'; | import { CommonTabKeys } from '@/enums'; | ||||
| import { useCacheState } from '@/hooks/pageCacheState'; | |||||
| import { deleteMirrorReq, getMirrorListReq } from '@/services/mirror'; | import { deleteMirrorReq, getMirrorListReq } from '@/services/mirror'; | ||||
| import themes from '@/styles/theme.less'; | import themes from '@/styles/theme.less'; | ||||
| import { to } from '@/utils/promise'; | import { to } from '@/utils/promise'; | ||||
| import { modalConfirm } from '@/utils/ui'; | import { modalConfirm } from '@/utils/ui'; | ||||
| import { useNavigate, useSearchParams } from '@umijs/max'; | |||||
| import { useNavigate } from '@umijs/max'; | |||||
| import { | import { | ||||
| Button, | Button, | ||||
| ConfigProvider, | ConfigProvider, | ||||
| @@ -50,20 +51,17 @@ export type MirrorData = { | |||||
| function MirrorList() { | function MirrorList() { | ||||
| const navigate = useNavigate(); | const navigate = useNavigate(); | ||||
| const [searchParams, setSearchParams] = useSearchParams(); | |||||
| const isPrivate = searchParams.get('isPublic') === 'false'; | |||||
| const [activeTab, setActiveTab] = useState<string>( | |||||
| isPrivate ? CommonTabKeys.Private : CommonTabKeys.Public, | |||||
| ); | |||||
| const [searchText, setSearchText] = useState(''); | |||||
| const [cacheState, setCacheState] = useCacheState(); | |||||
| const [activeTab, setActiveTab] = useState<string>(cacheState?.activeTab ?? CommonTabKeys.Public); | |||||
| const [searchText, setSearchText] = useState(cacheState?.searchText); | |||||
| const [tableData, setTableData] = useState<MirrorData[]>([]); | const [tableData, setTableData] = useState<MirrorData[]>([]); | ||||
| const [total, setTotal] = useState(0); | const [total, setTotal] = useState(0); | ||||
| const [pagination, setPagination] = useState<TablePaginationConfig>({ | |||||
| showSizeChanger: true, | |||||
| showQuickJumper: true, | |||||
| current: 1, | |||||
| pageSize: 10, | |||||
| }); | |||||
| const [pagination, setPagination] = useState<TablePaginationConfig>( | |||||
| cacheState?.pagination ?? { | |||||
| current: 1, | |||||
| pageSize: 10, | |||||
| }, | |||||
| ); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| getMirrorList(); | getMirrorList(); | ||||
| @@ -73,17 +71,12 @@ function MirrorList() { | |||||
| const hanleTabChange: TabsProps['onChange'] = (value) => { | const hanleTabChange: TabsProps['onChange'] = (value) => { | ||||
| setSearchText(''); | setSearchText(''); | ||||
| setPagination({ | setPagination({ | ||||
| showSizeChanger: true, | |||||
| showQuickJumper: true, | |||||
| current: 1, | current: 1, | ||||
| pageSize: 10, | pageSize: 10, | ||||
| }); | }); | ||||
| setTotal(0); | setTotal(0); | ||||
| setTableData([]); | setTableData([]); | ||||
| setActiveTab(value); | setActiveTab(value); | ||||
| setSearchParams([['isPublic', value === CommonTabKeys.Public ? 'true' : 'false']], { | |||||
| replace: true, | |||||
| }); | |||||
| }; | }; | ||||
| // 获取镜像列表 | // 获取镜像列表 | ||||
| const getMirrorList = async (params?: Record<string, any>) => { | const getMirrorList = async (params?: Record<string, any>) => { | ||||
| @@ -131,11 +124,11 @@ function MirrorList() { | |||||
| // 查看详情 | // 查看详情 | ||||
| const toDetail = (record: MirrorData) => { | const toDetail = (record: MirrorData) => { | ||||
| console.log('record', record); | |||||
| navigate(`/dataset/mirror/${record.id}?isPublic=${activeTab === CommonTabKeys.Public}`, { | |||||
| state: { | |||||
| isPublic: activeTab === CommonTabKeys.Public, | |||||
| }, | |||||
| navigate(`/dataset/mirror/${record.id}?isPublic=${activeTab === CommonTabKeys.Public}`); | |||||
| setCacheState({ | |||||
| activeTab, | |||||
| pagination, | |||||
| searchText, | |||||
| }); | }); | ||||
| }; | }; | ||||
| @@ -153,6 +146,11 @@ function MirrorList() { | |||||
| // 创建镜像 | // 创建镜像 | ||||
| const createMirror = () => { | const createMirror = () => { | ||||
| navigate(`/dataset/mirror/create`); | navigate(`/dataset/mirror/create`); | ||||
| setCacheState({ | |||||
| activeTab, | |||||
| pagination, | |||||
| searchText, | |||||
| }); | |||||
| }; | }; | ||||
| // 分页切换 | // 分页切换 | ||||
| @@ -276,7 +274,12 @@ function MirrorList() { | |||||
| dataSource={tableData} | dataSource={tableData} | ||||
| columns={columns} | columns={columns} | ||||
| scroll={{ y: 'calc(100% - 55px)' }} | scroll={{ y: 'calc(100% - 55px)' }} | ||||
| pagination={{ ...pagination, total: total }} | |||||
| pagination={{ | |||||
| ...pagination, | |||||
| total: total, | |||||
| showSizeChanger: true, | |||||
| showQuickJumper: true, | |||||
| }} | |||||
| onChange={handleTableChange} | onChange={handleTableChange} | ||||
| rowKey="id" | rowKey="id" | ||||
| /> | /> | ||||