Parcourir la source

use airbnb eslint config and fix some rule

愚道 il y a 7 ans
Parent
commit
8cf518a865
43 fichiers modifiés avec 376 ajouts et 416 suppressions
  1. 1 1
      .eslintignore
  2. 16 3
      .eslintrc.js
  3. 0 1
      package.json
  4. 2 3
      src/components/Authorized/CheckPermissions.js
  5. 1 1
      src/components/Authorized/CheckPermissions.test.js
  6. 1 1
      src/components/Authorized/index.js
  7. 14 16
      src/components/Authorized/renderAuthorize.js
  8. 2 4
      src/components/Charts/Gauge/index.js
  9. 2 3
      src/components/Charts/Pie/index.js
  10. 2 3
      src/components/Charts/autoHeight.js
  11. 4 9
      src/components/CountDown/index.js
  12. 19 25
      src/components/Ellipsis/index.js
  13. 1 1
      src/components/Ellipsis/index.test.js
  14. 2 0
      src/components/Exception/index.js
  15. 14 16
      src/components/Login/LoginItem.js
  16. 5 9
      src/components/Login/LoginTab.js
  17. 1 0
      src/components/NoticeIcon/NoticeList.js
  18. 5 9
      src/components/PageHeader/index.test.js
  19. 23 27
      src/components/SettingDrawer/BlockChecbox.js
  20. 19 23
      src/components/SettingDrawer/ThemeColor.js
  21. 1 3
      src/components/SettingDrawer/index.js
  22. 5 9
      src/components/SiderMenu/BaseMenu.js
  23. 4 3
      src/components/SiderMenu/SliderMenu.js
  24. 4 8
      src/components/StandardTable/index.js
  25. 5 7
      src/components/TagSelect/index.js
  26. 2 3
      src/components/_utils/pathTools.js
  27. 2 1
      src/layouts/BasicLayout.js
  28. 1 2
      src/layouts/Header.js
  29. 17 19
      src/layouts/PageHeaderLayout.js
  30. 2 1
      src/pages/Account/Center/Articles.js
  31. 32 34
      src/pages/Account/Settings/BindingView.js
  32. 5 7
      src/pages/Account/Settings/GeographicView.js
  33. 58 60
      src/pages/Account/Settings/SecurityView.js
  34. 6 7
      src/pages/Dashboard/Analysis.js
  35. 7 4
      src/pages/Dashboard/Workplace.js
  36. 4 7
      src/pages/Forms/TableForm.js
  37. 5 6
      src/pages/List/BasicList.js
  38. 61 61
      src/pages/List/TableList.js
  39. 5 6
      src/pages/User/Login.js
  40. 2 1
      src/pages/User/RegisterResult.js
  41. 1 1
      src/services/error.js
  42. 10 9
      src/utils/request.js
  43. 3 2
      src/utils/utils.js

+ 1 - 1
.eslintignore

@@ -1 +1 @@
-/functions/mock
+/functions/mock

+ 16 - 3
.eslintrc.js

