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
354e866a
authored
Sep 01, 2025
by
F。
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复"边栏"隐藏后无法即时生效问题
parent
9ba37555
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
web/src/components/settings/personal/cards/NotificationSettings.jsx
+8
-1
web/src/hooks/common/useSidebar.js
+23
-2
No files found.
web/src/components/settings/personal/cards/NotificationSettings.jsx
View file @
354e866a
...
...
@@ -44,6 +44,7 @@ import CodeViewer from '../../../playground/CodeViewer';
import
{
StatusContext
}
from
'../../../../context/Status'
;
import
{
UserContext
}
from
'../../../../context/User'
;
import
{
useUserPermissions
}
from
'../../../../hooks/common/useUserPermissions'
;
import
{
useSidebar
}
from
'../../../../hooks/common/useSidebar'
;
const
NotificationSettings
=
({
t
,
...
...
@@ -97,6 +98,9 @@ const NotificationSettings = ({
isSidebarModuleAllowed
,
}
=
useUserPermissions
();
// 使用useSidebar钩子获取刷新方法
const
{
refreshUserConfig
}
=
useSidebar
();
// 左侧边栏设置处理函数
const
handleSectionChange
=
(
sectionKey
)
=>
{
return
(
checked
)
=>
{
...
...
@@ -132,6 +136,9 @@ const NotificationSettings = ({
});
if
(
res
.
data
.
success
)
{
showSuccess
(
t
(
'侧边栏设置保存成功'
));
// 刷新useSidebar钩子中的用户配置,实现实时更新
await
refreshUserConfig
();
}
else
{
showError
(
res
.
data
.
message
);
}
...
...
@@ -334,7 +341,7 @@ const NotificationSettings = ({
loading=
{
sidebarLoading
}
className=
'!rounded-lg'
>
{
t
(
'保存
边栏
设置'
)
}
{
t
(
'保存设置'
)
}
</
Button
>
</>
)
:
(
...
...
web/src/hooks/common/useSidebar.js
View file @
354e866a
...
...
@@ -21,6 +21,10 @@ import { useState, useEffect, useMemo, useContext } from 'react';
import
{
StatusContext
}
from
'../../context/Status'
;
import
{
API
}
from
'../../helpers'
;
// 创建一个全局事件系统来同步所有useSidebar实例
const
sidebarEventTarget
=
new
EventTarget
();
const
SIDEBAR_REFRESH_EVENT
=
'sidebar-refresh'
;
export
const
useSidebar
=
()
=>
{
const
[
statusState
]
=
useContext
(
StatusContext
);
const
[
userConfig
,
setUserConfig
]
=
useState
(
null
);
...
...
@@ -124,9 +128,11 @@ export const useSidebar = () => {
// 刷新用户配置的方法(供外部调用)
const
refreshUserConfig
=
async
()
=>
{
if
(
Object
.
keys
(
adminConfig
).
length
>
0
)
{
// 移除adminConfig的条件限制,直接刷新用户配置
await
loadUserConfig
();
}
// 触发全局刷新事件,通知所有useSidebar实例更新
sidebarEventTarget
.
dispatchEvent
(
new
CustomEvent
(
SIDEBAR_REFRESH_EVENT
));
};
// 加载用户配置
...
...
@@ -137,6 +143,21 @@ export const useSidebar = () => {
}
},
[
adminConfig
]);
// 监听全局刷新事件
useEffect
(()
=>
{
const
handleRefresh
=
()
=>
{
if
(
Object
.
keys
(
adminConfig
).
length
>
0
)
{
loadUserConfig
();
}
};
sidebarEventTarget
.
addEventListener
(
SIDEBAR_REFRESH_EVENT
,
handleRefresh
);
return
()
=>
{
sidebarEventTarget
.
removeEventListener
(
SIDEBAR_REFRESH_EVENT
,
handleRefresh
);
};
},
[
adminConfig
]);
// 计算最终的显示配置
const
finalConfig
=
useMemo
(()
=>
{
const
result
=
{};
...
...
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