Skip to content

Commit bac1e73

Browse files
appleapple
authored andcommitted
部门树形结构
1 parent 4e7a3e8 commit bac1e73

File tree

13 files changed

+263
-375
lines changed

13 files changed

+263
-375
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ src/page/heightEchart/index.js
66
src/page/chinaMap/index.js
77
src/page/useCallBack/index.js
88
src/serviceWorker.js
9-
# src/index.js
9+
src/page/Department/Item/index.jsx
10+
# src/index.js

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
"webpack-dev-server": "3.2.1",
7474
"webpack-manifest-plugin": "2.0.4",
7575
"workbox-webpack-plugin": "4.3.1",
76-
"history": "^4.7.2"
76+
"history": "^4.7.2",
77+
"flex.css": "^1.1.7"
7778
},
7879
"husky": {
7980
"hooks": {

src/img/[email protected]

1.85 KB
Loading

src/img/[email protected]

946 Bytes
Loading

src/img/[email protected]

918 Bytes
Loading

src/img/[email protected]

1.07 KB
Loading

src/img/[email protected]

1.46 KB
Loading

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import React from "react";
22

33
import ReactDOM from "react-dom";
44
import "./index.css";
5-
65
import { createStore, applyMiddleware } from "redux";
76
import { createLogger } from "redux-logger";
87
import { Provider } from "react-redux";
9-
8+
import "flex.css/dist/data-flex.css";
109
import reducer from "./page/reducer/index";
1110
import AppRouter from "./router/index";
1211
import thunkMiddleware from "./thunkMiddleware";

src/page/Department/Add/index.jsx

Whitespace-only changes.

src/page/Department/Item/index.jsx

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import React, { useState } from "react";
2+
import PropTypes from "prop-types";
3+
import styled from "styled-components";
4+
// import config from '../../../../config';
5+
// import req from '../../../../req';
6+
import foldIcon from "../../../img/[email protected]";
7+
import unfoldIcon from "../../../img/[email protected]";
8+
import editIcon from "../../../img/[email protected]";
9+
import deleteIcon from "../../../img/[email protected]";
10+
import chooseIcon from "../../../img/[email protected]";
11+
12+
const StyledItem = styled.div`
13+
height: 50px;
14+
.icon {
15+
width: 30px;
16+
height: 30px;
17+
}
18+
.content {
19+
text-align: right;
20+
overflow: hidden;
21+
border-bottom: 1px solid #e6e6e6;
22+
}
23+
.name,
24+
.count {
25+
font-size: 16px;
26+
color: rgba(33, 39, 50, 0.85);
27+
}
28+
.name {
29+
white-space: nowrap;
30+
word-break: break-all;
31+
overflow: hidden;
32+
text-overflow: ellipsis;
33+
}
34+
.count {
35+
margin-left: 4px;
36+
}
37+
.choose_icon,
38+
.edit_icon,
39+
.delete_icon {
40+
width: 40px;
41+
height: 40px;
42+
}
43+
`;
44+
45+
function Page({ hasDelete, info, selectList, departmentCountMap, space, isLast }) {
46+
console.log("isLast", isLast, info);
47+
const [showAll, setShowAll] = useState(false);
48+
return (
49+
<>
50+
<StyledItem data-flex="main:left cross:center" style={{ paddingLeft: space * 28 }}>
51+
{showAll ? (
52+
<img className="icon" src={unfoldIcon} alt="" data-flex-box="0" onClick={() => setShowAll(!showAll)} />
53+
) : (
54+
<img src={foldIcon} className="icon" data-flex-box="0" alt="" onClick={() => setShowAll(!showAll)} />
55+
)}
56+
<div
57+
className="content"
58+
data-flex-box="1"
59+
data-flex="main:left cross:center"
60+
style={{
61+
borderBottomColor: isLast && (!info.childDepartment.length || !showAll) ? "transparent" : "#e6e6e6",
62+
}}
63+
>
64+
<div className="name">{info.departmentName}</div>
65+
{!!departmentCountMap[info.departmentId] && (
66+
<div className="count">{departmentCountMap[info.departmentId]}</div>
67+
)}
68+
<div data-flex-box="1" style={{ marginLeft: 20 }} />
69+
{hasDelete ? (
70+
<>
71+
<img className="edit_icon" src={editIcon} data-flex-box="0" alt="" />
72+
<img className="delete_icon" src={deleteIcon} data-flex-box="0" alt="" />
73+
</>
74+
) : (
75+
selectList.includes(info.departmentId) && (
76+
<img className="check_icon" src={chooseIcon} data-flex-box="0" alt="" />
77+
)
78+
)}
79+
</div>
80+
</StyledItem>
81+
{showAll &&
82+
info.childDepartment.map((item, index) => (
83+
<Page
84+
hasDelete={hasDelete}
85+
info={item}
86+
space={space + 1}
87+
key={item.departmentId}
88+
selectList={selectList}
89+
isLast={index === info.childDepartment.length - 1}
90+
departmentCountMap={departmentCountMap}
91+
/>
92+
))}
93+
</>
94+
);
95+
}
96+
Page.propTypes = {
97+
hasDelete: PropTypes.bool,
98+
info: PropTypes.object.isRequired,
99+
selectList: PropTypes.array,
100+
departmentCountMap: PropTypes.object,
101+
space: PropTypes.number,
102+
isLast: PropTypes.bool,
103+
};
104+
Page.defaultProps = {
105+
hasDelete: false,
106+
isLast: false,
107+
selectList: [],
108+
departmentCountMap: {},
109+
space: 0,
110+
};
111+
112+
export default Page;

0 commit comments

Comments
 (0)