Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivWeb
Commits
6d04fb61
Commit
6d04fb61
authored
Jul 04, 2022
by
崔佳豪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加主题变更全局事件监听
parent
a489ef85
Pipeline
#54478
waiting for manual action with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
2 deletions
+55
-2
reducer.js
src/containers/App/store/reducer.js
+0
-1
BasicLayout.js
src/layouts/BasicLayout.js
+1
-1
render.js
src/render.js
+54
-0
No files found.
src/containers/App/store/reducer.js
View file @
6d04fb61
...
...
@@ -92,7 +92,6 @@ const appReducer = (state = initialState, action) => {
// 临时补充messageVoice。后续需要加到AppConfig中。
action
.
data
&&
action
.
data
.
hasOwnProperty
(
'messageVoice'
)
&&
(
window
.
globalConfig
.
messageVoice
=
action
.
data
.
messageVoice
)
action
.
data
&&
action
.
data
.
hasOwnProperty
(
'topMenu'
)
&&
(
window
.
globalConfig
.
topMenu
=
action
.
data
.
topMenu
)
action
.
data
&&
action
.
data
.
hasOwnProperty
(
'navTheme'
)
&&
(
window
.
globalConfig
.
navTheme
=
action
.
data
.
navTheme
)
// eslint-disable-next-line no-undef
...
...
src/layouts/BasicLayout.js
View file @
6d04fb61
...
...
@@ -358,7 +358,7 @@ const Layout = (props) => {
title
=
{
props
.
global
.
title
}
route
=
{
props
.
route
}
location
=
{
location
}
navTheme
=
{
props
.
global
?.
navTheme
??
'dark'
}
navTheme
=
{
props
.
global
?.
variableTheme
?.
navTheme
??
'dark'
}
mode
=
"MDI"
fixedHeader
headerHeight
=
{
52
}
...
...
src/render.js
View file @
6d04fb61
...
...
@@ -218,10 +218,64 @@ export const AppInitState = () => {
};
};
// 添加主题变更事件监听
const
initAppTheme
=
()
=>
{
const
hasThemeChanged
=
(
preTheme
,
theme
)
=>
{
if
(
!
preTheme
&&
!
theme
)
return
false
if
(
preTheme
&&
theme
&&
(
!
theme
.
primaryColor
||
theme
.
primaryColor
===
preTheme
.
primaryColor
)
&&
(
!
theme
.
navTheme
||
theme
.
navTheme
===
preTheme
.
navTheme
)
&&
(
!
theme
.
headerPrimaryColor
||
theme
.
headerPrimaryColor
===
preTheme
.
headerPrimaryColor
)
)
return
false
return
true
}
/**
* @param {Object} theme
* primaryColor:
* navTheme: "dark" or "light"
* headerPrimaryColor:
*/
window
.
share
&&
window
.
share
.
event
&&
window
.
share
.
event
.
on
(
'update:theme'
,
function
(
theme
)
{
if
(
!
theme
||
!
hasThemeChanged
(
window
.
globalConfig
.
variableTheme
,
theme
))
return
;
const
preVariableTheme
=
window
.
globalConfig
.
variableTheme
??
{};
const
{
primaryColor
:
prePrimaryColor
,
navTheme
:
preNavTheme
,
headerPrimaryColor
:
preHeaderPrimaryColor
,
}
=
preVariableTheme
;
const
{
primaryColor
,
navTheme
,
headerPrimaryColor
}
=
theme
;
if
(
primaryColor
&&
primaryColor
!==
prePrimaryColor
)
{
ConfigProvider
.
config
({
prefixCls
:
customPrefixCls
,
theme
:
{
primaryColor
,
}
});
}
if
(
navTheme
&&
navTheme
!==
preNavTheme
)
{
// do nothing
}
if
(
headerPrimaryColor
&&
headerPrimaryColor
!==
preHeaderPrimaryColor
)
{
registerTheme
(
customPrefixCls
,
{
'header-bg-color'
:
headerPrimaryColor
,
});
}
// updage global config
const
variableTheme
=
Object
.
assign
({},
preVariableTheme
,
theme
);
store
.
dispatch
(
actionCreators
.
getConfig
(
Object
.
assign
({},
window
.
globalConfig
,
{
variableTheme
:
variableTheme
,
})));
})
};
initLocale
();
initMessageVoice
();
initGeteWay
();
initAppTheme
();
}
const
RootContainer
=
()
=>
{
...
...
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