Skip to content

Commit 8ff5934

Browse files
authored
Merge pull request #144 from ts-react/v1
V1
2 parents ac65515 + f6ed026 commit 8ff5934

File tree

8 files changed

+118
-122
lines changed

8 files changed

+118
-122
lines changed

.prettierignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
**.*.md
21
**/*.svg
3-
**/*.ejs
4-
**/*.html
52
package.json
3+
64
.umi
75
.umi-production

.prettierrc.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
module.exports = {
2-
tabWidth: 2,
3-
semi: true,
2+
// 行最大长度规则
3+
printWidth: 100,
4+
// 使用单引号
45
singleQuote: true,
56
bracketSpacing: true,
6-
jsxBracketSameLine: false,
7-
arrowParens: 'always'
7+
trailingComma: 'all',
8+
proseWrap: 'never'
89
};

.stylelintrc.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"extends": [
33
"stylelint-config-standard",
44
"stylelint-config-rational-order",
5-
"stylelint-config-prettier"
5+
"stylelint-prettier/recommended"
66
],
77
"plugins": [
8+
"stylelint-prettier",
89
"stylelint-order",
910
"stylelint-declaration-block-no-ignored-properties"
1011
],
1112
"rules": {
13+
"prettier/prettier": true,
1214
"no-descending-specificity": null,
1315
"plugin/declaration-block-no-ignored-properties": true
1416
}

lint-staged.config.js

-6
This file was deleted.

package.json

+12-6
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
"build:prod": "cross-env SERVER_ENV=production umi build",
1313
"build:web": "yarn build && cd ./dist && anywhere -h localhost -p 8080",
1414
"gh-pages": "yarn build:prod && gh-pages -d dist",
15-
"lint-staged": "lint-staged",
16-
"lint-staged:ts": "npm run tsc",
1715
"lint:ts": "tslint --project tsconfig.json --format codeFrame",
1816
"lint:style": "stylelint --fix 'src/**/*.less' --syntax less",
1917
"docker:build": "./scripts/docker-build.sh",
2018
"tsc": "tsc",
2119
"test": "umi test",
2220
"test:component": "umi test ./src/components",
23-
"deploy": "yarn build && rm -rf node_modules/gh-pages/.cache && gh-pages -d dist",
24-
"prettier": "prettier --write ./src/**/**/**/*"
21+
"deploy": "yarn build && rm -rf node_modules/gh-pages/.cache && gh-pages -d dist"
2522
},
2623
"repository": "https://github.com/ts-react/react-admin-template.git",
2724
"author": "JiuMao FE Team",
@@ -89,26 +86,35 @@
8986
"husky": "^2.2.0",
9087
"identity-obj-proxy": "^3.0.0",
9188
"jest": "^24.1.0",
92-
"lint-staged": "^8.1.4",
89+
"lint-staged": "^8.1.7",
9390
"mockjs": "^1.0.1-beta3",
94-
"prettier": "^1.17.0",
91+
"prettier": "^1.17.1",
9592
"rimraf": "^2.6.2",
9693
"stylelint": "^10.0.1",
9794
"stylelint-config-prettier": "^5.2.0",
9895
"stylelint-config-rational-order": "^0.1.2",
9996
"stylelint-config-standard": "^18.3.0",
10097
"stylelint-declaration-block-no-ignored-properties": "^2.1.0",
10198
"stylelint-order": "^3.0.0",
99+
"stylelint-prettier": "^1.1.1",
102100
"typescript": "^3.5.1",
103101
"umi": "^2.6.17",
104102
"umi-plugin-react": "^1.7.5",
105103
"umi-types": "^0.3.2"
106104
},
107105
"husky": {
108106
"hooks": {
107+
"pre-commit": "lint-staged",
109108
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
110109
}
111110
},
111+
"lint-staged": {
112+
"**/*.less": "stylelint --syntax less",
113+
"**/*.{js,ts,tsx,md,json,jsx,less}": [
114+
"prettier --write",
115+
"git add"
116+
]
117+
},
112118
"engines": {
113119
"node": ">=8.9.0"
114120
}

src/components/page-header-wrapper/page-header-wrapper.tsx

+12-9
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ interface IProps extends PageHeaderProps {
1111
wrapperClassName?: string;
1212
}
1313

14-
const PageHeaderWrapper: React.FC<IProps> = (props) => {
14+
const PageHeaderWrapper: React.FC<IProps> = props => {
1515
const { wrapperClassName, prefixCls, ...restProps } = props;
1616
const { location, breadcrumbNameMap } = React.useContext(MenuContext);
1717

1818
const getRoutes = (pathname, breadcrumbNameMap) => {
1919
const pathSnippets = urlToList(pathname);
2020
const routes = [];
2121

22-
pathSnippets.forEach((url) => {
22+
pathSnippets.forEach(url => {
2323
const menuData = breadcrumbNameMap[url];
24+
if (!menuData) return;
2425
routes.push({
2526
path: menuData.path,
2627
breadcrumbName: menuData.name,
@@ -32,9 +33,11 @@ const PageHeaderWrapper: React.FC<IProps> = (props) => {
3233

3334
const itemRender = (route, params, routes) => {
3435
const last = routes.indexOf(route) === routes.length - 1;
35-
return last
36-
? <span>{route.breadcrumbName}</span>
37-
: <Link to={route.path}>{route.breadcrumbName}</Link>;
36+
return last ? (
37+
<span>{route.breadcrumbName}</span>
38+
) : (
39+
<Link to={route.path}>{route.breadcrumbName}</Link>
40+
);
3841
};
3942

4043
const pathname = location!.pathname;
@@ -43,22 +46,22 @@ const PageHeaderWrapper: React.FC<IProps> = (props) => {
4346
return (
4447
<div
4548
className={classNames(wrapperClassName, {
46-
[`${prefixCls}`]: true
49+
[`${prefixCls}`]: true,
4750
})}
4851
>
4952
<PageHeader
5053
breadcrumb={{
5154
itemRender,
52-
routes
55+
routes,
5356
}}
5457
{...restProps}
5558
/>
5659
</div>
57-
)
60+
);
5861
};
5962

6063
PageHeaderWrapper.defaultProps = {
61-
prefixCls: 'lotus-page-header-wrapper'
64+
prefixCls: 'lotus-page-header-wrapper',
6265
};
6366

6467
export default PageHeaderWrapper;
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import React, { useState } from 'react';
22
import classNames from 'classnames';
33
import { Table } from 'antd';
4-
import {
5-
PaginationConfig,
6-
TableProps,
7-
SorterResult,
8-
TableCurrentDataSource
9-
} from 'antd/es/table';
4+
import { PaginationConfig, TableProps, SorterResult, TableCurrentDataSource } from 'antd/es/table';
105
import './standard-table.less';
116

127
export interface ITableData<T> {
138
list: T[];
14-
pagination?: PaginationConfig
9+
pagination?: PaginationConfig;
1510
}
1611

1712
interface IProps<T> extends TableProps<T> {
@@ -26,50 +21,57 @@ interface IProps<T> extends TableProps<T> {
2621
) => void;
2722
}
2823

29-
const StandardTable: React.FC<IProps<any>> = (props) => {
30-
const {
31-
className,
32-
prefixCls,
33-
style,
34-
rowKey,
35-
data,
36-
onChange,
37-
...restProps
38-
} = props;
24+
const StandardTable: React.FC<IProps<any>> = props => {
25+
const { className, prefixCls, style, rowKey, data, onChange, onSelectRow, ...restProps } = props;
3926
const { list = [], pagination } = data;
4027
const [selectedRowKeys, setSelectedRowKeys] = useState<string[] | number[]>([]);
4128

42-
const handleTableChange = (
43-
pagination,
44-
filters,
45-
sorter
46-
) => {
29+
const handleTableChange = (pagination, filters, sorter) => {
4730
onChange && onChange(pagination, filters, sorter);
4831
};
4932

33+
const handleShowTotal = (total, range) => {
34+
return `共 ${total} 条`;
35+
};
36+
5037
const paginationProps = {
5138
showSizeChanger: true,
5239
showQuickJumper: true,
40+
showTotal: handleShowTotal,
41+
pageSizeOptions: ['10', '30', '50'],
5342
...pagination,
5443
};
5544

45+
const handleRowSelectChange = (selectedRowKeys: string[] | number[], selectedRows: any[]) => {
46+
onSelectRow && onSelectRow(selectedRows);
47+
48+
setSelectedRowKeys(selectedRowKeys);
49+
};
50+
51+
const rowSelection = {
52+
selectedRowKeys,
53+
onChange: handleRowSelectChange,
54+
};
55+
5656
return (
5757
<Table
5858
className={classNames(className, {
59-
[`${prefixCls}`]: true
59+
[`${prefixCls}`]: true,
6060
})}
6161
style={style}
6262
rowKey={rowKey}
6363
dataSource={list}
64+
rowSelection={onSelectRow ? rowSelection : null}
6465
pagination={paginationProps}
6566
onChange={handleTableChange}
6667
{...restProps}
6768
/>
68-
)
69+
);
6970
};
7071

7172
StandardTable.defaultProps = {
72-
rowKey: 'id'
73+
prefixCls: 'lotus-standard-table',
74+
rowKey: 'id',
7375
};
7476

7577
export default StandardTable;

0 commit comments

Comments
 (0)