Commit f046426b authored by 何乐's avatar 何乐 Committed by 陈小聪

[v4] fix type definition (#3851)

- location, history, match 等定义改为从 umi 引入继承
- 更新部分依赖的版本
- 一些其他的类型定义优化
parent 0bc812b7
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
"docker:push": "npm run docker-hub:build && npm run docker:tag && docker push antdesign/ant-design-pro" "docker:push": "npm run docker-hub:build && npm run docker:tag && docker push antdesign/ant-design-pro"
}, },
"dependencies": { "dependencies": {
"ant-design-pro": "^2.1.1", "ant-design-pro": "^2.3.0",
"antd": "^3.10.9", "antd": "^3.15.0",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"dva": "^2.4.0", "dva": "^2.4.0",
"lodash": "^4.17.10", "lodash": "^4.17.10",
...@@ -43,13 +43,13 @@ ...@@ -43,13 +43,13 @@
"moment": "^2.22.2", "moment": "^2.22.2",
"omit.js": "^1.0.0", "omit.js": "^1.0.0",
"path-to-regexp": "^2.4.0", "path-to-regexp": "^2.4.0",
"prop-types": "^15.5.10",
"rc-animate": "^2.4.4", "rc-animate": "^2.4.4",
"react": "^16.6.3", "react": "^16.8.5",
"react-container-query": "^0.11.0", "react-container-query": "^0.11.0",
"react-copy-to-clipboard": "^5.0.1", "react-copy-to-clipboard": "^5.0.1",
"react-document-title": "^2.0.3", "react-document-title": "^2.0.3",
"react-media-hook2": "^1.0.2", "react-media-hook2": "^1.0.2",
"umi": "^2.6.10",
"umi-request": "^1.0.0" "umi-request": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
...@@ -60,7 +60,6 @@ ...@@ -60,7 +60,6 @@
"@types/memoize-one": "^4.1.0", "@types/memoize-one": "^4.1.0",
"@types/react": "^16.8.1", "@types/react": "^16.8.1",
"@types/react-document-title": "^2.0.3", "@types/react-document-title": "^2.0.3",
"@types/react-dom": "^16.0.11",
"antd-pro-merge-less": "^1.0.0", "antd-pro-merge-less": "^1.0.0",
"antd-theme-webpack-plugin": "^1.2.0", "antd-theme-webpack-plugin": "^1.2.0",
"babel-eslint": "^10.0.1", "babel-eslint": "^10.0.1",
...@@ -98,7 +97,6 @@ ...@@ -98,7 +97,6 @@
"tslint-config-prettier": "^1.17.0", "tslint-config-prettier": "^1.17.0",
"tslint-eslint-rules": "^5.4.0", "tslint-eslint-rules": "^5.4.0",
"tslint-react": "^3.6.0", "tslint-react": "^3.6.0",
"umi": "^2.4.4",
"umi-plugin-ga": "^1.1.3", "umi-plugin-ga": "^1.1.3",
"umi-plugin-pro-block": "^1.2.0", "umi-plugin-pro-block": "^1.2.0",
"umi-plugin-react": "^1.3.4", "umi-plugin-react": "^1.3.4",
......
...@@ -170,7 +170,7 @@ export default class GlobalHeaderRight extends Component<GlobalHeaderRightProps> ...@@ -170,7 +170,7 @@ export default class GlobalHeaderRight extends Component<GlobalHeaderRightProps>
title="notification" title="notification"
emptyText={formatMessage({ id: 'component.globalHeader.notification.empty' })} emptyText={formatMessage({ id: 'component.globalHeader.notification.empty' })}
emptyImage="https://gw.alipayobjects.com/zos/rmsportal/wAhyIChODzsoKIOBHcBk.svg" emptyImage="https://gw.alipayobjects.com/zos/rmsportal/wAhyIChODzsoKIOBHcBk.svg"
showViewMore // todo:showViewMore?: boolean; skeletonProps?: SkeletonProps; showViewMore
/> />
<NoticeIcon.Tab <NoticeIcon.Tab
count={unreadMsg.message} count={unreadMsg.message}
......
...@@ -4,6 +4,7 @@ import { Icon, Menu } from 'antd'; ...@@ -4,6 +4,7 @@ import { Icon, Menu } from 'antd';
import { MenuMode, MenuTheme } from 'antd/es/menu'; import { MenuMode, MenuTheme } from 'antd/es/menu';
import classNames from 'classnames'; import classNames from 'classnames';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { RouterTypes } from 'umi';
import Link from 'umi/link'; import Link from 'umi/link';
import { urlToList } from '../_utils/pathTools'; import { urlToList } from '../_utils/pathTools';
import styles from './index.less'; import styles from './index.less';
...@@ -29,10 +30,7 @@ const getIcon = (icon?: string | React.ReactNode) => { ...@@ -29,10 +30,7 @@ const getIcon = (icon?: string | React.ReactNode) => {
return icon; return icon;
}; };
/** export interface MenuDataItem {
* @type R: is route
*/
export interface MenuDataItem<R extends boolean = false> {
authority?: string[] | string; authority?: string[] | string;
children?: MenuDataItem[]; children?: MenuDataItem[];
hideChildrenInMenu?: boolean; hideChildrenInMenu?: boolean;
...@@ -41,17 +39,19 @@ export interface MenuDataItem<R extends boolean = false> { ...@@ -41,17 +39,19 @@ export interface MenuDataItem<R extends boolean = false> {
locale?: string; locale?: string;
name?: string; name?: string;
path: string; path: string;
routes?: R extends true ? MenuDataItem<R>[] : never;
[key: string]: any; [key: string]: any;
} }
export interface BaseMenuProps { export interface Route extends MenuDataItem {
routes?: Route[];
}
export interface BaseMenuProps extends Partial<RouterTypes<Route>> {
className?: string; className?: string;
collapsed?: boolean; collapsed?: boolean;
flatMenuKeys?: any[]; flatMenuKeys?: any[];
handleOpenChange?: (openKeys: string[]) => void; handleOpenChange?: (openKeys: string[]) => void;
isMobile?: boolean; isMobile?: boolean;
location?: Location;
menuData?: MenuDataItem[]; menuData?: MenuDataItem[];
mode?: MenuMode; mode?: MenuMode;
onCollapse?: (collapsed: boolean) => void; onCollapse?: (collapsed: boolean) => void;
...@@ -62,9 +62,8 @@ export interface BaseMenuProps { ...@@ -62,9 +62,8 @@ export interface BaseMenuProps {
} }
export default class BaseMenu extends Component<BaseMenuProps> { export default class BaseMenu extends Component<BaseMenuProps> {
static defaultProps: BaseMenuProps = { static defaultProps: Partial<BaseMenuProps> = {
flatMenuKeys: [], flatMenuKeys: [],
location: window.location,
onCollapse: () => void 0, onCollapse: () => void 0,
isMobile: false, isMobile: false,
openKeys: [], openKeys: [],
...@@ -107,7 +106,7 @@ export default class BaseMenu extends Component<BaseMenuProps> { ...@@ -107,7 +106,7 @@ export default class BaseMenu extends Component<BaseMenuProps> {
item.icon ? ( item.icon ? (
<span> <span>
{getIcon(item.icon)} {getIcon(item.icon)}
<span>{name}</span> <span>{item.name}</span>
</span> </span>
) : ( ) : (
item.name item.name
......
...@@ -25,9 +25,8 @@ interface SiderMenuState { ...@@ -25,9 +25,8 @@ interface SiderMenuState {
} }
export default class SiderMenu extends Component<SiderMenuProps, SiderMenuState> { export default class SiderMenu extends Component<SiderMenuProps, SiderMenuState> {
static defaultProps: SiderMenuProps = { static defaultProps: Partial<SiderMenuProps> = {
flatMenuKeys: [], flatMenuKeys: [],
location: window.location,
onCollapse: () => void 0, onCollapse: () => void 0,
isMobile: false, isMobile: false,
openKeys: [], openKeys: [],
......
...@@ -5,7 +5,7 @@ import SiderMenu from './SiderMenu'; ...@@ -5,7 +5,7 @@ import SiderMenu from './SiderMenu';
import { getFlatMenuKeys } from './SiderMenuUtils'; import { getFlatMenuKeys } from './SiderMenuUtils';
export { SiderMenuProps }; export { SiderMenuProps };
export { MenuDataItem } from './BaseMenu'; export { MenuDataItem, Route } from './BaseMenu';
const SiderMenuWrapper: React.FC<SiderMenuProps> = props => { const SiderMenuWrapper: React.FC<SiderMenuProps> = props => {
const { isMobile, menuData, collapsed, onCollapse } = props; const { isMobile, menuData, collapsed, onCollapse } = props;
......
import PageLoading from '@/components/PageLoading';
import SiderMenu, { MenuDataItem, SiderMenuProps } from '@/components/SiderMenu'; import SiderMenu, { MenuDataItem, SiderMenuProps } from '@/components/SiderMenu';
import { ConnectProps, ConnectState, SettingModelState } from '@/models/connect'; import { ConnectProps, ConnectState, SettingModelState } from '@/models/connect';
import getPageTitle from '@/utils/getPageTitle'; import getPageTitle from '@/utils/getPageTitle';
...@@ -51,13 +50,11 @@ export interface BasicLayoutProps ...@@ -51,13 +50,11 @@ export interface BasicLayoutProps
HeaderViewProps, HeaderViewProps,
Partial<SettingModelState> { Partial<SettingModelState> {
breadcrumbNameMap: { [path: string]: MenuDataItem }; breadcrumbNameMap: { [path: string]: MenuDataItem };
route: MenuDataItem;
} }
export interface BasicLayoutContext { export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & {
location: Location;
breadcrumbNameMap: { [path: string]: MenuDataItem }; breadcrumbNameMap: { [path: string]: MenuDataItem };
} };
const BasicLayout: React.FC<BasicLayoutProps> = props => { const BasicLayout: React.FC<BasicLayoutProps> = props => {
const { const {
...@@ -71,8 +68,9 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => { ...@@ -71,8 +68,9 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
location, location,
menuData, menuData,
navTheme, navTheme,
route: { routes, authority }, route,
} = props; } = props;
const { routes, authority } = route!;
/** /**
* constructor * constructor
*/ */
...@@ -130,13 +128,13 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => { ...@@ -130,13 +128,13 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
<DocumentTitle title={getPageTitle(location!.pathname, breadcrumbNameMap)}> <DocumentTitle title={getPageTitle(location!.pathname, breadcrumbNameMap)}>
<ContainerQuery query={query}> <ContainerQuery query={query}>
{params => ( {params => (
<Context.Provider value={{ location: location!, breadcrumbNameMap }}> <Context.Provider value={{ location, breadcrumbNameMap }}>
<div className={classNames(params)}>{layout}</div> <div className={classNames(params)}>{layout}</div>
</Context.Provider> </Context.Provider>
)} )}
</ContainerQuery> </ContainerQuery>
</DocumentTitle> </DocumentTitle>
<Suspense fallback={<PageLoading />}>{renderSettingDrawer()}</Suspense> <Suspense fallback={null}>{renderSettingDrawer()}</Suspense>
</React.Fragment> </React.Fragment>
); );
}; };
......
...@@ -28,7 +28,7 @@ const FooterView = () => ( ...@@ -28,7 +28,7 @@ const FooterView = () => (
]} ]}
copyright={ copyright={
<Fragment> <Fragment>
Copyright <Icon type="copyright" /> 2018 蚂蚁金服体验技术部出品 Copyright <Icon type="copyright" /> 2019 蚂蚁金服体验技术部出品
</Fragment> </Fragment>
} }
/> />
......
...@@ -25,7 +25,7 @@ interface HeaderViewState { ...@@ -25,7 +25,7 @@ interface HeaderViewState {
} }
class HeaderView extends Component<HeaderViewProps, HeaderViewState> { class HeaderView extends Component<HeaderViewProps, HeaderViewState> {
static defaultProps: HeaderViewProps = { static defaultProps: Partial<HeaderViewProps> = {
handleMenuCollapse: () => void 0, handleMenuCollapse: () => void 0,
}; };
......
...@@ -37,17 +37,14 @@ const copyright = ( ...@@ -37,17 +37,14 @@ const copyright = (
); );
export interface UserLayoutProps extends ConnectProps { export interface UserLayoutProps extends ConnectProps {
route: MenuDataItem;
breadcrumbNameMap: { [path: string]: MenuDataItem }; breadcrumbNameMap: { [path: string]: MenuDataItem };
navTheme: string; navTheme: string;
} }
class UserLayout extends Component<UserLayoutProps> { class UserLayout extends Component<UserLayoutProps> {
componentDidMount() { componentDidMount() {
const { const { dispatch, route } = this.props;
dispatch, const { routes, authority } = route!;
route: { routes, authority },
} = this.props;
dispatch!({ dispatch!({
type: 'menu/getMenuData', type: 'menu/getMenuData',
payload: { routes, authority }, payload: { routes, authority },
......
import { Route } from '@/components/SiderMenu';
import { EffectsCommandMap } from 'dva'; import { EffectsCommandMap } from 'dva';
import { AnyAction } from 'redux'; import { AnyAction } from 'redux';
import { RouterTypes } from 'umi';
import { GlobalModelState } from './global'; import { GlobalModelState } from './global';
import { MenuModelState } from './menu'; import { MenuModelState } from './menu';
import { UserModelState } from './user'; import { UserModelState } from './user';
...@@ -44,18 +46,10 @@ export interface ConnectState { ...@@ -44,18 +46,10 @@ export interface ConnectState {
/** /**
* @type T: Params matched in dynamic routing * @type T: Params matched in dynamic routing
* @type R: Instance type of ref
*/ */
export interface ConnectProps<T extends { [key: string]: any } = {}, R = any> export interface ConnectProps<T extends { [key: string]: any } = {}>
extends React.Props<R> { extends Partial<RouterTypes<Route>> {
dispatch?: Dispatch; dispatch?: Dispatch;
location?: Location;
match?: {
isExact: boolean;
params: T;
path: string;
url: string;
};
} }
export default ConnectState; export default ConnectState;
...@@ -2,9 +2,9 @@ import { queryNotices } from '@/services/user'; ...@@ -2,9 +2,9 @@ import { queryNotices } from '@/services/user';
import { Subscription } from 'dva'; import { Subscription } from 'dva';
import { Reducer } from 'redux'; import { Reducer } from 'redux';
import { Effect } from './connect'; 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; id: string;
type: string; type: string;
[key: string]: any; [key: string]: any;
......
import { MenuDataItem } from '@/components/SiderMenu'; import { MenuDataItem, Route } from '@/components/SiderMenu';
import Authorized from '@/utils/Authorized'; import Authorized from '@/utils/Authorized';
import { Effect } from 'dva'; import { Effect } from 'dva';
import isEqual from 'lodash/isEqual'; import isEqual from 'lodash/isEqual';
...@@ -10,7 +10,7 @@ import defaultSettings from '../../config/defaultSettings'; ...@@ -10,7 +10,7 @@ import defaultSettings from '../../config/defaultSettings';
// Conversion router to menu. // Conversion router to menu.
function formatter( function formatter(
data: MenuDataItem[], data: Route[],
parentAuthority?: string[] | string, parentAuthority?: string[] | string,
parentName?: string, parentName?: string,
): MenuDataItem[] { ): MenuDataItem[] {
...@@ -27,6 +27,7 @@ function formatter( ...@@ -27,6 +27,7 @@ function formatter(
...item, ...item,
name, name,
locale, locale,
routes: void 0,
authority: item.authority || parentAuthority, authority: item.authority || parentAuthority,
}; };
if (item.routes) { if (item.routes) {
...@@ -34,7 +35,6 @@ function formatter( ...@@ -34,7 +35,6 @@ function formatter(
// Reduce memory usage // Reduce memory usage
result.children = children; result.children = children;
} }
delete result.routes;
return result; return result;
}); });
} }
......
import Authorized from '@/utils/Authorized'; import Authorized from '@/utils/Authorized';
import { Route } from '@/components/SiderMenu';
import { ConnectProps, ConnectState, UserModelState } from '@/models/connect'; import { ConnectProps, ConnectState, UserModelState } from '@/models/connect';
import { connect } from 'dva'; import { connect } from 'dva';
import pathToRegexp from 'path-to-regexp'; import pathToRegexp from 'path-to-regexp';
import React from 'react'; import React from 'react';
import Redirect from 'umi/redirect'; import Redirect from 'umi/redirect';
import { IRoute } from 'umi-types';
interface AuthComponentProps extends ConnectProps { interface AuthComponentProps extends ConnectProps {
location: Location; routerData: Route[];
routerData: IRoute[];
user: UserModelState; user: UserModelState;
} }
const getRouteAuthority = (path: string, routeData: IRoute[]) => { const getRouteAuthority = (path: string, routeData: Route[]) => {
let authorities: string[] | string | undefined = void 0; let authorities: string[] | string | undefined = void 0;
routeData.forEach(route => { routeData.forEach(route => {
// match prefix // match prefix
...@@ -32,7 +31,7 @@ const AuthComponent: React.FC<AuthComponentProps> = ({ children, location, route ...@@ -32,7 +31,7 @@ const AuthComponent: React.FC<AuthComponentProps> = ({ children, location, route
const isLogin = currentUser && currentUser.name; const isLogin = currentUser && currentUser.name;
return ( return (
<Authorized <Authorized
authority={getRouteAuthority(location.pathname, routerData)!} authority={getRouteAuthority(location!.pathname, routerData)!}
noMatch={isLogin ? <Redirect to="/exception/403" /> : <Redirect to="/user/login" />} noMatch={isLogin ? <Redirect to="/exception/403" /> : <Redirect to="/user/login" />}
> >
{children} {children}
......
...@@ -13,29 +13,3 @@ declare module 'rc-animate'; ...@@ -13,29 +13,3 @@ declare module 'rc-animate';
declare module 'omit.js'; declare module 'omit.js';
declare module 'react-copy-to-clipboard'; declare module 'react-copy-to-clipboard';
declare var APP_TYPE: string; 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<keyof INoticeIconProps, 'locale'>]?: INoticeIconProps[K]
};
interface MixinNoticeIconProps extends PartialNoticeIconProps {
locale?: {
emptyText: string;
clear: string;
viewMore: string;
[key: string]: string;
};
onViewMore?: (tabProps: INoticeIconProps) => void;
}
interface MixinNoticeIconTabProps extends Partial<INoticeIconTabProps> {
showViewMore?: boolean;
}
class NoticeIconTab extends React.Component<MixinNoticeIconTabProps, any> {}
export class NoticeIcon extends React.Component<MixinNoticeIconProps, any> {
public static Tab: typeof NoticeIconTab;
}
export * from 'ant-design-pro/lib';
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment