Skip to content

Commit

Permalink
remove all code
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed May 14, 2019
1 parent 6639cbe commit 7e187a9
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 272 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = {
jasmine: true,
},
globals: {
ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true, // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
page: true,
},
rules: {
Expand Down
6 changes: 4 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"overrides": [
{
"files": ".prettierrc",
"options": { "parser": "json" }
"options": {
"parser": "json"
}
}
]
}
}
12 changes: 9 additions & 3 deletions config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ export default {
disableRedirectHoist: true,
cssLoaderOptions: {
modules: true,
getLocalIdent: (context, localIdentName, localName) => {
getLocalIdent: (
context: {
resourcePath: string;
},
localIdentName: string,
localName: string,
) => {
if (
context.resourcePath.includes('node_modules') ||
context.resourcePath.includes('ant.design.pro.less') ||
Expand All @@ -134,8 +140,8 @@ export default {
const antdProPath = match[1].replace('.less', '');
const arr = slash(antdProPath)
.split('/')
.map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase());
.map((a: string) => a.replace(/([A-Z])/g, '-$1'))
.map((a: string) => a.toLowerCase());
return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
}
return localName;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
"not ie <= 10"
],
"dependencies": {
"@ant-design/pro-layout": "^4.1.0",
"@ant-design/pro-layout": "^4.2.0",
"@antv/data-set": "^0.10.1",
"antd": "^3.16.1",
"antd": "^3.18.1",
"bizcharts": "3.5.2-beta.1",
"bizcharts-plugin-slider": "^2.1.1-beta.1",
"classnames": "^2.2.6",
Expand Down Expand Up @@ -146,4 +146,4 @@
"config/**/*.js*",
"scripts/**/*.js"
]
}
}
4 changes: 0 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ export const dva = {
},
},
};

export function render(oldRender) {
oldRender();
}
2 changes: 1 addition & 1 deletion src/components/Authorized/AuthorizedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IAuthorityType } from './CheckPermissions';
interface IAuthorizedRoutePops {
currentAuthority: string;
component: React.ComponentClass<any, any>;
render: () => React.ReactNode;
render: (props: any) => React.ReactNode;
redirectPath: string;
authority: IAuthorityType;
}
Expand Down
20 changes: 9 additions & 11 deletions src/components/Authorized/CheckPermissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export type IAuthorityType =
* @param { 通过的组件 | Passing components } target
* @param { 未通过的组件 | no pass components } Exception
*/
const checkPermissions = (
const checkPermissions = <T, K>(
authority: IAuthorityType,
currentAuthority: string | string[],
target: React.ComponentClass<any, any> | React.ReactNode,
Exception: React.ReactNode,
): React.ReactNode => {
target: T,
Exception: K,
): T | K | React.ReactNode => {
// 没有判定权限.默认查看所有
// Retirement authority, return target;
if (!authority) {
Expand Down Expand Up @@ -52,15 +52,15 @@ const checkPermissions = (
}
// Promise 处理
if (authority instanceof Promise) {
return <PromiseRender ok={target} error={Exception} promise={authority} />;
return <PromiseRender<T, K> ok={target} error={Exception} promise={authority} />;
}
// Function 处理
if (typeof authority === 'function') {
try {
const bool = authority(currentAuthority);
// 函数执行后返回值是 Promise
if (bool instanceof Promise) {
return <PromiseRender ok={target} error={Exception} promise={bool} />;
return <PromiseRender<T, K> ok={target} error={Exception} promise={bool} />;
}
if (bool) {
return target;
Expand All @@ -75,10 +75,8 @@ const checkPermissions = (

export { checkPermissions };

const check = (
authority: IAuthorityType,
target: React.ComponentClass<any, any> | React.ReactNode,
Exception: React.ReactNode,
): React.ReactNode => checkPermissions(authority, CURRENT, target, Exception);
function check<T, K>(authority: IAuthorityType, target: T, Exception: K): T | K | React.ReactNode {
return checkPermissions<T, K>(authority, CURRENT, target, Exception);
}

export default check;
17 changes: 10 additions & 7 deletions src/components/Authorized/PromiseRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import React from 'react';
// eslint-disable-next-line import/no-cycle
import { isComponentClass } from './Secured';

interface IPromiseRenderProps {
ok: React.ReactNode;
error: React.ReactNode;
interface IPromiseRenderProps<T, K> {
ok: T;
error: K;
promise: Promise<any>;
}

interface IPromiseRenderState {
component: React.ComponentClass<any, any> | React.FunctionComponent<any>;
}

export default class PromiseRender extends React.Component<
IPromiseRenderProps,
export default class PromiseRender<T, K> extends React.Component<
IPromiseRenderProps<T, K>,
IPromiseRenderState
> {
state: IPromiseRenderState = {
Expand All @@ -26,7 +26,10 @@ export default class PromiseRender extends React.Component<
this.setRenderComponent(this.props);
}

shouldComponentUpdate = (nextProps: IPromiseRenderProps, nextState: IPromiseRenderState) => {
shouldComponentUpdate = (
nextProps: IPromiseRenderProps<T, K>,
nextState: IPromiseRenderState,
) => {
const { component } = this.state;
if (!isEqual(nextProps, this.props)) {
this.setRenderComponent(nextProps);
Expand All @@ -36,7 +39,7 @@ export default class PromiseRender extends React.Component<
};

// set render Component : ok or error
setRenderComponent(props: IPromiseRenderProps) {
setRenderComponent(props: IPromiseRenderProps<T, K>) {
const ok = this.checkIsInstantiation(props.ok);
const error = this.checkIsInstantiation(props.error);
props.promise
Expand Down
1 change: 1 addition & 0 deletions src/components/Authorized/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Authorized.AuthorizedRoute = AuthorizedRoute;
Authorized.check = check;

const RenderAuthorize = renderAuthorize(Authorized);

export default RenderAuthorize;
8 changes: 4 additions & 4 deletions src/components/Authorized/renderAuthorize.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable import/no-mutable-exports */
let CURRENT: string | string[] = 'NULL';
type CurrentAuthorityType = string | string[] | (() => typeof CURRENT);
/**
* use authority or getAuthority
* @param {string|()=>String} currentAuthority
*/
const renderAuthorize = (Authorized: any) => (
currentAuthority: string | string[] | (() => typeof CURRENT),
const renderAuthorize = <T>(Authorized: T): ((currentAuthority: CurrentAuthorityType) => T) => (
currentAuthority: CurrentAuthorityType,
) => {
if (currentAuthority) {
if (typeof currentAuthority === 'function') {
Expand All @@ -24,4 +24,4 @@ const renderAuthorize = (Authorized: any) => (
};

export { CURRENT };
export default (Authorized: any) => renderAuthorize(Authorized);
export default <T>(Authorized: T) => renderAuthorize<T>(Authorized);
18 changes: 0 additions & 18 deletions src/components/_utils/pathTools.test.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/components/_utils/pathTools.ts

This file was deleted.

10 changes: 3 additions & 7 deletions src/layouts/BasicLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import RightContent from '@/components/GlobalHeader/RightContent';
import { connect } from 'dva';
import React, { useState } from 'react';
import logo from '../assets/logo.svg';

import {
BasicLayout as BasicLayoutComponents,
BasicLayoutProps as BasicLayoutComponentsProps,
Expand All @@ -23,21 +22,20 @@ export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & {
};

const BasicLayout: React.FC<BasicLayoutProps> = props => {
const { dispatch, children, route, settings } = props;
const { routes, authority } = route!;
const { dispatch, children, settings } = props;
/**
* constructor
*/
useState(() => {
dispatch!({ type: 'user/fetchCurrent' });
dispatch!({ type: 'settings/getSetting' });
dispatch!({ type: 'menu/getMenuData', payload: { routes, authority } });
});
/**
* init variables
*/
const handleMenuCollapse = (payload: boolean) =>
dispatch!({ type: 'global/changeLayoutCollapsed', payload });

return (
<>
<BasicLayoutComponents
Expand Down Expand Up @@ -65,9 +63,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
);
};

export default connect(({ global, settings, menu: menuModel }: ConnectState) => ({
export default connect(({ global, settings }: ConnectState) => ({
collapsed: global.collapsed,
settings,
menuData: menuModel.menuData,
breadcrumbNameMap: menuModel.breadcrumbNameMap,
}))(BasicLayout);
37 changes: 18 additions & 19 deletions src/layouts/UserLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import SelectLang from '@/components/SelectLang';
import GlobalFooter from '@/components/GlobalFooter';
import { ConnectProps, ConnectState } from '@/models/connect';
import getPageTitle from '@/utils/getPageTitle';
import { ConnectProps } from '@/models/connect';
import { Icon } from 'antd';
import { connect } from 'dva';
import React, { Component, Fragment } from 'react';
import DocumentTitle from 'react-document-title';
import { formatMessage } from 'umi-plugin-locale';
import Link from 'umi/link';
import logo from '../assets/logo.svg';
import styles from './UserLayout.less';
import { MenuDataItem } from '@ant-design/pro-layout';
import { MenuDataItem, getPageTitle, getMenuData } from '@ant-design/pro-layout';

const links = [
{
Expand Down Expand Up @@ -42,19 +40,23 @@ export interface UserLayoutProps extends ConnectProps {
}

class UserLayout extends Component<UserLayoutProps> {
componentDidMount() {
const { dispatch, route } = this.props;
const { routes, authority } = route!;
dispatch!({
type: 'menu/getMenuData',
payload: { routes, authority },
});
}

render() {
const { children, location, breadcrumbNameMap } = this.props;
const {
route = {
routes: [],
},
} = this.props;
const { routes = [] } = route;
const { children, location } = this.props;
const { breadcrumb } = getMenuData(routes, this.props);
return (
<DocumentTitle title={getPageTitle(location!.pathname, breadcrumbNameMap)}>
<DocumentTitle
title={getPageTitle({
pathname: location!.pathname,
breadcrumb,
formatMessage,
})}
>
<div className={styles.container}>
<div className={styles.lang}>
<SelectLang />
Expand All @@ -78,7 +80,4 @@ class UserLayout extends Component<UserLayoutProps> {
}
}

export default connect(({ menu: menuModel }: ConnectState) => ({
menuDaDocumentTitleta: menuModel.menuData,
breadcrumbNameMap: menuModel.breadcrumbNameMap,
}))(UserLayout);
export default UserLayout;
4 changes: 1 addition & 3 deletions src/models/connect.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { EffectsCommandMap } from 'dva';
import { AnyAction } from 'redux';
import { RouterTypes } from 'umi';
import { GlobalModelState } from './global';
import { MenuModelState } from './menu';
import { UserModelState } from './user';
import { DefaultSettings as SettingModelState } from '../../config/defaultSettings';
import { MenuDataItem } from '@ant-design/pro-layout';
export { GlobalModelState, MenuModelState, SettingModelState, UserModelState };
export { GlobalModelState, SettingModelState, UserModelState };

export type Effect = (
action: AnyAction,
Expand Down Expand Up @@ -39,7 +38,6 @@ export interface ConnectState {
global: GlobalModelState;
loading: Loading;
settings: SettingModelState;
menu: MenuModelState;
user: UserModelState;
}

Expand Down
Loading

2 comments on commit 7e187a9

@ostli
Copy link
Contributor

@ostli ostli commented on 7e187a9 May 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是把菜单的国际化删掉了?

@chenshuai2144
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放到 layout 中了

Please sign in to comment.