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
0db8892f
authored
Sep 21, 2025
by
IcedTangerine
Committed by
GitHub
Sep 21, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1841 from x-Ai/fix/sidebar-permissions
fix: 个人设置中修改边栏设置不立即生效
parents
dc241175
09374778
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
web/src/components/settings/personal/cards/NotificationSettings.jsx
+8
-1
web/src/hooks/common/useSidebar.js
+23
-1
No files found.
web/src/components/settings/personal/cards/NotificationSettings.jsx
View file @
0db8892f
...
@@ -44,6 +44,7 @@ import CodeViewer from '../../../playground/CodeViewer';
...
@@ -44,6 +44,7 @@ import CodeViewer from '../../../playground/CodeViewer';
import
{
StatusContext
}
from
'../../../../context/Status'
;
import
{
StatusContext
}
from
'../../../../context/Status'
;
import
{
UserContext
}
from
'../../../../context/User'
;
import
{
UserContext
}
from
'../../../../context/User'
;
import
{
useUserPermissions
}
from
'../../../../hooks/common/useUserPermissions'
;
import
{
useUserPermissions
}
from
'../../../../hooks/common/useUserPermissions'
;
import
{
useSidebar
}
from
'../../../../hooks/common/useSidebar'
;
const
NotificationSettings
=
({
const
NotificationSettings
=
({
t
,
t
,
...
@@ -97,6 +98,9 @@ const NotificationSettings = ({
...
@@ -97,6 +98,9 @@ const NotificationSettings = ({
isSidebarModuleAllowed
,
isSidebarModuleAllowed
,
}
=
useUserPermissions
();
}
=
useUserPermissions
();
// 使用useSidebar钩子获取刷新方法
const
{
refreshUserConfig
}
=
useSidebar
();
// 左侧边栏设置处理函数
// 左侧边栏设置处理函数
const
handleSectionChange
=
(
sectionKey
)
=>
{
const
handleSectionChange
=
(
sectionKey
)
=>
{
return
(
checked
)
=>
{
return
(
checked
)
=>
{
...
@@ -132,6 +136,9 @@ const NotificationSettings = ({
...
@@ -132,6 +136,9 @@ const NotificationSettings = ({
});
});
if
(
res
.
data
.
success
)
{
if
(
res
.
data
.
success
)
{
showSuccess
(
t
(
'侧边栏设置保存成功'
));
showSuccess
(
t
(
'侧边栏设置保存成功'
));
// 刷新useSidebar钩子中的用户配置,实现实时更新
await
refreshUserConfig
();
}
else
{
}
else
{
showError
(
res
.
data
.
message
);
showError
(
res
.
data
.
message
);
}
}
...
@@ -334,7 +341,7 @@ const NotificationSettings = ({
...
@@ -334,7 +341,7 @@ const NotificationSettings = ({
loading=
{
sidebarLoading
}
loading=
{
sidebarLoading
}
className=
'!rounded-lg'
className=
'!rounded-lg'
>
>
{
t
(
'保存
边栏
设置'
)
}
{
t
(
'保存设置'
)
}
</
Button
>
</
Button
>
</>
</>
)
:
(
)
:
(
...
...
web/src/hooks/common/useSidebar.js
View file @
0db8892f
...
@@ -21,6 +21,10 @@ import { useState, useEffect, useMemo, useContext } from 'react';
...
@@ -21,6 +21,10 @@ import { useState, useEffect, useMemo, useContext } from 'react';
import
{
StatusContext
}
from
'../../context/Status'
;
import
{
StatusContext
}
from
'../../context/Status'
;
import
{
API
}
from
'../../helpers'
;
import
{
API
}
from
'../../helpers'
;
// 创建一个全局事件系统来同步所有useSidebar实例
const
sidebarEventTarget
=
new
EventTarget
();
const
SIDEBAR_REFRESH_EVENT
=
'sidebar-refresh'
;
export
const
useSidebar
=
()
=>
{
export
const
useSidebar
=
()
=>
{
const
[
statusState
]
=
useContext
(
StatusContext
);
const
[
statusState
]
=
useContext
(
StatusContext
);
const
[
userConfig
,
setUserConfig
]
=
useState
(
null
);
const
[
userConfig
,
setUserConfig
]
=
useState
(
null
);
...
@@ -124,9 +128,12 @@ export const useSidebar = () => {
...
@@ -124,9 +128,12 @@ export const useSidebar = () => {
// 刷新用户配置的方法(供外部调用)
// 刷新用户配置的方法(供外部调用)
const
refreshUserConfig
=
async
()
=>
{
const
refreshUserConfig
=
async
()
=>
{
if
(
Object
.
keys
(
adminConfig
).
length
>
0
)
{
if
(
Object
.
keys
(
adminConfig
).
length
>
0
)
{
await
loadUserConfig
();
await
loadUserConfig
();
}
}
// 触发全局刷新事件,通知所有useSidebar实例更新
sidebarEventTarget
.
dispatchEvent
(
new
CustomEvent
(
SIDEBAR_REFRESH_EVENT
));
};
};
// 加载用户配置
// 加载用户配置
...
@@ -137,6 +144,21 @@ export const useSidebar = () => {
...
@@ -137,6 +144,21 @@ export const useSidebar = () => {
}
}
},
[
adminConfig
]);
},
[
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
finalConfig
=
useMemo
(()
=>
{
const
result
=
{};
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