Skip to content

Commit 51f2746

Browse files
committed
refactor: 重构tagsView
1 parent 261b533 commit 51f2746

File tree

7 files changed

+87
-111
lines changed

7 files changed

+87
-111
lines changed

src/components/TagList/index.jsx

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/views/layout/Header/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.ant-layout-header {
22
transition: width 0.2s;
3-
// padding: 0px !important;
43
z-index: 9;
54
position: relative;
65
height: 64px;
6+
padding:0 20px 0 50px !important;
77
background: #fff !important;
88
box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
99
.right-menu {

src/views/layout/Sider/Menu/index.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ class Meun extends Component {
9797
});
9898
};
9999

100-
handleMenuSelect = ({ key }) => {
101-
let menuItem = getMenuItemInMenuListByProperty(menuList,'path',key)
100+
handleMenuSelect = ({ key = "/dashboard" }) => {
101+
let menuItem = getMenuItemInMenuListByProperty(menuList, "path", key);
102102
this.props.addTaglist(menuItem);
103103
};
104104

@@ -107,6 +107,7 @@ class Meun extends Component {
107107
this.setState({
108108
menuTreeNode,
109109
});
110+
this.handleMenuSelect(this.state.openKey);
110111
}
111112
render() {
112113
const path = this.props.location.pathname;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, { Component } from "react";
2+
import { connect } from "react-redux";
3+
import { withRouter } from "react-router-dom";
4+
import { Scrollbars } from "react-custom-scrollbars";
5+
import { Tag } from "antd";
6+
import { deleteTaglist } from "@/store/actions";
7+
8+
class TagList extends Component {
9+
handleClose = (tag) => {
10+
const { history, deleteTaglist, taglist } = this.props;
11+
const path = tag.path;
12+
const currentPath = history.location.pathname;
13+
const length = taglist.length;
14+
// 如果关闭的是当前页,跳转到最后一个tag
15+
if (path === currentPath) {
16+
history.push(taglist[length - 1].path);
17+
}
18+
// 如果关闭的是最后的tag ,且当前显示的也是最后的tag对应的页面,才做路由跳转
19+
if (
20+
path === taglist[length - 1].path &&
21+
currentPath === taglist[length - 1].path
22+
) {
23+
// 因为cutTaglist在最后执行,所以跳转到上一个tags的对应的路由,应该-2
24+
if (length - 2 > 0) {
25+
history.push(taglist[length - 2].path);
26+
} else if (length === 2) {
27+
history.push(taglist[0].path);
28+
}
29+
}
30+
31+
// 先跳转路由,再修改state树的taglist
32+
deleteTaglist(tag);
33+
};
34+
handleClick = (path) => {
35+
this.props.history.push(path);
36+
};
37+
render() {
38+
const { taglist, history } = this.props;
39+
const currentPath = history.location.pathname;
40+
return (
41+
<Scrollbars
42+
autoHide
43+
autoHideTimeout={1000}
44+
autoHideDuration={200}
45+
hideTracksWhenNotNeeded={true}
46+
renderView={props => <div {...props} className="scrollbar-container" />}
47+
renderTrackVertical={props => <div {...props} className="scrollbar-track-vertical"/>}
48+
>
49+
<ul className="tags-wrap">
50+
{taglist.map((tag) => (
51+
<li key={tag.path}>
52+
<Tag
53+
onClose={this.handleClose.bind(null, tag)}
54+
closable={tag.path !== "/dashboard"}
55+
color={currentPath === tag.path ? "geekblue" : "gold"}
56+
onClick={this.handleClick.bind(null, tag.path)}
57+
>
58+
{tag.title}
59+
</Tag>
60+
</li>
61+
))}
62+
</ul>
63+
</Scrollbars>
64+
);
65+
}
66+
}
67+
export default withRouter(
68+
connect((state) => state.tagsView, { deleteTaglist })(TagList)
69+
);

src/views/layout/TagsView/components/Tags.jsx

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import React from "react";
2-
import { withRouter } from "react-router-dom";
3-
import Tags from "./components/Tags";
4-
// import Dropdown from "./component/Dropdown";
2+
import TagList from "./components/TagList";
53
import "./index.less";
64

75
const TagsView = () => {
86
return (
9-
<div className="tags-row-wrap">
10-
<Tags />
11-
{/* <Dropdown /> */}
12-
</div>
7+
<div className="tagsView-container">
8+
<TagList />
9+
</div>
1310
);
1411
};
1512

16-
export default withRouter(TagsView);
13+
export default TagsView;
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
.tags-row-wrap {
1+
.tagsView-container {
22
white-space: nowrap;
3-
overflow-x: auto;
4-
overflow-y: hidden;
53
width: 100%;
64
height: 36px;
75
line-height: 36px;
86
border-bottom: 1px solid #d8dce5;
97
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12), 0 0 3px 0 rgba(0, 0, 0, 0.04);
10-
background-color: #fff;
8+
background: #fff;
119
padding: 0 16px;
1210
.tags-wrap {
1311
padding: 0;
@@ -16,3 +14,10 @@
1614
}
1715
}
1816
}
17+
18+
.scrollbar-container {
19+
overflow-y: hidden !important;
20+
}
21+
.scrollbar-track-vertical {
22+
visibility: hidden !important;
23+
}

0 commit comments

Comments
 (0)