diff --git a/.eslintrc.js b/.eslintrc.js index a8d6638874f6e7687714b5b061125bbf3bc00677..f06f75feef4a196fa4d71d8388a892d7aaf54c74 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,28 +1,9 @@ -const fabric = require('@umijs/fabric'); +const fabric = require('@duanledexian/umi-config'); module.exports = { ...fabric.default, rules: { ...fabric.default.rules, - 'import/no-extraneous-dependencies': [ - 2, - { - optionalDependencies: true, - devDependencies: ['**/tests/**.js', '/mock/**/**.js', '**/**.test.js', '**/**._mock.js'], - }, - ], - 'import/no-named-as-default': 0, - }, - settings: { - ...fabric.default.settings, - // support import modules from TypeScript files in JavaScript files - 'import/resolver': { - node: { extensions: ['.js', '.ts', '.tsx'] }, - alias: { - map: [['@', './src'], ['utils', './src/utils'], ['config', './config']], - extensions: ['.ts', '.js', '.jsx', '.json'], - }, - }, }, globals: { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true, diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000000000000000000000000000000000000..882af8d093d51a42791c7c1d7c9ce0551cbdfa32 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +puppeteer_download_host = https://npm.taobao.org/mirrors \ No newline at end of file diff --git a/.prettierrc.js b/.prettierrc.js index 7b597d78917c7e33a81bb3e83c6067f6a9a970e6..347877026736179f959197dbff152922a90532e3 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,4 @@ -const fabric = require('@umijs/fabric'); +const fabric = require('@duanledexian/umi-config'); module.exports = { ...fabric.prettier, diff --git a/.stylelintrc.js b/.stylelintrc.js index c2030787de72c5cffc44099fbdbae55c32afd482..559ecd841804b23e5cf58a4d60716ee9916242d8 100644 --- a/.stylelintrc.js +++ b/.stylelintrc.js @@ -1,4 +1,4 @@ -const fabric = require('@umijs/fabric'); +const fabric = require('@duanledexian/umi-config'); module.exports = { ...fabric.stylelint, diff --git a/config/config.ts b/config/config.ts index cd2052c8ece4730c4abecea94e26c5868fb17833..0dca86014d40fd9e39be03120ea2ee5a69e271d4 100644 --- a/config/config.ts +++ b/config/config.ts @@ -1,16 +1,15 @@ import { IConfig, IPlugin } from 'umi-types'; import defaultSettings from './defaultSettings'; // https://umijs.org/config/ -import theme from './theme.config'; - -import os from 'os'; import slash from 'slash2'; import webpackPlugin from './plugin.config'; const path = require('path'); const { pwa } = defaultSettings; // preview.pro.ant.design only do not use in your production ; // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 +const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env; + +const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site'; -const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST, NODE_ENV } = process.env; const plugins: IPlugin[] = [ [ 'umi-plugin-react', @@ -40,15 +39,10 @@ const plugins: IPlugin[] = [ }, } : false, - ...(!TEST && os.platform() === 'darwin' - ? { - dll: { - include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'], - exclude: ['@babel/runtime', 'netlify-lambda'], - }, - hardSource: false, - } - : {}), + dll: { + include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'], + exclude: ['@babel/runtime', 'netlify-lambda'], + }, }, ], [ @@ -60,10 +54,10 @@ const plugins: IPlugin[] = [ autoAddMenu: true, }, ], -]; // 针对 preview.pro.ant.design 的 GA 统计代码 -// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 +]; -if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') { +// 针对 preview.pro.ant.design 的 GA 统计代码 +if (isAntDesignProPreview) { plugins.push([ 'umi-plugin-ga', { @@ -72,34 +66,17 @@ if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') { ]); } -const uglifyJSOptions = - NODE_ENV === 'production' - ? { - uglifyOptions: { - // remove console.* except console.error - compress: { - drop_console: true, - pure_funcs: ['console.error'], - }, - }, - } - : {}; export default { - // add for transfer to umi plugins, - define: { - ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: - ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 - }, block: { defaultGitUrl: 'https://github.com/ant-design/pro-blocks', }, - treeShaking: true, + hash: true, targets: { ie: 11, }, - devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false, - // 路由配置 + devtool: isAntDesignProPreview ? 'source-map' : false, + // umi routes: https://umijs.org/zh/guide/router.html routes: [ { path: '/', @@ -336,8 +313,14 @@ export default { }, ], }, + { + component: './404', + }, ], }, + { + component: './404', + }, ], // Theme for antd // https://ant.design/docs/react/customize-theme-cn @@ -349,6 +332,14 @@ export default { // pathRewrite: { '^/server': '' }, // }, // }, + // Theme for antd: https://ant.design/docs/react/customize-theme-cn + theme: { + 'primary-color': primaryColor, + }, + define: { + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 + }, ignoreMomentLocale: true, lessLoaderOptions: { javascriptEnabled: true, @@ -360,7 +351,7 @@ export default { context: { resourcePath: string; }, - localIdentName: string, + _: string, localName: string, ) => { if ( @@ -400,4 +391,13 @@ export default { config: path.join(__dirname, '../src', '../config'), public: path.join(__dirname, '../public'), }, + /* + proxy: { + '/server/api/': { + target: 'https://preview.pro.ant.design/', + changeOrigin: true, + pathRewrite: { '^/server': '' }, + }, + }, + */ } as IConfig; diff --git a/jest.config.js b/jest.config.js index 147a0252e938fa18917cac5bdc4446e1f86765a8..c06625f492d3f6d65eecbc1368db83d3ae9e6787 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,6 +3,6 @@ module.exports = { preset: 'jest-puppeteer', extraSetupFiles: ['./tests/setupTests.js'], globals: { - ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false, // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false, }, }; diff --git a/package.json b/package.json index 02f18ae625d279743680cd88e74ee86d68a55dcf..12f7bc146efde853cac88a1817d8fa60ae0c4752 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ }, "husky": { "hooks": { - + "pre-commit": "npm run lint-staged" } }, "lint-staged": { @@ -94,16 +94,18 @@ }, "devDependencies": { "@ant-design/colors": "^3.1.0", + "@duanledexian/umi-config": "^1.0.10", "@types/classnames": "^2.2.7", "@types/history": "^4.7.2", "@types/jest": "^24.0.13", "@types/lodash": "^4.14.134", + "@types/mockjs": "^1.0.2", + "@types/numeral": "^0.0.25", "@types/qs": "^6.5.3", "@types/react": "^16.8.19", "@types/react-document-title": "^2.0.3", "@types/react-dom": "^16.8.4", "@types/numeral":"^0.0.25", - "@umijs/fabric": "^1.0.5", "babel-eslint": "^10.0.1", "chalk": "^2.4.2", "check-prettier": "^1.0.3", @@ -129,9 +131,8 @@ "stylelint": "^10.1.0", "webpack-theme-color-replacer": "^1.1.5", "mockjs": "^1.0.1-beta3", - "@types/mockjs":"^1.0.2", - "eslint-import-resolver-alias": "^1.1.2" - }, + "@types/mockjs":"^1.0.2" + }, "optionalDependencies": { "puppeteer": "^1.17.0" }, diff --git a/scripts/fetch-blocks.js b/scripts/fetch-blocks.js index 9e182b75e96a3a0a8f36c90ad6899f83510b3f17..996ef78f8f28630d3e61daafbbd5cff3e7916ee5 100644 --- a/scripts/fetch-blocks.js +++ b/scripts/fetch-blocks.js @@ -41,6 +41,9 @@ const findAllInstallRouter = router => { const filterParentRouter = (router, layout) => { return [...router] .map(item => { + if (!item.path && item.component === '404') { + return item; + } if (item.routes && (!router.component || layout)) { return { ...item, routes: filterParentRouter(item.routes, false) }; } @@ -94,7 +97,7 @@ const installBlock = async () => { console.log('install ' + chalk.green(item.name) + ' to: ' + chalk.yellow(item.path)); gitFiles = gitFiles.filter(file => file.path !== gitPath); const skipModifyRouter = item.routes ? '--skip-modify-routes' : ''; - const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${gitPath} --path=${item.path} ${skipModifyRouter}`; + const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${gitPath} --path=${item.path} ${skipModifyRouter}`; try { await execCmd(cmd); console.log(`install ${chalk.hex('#1890ff')(item.name)} success`); diff --git a/src/components/CopyBlock/index.tsx b/src/components/CopyBlock/index.tsx index 9ee05ae8739bd1f254aad654f0fe0911feebad7e..fb9d8ac09a40007aaab24e13a29fc1dbc13658ef 100644 --- a/src/components/CopyBlock/index.tsx +++ b/src/components/CopyBlock/index.tsx @@ -33,7 +33,7 @@ const onBlockCopy = (label: string) => { const BlockCodeView: React.SFC<{ url: string; }> = ({ url }) => { - const blockUrl = `npx umi block add ${firstUpperCase(url)} --path=${url}`; + const blockUrl = `npx umi block add ${firstUpperCase(url)} --path=${url}`; return (
void; } const NoticeList: React.SFC = ({ diff --git a/src/components/NoticeIcon/index.tsx b/src/components/NoticeIcon/index.tsx index 322ca3e8543c96221c04b1df7132e4fac32a1ce2..8876ef9312740653e95263847102ed37886a9993 100644 --- a/src/components/NoticeIcon/index.tsx +++ b/src/components/NoticeIcon/index.tsx @@ -117,7 +117,7 @@ export default class NoticeIcon extends Component { }, ); return ( - + {panes} diff --git a/src/models/global.ts b/src/models/global.ts index 367ac486171ffd9bac371993b0e1d4822a039895..a79cac67d800178bde088e6440556bcfb25f42a2 100644 --- a/src/models/global.ts +++ b/src/models/global.ts @@ -7,6 +7,7 @@ import { queryNotices } from '@/services/user'; export interface NoticeItem extends NoticeIconData { id: string; type: string; + status: string; } export interface GlobalModelState { diff --git a/src/pages/404.tsx b/src/pages/404.tsx new file mode 100644 index 0000000000000000000000000000000000000000..80fe09c9427ee294a7c8385cf8b1083b0dac3e4d --- /dev/null +++ b/src/pages/404.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import { Button } from 'antd'; +import router from 'umi/router'; + +// 这里应该使用 antd 的 404 result 组件, +// 但是还没发布,先来个简单的。 + +const NoFoundPage: React.FC<{}> = () => ( +
+ 404 +
+
+

404

+

Sorry, the page you visited does not exist.

+ +
+); + +export default NoFoundPage; diff --git a/src/pages/Authorized.tsx b/src/pages/Authorized.tsx index 9951b11e70ae6c5dc40ebf0c985290565b585097..8de52d42ccea89b2d0b9809e8e519d9c57b140ce 100644 --- a/src/pages/Authorized.tsx +++ b/src/pages/Authorized.tsx @@ -14,7 +14,10 @@ const getRouteAuthority = (path: string, routeData: Route[]) => { routeData.forEach(route => { // match prefix if (pathToRegexp(`${route.path}(.*)`).test(path)) { - authorities = route.authority || authorities; + // exact match + if (route.path === path) { + authorities = route.authority || authorities; + } // get children authority recursively if (route.routes) { authorities = getRouteAuthority(path, route.routes) || authorities; diff --git a/src/pages/account/settings/components/base.tsx b/src/pages/account/settings/components/base.tsx index e7968677bdcf8e0c6a8b85c6ee1952e7242b34e8..c9fc2ee11bedbdd48ba7f576a270a3718b1dfdcb 100644 --- a/src/pages/account/settings/components/base.tsx +++ b/src/pages/account/settings/components/base.tsx @@ -24,7 +24,10 @@ const AvatarView = ({ avatar }: { avatar: string }) => (
@@ -207,7 +210,10 @@ class BaseView extends Component { })()}
diff --git a/src/pages/account/settings/components/notification.tsx b/src/pages/account/settings/components/notification.tsx index 334686fb287467cc86826e30efed564ed36134b5..7ea84bc9acc928e5aba2c3a8ada5112519428072 100644 --- a/src/pages/account/settings/components/notification.tsx +++ b/src/pages/account/settings/components/notification.tsx @@ -17,12 +17,18 @@ class NotificationView extends Component { return [ { title: formatMessage({ id: 'account-settings.notification.password' }, {}), - description: formatMessage({ id: 'account-settings.notification.password-description' }, {}), + description: formatMessage( + { id: 'account-settings.notification.password-description' }, + {}, + ), actions: [Action], }, { title: formatMessage({ id: 'account-settings.notification.messages' }, {}), - description: formatMessage({ id: 'account-settings.notification.messages-description' }, {}), + description: formatMessage( + { id: 'account-settings.notification.messages-description' }, + {}, + ), actions: [Action], }, { diff --git a/src/pages/account/settings/index.tsx b/src/pages/account/settings/index.tsx index 5ebf0a71dedd7bf7e3727ce4fdadb955d6e4ee70..32f42ae7edc6074c037191918dd33ea5e99af3b0 100644 --- a/src/pages/account/settings/index.tsx +++ b/src/pages/account/settings/index.tsx @@ -30,18 +30,20 @@ interface SettingsState { @connect(({ accountSettings }: { accountSettings: { currentUser: CurrentUser } }) => ({ currentUser: accountSettings.currentUser, })) -class Settings extends Component< - SettingsProps, - SettingsState -> { +class Settings extends Component { main: HTMLDivElement | undefined = undefined; constructor(props: SettingsProps) { super(props); const menuMap = { - base: , + base: ( + + ), security: ( - + ), binding: ( diff --git a/src/pages/dashboard/analysis/components/IntroduceRow.tsx b/src/pages/dashboard/analysis/components/IntroduceRow.tsx index e32004c6afd68306d02ce5b91efd34381f631abc..950743fa43e792dca8756a0af3df01b61036863c 100644 --- a/src/pages/dashboard/analysis/components/IntroduceRow.tsx +++ b/src/pages/dashboard/analysis/components/IntroduceRow.tsx @@ -24,12 +24,18 @@ const IntroduceRow = ({ loading, visitData }: { loading: boolean; visitData: Vis + } action={ + } > @@ -40,7 +46,10 @@ const IntroduceRow = ({ loading, visitData }: { loading: boolean; visitData: Vis footer={ + } value={`¥${numeral(12423).format('0,0')}`} /> @@ -66,7 +75,10 @@ const IntroduceRow = ({ loading, visitData }: { loading: boolean; visitData: Vis action={ + } > @@ -76,7 +88,10 @@ const IntroduceRow = ({ loading, visitData }: { loading: boolean; visitData: Vis footer={ + } value={numeral(1234).format('0,0')} /> @@ -90,11 +105,16 @@ const IntroduceRow = ({ loading, visitData }: { loading: boolean; visitData: Vis } + title={ + + } action={ + } > @@ -130,7 +150,10 @@ const IntroduceRow = ({ loading, visitData }: { loading: boolean; visitData: Vis action={ + } > @@ -140,11 +163,17 @@ const IntroduceRow = ({ loading, visitData }: { loading: boolean; visitData: Vis footer={
- + 12% - + 11%
diff --git a/src/pages/dashboard/analysis/components/ProportionSales.tsx b/src/pages/dashboard/analysis/components/ProportionSales.tsx index 3a5b18802625dd17f145fc36e92dd3716809b044..feab6c1d0230b251a13923c62ea123019e1ffd84 100644 --- a/src/pages/dashboard/analysis/components/ProportionSales.tsx +++ b/src/pages/dashboard/analysis/components/ProportionSales.tsx @@ -59,7 +59,9 @@ const ProportionSales = ({ } + subTitle={ + + } total={() => {salesPieData.reduce((pre, now) => now.y + pre, 0)}} data={salesPieData} valueFormat={value => {value}} diff --git a/src/pages/dashboard/analysis/components/SalesCard.tsx b/src/pages/dashboard/analysis/components/SalesCard.tsx index c2a21fcf5093066366cd5d14381b7be7c140ed16..224769afec4a2d700f9ba0b12349edb6e3c28c7b 100644 --- a/src/pages/dashboard/analysis/components/SalesCard.tsx +++ b/src/pages/dashboard/analysis/components/SalesCard.tsx @@ -41,16 +41,28 @@ const SalesCard = ({
+ ), dataIndex: 'keyword', key: 'keyword', @@ -31,7 +34,9 @@ const columns = [ className: styles.alignRight, }, { - title: , + title: ( + + ), dataIndex: 'range', key: 'range', sorter: (a: { range: number }, b: { range: number }) => a.range - b.range, @@ -79,7 +84,10 @@ const TopSearch = ({ /> + } > @@ -103,7 +111,10 @@ const TopSearch = ({ /> + } > diff --git a/src/pages/form/basic-form/index.tsx b/src/pages/form/basic-form/index.tsx index 3a65b2bb0c61ec8e6e4d64d957d05608438d735c..33aac5ae326edaebead01b30eac81b7fe6251cfc 100644 --- a/src/pages/form/basic-form/index.tsx +++ b/src/pages/form/basic-form/index.tsx @@ -71,7 +71,10 @@ class BasicForm extends Component { }>
- }> + } + > {getFieldDecorator('title', { rules: [ { @@ -79,9 +82,14 @@ class BasicForm extends Component { message: formatMessage({ id: 'form-basic-form.title.required' }), }, ], - })()} + })( + , + )} - }> + } + > {getFieldDecorator('date', { rules: [ { @@ -99,7 +107,10 @@ class BasicForm extends Component { />, )} - }> + } + > {getFieldDecorator('goal', { rules: [ { @@ -164,7 +175,9 @@ class BasicForm extends Component { } > {getFieldDecorator('invites')( - , + , )} { +class BasicList extends Component { state: BasicListState = { visible: false, done: false, current: undefined }; formLayout = { diff --git a/src/pages/list/card-list/index.tsx b/src/pages/list/card-list/index.tsx index 6a39333ff3deb42d90f4d27ec9657f4db15d3da0..61ac71b8343fb91a6281df266278578056c59ead 100644 --- a/src/pages/list/card-list/index.tsx +++ b/src/pages/list/card-list/index.tsx @@ -35,10 +35,7 @@ interface CardListState { loading: loading.models.list, }), ) -class CardList extends Component< - CardListProps, - CardListState -> { +class CardList extends Component { componentDidMount() { const { dispatch } = this.props; dispatch({ diff --git a/src/pages/list/table-list/_mock.ts b/src/pages/list/table-list/_mock.ts index c22e0ca05fd97f6bed226cd022b71e48e90919f0..6f0799956369413d6b88e33c6efbe6a8ef11b071 100644 --- a/src/pages/list/table-list/_mock.ts +++ b/src/pages/list/table-list/_mock.ts @@ -28,12 +28,10 @@ for (let i = 0; i < 8; i += 1) { function getRule( req: { url: any }, res: { - json: ( - arg0: { - list: TableListItem[]; - pagination: { total: number; pageSize: number; current: number }; - }, - ) => void; + json: (arg0: { + list: TableListItem[]; + pagination: { total: number; pageSize: number; current: number }; + }) => void; }, u: any, ) { diff --git a/src/pages/list/table-list/components/CreateForm.tsx b/src/pages/list/table-list/components/CreateForm.tsx index 323dc31f0c9b176fbb408281a9f0fef3b2334e39..35efb1e837d4acc6c243f87a1ded58536d33a9cc 100644 --- a/src/pages/list/table-list/components/CreateForm.tsx +++ b/src/pages/list/table-list/components/CreateForm.tsx @@ -7,11 +7,7 @@ const FormItem = Form.Item; interface CreateFormProps extends FormComponentProps { modalVisible: boolean; - handleAdd: ( - fieldsValue: { - desc: string; - }, - ) => void; + handleAdd: (fieldsValue: { desc: string }) => void; handleModalVisible: () => void; } const CreateForm: React.SFC = props => { diff --git a/src/pages/profile/basic/index.tsx b/src/pages/profile/basic/index.tsx index 22a1e43519acdf39d579e207d7fa4d21e4ffe4bd..19671235aa1f6213ed59ad7e9cb87b4868a955ab 100644 --- a/src/pages/profile/basic/index.tsx +++ b/src/pages/profile/basic/index.tsx @@ -65,10 +65,7 @@ interface BasicState { loading: loading.effects['profileBasic/fetchBasic'], }), ) -class Basic extends Component< - BasicProps, - BasicState -> { +class Basic extends Component { componentDidMount() { const { dispatch } = this.props; dispatch({ diff --git a/src/pages/result/success/index.tsx b/src/pages/result/success/index.tsx index c77a857065fb70e3890d9ad08b1ad5890d38ce0d..94a0bc593ec3537c657b8746bb7c72073393c7dc 100644 --- a/src/pages/result/success/index.tsx +++ b/src/pages/result/success/index.tsx @@ -64,7 +64,10 @@ const extra = ( - + } description={desc1} diff --git a/src/pages/user/login/index.tsx b/src/pages/user/login/index.tsx index 1be1f7321c58f456f8cc906c196ac37beecd6bd7..942b46f7134c6878cfe853376aa2e2fbc61ab889 100644 --- a/src/pages/user/login/index.tsx +++ b/src/pages/user/login/index.tsx @@ -45,10 +45,7 @@ export interface FromDataType { submitting: loading.effects['userLogin/login'], }), ) -class Login extends Component< - LoginProps, - LoginState -> { +class Login extends Component { loginForm: FormComponentProps['form'] | undefined | null = undefined; state: LoginState = { diff --git a/src/typings.d.ts b/src/typings.d.ts index fff79b4347eb239612e60fb3129d76ad766f1722..c06709b6769b85ea747581ad7aa11cb49623f2c7 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -21,6 +21,13 @@ declare module 'nzh/cn'; declare module 'webpack-theme-color-replacer'; declare module 'webpack-theme-color-replacer/client'; +// src/typings.d.ts +declare module 'umi-plugin-react/locale' { + export default interface MessageDescriptor { + id: string; + } /* eslint-disable-line */ +} + declare let ga: Function; // preview.pro.ant.design only do not use in your production ;