Procházet zdrojové kódy

fix dll bug and add typescript typings (#3892)

* fix dll bug and add typescript typings

* fix eslint error
陈小聪 před 7 roky
rodič
revize
ebd13177d4

+ 1 - 1
config/config.ts

@@ -38,7 +38,7 @@ const plugins: IPlugin[] = [
         ? {
             dll: {
               include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
-              exclude: ['@babel/runtime'],
+              exclude: ['@babel/runtime', 'netlify-lambda'],
             },
             hardSource: false,
           }

+ 4 - 3
package.json

@@ -18,7 +18,7 @@
     "functions:build": "npm run generateMock && netlify-lambda build ./lambda",
     "functions:run": "npm run generateMock && cross-env NODE_ENV=dev netlify-lambda serve ./lambda",
     "generateMock": "node ./scripts/generateMock",
-    "lint": "eslint --ext .js src mock tests && npm run lint:style && npm run lint:prettier",
+    "lint": "npm run lint:js && npm run lint:ts && npm run lint:style && npm run lint:prettier",
     "lint-staged": "lint-staged",
     "lint-staged:js": "eslint --ext .js",
     "lint-staged:ts": "tslint",
@@ -80,6 +80,7 @@
   "devDependencies": {
     "@types/classnames": "^2.2.7",
     "@types/history": "^4.7.2",
+    "@types/lodash": "^4.14.123",
     "@types/react": "^16.8.1",
     "@types/react-document-title": "^2.0.3",
     "@types/react-dom": "^16.0.11",
@@ -107,6 +108,7 @@
     "lint-staged": "^8.1.1",
     "merge-umi-mock-data": "^1.0.4",
     "mockjs": "^1.0.1-beta3",
+    "netlify-lambda": "^1.4.3",
     "prettier": "^1.16.4",
     "slash2": "^2.0.0",
     "stylelint": "^9.10.1",
@@ -123,8 +125,7 @@
     "umi-plugin-ga": "^1.1.3",
     "umi-plugin-pro-block": "^1.3.0",
     "umi-plugin-react": "^1.7.2",
-    "umi-types": "^0.2.0",
-    "netlify-lambda": "^1.4.3"
+    "umi-types": "^0.2.0"
   },
   "optionalDependencies": {
     "puppeteer": "^1.12.1"

+ 1 - 1
src/components/GlobalHeader/RightContent.tsx

@@ -146,7 +146,7 @@ export default class GlobalHeaderRight extends Component<GlobalHeaderRightProps>
         <NoticeIcon
           className={styles.action}
           count={currentUser && currentUser.unreadCount}
-          onItemClick={(item, tabProps) => {
+          onItemClick={(item: NoticeItem, tabProps: any) => {
             console.log(item, tabProps); // tslint:disable-line no-console
             this.changeReadState(item as NoticeItem);
           }}

+ 0 - 12
src/components/HeaderDropdown/index.d.ts

@@ -1,12 +0,0 @@
-import React from 'react';
-import { DropDownProps } from 'antd/lib/dropdown';
-
-declare type OverlayFunc = () => React.ReactNode;
-
-export interface HeaderDropdownProps extends DropDownProps {
-  overlayClassName?: string;
-  overlay: React.ReactNode | OverlayFunc;
-  placement?: 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topCenter' | 'topRight' | 'bottomCenter';
-}
-
-export default class HeaderDropdown extends React.Component<HeaderDropdownProps, any> {}

+ 4 - 0
src/components/HeaderDropdown/index.tsx

@@ -4,8 +4,12 @@ import { DropDownProps } from 'antd/es/dropdown';
 import classNames from 'classnames';
 import styles from './index.less';
 
+declare type OverlayFunc = () => React.ReactNode;
+
 export interface HeaderDropdownProps extends DropDownProps {
   overlayClassName?: string;
+  overlay: React.ReactNode | OverlayFunc;
+  placement?: 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topCenter' | 'topRight' | 'bottomCenter';
 }
 
 const HeaderDropdown: React.FC<HeaderDropdownProps> = ({ overlayClassName: cls, ...restProps }) => (

+ 0 - 15
src/components/HeaderSearch/index.d.ts

@@ -1,15 +0,0 @@
-import React from 'react';
-export interface HeaderSearchProps {
-  placeholder?: string;
-  dataSource?: string[];
-  defaultOpen?: boolean;
-  open?: boolean;
-  onSearch?: (value: string) => void;
-  onChange?: (value: string) => void;
-  onVisibleChange?: (visible: boolean) => void;
-  onPressEnter?: (value: string) => void;
-  style?: React.CSSProperties;
-  className?: string;
-}
-
-export default class HeaderSearch extends React.Component<HeaderSearchProps, any> {}

+ 0 - 9
src/components/SettingDrawer/BlockCheckbox.d.ts

@@ -1,9 +0,0 @@
-import React from 'react';
-
-export interface BlockChecboxProps {
-  value: string;
-  onChange: (key: string) => void;
-  list: any[];
-}
-
-export default class BlockChecbox extends React.Component<BlockChecboxProps, any> {}

+ 0 - 24
src/components/SettingDrawer/index.d.ts

@@ -1,24 +0,0 @@
-import React from 'react';
-import { SiderTheme } from 'antd/es/Layout/Sider';
-
-export interface SettingModelState {
-  navTheme: string | SiderTheme;
-  primaryColor: string;
-  layout: string;
-  contentWidth: string;
-  fixedHeader: boolean;
-  autoHideHeader: boolean;
-  fixSiderbar: boolean;
-  menu: { disableLocal: boolean };
-  title: string;
-  pwa: boolean;
-  iconfontUrl: string;
-  colorWeak: boolean;
-}
-
-export interface SettingDrawerProps {
-  setting?: SettingModelState;
-  dispatch?: (args: any) => void;
-}
-
-export default class SettingDrawer extends React.Component<SettingDrawerProps, any> {}

+ 69 - 0
src/typings.d.ts

@@ -12,4 +12,73 @@ declare module '*.tiff';
 declare module 'rc-animate';
 declare module 'omit.js';
 declare module 'react-copy-to-clipboard';
+declare module 'react-fittext';
+declare module '@antv/data-set';
+declare module 'nzh/cn';
 declare var APP_TYPE: string;
+declare module 'memoize-one' {
+  function memoizeOne<T extends (...args: any[]) => any>(
+    resultFn: T,
+    isEqual?: (a: any, b: any, index: number) => boolean,
+  ): T;
+  export default memoizeOne;
+}
+
+declare module 'ant-design-pro' {
+  import { Component } from 'react';
+  export interface NoticeIconTabProps<T extends NoticeIconData = NoticeIconData> {
+    className?: string;
+    count?: number;
+    emptyText?: React.ReactNode;
+    emptyImage?: string;
+    list?: T[];
+    showClear?: boolean;
+    showViewMore?: boolean;
+    style?: React.CSSProperties;
+    title?: string;
+  }
+
+  export type NoticeIconTabComponent<T extends NoticeIconData = NoticeIconData> = React.FC<
+    NoticeIconTabProps<T>
+  >;
+
+  export interface NoticeIconData {
+    avatar?: string | React.ReactNode;
+    clickClose?: boolean;
+    description?: React.ReactNode;
+    datetime?: React.ReactNode;
+    extra?: React.ReactNode;
+    key?: string | number;
+    read?: boolean;
+    style?: React.CSSProperties;
+    title?: React.ReactNode;
+    [key: string]: any;
+  }
+
+  export interface NoticeIconProps<T extends NoticeIconData = NoticeIconData> {
+    count?: number;
+    bell?: React.ReactNode;
+    className?: string;
+    loading?: boolean;
+    onClear?: (tabTitle?: string) => void;
+    onItemClick?: (item: T, tabProps: NoticeIconProps<T>) => void;
+    onViewMore?: (tabProps: NoticeIconProps<T>, e: React.MouseEvent) => void;
+    onTabChange?: (tabTile?: string) => void;
+    style?: React.CSSProperties;
+    onPopupVisibleChange?: (visible: boolean) => void;
+    popupVisible?: boolean;
+    locale?: {
+      emptyText: string;
+      clear: string;
+      viewMore: string;
+      [key: string]: string;
+    };
+    clearClose?: boolean;
+  }
+
+  export default class NoticeIcon<T extends NoticeIconData = NoticeIconData> extends Component<
+    NoticeIconProps<T>
+  > {
+    static Tab: NoticeIconTabComponent;
+  }
+}