Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e704f076
authored
Mar 10, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Improve sidebar state management and layout responsiveness
parent
ddd6706c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
6 deletions
+17
-6
web/src/components/PageLayout.js
+1
-1
web/src/components/SiderBar.js
+5
-5
web/src/context/Style/index.js
+11
-0
No files found.
web/src/components/PageLayout.js
View file @
e704f076
...
@@ -113,7 +113,7 @@ const PageLayout = () => {
...
@@ -113,7 +113,7 @@ const PageLayout = () => {
<
/Sider
>
<
/Sider
>
)}
)}
<
Layout
style
=
{{
<
Layout
style
=
{{
marginLeft
:
styleState
.
isMobile
?
'0'
:
(
styleState
.
showSider
?
(
isSidebarCollapsed
?
'60px'
:
'200px'
)
:
'0'
),
marginLeft
:
styleState
.
isMobile
?
'0'
:
(
styleState
.
showSider
?
(
styleState
.
siderCollapsed
?
'60px'
:
'200px'
)
:
'0'
),
transition
:
'margin-left 0.3s ease'
,
transition
:
'margin-left 0.3s ease'
,
flex
:
'1 1 auto'
,
flex
:
'1 1 auto'
,
display
:
'flex'
,
display
:
'flex'
,
...
...
web/src/components/SiderBar.js
View file @
e704f076
...
@@ -316,10 +316,10 @@ const SiderBar = () => {
...
@@ -316,10 +316,10 @@ const SiderBar = () => {
isCollapsed
=
{
isCollapsed
}
isCollapsed
=
{
isCollapsed
}
onCollapseChange
=
{(
collapsed
)
=>
{
onCollapseChange
=
{(
collapsed
)
=>
{
setIsCollapsed
(
collapsed
);
setIsCollapsed
(
collapsed
);
// styleDispatch({ type: 'SET_SIDER', payload: true });
styleDispatch
({
type
:
'SET_SIDER_COLLAPSED'
,
payload
:
collapsed
});
localStorage
.
setItem
(
'default_collapse_sidebar'
,
collapsed
);
localStorage
.
setItem
(
'default_collapse_sidebar'
,
collapsed
);
// 始终保持侧边栏显示,只是宽度不同
styleDispatch
({
type
:
'SET_SIDER'
,
payload
:
true
});
// 确保在收起侧边栏时有选中的项目,避免不必要的计算
// 确保在收起侧边栏时有选中的项目,避免不必要的计算
if
(
selectedKeys
.
length
===
0
)
{
if
(
selectedKeys
.
length
===
0
)
{
const
currentPath
=
location
.
pathname
;
const
currentPath
=
location
.
pathname
;
...
@@ -330,7 +330,7 @@ const SiderBar = () => {
...
@@ -330,7 +330,7 @@ const SiderBar = () => {
}
else
if
(
currentPath
.
startsWith
(
'/chat/'
))
{
}
else
if
(
currentPath
.
startsWith
(
'/chat/'
))
{
setSelectedKeys
([
'chat'
]);
setSelectedKeys
([
'chat'
]);
}
else
{
}
else
{
setSelectedKeys
([
'
home
'
]);
// 默认选中首页
setSelectedKeys
([
'
detail
'
]);
// 默认选中首页
}
}
}
}
}}
}}
...
@@ -467,7 +467,7 @@ const SiderBar = () => {
...
@@ -467,7 +467,7 @@ const SiderBar = () => {
<
Nav
.
Footer
<
Nav
.
Footer
style
=
{{
style
=
{{
paddingBottom
:
styleState
?.
isMobile
?
'112px'
:
'
0
'
,
paddingBottom
:
styleState
?.
isMobile
?
'112px'
:
'
20px
'
,
}}
}}
collapseButton
=
{
true
}
collapseButton
=
{
true
}
collapseText
=
{(
collapsed
)
=>
collapseText
=
{(
collapsed
)
=>
...
...
web/src/context/Style/index.js
View file @
e704f076
...
@@ -11,6 +11,7 @@ export const StyleProvider = ({ children }) => {
...
@@ -11,6 +11,7 @@ export const StyleProvider = ({ children }) => {
const
[
state
,
setState
]
=
useState
({
const
[
state
,
setState
]
=
useState
({
isMobile
:
isMobile
(),
isMobile
:
isMobile
(),
showSider
:
false
,
showSider
:
false
,
siderCollapsed
:
false
,
shouldInnerPadding
:
false
,
shouldInnerPadding
:
false
,
});
});
...
@@ -26,6 +27,9 @@ export const StyleProvider = ({ children }) => {
...
@@ -26,6 +27,9 @@ export const StyleProvider = ({ children }) => {
case
'SET_MOBILE'
:
case
'SET_MOBILE'
:
setState
(
prev
=>
({
...
prev
,
isMobile
:
action
.
payload
}));
setState
(
prev
=>
({
...
prev
,
isMobile
:
action
.
payload
}));
break
;
break
;
case
'SET_SIDER_COLLAPSED'
:
setState
(
prev
=>
({
...
prev
,
siderCollapsed
:
action
.
payload
}));
break
case
'SET_INNER_PADDING'
:
case
'SET_INNER_PADDING'
:
setState
(
prev
=>
({
...
prev
,
shouldInnerPadding
:
action
.
payload
}));
setState
(
prev
=>
({
...
prev
,
shouldInnerPadding
:
action
.
payload
}));
break
;
break
;
...
@@ -65,6 +69,13 @@ export const StyleProvider = ({ children }) => {
...
@@ -65,6 +69,13 @@ export const StyleProvider = ({ children }) => {
updateShowSider
();
updateShowSider
();
const
updateSiderCollapsed
=
()
=>
{
const
isCollapsed
=
localStorage
.
getItem
(
'default_collapse_sidebar'
)
===
'true'
;
dispatch
({
type
:
'SET_SIDER_COLLAPSED'
,
payload
:
isCollapsed
});
};
updateSiderCollapsed
();
// Add event listeners to handle window resize
// Add event listeners to handle window resize
const
handleResize
=
()
=>
{
const
handleResize
=
()
=>
{
updateIsMobile
();
updateIsMobile
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment