From 0422f6d51e8b1f8e91c2ddeb3fff538ec7bf539f Mon Sep 17 00:00:00 2001 From: Baorong Li Date: Tue, 24 Mar 2020 12:12:20 +0800 Subject: [PATCH] upgrade umi@3 partly --- .umirc.js | 1 - package.json | 1 + src/layouts/BaseLayout.js | 2 +- src/layouts/PrimaryLayout.js | 2 +- src/pages/dashboard/index.js | 2 +- src/pages/login/index.js | 28 ++--- src/pages/login/model.js | 9 +- src/pages/post/index.js | 2 +- src/pages/user/[id]/index.js | 2 +- src/pages/user/components/Filter.js | 154 +++++++++++++--------------- src/pages/user/index.js | 2 +- src/themes/index.less | 8 +- src/utils/config.js | 2 +- src/utils/index.js | 8 +- 14 files changed, 107 insertions(+), 116 deletions(-) diff --git a/.umirc.js b/.umirc.js index 4a522b1..21a9aa3 100644 --- a/.umirc.js +++ b/.umirc.js @@ -39,7 +39,6 @@ export default { components: resolve(__dirname, './src/components'), config: resolve(__dirname, './src/utils/config'), models: resolve(__dirname, './src/models'), - routes: resolve(__dirname, './src/routes'), services: resolve(__dirname, './src/services'), themes: resolve(__dirname, './src/themes'), utils: resolve(__dirname, './src/utils'), diff --git a/package.json b/package.json index 6b4d28a..185c226 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "scripts": { "analyze": "cross-env ANALYZE=1 umi build", "build": "umi build", + "check:model": "umi dva list model", "lint:js": "eslint --ext .js src", "lint:style": "stylelint \"src/**/*.less\" --syntax less", "start": "umi dev", diff --git a/src/layouts/BaseLayout.js b/src/layouts/BaseLayout.js index ef5b143..4e36bed 100644 --- a/src/layouts/BaseLayout.js +++ b/src/layouts/BaseLayout.js @@ -1,6 +1,6 @@ import React, { PureComponent, Fragment } from 'react' import PropTypes from 'prop-types' -import { connect } from 'dva' +import { connect } from 'umi' import { Helmet } from 'react-helmet' import { Loader } from 'components' import { queryLayout } from 'utils' diff --git a/src/layouts/PrimaryLayout.js b/src/layouts/PrimaryLayout.js index acafce3..b054705 100644 --- a/src/layouts/PrimaryLayout.js +++ b/src/layouts/PrimaryLayout.js @@ -3,7 +3,7 @@ import React, { PureComponent, Fragment } from 'react' import PropTypes from 'prop-types' import { withRouter } from 'umi' -import { connect } from 'dva' +import { connect } from 'umi' import { MyLayout, GlobalFooter } from 'components' import { BackTop, Layout, Drawer } from 'antd' import { enquireScreen, unenquireScreen } from 'enquire-js' diff --git a/src/pages/dashboard/index.js b/src/pages/dashboard/index.js index a010f29..0fbc129 100644 --- a/src/pages/dashboard/index.js +++ b/src/pages/dashboard/index.js @@ -1,6 +1,6 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' -import { connect } from 'dva' +import { connect } from 'umi' import { Row, Col, Card } from 'antd' import { Color } from 'utils' import { Page, ScrollBar } from 'components' diff --git a/src/pages/login/index.js b/src/pages/login/index.js index ded757c..0529c46 100644 --- a/src/pages/login/index.js +++ b/src/pages/login/index.js @@ -1,6 +1,6 @@ import React, { PureComponent, Fragment } from 'react' import PropTypes from 'prop-types' -import { connect } from 'dva' +import { connect } from 'umi' import { Button, Row, Input, Form } from 'antd' import { GlobalFooter } from 'components' import { GithubOutlined } from '@ant-design/icons' @@ -9,25 +9,19 @@ import { setLocale } from 'utils' import config from 'utils/config' import styles from './index.less' + const FormItem = Form.Item -const [form] = Form.useForm(); @withI18n() @connect(({ loading, dispatch }) => ({ loading, dispatch })) class Login extends PureComponent { - handleOk = () => { - const { validateFieldsAndScroll } = form - validateFieldsAndScroll((errors, values) => { - if (errors) { - return - } - dispatch({ type: 'login/login', payload: values }) - }) - } render() { - const { loading, i18n } = this.props - + const { dispatch, loading, i18n } = this.props + + const handleOk = values => { + dispatch({ type: 'login/login', payload: values }) + } let footerLinks = [ { key: 'github', @@ -55,11 +49,12 @@ class Login extends PureComponent { logo {config.siteName} -
+ @@ -67,14 +62,13 @@ class Login extends PureComponent { rules={[{ required: true }]} hasFeedback> + + + - - - - - -
+ + + + ) } } Filter.propTypes = { onAdd: PropTypes.func, - form: PropTypes.object, filter: PropTypes.object, onFilterChange: PropTypes.func, } diff --git a/src/pages/user/index.js b/src/pages/user/index.js index e9602bc..6a9f4da 100644 --- a/src/pages/user/index.js +++ b/src/pages/user/index.js @@ -1,7 +1,7 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import { history } from 'umi' -import { connect } from 'dva' +import { connect } from 'umi' import { Row, Col, Button, Popconfirm } from 'antd' import { withI18n } from '@lingui/react' import { Page } from 'components' diff --git a/src/themes/index.less b/src/themes/index.less index e98163e..fc5d498 100644 --- a/src/themes/index.less +++ b/src/themes/index.less @@ -15,6 +15,10 @@ body { height: 8px; } +.margin-right { + margin-right: 16px; +} + :global { .ant-breadcrumb { & > span { @@ -79,10 +83,6 @@ body { padding: 12px 16px !important; } - .margin-right { - margin-right: 16px; - } - a:focus { text-decoration: none; } diff --git a/src/utils/config.js b/src/utils/config.js index 3444f67..f2b6acd 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -1,6 +1,6 @@ module.exports = { siteName: 'AntD Admin', - copyright: 'Ant Design Admin ©2019 zuiidea', + copyright: 'Ant Design Admin ©2020 zuiidea', logoPath: '/logo.svg', apiPrefix: '/api/v1', fixedHeader: true, // sticky primary layout header diff --git a/src/utils/index.js b/src/utils/index.js index e2d0ee5..925bc5b 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,5 +1,6 @@ import { cloneDeep } from 'lodash' const { pathToRegexp } = require("path-to-regexp") +import moment from 'moment' import 'moment/locale/zh-cn' import store from 'store' import { i18n } from './config' @@ -159,16 +160,13 @@ export function queryLayout(layouts, pathname) { export function getLocale() { - return store.get('locale') + return store.get('locale') || defaultLanguage } export function setLocale(language) { if (getLocale() !== language) { moment.locale(language === 'zh' ? 'zh-cn' : language) store.set('locale', language) - history.push({ - pathname: `/${window.location.pathname}`, - search: window.location.search, - }) + window.location.reload() } } \ No newline at end of file