Skip to content

Commit 35b81fa

Browse files
committed
perf: Optimize tabs
1 parent aa49edf commit 35b81fa

5 files changed

Lines changed: 48 additions & 14 deletions

File tree

chat2db-client/src/components/Tabs/index.less

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
background-color: var(--color-bg-subtle);
55
// 添加内阴影
66
box-shadow: inset 0px -1px 0px var(--color-primary);
7+
78
.icon {
89
opacity: 1;
910
}
@@ -12,6 +13,7 @@
1213
.tab-focus-line() {
1314
color: var(--color-primary);
1415
background-color: var(--color-bg-subtle);
16+
1517
.icon {
1618
display: flex;
1719
}
@@ -30,6 +32,7 @@
3032
flex-shrink: 0;
3133
background-color: var(--color-bg-base);
3234
border-bottom: 1px solid var(--color-border);
35+
3336
&::-webkit-scrollbar {
3437
display: none;
3538
}
@@ -38,12 +41,14 @@
3841
.tabsContent {
3942
flex: 1;
4043
height: 0px;
44+
4145
.tabsContentItem {
4246
height: 100%;
4347
width: 100%;
4448
display: none;
4549
position: relative;
4650
}
51+
4752
.tabsContentItemActive {
4853
display: block;
4954
}
@@ -67,19 +72,23 @@
6772
cursor: pointer;
6873
user-select: none;
6974
border-right: 1px solid var(--color-border);
75+
7076
&:last-child {
7177
border-right: 0;
7278
}
79+
7380
.textBox {
7481
flex: 1;
7582
display: flex;
7683
align-items: center;
7784
}
85+
7886
.text {
7987
flex: 1;
8088
width: fit-content;
8189
.f-single-line();
8290
}
91+
8392
.icon {
8493
flex-shrink: 0;
8594
display: flex;
@@ -92,18 +101,22 @@
92101
cursor: pointer;
93102
color: var(--color-text-secondary);
94103
opacity: 0;
104+
95105
i {
96106
font-size: 12px;
97107
}
108+
98109
&:hover {
99110
color: var(--color-primary);
100111
background-color: var(--color-hover-bg);
101112
}
102113
}
114+
103115
&:hover {
104116
// .tab-focus();
105117
color: var(--color-primary);
106-
.icon{
118+
119+
.icon {
107120
opacity: 1;
108121
}
109122
}
@@ -114,31 +127,33 @@
114127
}
115128

116129
.rightBox {
117-
flex: 1;
130+
// flex: 1;
118131
position: sticky;
119132
right: 0;
120133
top: 0;
121134
bottom: 0;
122135
background-color: var(--color-bg-base);
123-
border-left: 1px solid var(--color-border);
124-
border-right: 1px solid var(--color-border);
125-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
136+
border-left: 1px solid var(--color-border);
137+
border-right: 1px solid var(--color-border);
138+
box-shadow: -2px 0 4px rgba(0, 0, 0, 0.1);
126139
display: flex;
127140

128141

129142
}
130143

131-
.moreTabs{
144+
.moreTabs {
132145
width: 30px;
133146
height: 100%;
134147
display: flex;
135148
justify-content: center;
136149
align-items: center;
137150
cursor: pointer;
151+
138152
&:hover {
139153
color: var(--color-primary);
140154
}
141155

156+
142157
}
143158

144159
.addIcon {
@@ -148,13 +163,21 @@
148163
justify-content: center;
149164
align-items: center;
150165
cursor: pointer;
151-
border-left: 1px solid var(--color-border);
166+
border-left: 1px solid var(--color-border);
152167

153168
&:hover {
154169
color: var(--color-primary);
155170
}
156171
}
157172

173+
.addIconDisabled {
174+
color: var(--color-text-disabled);
175+
cursor: not-allowed;
176+
&:hover {
177+
color: var(--color-text-disabled);
178+
}
179+
}
180+
158181
.input {
159182
border: 0;
160183
width: 86px;
@@ -165,6 +188,7 @@
165188
font-weight: 400;
166189
background-color: var(--color-bg-subtle);
167190
color: var(--color-text);
191+
168192
input:focus {
169193
outline: none;
170194
}
@@ -173,7 +197,4 @@
173197
.prefixIcon {
174198
flex-shrink: 0;
175199
margin-right: 4px;
176-
}
177-
178-
.activeContent {
179-
}
200+
}

chat2db-client/src/components/Tabs/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface IOnchangeProps {
2323
data?: ITabItem;
2424
}
2525

26+
const MAX_TABS = 20;
27+
2628
interface IProps {
2729
className?: string;
2830
items?: ITabItem[];
@@ -92,7 +94,7 @@ export default memo<IProps>((props) => {
9294
if (activeTab) {
9395
setTimeout(() => {
9496
activeTab.scrollIntoView({ behavior: 'smooth', inline: 'start' });
95-
}, 50);
97+
}, 100);
9698
}
9799
}
98100

@@ -136,6 +138,9 @@ export default memo<IProps>((props) => {
136138
};
137139

138140
const handleAdd = () => {
141+
if (internalTabs.length >= MAX_TABS) {
142+
return;
143+
}
139144
onEdit?.('add');
140145
};
141146

@@ -260,6 +265,7 @@ export default memo<IProps>((props) => {
260265
<div className={styles.moreTabs}>
261266
<Dropdown
262267
menu={{
268+
style: { maxHeight: '200px', overflowY: 'auto' },
263269
items: moreTabsMenu,
264270
selectable: true,
265271
selectedKeys: [`${activeKey}`],
@@ -272,7 +278,12 @@ export default memo<IProps>((props) => {
272278
</a>
273279
</Dropdown>
274280
</div>
275-
<div className={styles.addIcon} onClick={handleAdd}>
281+
<div
282+
className={classnames(styles.addIcon, {
283+
[styles.addIconDisabled]: internalTabs.length >= MAX_TABS,
284+
})}
285+
onClick={handleAdd}
286+
>
276287
<Iconfont code="&#xe631;" />
277288
</div>
278289
</div>

chat2db-client/src/i18n/en-us/team.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
'team.title': 'Team Management',
23
'team.tab.datasource': 'DataSource Management',
34
'team.tab.user': 'User Management',
45
'team.tab.team': 'Team Management',

chat2db-client/src/i18n/zh-cn/team.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
'team.title': '团队管理',
23
'team.tab.datasource': '链接管理',
34
'team.tab.user': '用户管理',
45
'team.tab.team': '团队管理',

chat2db-client/src/pages/main/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function MainPage(props: IProps) {
130130
iconFontSize: 24,
131131
isLoad: false,
132132
component: <Team />,
133-
name: '团队协作',
133+
name: i18n('team.title'),
134134
});
135135
if (localStorage.getItem('curPage') === 'team') {
136136
setActiveNav(navConfig[3]);

0 commit comments

Comments
 (0)