@@ -1,5 +1,6 @@
 module.exports = {
-  extends: ['eslint-config-umi', 'prettier'],
+  parser: 'babel-eslint',
+  extends: ['airbnb', 'prettier'],
   env: {
     browser: true,
     node: true,
@@ -9,8 +10,20 @@ module.exports = {
     jasmine: true,
   },
   rules: {
-    'jsx-a11y/href-no-hash': [0],
-    'react/sort-comp': 1,
+    'react/jsx-filename-extension': [1, { extensions: ['.js'] }],
+    'import/no-unresolved': 0,
+    'jsx-a11y/anchor-is-valid': 0,
+    'react/jsx-wrap-multilines': 0,
+    'import/no-extraneous-dependencies': 0,
+    'consistent-return': 0,
+    'import/no-extraneous-dependencies': 0,
+    'react/prop-types': 0,
+    'jsx-a11y/click-events-have-key-events': 0,
+    'jsx-a11y/no-static-element-interactions': 0,
+    'react/prefer-stateless-function': 0,
+    'jsx-a11y/no-noninteractive-element-interactions': 0,
+    'react/forbid-prop-types': 0,
+    'react/jsx-one-expression-per-line': 0,
   },
   settings: {
     polyfills: ['fetch', 'promises'],

+ 0 - 1
package.json

@@ -60,7 +60,6 @@
     "eslint": "^5.4.0",
     "eslint-config-airbnb": "^17.0.0",
     "eslint-config-prettier": "^3.0.1",
-    "eslint-config-umi": "^0.1.4",
     "eslint-plugin-babel": "^5.1.0",
     "eslint-plugin-compat": "^2.5.1",
     "eslint-plugin-flowtype": "2.50.0",

+ 2 - 3
src/components/Authorized/CheckPermissions.js

@@ -82,8 +82,7 @@ const checkPermissions = (authority, currentAuthority, target, Exception) => {
 
 export { checkPermissions };
 
-const check = (authority, target, Exception) => {
-  return checkPermissions(authority, CURRENT, target, Exception);
-};
+const check = (authority, target, Exception) =>
+  checkPermissions(authority, CURRENT, target, Exception);
 
 export default check;

+ 1 - 1
src/components/Authorized/CheckPermissions.test.js

@@ -1,4 +1,4 @@
-import { checkPermissions } from './CheckPermissions.js';
+import { checkPermissions } from './CheckPermissions';
 
 const target = 'ok';
 const error = 'error';

+ 1 - 1
src/components/Authorized/index.js

@@ -1,7 +1,7 @@
 import Authorized from './Authorized';
 import AuthorizedRoute from './AuthorizedRoute';
 import Secured from './Secured';
-import check from './CheckPermissions.js';
+import check from './CheckPermissions';
 import renderAuthorize from './renderAuthorize';
 
 Authorized.Secured = Secured;

+ 14 - 16
src/components/Authorized/renderAuthorize.js

@@ -4,23 +4,21 @@ let CURRENT = 'NULL';
  * use  authority or getAuthority
  * @param {string|()=>String} currentAuthority
  */
-const renderAuthorize = Authorized => {
-  return currentAuthority => {
-    if (currentAuthority) {
-      if (currentAuthority.constructor.name === 'Function') {
-        CURRENT = currentAuthority();
-      }
-      if (
-        currentAuthority.constructor.name === 'String' ||
-        currentAuthority.constructor.name === 'Array'
-      ) {
-        CURRENT = currentAuthority;
-      }
-    } else {
-      CURRENT = 'NULL';
+const renderAuthorize = Authorized => currentAuthority => {
+  if (currentAuthority) {
+    if (currentAuthority.constructor.name === 'Function') {
+      CURRENT = currentAuthority();
     }
-    return Authorized;
-  };
+    if (
+      currentAuthority.constructor.name === 'String' ||
+      currentAuthority.constructor.name === 'Array'
+    ) {
+      CURRENT = currentAuthority;
+    }
+  } else {
+    CURRENT = 'NULL';
+  }
+  return Authorized;
 };
 
 export { CURRENT };

+ 2 - 4
src/components/Charts/Gauge/index.js

@@ -142,15 +142,13 @@ export default class Gauge extends React.Component {
           />
           <Html
             position={['50%', '95%']}
-            html={() => {
-              return `
+            html={() => `
                 <div style="width: 300px;text-align: center;font-size: 12px!important;">
                   <p style="font-size: 14px; color: rgba(0,0,0,0.43);margin: 0;">${title}</p>
                   <p style="font-size: 24px;color: rgba(0,0,0,0.85);margin: 0;">
                     ${data[0].value * 10}%
                   </p>
-                </div>`;
-            }}
+                </div>`}
           />
         </Guide>
         <Geom

+ 2 - 3
src/components/Charts/Pie/index.js

@@ -172,9 +172,8 @@ export default class Pie extends Component {
       formatColor = value => {
         if (value === '占比') {
           return color || 'rgba(24, 144, 255, 0.85)';
-        } else {
-          return '#F0F2F5';
         }
+        return '#F0F2F5';
       };
 
       data = [
@@ -257,7 +256,7 @@ export default class Pie extends Component {
                 <span className={styles.legendTitle}>{item.x}</span>
                 <Divider type="vertical" />
                 <span className={styles.percent}>
-                  {`${(isNaN(item.percent) ? 0 : item.percent * 100).toFixed(2)}%`}
+                  {`${(Number.isNaN(item.percent) ? 0 : item.percent * 100).toFixed(2)}%`}
                 </span>
                 <span className={styles.value}>{valueFormat ? valueFormat(item.y) : item.y}</span>
               </li>

+ 2 - 3
src/components/Charts/autoHeight.js

@@ -30,8 +30,8 @@ function getAutoHeight(n) {
   return height;
 }
 
-const autoHeight = () => WrappedComponent => {
-  return class extends React.Component {
+const autoHeight = () => WrappedComponent =>
+  class extends React.Component {
     state = {
       computedHeight: 0,
     };
@@ -58,6 +58,5 @@ const autoHeight = () => WrappedComponent => {
       );
     }
   };
-};
 
 export default autoHeight;

+ 4 - 9
src/components/CountDown/index.js

@@ -23,6 +23,9 @@ const initTime = props => {
 };
 
 class CountDown extends Component {
+  timer = 0;
+
+  interval = 1000;
 
   constructor(props) {
     super(props);
@@ -58,10 +61,6 @@ class CountDown extends Component {
     clearTimeout(this.timer);
   }
 
-  timer = 0;
-
-  interval = 1000;
-
   // defaultFormat = time => (
   //  <span>{moment(time).format('hh:mm:ss')}</span>
   // );
@@ -74,11 +73,7 @@ class CountDown extends Component {
     const s = Math.floor((time - h * hours - m * minutes) / 1000);
     return (
       <span>
-        {fixedZero(h)}
-        :
-        {fixedZero(m)}
-        :
-        {fixedZero(s)}
+        {fixedZero(h)}:{fixedZero(m)}:{fixedZero(s)}
       </span>
     );
   };

+ 19 - 25
src/components/Ellipsis/index.js

@@ -13,16 +13,14 @@ const TooltipOverlayStyle = {
   wordWrap: 'break-word',
 };
 
-export const getStrFullLength = (str = '') => {
-  return str.split('').reduce((pre, cur) => {
+export const getStrFullLength = (str = '') =>
+  str.split('').reduce((pre, cur) => {
     const charCode = cur.charCodeAt(0);
     if (charCode >= 0 && charCode <= 128) {
       return pre + 1;
-    } else {
-      return pre + 2;
     }
+    return pre + 2;
   }, 0);
-};
 
 export const cutStrByFullLength = (str = '', maxLength) => {
   let showLength = 0;
@@ -35,9 +33,8 @@ export const cutStrByFullLength = (str = '', maxLength) => {
     }
     if (showLength <= maxLength) {
       return pre + cur;
-    } else {
-      return pre;
     }
+    return pre;
   }, '');
 };
 
@@ -139,29 +136,26 @@ export default class Ellipsis extends Component {
       sh = shadowNode.offsetHeight;
       if (sh > th || mid === begin) {
         return mid;
-      } else {
-        begin = mid;
-        if (end - begin === 1) {
-          mid = 1 + begin;
-        } else {
-          mid = Math.floor((end - begin) / 2) + begin;
-        }
-        return this.bisection(th, mid, begin, end, text, shadowNode);
-      }
-    } else {
-      if (mid - 1 < 0) {
-        return mid;
       }
-      shadowNode.innerHTML = text.substring(0, mid - 1) + suffix;
-      sh = shadowNode.offsetHeight;
-      if (sh <= th) {
-        return mid - 1;
+      begin = mid;
+      if (end - begin === 1) {
+        mid = 1 + begin;
       } else {
-        end = mid;
         mid = Math.floor((end - begin) / 2) + begin;
-        return this.bisection(th, mid, begin, end, text, shadowNode);
       }
+      return this.bisection(th, mid, begin, end, text, shadowNode);
+    }
+    if (mid - 1 < 0) {
+      return mid;
+    }
+    shadowNode.innerHTML = text.substring(0, mid - 1) + suffix;
+    sh = shadowNode.offsetHeight;
+    if (sh <= th) {
+      return mid - 1;
     }
+    end = mid;
+    mid = Math.floor((end - begin) / 2) + begin;
+    return this.bisection(th, mid, begin, end, text, shadowNode);
   };
 
   handleRoot = n => {

+ 1 - 1
src/components/Ellipsis/index.test.js

@@ -1,4 +1,4 @@
-import { getStrFullLength, cutStrByFullLength } from './index.js';
+import { getStrFullLength, cutStrByFullLength } from './index';
 
 describe('test calculateShowLength', () => {
   it('get full length', () => {

+ 2 - 0
src/components/Exception/index.js

@@ -8,10 +8,12 @@ class Excrption extends React.PureComponent {
   static defaultProps = {
     backText: 'back to home',
   };
+
   constructor(props) {
     super(props);
     this.state = {};
   }
+
   render() {
     const {
       className,

+ 14 - 16
src/components/Login/LoginItem.js

@@ -122,22 +122,20 @@ class WarpFormItem extends Component {
 const LoginItem = {};
 Object.keys(ItemMap).forEach(key => {
   const item = ItemMap[key];
-  LoginItem[key] = props => {
-    return (
-      <LoginContext.Consumer>
-        {context => (
-          <WarpFormItem
-            customprops={item.props}
-            {...props}
-            rules={item.rules}
-            type={key}
-            updateActive={context.updateActive}
-            form={context.form}
-          />
-        )}
-      </LoginContext.Consumer>
-    );
-  };
+  LoginItem[key] = props => (
+    <LoginContext.Consumer>
+      {context => (
+        <WarpFormItem
+          customprops={item.props}
+          {...props}
+          rules={item.rules}
+          type={key}
+          updateActive={context.updateActive}
+          form={context.form}
+        />
+      )}
+    </LoginContext.Consumer>
+  );
 });
 
 export default LoginItem;

+ 5 - 9
src/components/Login/LoginTab.js

@@ -29,15 +29,11 @@ class LoginTab extends Component {
   }
 }
 
-const warpContext = props => {
-  return (
-    <LoginContext.Consumer>
-      {value => {
-        return <LoginTab tabUtil={value.tabUtil} {...props} />;
-      }}
-    </LoginContext.Consumer>
-  );
-};
+const warpContext = props => (
+  <LoginContext.Consumer>
+    {value => <LoginTab tabUtil={value.tabUtil} {...props} />}
+  </LoginContext.Consumer>
+);
 // 标志位 用来判断是不是自定义组件
 warpContext.typeName = 'LoginTab';
 

+ 1 - 0
src/components/NoticeIcon/NoticeList.js

@@ -28,6 +28,7 @@ export default function NoticeList({
           const itemCls = classNames(styles.item, {
             [styles.read]: item.read,
           });
+          // eslint-disable-next-line no-nested-ternary
           const leftIcon = item.avatar ? (
             typeof item.avatar === 'string' ? (
               <Avatar className={styles.avatar} src={item.avatar} />

+ 5 - 9
src/components/PageHeader/index.test.js

@@ -26,22 +26,18 @@ describe('test getBreadcrumb', () => {
     expect(getBreadcrumb(routerData, '/userinfo/2144/addr').name).toEqual('收货订单');
   });
   it('Loop through the parameters', () => {
-    const urlNameList = urlToList('/userinfo/2144/addr').map(url => {
-      return getBreadcrumb(routerData, url).name;
-    });
+    const urlNameList = urlToList('/userinfo/2144/addr').map(
+      url => getBreadcrumb(routerData, url).name
+    );
     expect(urlNameList).toEqual(['用户列表', '用户信息', '收货订单']);
   });
 
   it('a path', () => {
-    const urlNameList = urlToList('/userinfo').map(url => {
-      return getBreadcrumb(routerData, url).name;
-    });
+    const urlNameList = urlToList('/userinfo').map(url => getBreadcrumb(routerData, url).name);
     expect(urlNameList).toEqual(['用户列表']);
   });
   it('Secondary path', () => {
-    const urlNameList = urlToList('/userinfo/2144').map(url => {
-      return getBreadcrumb(routerData, url).name;
-    });
+    const urlNameList = urlToList('/userinfo/2144').map(url => getBreadcrumb(routerData, url).name);
     expect(urlNameList).toEqual(['用户列表', '用户信息']);
   });
 });

+ 23 - 27
src/components/SettingDrawer/BlockChecbox.js

@@ -2,32 +2,28 @@ import { Icon } from 'antd';
 import React from 'react';
 import style from './index.less';
 
-const BlockChecbox = ({ value, onChange, list }) => {
-  return (
-    <div className={style.blockChecbox} key={value}>
-      {list.map(item => {
-        return (
-          <div
-            key={item.key}
-            className={style.item}
-            onClick={() => {
-              onChange(item.key);
-            }}
-          >
-            <img src={item.url} alt={item.key} />
-            <div
-              className={style.selectIcon}
-              style={{
-                display: value === item.key ? 'block' : 'none',
-              }}
-            >
-              <Icon type="check" />
-            </div>
-          </div>
-        );
-      })}
-    </div>
-  );
-};
+const BlockChecbox = ({ value, onChange, list }) => (
+  <div className={style.blockChecbox} key={value}>
+    {list.map(item => (
+      <div
+        key={item.key}
+        className={style.item}
+        onClick={() => {
+          onChange(item.key);
+        }}
+      >
+        <img src={item.url} alt={item.key} />
+        <div
+          className={style.selectIcon}
+          style={{
+            display: value === item.key ? 'block' : 'none',
+          }}
+        >
+          <Icon type="check" />
+        </div>
+      </div>
+    ))}
+  </div>
+);
 
 export default BlockChecbox;

+ 19 - 23
src/components/SettingDrawer/ThemeColor.js

@@ -2,18 +2,16 @@ import { Icon } from 'antd';
 import React from 'react';
 import styles from './ThemeColor.less';
 
-const Tag = ({ color, check, ...rest }) => {
-  return (
-    <div
-      {...rest}
-      style={{
-        backgroundColor: color,
-      }}
-    >
-      {check ? <Icon type="check" /> : ''}
-    </div>
-  );
-};
+const Tag = ({ color, check, ...rest }) => (
+  <div
+    {...rest}
+    style={{
+      backgroundColor: color,
+    }}
+  >
+    {check ? <Icon type="check" /> : ''}
+  </div>
+);
 
 const ThemeColor = ({ colors, title, value, onChange }) => {
   let colorList = colors;
@@ -33,17 +31,15 @@ const ThemeColor = ({ colors, title, value, onChange }) => {
     <div className={styles.themeColor}>
       <h3 className={styles.title}>{title}</h3>
       <div className={styles.content}>
-        {colorList.map(color => {
-          return (
-            <Tag
-              className={styles.colorBlock}
-              key={color}
-              color={color}
-              check={value === color}
-              onClick={() => onChange && onChange(color)}
-            />
-          );
-        })}
+        {colorList.map(color => (
+          <Tag
+            className={styles.colorBlock}
+            key={color}
+            color={color}
+            check={value === color}
+            onClick={() => onChange && onChange(color)}
+          />
+        ))}
       </div>
     </div>
   );

+ 1 - 3
src/components/SettingDrawer/index.js

@@ -76,9 +76,7 @@ class SettingDrawer extends PureComponent {
           />,
         ],
       },
-    ].filter(item => {
-      return !item.hide;
-    });
+    ].filter(item => !item.hide);
   };
 
   changeSetting = (key, value) => {

+ 5 - 9
src/components/SiderMenu/BaseMenu.js

@@ -22,11 +22,8 @@ const getIcon = icon => {
   return icon;
 };
 
-export const getMenuMatches = (flatMenuKeys, path) => {
-  return flatMenuKeys.filter(item => {
-    return pathToRegexp(item).test(path);
-  });
-};
+export const getMenuMatches = (flatMenuKeys, path) =>
+  flatMenuKeys.filter(item => pathToRegexp(item).test(path));
 
 export default class BaseMenu extends PureComponent {
   constructor(props) {
@@ -100,9 +97,8 @@ export default class BaseMenu extends PureComponent {
           {this.getNavMenuItems(item.children)}
         </SubMenu>
       );
-    } else {
-      return <Menu.Item key={item.path}>{this.getMenuItemPath(item)}</Menu.Item>;
     }
+    return <Menu.Item key={item.path}>{this.getMenuItemPath(item)}</Menu.Item>;
   };
 
   /**
@@ -143,6 +139,7 @@ export default class BaseMenu extends PureComponent {
       </Link>
     );
   };
+
   // permission to check
   checkPermissionItem = (authority, ItemDom) => {
     const { Authorized } = this.props;
@@ -156,9 +153,8 @@ export default class BaseMenu extends PureComponent {
   conversionPath = path => {
     if (path && path.indexOf('http') === 0) {
       return path;
-    } else {
-      return `/${path || ''}`.replace(/\/+/g, '/');
     }
+    return `/${path || ''}`.replace(/\/+/g, '/');
   };
 
   render() {

+ 4 - 3
src/components/SiderMenu/SliderMenu.js

@@ -18,9 +18,7 @@ const getDefaultCollapsedSubMenus = props => {
     flatMenuKeys,
   } = props;
   return urlToList(pathname)
-    .map(item => {
-      return getMenuMatches(flatMenuKeys, item)[0];
-    })
+    .map(item => getMenuMatches(flatMenuKeys, item)[0])
     .filter(item => item);
 };
 
@@ -69,6 +67,7 @@ export default class SiderMenu extends PureComponent {
     }
     return null;
   }
+
   isMainMenu = key => {
     const { menuData } = this.props;
     return menuData.some(item => {
@@ -78,12 +77,14 @@ export default class SiderMenu extends PureComponent {
       return false;
     });
   };
+
   handleOpenChange = openKeys => {
     const moreThanOne = openKeys.filter(openKey => this.isMainMenu(openKey)).length > 1;
     this.setState({
       openKeys: moreThanOne ? [openKeys.pop()] : [...openKeys],
     });
   };
+
   render() {
     const { logo, collapsed, onCollapse, fixSiderbar, theme } = this.props;
     const { openKeys } = this.state;

+ 4 - 8
src/components/StandardTable/index.js

@@ -38,14 +38,10 @@ class StandardTable extends PureComponent {
 
   handleRowSelectChange = (selectedRowKeys, selectedRows) => {
     let { needTotalList } = this.state;
-    needTotalList = needTotalList.map(item => {
-      return {
-        ...item,
-        total: selectedRows.reduce((sum, val) => {
-          return sum + parseFloat(val[item.dataIndex], 10);
-        }, 0),
-      };
-    });
+    needTotalList = needTotalList.map(item => ({
+      ...item,
+      total: selectedRows.reduce((sum, val) => sum + parseFloat(val[item.dataIndex], 10), 0),
+    }));
     const { onSelectRow } = this.props;
     if (onSelectRow) {
       onSelectRow(selectedRows);

+ 5 - 7
src/components/TagSelect/index.js

@@ -18,6 +18,7 @@ class TagSelect extends Component {
   static defaultProps = {
     hideCheckAll: false,
   };
+
   constructor(props) {
     super(props);
     this.state = {
@@ -80,13 +81,10 @@ class TagSelect extends Component {
     });
   };
 
-  isTagSelectOption = node => {
-    return (
-      node &&
-      node.type &&
-      (node.type.isTagSelectOption || node.type.displayName === 'TagSelectOption')
-    );
-  };
+  isTagSelectOption = node =>
+    node &&
+    node.type &&
+    (node.type.isTagSelectOption || node.type.displayName === 'TagSelectOption');
 
   render() {
     const { value, expand } = this.state;

+ 2 - 3
src/components/_utils/pathTools.js

@@ -1,7 +1,6 @@
 // /userinfo/2144/id => ['/userinfo','/useinfo/2144,'/userindo/2144/id']
+// eslint-disable-next-line import/prefer-default-export
 export function urlToList(url) {
   const urllist = url.split('/').filter(i => i);
-  return urllist.map((urlItem, index) => {
-    return `/${urllist.slice(0, index + 1).join('/')}`;
-  });
+  return urllist.map((urlItem, index) => `/${urllist.slice(0, index + 1).join('/')}`);
 }

+ 2 - 1
src/layouts/BasicLayout.js

@@ -174,6 +174,7 @@ class BasicLayout extends React.PureComponent {
       children,
       location: { pathname },
     } = this.props;
+    const { rendering } = this.state;
     const isTop = PropsLayout === 'topmenu';
     const layout = (
       <Layout>
@@ -209,7 +210,7 @@ class BasicLayout extends React.PureComponent {
             )}
           </ContainerQuery>
         </DocumentTitle>
-        {this.state.rendering && process.env.NODE_ENV === 'production' ? null : ( // Do show SettingDrawer in production
+        {rendering && process.env.NODE_ENV === 'production' ? null : ( // Do show SettingDrawer in production
           <SettingDrawer />
         )}
       </React.Fragment>

+ 1 - 2
src/layouts/Header.js

@@ -71,7 +71,7 @@ class HeaderView extends PureComponent {
     }
   };
 
-  handScroll = e => {
+  handScroll = () => {
     const { autoHideHeader } = this.props;
     const { visible } = this.state;
     if (!autoHideHeader) {
@@ -99,7 +99,6 @@ class HeaderView extends PureComponent {
         }
         this.oldScrollTop = scrollTop;
         this.ticking = false;
-        return;
       });
     }
     this.ticking = false;

+ 17 - 19
src/layouts/PageHeaderLayout.js

@@ -2,33 +2,31 @@ import React from 'react';
 import { FormattedMessage } from 'umi/locale';
 import Link from 'umi/link';
 import PageHeader from '@/components/PageHeader';
+import { connect } from 'dva';
 import GridContent from './GridContent';
 import styles from './PageHeaderLayout.less';
 import MenuContext from './MenuContext';
-import { connect } from 'dva';
 
 const PageHeaderLayout = ({ children, grid, wrapperClassName, top, ...restProps }) => (
   <div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}>
     {top}
     <MenuContext.Consumer>
-      {value => {
-        return (
-          <PageHeader
-            wide={grid === 'Wide'}
-            home={<FormattedMessage id="menu.home" defaultMessage="Home" />}
-            {...value}
-            key="pageheader"
-            {...restProps}
-            linkElement={Link}
-            itemRender={item => {
-              if (item.locale) {
-                return <FormattedMessage id={item.locale} defaultMessage={item.name} />;
-              }
-              return item.name;
-            }}
-          />
-        );
-      }}
+      {value => (
+        <PageHeader
+          wide={grid === 'Wide'}
+          home={<FormattedMessage id="menu.home" defaultMessage="Home" />}
+          {...value}
+          key="pageheader"
+          {...restProps}
+          linkElement={Link}
+          itemRender={item => {
+            if (item.locale) {
+              return <FormattedMessage id={item.locale} defaultMessage={item.name} />;
+            }
+            return item.name;
+          }}
+        />
+      )}
     </MenuContext.Consumer>
     {children ? (
       <div className={styles.content}>

+ 2 - 1
src/pages/Account/Center/Articles.js

@@ -24,7 +24,8 @@ export default class Center extends PureComponent {
         <div className={stylesArticles.description}>{content}</div>
         <div className={stylesArticles.extra}>
           <Avatar src={avatar} size="small" />
-          <a href={href}>{owner}</a> 发布在 <a href={href}>{href}</a>
+          <a href={href}>{owner}</a> 发布在
+          <a href={href}>{href}</a>
           <em>{moment(updatedAt).format('YYYY-MM-DD HH:mm')}</em>
         </div>
       </div>

+ 32 - 34
src/pages/Account/Settings/BindingView.js

@@ -3,40 +3,38 @@ import { formatMessage, FormattedMessage } from 'umi/locale';
 import { Icon, List } from 'antd';
 
 class BindingView extends Component {
-  getData = () => {
-    return [
-      {
-        title: formatMessage({ id: 'app.settings.binding.taobao' }, {}),
-        description: formatMessage({ id: 'app.settings.binding.taobao-description' }, {}),
-        actions: [
-          <a>
-            <FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" />
-          </a>,
-        ],
-        avatar: <Icon type="taobao" className="taobao" />,
-      },
-      {
-        title: formatMessage({ id: 'app.settings.binding.alipay' }, {}),
-        description: formatMessage({ id: 'app.settings.binding.alipay-description' }, {}),
-        actions: [
-          <a>
-            <FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" />
-          </a>,
-        ],
-        avatar: <Icon type="alipay" className="alipay" />,
-      },
-      {
-        title: formatMessage({ id: 'app.settings.binding.dingding' }, {}),
-        description: formatMessage({ id: 'app.settings.binding.dingding-description' }, {}),
-        actions: [
-          <a>
-            <FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" />
-          </a>,
-        ],
-        avatar: <Icon type="dingding" className="dingding" />,
-      },
-    ];
-  };
+  getData = () => [
+    {
+      title: formatMessage({ id: 'app.settings.binding.taobao' }, {}),
+      description: formatMessage({ id: 'app.settings.binding.taobao-description' }, {}),
+      actions: [
+        <a>
+          <FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" />
+        </a>,
+      ],
+      avatar: <Icon type="taobao" className="taobao" />,
+    },
+    {
+      title: formatMessage({ id: 'app.settings.binding.alipay' }, {}),
+      description: formatMessage({ id: 'app.settings.binding.alipay-description' }, {}),
+      actions: [
+        <a>
+          <FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" />
+        </a>,
+      ],
+      avatar: <Icon type="alipay" className="alipay" />,
+    },
+    {
+      title: formatMessage({ id: 'app.settings.binding.dingding' }, {}),
+      description: formatMessage({ id: 'app.settings.binding.dingding-description' }, {}),
+      actions: [
+        <a>
+          <FormattedMessage id="app.settings.binding.bind" defaultMessage="Bind" />
+        </a>,
+      ],
+      avatar: <Icon type="dingding" className="dingding" />,
+    },
+  ];
 
   render() {
     return (

+ 5 - 7
src/pages/Account/Settings/GeographicView.js

@@ -55,13 +55,11 @@ export default class GeographicView extends PureComponent {
         </Option>
       );
     }
-    return list.map(item => {
-      return (
-        <Option key={item.id} value={item.id}>
-          {item.name}
-        </Option>
-      );
-    });
+    return list.map(item => (
+      <Option key={item.id} value={item.id}>
+        {item.name}
+      </Option>
+    ));
   };
 
   selectProvinceItem = item => {

+ 58 - 60
src/pages/Account/Settings/SecurityView.js

@@ -23,66 +23,64 @@ const passwordStrength = {
 };
 
 class SecurityView extends Component {
-  getData = () => {
-    return [
-      {
-        title: formatMessage({ id: 'app.settings.security.password' }, {}),
-        description: (
-          <Fragment>
-            {formatMessage({ id: 'app.settings.security.password-description' }, {})}:
-            {passwordStrength.strong}
-          </Fragment>
-        ),
-        actions: [
-          <a>
-            <FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" />
-          </a>,
-        ],
-      },
-      {
-        title: formatMessage({ id: 'app.settings.security.phone' }, {}),
-        description: `${formatMessage(
-          { id: 'app.settings.security.phone-description' },
-          {}
-        )}:138****8293`,
-        actions: [
-          <a>
-            <FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" />
-          </a>,
-        ],
-      },
-      {
-        title: formatMessage({ id: 'app.settings.security.question' }, {}),
-        description: formatMessage({ id: 'app.settings.security.question-description' }, {}),
-        actions: [
-          <a>
-            <FormattedMessage id="app.settings.security.set" defaultMessage="Set" />
-          </a>,
-        ],
-      },
-      {
-        title: formatMessage({ id: 'app.settings.security.email' }, {}),
-        description: `${formatMessage(
-          { id: 'app.settings.security.email-description' },
-          {}
-        )}:ant***sign.com`,
-        actions: [
-          <a>
-            <FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" />
-          </a>,
-        ],
-      },
-      {
-        title: formatMessage({ id: 'app.settings.security.mfa' }, {}),
-        description: formatMessage({ id: 'app.settings.security.mfa-description' }, {}),
-        actions: [
-          <a>
-            <FormattedMessage id="app.settings.security.bind" defaultMessage="Bind" />
-          </a>,
-        ],
-      },
-    ];
-  };
+  getData = () => [
+    {
+      title: formatMessage({ id: 'app.settings.security.password' }, {}),
+      description: (
+        <Fragment>
+          {formatMessage({ id: 'app.settings.security.password-description' }, {})}:
+          {passwordStrength.strong}
+        </Fragment>
+      ),
+      actions: [
+        <a>
+          <FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" />
+        </a>,
+      ],
+    },
+    {
+      title: formatMessage({ id: 'app.settings.security.phone' }, {}),
+      description: `${formatMessage(
+        { id: 'app.settings.security.phone-description' },
+        {}
+      )}:138****8293`,
+      actions: [
+        <a>
+          <FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" />
+        </a>,
+      ],
+    },
+    {
+      title: formatMessage({ id: 'app.settings.security.question' }, {}),
+      description: formatMessage({ id: 'app.settings.security.question-description' }, {}),
+      actions: [
+        <a>
+          <FormattedMessage id="app.settings.security.set" defaultMessage="Set" />
+        </a>,
+      ],
+    },
+    {
+      title: formatMessage({ id: 'app.settings.security.email' }, {}),
+      description: `${formatMessage(
+        { id: 'app.settings.security.email-description' },
+        {}
+      )}:ant***sign.com`,
+      actions: [
+        <a>
+          <FormattedMessage id="app.settings.security.modify" defaultMessage="Modify" />
+        </a>,
+      ],
+    },
+    {
+      title: formatMessage({ id: 'app.settings.security.mfa' }, {}),
+      description: formatMessage({ id: 'app.settings.security.mfa-description' }, {}),
+      actions: [
+        <a>
+          <FormattedMessage id="app.settings.security.bind" defaultMessage="Bind" />
+        </a>,
+      ],
+    },
+  ];
 
   render() {
     return (

+ 6 - 7
src/pages/Dashboard/Analysis.js

@@ -157,13 +157,12 @@ class Analysis extends Component {
       salesTypeDataOffline,
     } = chart;
     const loading = propsLoding || stateLoading;
-    const salesPieData =
-      salesType === 'all'
-        ? salesTypeData
-        : salesType === 'online'
-          ? salesTypeDataOnline
-          : salesTypeDataOffline;
-
+    let salesPieData;
+    if (salesType === 'all') {
+      salesPieData = salesTypeData;
+    } else {
+      salesPieData = salesType === 'online' ? salesTypeDataOnline : salesTypeDataOffline;
+    }
     const menu = (
       <Menu>
         <Menu.Item>操作一</Menu.Item>

+ 7 - 4
src/pages/Dashboard/Workplace.js

@@ -124,9 +124,13 @@ export default class Workplace extends PureComponent {
             <Avatar size="large" src={currentUser.avatar} />
           </div>
           <div className={styles.content}>
-            <div className={styles.contentTitle}>早安,{currentUser.name},祝你开心每一天!</div>
+            <div className={styles.contentTitle}>
+              早安,
+              {currentUser.name}
+              ,祝你开心每一天!
+            </div>
             <div>
-              {currentUser.title} | {currentUser.group}
+              {currentUser.title} |{currentUser.group}
             </div>
           </div>
         </div>
@@ -141,8 +145,7 @@ export default class Workplace extends PureComponent {
         <div className={styles.statItem}>
           <p>团队内排名</p>
           <p>
-            8
-            <span> / 24</span>
+            8<span> / 24</span>
           </p>
         </div>
         <div className={styles.statItem}>

+ 4 - 7
src/pages/Forms/TableForm.js

@@ -4,6 +4,9 @@ import isEqual from 'lodash.isequal';
 import styles from './style.less';
 
 export default class TableForm extends PureComponent {
+  index = 0;
+
+  cacheOriginData = {};
 
   constructor(props) {
     super(props);
@@ -26,10 +29,6 @@ export default class TableForm extends PureComponent {
     };
   }
 
-  index = 0;
-
-  cacheOriginData = {};
-
   getRowByKey(key, newData) {
     const { data } = this.state;
     return (newData || data).filter(item => item.key === key)[0];
@@ -244,9 +243,7 @@ export default class TableForm extends PureComponent {
           columns={columns}
           dataSource={data}
           pagination={false}
-          rowClassName={record => {
-            return record.editable ? styles.editable : '';
-          }}
+          rowClassName={record => (record.editable ? styles.editable : '')}
         />
         <Button
           style={{ width: '100%', marginTop: 16, marginBottom: 8 }}

+ 5 - 6
src/pages/List/BasicList.js

@@ -38,9 +38,13 @@ const { Search, TextArea } = Input;
 }))
 @Form.create()
 export default class BasicList extends PureComponent {
-
   state = { visible: false, done: false };
 
+  formLayout = {
+    labelCol: { span: 7 },
+    wrapperCol: { span: 13 },
+  };
+
   componentDidMount() {
     const { dispatch } = this.props;
     dispatch({
@@ -51,11 +55,6 @@ export default class BasicList extends PureComponent {
     });
   }
 
-  formLayout = {
-    labelCol: { span: 7 },
-    wrapperCol: { span: 13 },
-  };
-
   showModal = () => {
     this.setState({
       visible: true,

+ 61 - 61
src/pages/List/TableList.js

@@ -66,6 +66,67 @@ const CreateForm = Form.create()(props => {
 
 @Form.create()
 class UpdateForm extends PureComponent {
+  columns = [
+    {
+      title: '规则名称',
+      dataIndex: 'name',
+    },
+    {
+      title: '描述',
+      dataIndex: 'desc',
+    },
+    {
+      title: '服务调用次数',
+      dataIndex: 'callNo',
+      sorter: true,
+      align: 'right',
+      render: val => `${val} 万`,
+      // mark to display a total number
+      needTotal: true,
+    },
+    {
+      title: '状态',
+      dataIndex: 'status',
+      filters: [
+        {
+          text: status[0],
+          value: 0,
+        },
+        {
+          text: status[1],
+          value: 1,
+        },
+        {
+          text: status[2],
+          value: 2,
+        },
+        {
+          text: status[3],
+          value: 3,
+        },
+      ],
+      render(val) {
+        return <Badge status={statusMap[val]} text={status[val]} />;
+      },
+    },
+    {
+      title: '上次调度时间',
+      dataIndex: 'updatedAt',
+      sorter: true,
+      render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm:ss')}</span>,
+    },
+    {
+      title: '操作',
+      render: (text, record) => (
+        <Fragment>
+          <a onClick={() => this.handleUpdateModalVisible(true, record)}>配置</a>
+          <Divider type="vertical" />
+          <a href="">订阅警报</a>
+        </Fragment>
+      ),
+    },
+  ];
+
   constructor(props) {
     super(props);
 
@@ -288,67 +349,6 @@ export default class TableList extends PureComponent {
     });
   }
 
-  columns = [
-    {
-      title: '规则名称',
-      dataIndex: 'name',
-    },
-    {
-      title: '描述',
-      dataIndex: 'desc',
-    },
-    {
-      title: '服务调用次数',
-      dataIndex: 'callNo',
-      sorter: true,
-      align: 'right',
-      render: val => `${val} 万`,
-      // mark to display a total number
-      needTotal: true,
-    },
-    {
-      title: '状态',
-      dataIndex: 'status',
-      filters: [
-        {
-          text: status[0],
-          value: 0,
-        },
-        {
-          text: status[1],
-          value: 1,
-        },
-        {
-          text: status[2],
-          value: 2,
-        },
-        {
-          text: status[3],
-          value: 3,
-        },
-      ],
-      render(val) {
-        return <Badge status={statusMap[val]} text={status[val]} />;
-      },
-    },
-    {
-      title: '上次调度时间',
-      dataIndex: 'updatedAt',
-      sorter: true,
-      render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm:ss')}</span>,
-    },
-    {
-      title: '操作',
-      render: (text, record) => (
-        <Fragment>
-          <a onClick={() => this.handleUpdateModalVisible(true, record)}>配置</a>
-          <Divider type="vertical" />
-          <a href="">订阅警报</a>
-        </Fragment>
-      ),
-    },
-  ];
-
   handleStandardTableChange = (pagination, filtersArg, sorter) => {
     const { dispatch } = this.props;
     const { formValues } = this.state;

+ 5 - 6
src/pages/User/Login.js

@@ -21,8 +21,8 @@ export default class LoginPage extends Component {
     this.setState({ type });
   };
 
-  onGetCaptcha = () => {
-    return new Promise((resolve, reject) => {
+  onGetCaptcha = () =>
+    new Promise((resolve, reject) => {
       this.loginForm.validateFields(['mobile'], {}, (err, values) => {
         if (err) {
           reject(err);
@@ -37,7 +37,6 @@ export default class LoginPage extends Component {
         }
       });
     });
-  };
 
   handleSubmit = (err, values) => {
     const { type } = this.state;
@@ -59,9 +58,9 @@ export default class LoginPage extends Component {
     });
   };
 
-  renderMessage = content => {
-    return <Alert style={{ marginBottom: 24 }} message={content} type="error" showIcon />;
-  };
+  renderMessage = content => (
+    <Alert style={{ marginBottom: 24 }} message={content} type="error" showIcon />
+  );
 
   render() {
     const { login, submitting } = this.props;

+ 2 - 1
src/pages/User/RegisterResult.js

@@ -24,7 +24,8 @@ const RegisterResult = ({ location }) => (
     title={
       <div className={styles.title}>
         你的账户:
-        {location.state ? location.state.account : 'AntDesign@example.com'} 注册成功
+        {location.state ? location.state.account : 'AntDesign@example.com'}
+        注册成功
       </div>
     }
     description="激活邮件已发送到你的邮箱中,邮件有效期为24小时。请及时登录邮箱,点击邮件中的链接激活帐户。"

+ 1 - 1
src/services/error.js

@@ -1,5 +1,5 @@
 import request from '@/utils/request';
 
-export async function query(code) {
+export default async function query(code) {
   return request(`/api/${code}`);
 }

+ 10 - 9
src/utils/request.js

@@ -2,6 +2,7 @@ import fetch from 'dva/fetch';
 import { notification } from 'antd';
 import router from 'umi/router';
 import hash from 'hash.js';
+
 const codeMessage = {
   200: '服务器成功返回请求的数据。',
   201: '新建或修改数据成功。',
@@ -19,6 +20,7 @@ const codeMessage = {
   503: '服务不可用,服务器暂时过载或维护。',
   504: '网关超时。',
 };
+
 const checkStatus = response => {
   if (response.status >= 200 && response.status < 300) {
     return response;
@@ -39,7 +41,7 @@ const cachedSave = (response, hashcode) => {
    * Clone a response data and store it in sessionStorage
    * Does not support data other than json, Cache only json
    */
-  let contentType = response.headers.get('Content-Type');
+  const contentType = response.headers.get('Content-Type');
   if (contentType && contentType.match(/application\/json/i)) {
     // All data is saved as text
     response
@@ -47,7 +49,7 @@ const cachedSave = (response, hashcode) => {
       .text()
       .then(content => {
         sessionStorage.setItem(hashcode, content);
-        sessionStorage.setItem(hashcode + ':timestamp', Date.now());
+        sessionStorage.setItem(`${hashcode}:timestamp`, Date.now());
       });
   }
   return response;
@@ -99,17 +101,16 @@ export default function request(url, options = {}) {
   const expirys = options.expirys || 60;
   // options.expirys !== false, return the cache,
   if (options.expirys !== false) {
-    let cached = sessionStorage.getItem(hashcode);
-    let whenCached = sessionStorage.getItem(hashcode + ':timestamp');
+    const cached = sessionStorage.getItem(hashcode);
+    const whenCached = sessionStorage.getItem(`${hashcode}:timestamp`);
     if (cached !== null && whenCached !== null) {
-      let age = (Date.now() - whenCached) / 1000;
+      const age = (Date.now() - whenCached) / 1000;
       if (age < expirys) {
-        let response = new Response(new Blob([cached]));
+        const response = new Response(new Blob([cached]));
         return response.json();
-      } else {
-        sessionStorage.removeItem(hashcode);
-        sessionStorage.removeItem(hashcode + ':timestamp');
       }
+      sessionStorage.removeItem(hashcode);
+      sessionStorage.removeItem(`${hashcode}:timestamp`);
     }
   }
   return fetch(url, newOptions)

+ 3 - 2
src/utils/utils.js

@@ -115,7 +115,8 @@ function getRelation(str1, str2) {
   const arr2 = str2.split('/');
   if (arr2.every((item, index) => item === arr1[index])) {
     return 1;
-  } else if (arr1.every((item, index) => item === arr2[index])) {
+  }
+  if (arr1.every((item, index) => item === arr2[index])) {
     return 2;
   }
   return 3;
@@ -184,7 +185,7 @@ export function isUrl(path) {
 
 export function formatWan(val) {
   const v = val * 1;
-  if (!v || isNaN(v)) return '';
+  if (!v || Number.isNaN(v)) return '';
 
   let result = val;
   if (val > 10000) {