diff --git a/package.json b/package.json index 9794764aee4d0eb8526e1f9e937a38ff7a5228f1..9be65a898c2a22ee4381cc0f4b4a122688855282 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ "docker:push": "npm run docker-hub:build && npm run docker:tag && docker push antdesign/ant-design-pro" }, "dependencies": { - "ant-design-pro": "^2.1.1", - "antd": "^3.10.9", + "ant-design-pro": "^2.3.0", + "antd": "^3.15.0", "classnames": "^2.2.6", "dva": "^2.4.0", "lodash": "^4.17.10", @@ -43,13 +43,13 @@ "moment": "^2.22.2", "omit.js": "^1.0.0", "path-to-regexp": "^2.4.0", - "prop-types": "^15.5.10", "rc-animate": "^2.4.4", - "react": "^16.6.3", + "react": "^16.8.5", "react-container-query": "^0.11.0", "react-copy-to-clipboard": "^5.0.1", "react-document-title": "^2.0.3", "react-media-hook2": "^1.0.2", + "umi": "^2.6.10", "umi-request": "^1.0.0" }, "devDependencies": { @@ -60,7 +60,6 @@ "@types/memoize-one": "^4.1.0", "@types/react": "^16.8.1", "@types/react-document-title": "^2.0.3", - "@types/react-dom": "^16.0.11", "antd-pro-merge-less": "^1.0.0", "antd-theme-webpack-plugin": "^1.2.0", "babel-eslint": "^10.0.1", @@ -98,7 +97,6 @@ "tslint-config-prettier": "^1.17.0", "tslint-eslint-rules": "^5.4.0", "tslint-react": "^3.6.0", - "umi": "^2.4.4", "umi-plugin-ga": "^1.1.3", "umi-plugin-pro-block": "^1.2.0", "umi-plugin-react": "^1.3.4", diff --git a/src/components/GlobalHeader/RightContent.tsx b/src/components/GlobalHeader/RightContent.tsx index 69c61fae5d6d50f5b3b2aadd770cb413d94520be..919e8428914230ba6cc9391c055e2dbd427d7f1d 100644 --- a/src/components/GlobalHeader/RightContent.tsx +++ b/src/components/GlobalHeader/RightContent.tsx @@ -170,7 +170,7 @@ export default class GlobalHeaderRight extends Component title="notification" emptyText={formatMessage({ id: 'component.globalHeader.notification.empty' })} emptyImage="https://gw.alipayobjects.com/zos/rmsportal/wAhyIChODzsoKIOBHcBk.svg" - showViewMore // todo:showViewMore?: boolean; skeletonProps?: SkeletonProps; + showViewMore /> { return icon; }; -/** - * @type R: is route - */ -export interface MenuDataItem { +export interface MenuDataItem { authority?: string[] | string; children?: MenuDataItem[]; hideChildrenInMenu?: boolean; @@ -41,17 +39,19 @@ export interface MenuDataItem { locale?: string; name?: string; path: string; - routes?: R extends true ? MenuDataItem[] : never; [key: string]: any; } -export interface BaseMenuProps { +export interface Route extends MenuDataItem { + routes?: Route[]; +} + +export interface BaseMenuProps extends Partial> { className?: string; collapsed?: boolean; flatMenuKeys?: any[]; handleOpenChange?: (openKeys: string[]) => void; isMobile?: boolean; - location?: Location; menuData?: MenuDataItem[]; mode?: MenuMode; onCollapse?: (collapsed: boolean) => void; @@ -62,9 +62,8 @@ export interface BaseMenuProps { } export default class BaseMenu extends Component { - static defaultProps: BaseMenuProps = { + static defaultProps: Partial = { flatMenuKeys: [], - location: window.location, onCollapse: () => void 0, isMobile: false, openKeys: [], @@ -107,7 +106,7 @@ export default class BaseMenu extends Component { item.icon ? ( {getIcon(item.icon)} - {name} + {item.name} ) : ( item.name diff --git a/src/components/SiderMenu/SiderMenu.tsx b/src/components/SiderMenu/SiderMenu.tsx index 9325d1aee0a3cdb7909f25c665b81a29960ec22e..f09e627357163a7d979bfc8f66cbc7e894bd6693 100644 --- a/src/components/SiderMenu/SiderMenu.tsx +++ b/src/components/SiderMenu/SiderMenu.tsx @@ -25,9 +25,8 @@ interface SiderMenuState { } export default class SiderMenu extends Component { - static defaultProps: SiderMenuProps = { + static defaultProps: Partial = { flatMenuKeys: [], - location: window.location, onCollapse: () => void 0, isMobile: false, openKeys: [], diff --git a/src/components/SiderMenu/index.tsx b/src/components/SiderMenu/index.tsx index 6f1de3e7e0c6b0fb47ce10548bb3df546e67e687..ba5ab3da1025f064c202116fcb9964a1f2391834 100644 --- a/src/components/SiderMenu/index.tsx +++ b/src/components/SiderMenu/index.tsx @@ -5,7 +5,7 @@ import SiderMenu from './SiderMenu'; import { getFlatMenuKeys } from './SiderMenuUtils'; export { SiderMenuProps }; -export { MenuDataItem } from './BaseMenu'; +export { MenuDataItem, Route } from './BaseMenu'; const SiderMenuWrapper: React.FC = props => { const { isMobile, menuData, collapsed, onCollapse } = props; diff --git a/src/layouts/BasicLayout.tsx b/src/layouts/BasicLayout.tsx index f164d0fe7d659819e313d7c5d3bb5250e558f031..9bbf49e8bd57344648cc1fe7c94d9c087d2df8dd 100644 --- a/src/layouts/BasicLayout.tsx +++ b/src/layouts/BasicLayout.tsx @@ -1,4 +1,3 @@ -import PageLoading from '@/components/PageLoading'; import SiderMenu, { MenuDataItem, SiderMenuProps } from '@/components/SiderMenu'; import { ConnectProps, ConnectState, SettingModelState } from '@/models/connect'; import getPageTitle from '@/utils/getPageTitle'; @@ -51,13 +50,11 @@ export interface BasicLayoutProps HeaderViewProps, Partial { breadcrumbNameMap: { [path: string]: MenuDataItem }; - route: MenuDataItem; } -export interface BasicLayoutContext { - location: Location; +export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & { breadcrumbNameMap: { [path: string]: MenuDataItem }; -} +}; const BasicLayout: React.FC = props => { const { @@ -71,8 +68,9 @@ const BasicLayout: React.FC = props => { location, menuData, navTheme, - route: { routes, authority }, + route, } = props; + const { routes, authority } = route!; /** * constructor */ @@ -130,13 +128,13 @@ const BasicLayout: React.FC = props => { {params => ( - +
{layout}
)}
- }>{renderSettingDrawer()} + {renderSettingDrawer()} ); }; diff --git a/src/layouts/Footer.tsx b/src/layouts/Footer.tsx index bd23e56ae427beef7bea0819a10a881b2523f822..aa49ea2dc2fa471a9537ff3db9ac38a16b515e94 100644 --- a/src/layouts/Footer.tsx +++ b/src/layouts/Footer.tsx @@ -28,7 +28,7 @@ const FooterView = () => ( ]} copyright={ - Copyright 2018 蚂蚁金服体验技术部出品 + Copyright 2019 蚂蚁金服体验技术部出品 } /> diff --git a/src/layouts/Header.tsx b/src/layouts/Header.tsx index c948b355545a605ebf53beda734446fcfc740d71..9c064cace646ac9e0b55d8ec30e21226fd61f847 100644 --- a/src/layouts/Header.tsx +++ b/src/layouts/Header.tsx @@ -25,7 +25,7 @@ interface HeaderViewState { } class HeaderView extends Component { - static defaultProps: HeaderViewProps = { + static defaultProps: Partial = { handleMenuCollapse: () => void 0, }; diff --git a/src/layouts/UserLayout.tsx b/src/layouts/UserLayout.tsx index 7f8e110a28318c14537fc4e18d25fa589b79c548..2ac6a81f97b9c85ba5eabc925c5d07feee468b36 100644 --- a/src/layouts/UserLayout.tsx +++ b/src/layouts/UserLayout.tsx @@ -37,17 +37,14 @@ const copyright = ( ); export interface UserLayoutProps extends ConnectProps { - route: MenuDataItem; breadcrumbNameMap: { [path: string]: MenuDataItem }; navTheme: string; } class UserLayout extends Component { componentDidMount() { - const { - dispatch, - route: { routes, authority }, - } = this.props; + const { dispatch, route } = this.props; + const { routes, authority } = route!; dispatch!({ type: 'menu/getMenuData', payload: { routes, authority }, diff --git a/src/models/connect.d.ts b/src/models/connect.d.ts index 2b2e03de061c81e6826f0b565b2fbad286203f34..2bdf75bf88422947105f9dd3296ebf59d50b9cf9 100644 --- a/src/models/connect.d.ts +++ b/src/models/connect.d.ts @@ -1,5 +1,7 @@ +import { Route } from '@/components/SiderMenu'; import { EffectsCommandMap } from 'dva'; import { AnyAction } from 'redux'; +import { RouterTypes } from 'umi'; import { GlobalModelState } from './global'; import { MenuModelState } from './menu'; import { UserModelState } from './user'; @@ -44,18 +46,10 @@ export interface ConnectState { /** * @type T: Params matched in dynamic routing - * @type R: Instance type of ref */ -export interface ConnectProps - extends React.Props { +export interface ConnectProps + extends Partial> { dispatch?: Dispatch; - location?: Location; - match?: { - isExact: boolean; - params: T; - path: string; - url: string; - }; } export default ConnectState; diff --git a/src/models/global.ts b/src/models/global.ts index 5a0bc067954216201b37ff93a124881a473c6994..2a68a2ac7e8a8e866f55a0385639be31f375ffa5 100644 --- a/src/models/global.ts +++ b/src/models/global.ts @@ -2,9 +2,9 @@ import { queryNotices } from '@/services/user'; import { Subscription } from 'dva'; import { Reducer } from 'redux'; import { Effect } from './connect'; -import { INoticeIconData } from 'ant-design-pro/lib/NoticeIcon/NoticeIconTab'; +import { NoticeIconData } from 'ant-design-pro/lib/NoticeIcon/NoticeIconTab'; -export interface NoticeItem extends INoticeIconData { +export interface NoticeItem extends NoticeIconData { id: string; type: string; [key: string]: any; diff --git a/src/models/menu.ts b/src/models/menu.ts index 9166de2aa52a1d1a72be3b78e375a3030183fff5..2c09ce4120b1ac6a70ef472d802a30eb833fae30 100644 --- a/src/models/menu.ts +++ b/src/models/menu.ts @@ -1,4 +1,4 @@ -import { MenuDataItem } from '@/components/SiderMenu'; +import { MenuDataItem, Route } from '@/components/SiderMenu'; import Authorized from '@/utils/Authorized'; import { Effect } from 'dva'; import isEqual from 'lodash/isEqual'; @@ -10,7 +10,7 @@ import defaultSettings from '../../config/defaultSettings'; // Conversion router to menu. function formatter( - data: MenuDataItem[], + data: Route[], parentAuthority?: string[] | string, parentName?: string, ): MenuDataItem[] { @@ -27,6 +27,7 @@ function formatter( ...item, name, locale, + routes: void 0, authority: item.authority || parentAuthority, }; if (item.routes) { @@ -34,7 +35,6 @@ function formatter( // Reduce memory usage result.children = children; } - delete result.routes; return result; }); } diff --git a/src/pages/Authorized.tsx b/src/pages/Authorized.tsx index 7f26ef3b4297f4d12861bb40c2f97d0dd43f0706..80cb73a6b173bdbc957d2a5d9c43747aea100303 100644 --- a/src/pages/Authorized.tsx +++ b/src/pages/Authorized.tsx @@ -1,18 +1,17 @@ import Authorized from '@/utils/Authorized'; +import { Route } from '@/components/SiderMenu'; import { ConnectProps, ConnectState, UserModelState } from '@/models/connect'; import { connect } from 'dva'; import pathToRegexp from 'path-to-regexp'; import React from 'react'; import Redirect from 'umi/redirect'; -import { IRoute } from 'umi-types'; interface AuthComponentProps extends ConnectProps { - location: Location; - routerData: IRoute[]; + routerData: Route[]; user: UserModelState; } -const getRouteAuthority = (path: string, routeData: IRoute[]) => { +const getRouteAuthority = (path: string, routeData: Route[]) => { let authorities: string[] | string | undefined = void 0; routeData.forEach(route => { // match prefix @@ -32,7 +31,7 @@ const AuthComponent: React.FC = ({ children, location, route const isLogin = currentUser && currentUser.name; return ( : } > {children} diff --git a/src/typings.d.ts b/src/typings.d.ts index 5a447640d5dee14e440f64344dc3a1a6c2c843e4..a03b3ded1826f5ddb9ce6df14b53fab3af27e906 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -13,29 +13,3 @@ declare module 'rc-animate'; declare module 'omit.js'; declare module 'react-copy-to-clipboard'; declare var APP_TYPE: string; -declare module 'ant-design-pro' { - import React from 'react'; - import { INoticeIconProps } from 'ant-design-pro/lib/NoticeIcon'; - import { INoticeIconTabProps } from 'ant-design-pro/lib/NoticeIcon/NoticeIconTab'; - - type PartialNoticeIconProps = { - [K in Exclude]?: INoticeIconProps[K] - }; - interface MixinNoticeIconProps extends PartialNoticeIconProps { - locale?: { - emptyText: string; - clear: string; - viewMore: string; - [key: string]: string; - }; - onViewMore?: (tabProps: INoticeIconProps) => void; - } - interface MixinNoticeIconTabProps extends Partial { - showViewMore?: boolean; - } - class NoticeIconTab extends React.Component {} - export class NoticeIcon extends React.Component { - public static Tab: typeof NoticeIconTab; - } - export * from 'ant-design-pro/lib'; -}