Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
b1e03cbd
Commit
b1e03cbd
authored
Aug 28, 2018
by
afc163
Committed by
ιεΈ
Aug 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor less compile logic
parent
0a5a9fc8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
27 deletions
+33
-27
src/components/SettingDarwer/index.less
src/components/SettingDarwer/index.less
+1
-1
src/models/setting.js
src/models/setting.js
+32
-26
No files found.
src/components/SettingDarwer/index.less
View file @
b1e03cbd
...
@@ -71,5 +71,5 @@
...
@@ -71,5 +71,5 @@
.productionHint {
.productionHint {
font-size: 12px;
font-size: 12px;
color: @text-color-secondary;
color: @text-color-secondary;
margin-top:
4
px;
margin-top:
8
px;
}
}
src/models/setting.js
View file @
b1e03cbd
...
@@ -2,15 +2,13 @@ import { message } from 'antd';
...
@@ -2,15 +2,13 @@ import { message } from 'antd';
import
defaultSetting
from
'
../defaultSetting
'
;
import
defaultSetting
from
'
../defaultSetting
'
;
let
lessNodesAppended
;
let
lessNodesAppended
;
const
buildSettings
=
(
themeColor
,
colorWeak
)
=>
{
const
updateTheme
=
themeColor
=>
{
document
.
body
.
className
=
colorWeak
?
'
colorWeak
'
:
''
;
// Determine if the component is remounted
// Determine if the component is remounted
if
(
!
themeColor
||
themeColor
===
'
#1890FF
'
||
themeColor
===
window
[
'
antd_pro_less_color
'
]
)
{
if
(
!
themeColor
)
{
return
;
return
;
}
}
const
hideMessage
=
message
.
loading
(
'
ζ£ε¨ηΌθ―δΈ»ι’οΌ
'
,
0
);
const
hideMessage
=
message
.
loading
(
'
ζ£ε¨ηΌθ―δΈ»ι’οΌ
'
,
0
);
if
(
!
lessNodesAppended
)
{
if
(
!
lessNodesAppended
)
{
console
.
log
(
'
append less nodes
'
);
const
lessStyleNode
=
document
.
createElement
(
'
link
'
);
const
lessStyleNode
=
document
.
createElement
(
'
link
'
);
const
lessConfigNode
=
document
.
createElement
(
'
script
'
);
const
lessConfigNode
=
document
.
createElement
(
'
script
'
);
const
lessScriptNode
=
document
.
createElement
(
'
script
'
);
const
lessScriptNode
=
document
.
createElement
(
'
script
'
);
...
@@ -19,19 +17,18 @@ const buildSettings = (themeColor, colorWeak) => {
...
@@ -19,19 +17,18 @@ const buildSettings = (themeColor, colorWeak) => {
lessConfigNode
.
innerHTML
=
`
lessConfigNode
.
innerHTML
=
`
window.less = {
window.less = {
async: true,
async: true,
env: 'production',
env: 'production'
javascriptEnabled: true
};
};
`
;
`
;
lessScriptNode
.
src
=
'
https://gw.alipayobjects.com/os/lib/less.js/
3.8.1
/less.min.js
'
;
lessScriptNode
.
src
=
'
https://gw.alipayobjects.com/os/lib/less.js/
2.7.3
/less.min.js
'
;
lessScriptNode
.
async
=
true
;
lessScriptNode
.
async
=
true
;
lessScriptNode
.
onload
=
()
=>
{
lessScriptNode
.
onload
=
()
=>
{
buildIt
();
buildIt
();
lessScriptNode
.
onload
=
null
;
lessScriptNode
.
onload
=
null
;
};
};
document
.
head
.
appendChild
(
lessStyleNode
);
document
.
body
.
appendChild
(
lessStyleNode
);
document
.
head
.
appendChild
(
lessConfigNode
);
document
.
body
.
appendChild
(
lessConfigNode
);
document
.
head
.
appendChild
(
lessScriptNode
);
document
.
body
.
appendChild
(
lessScriptNode
);
lessNodesAppended
=
true
;
lessNodesAppended
=
true
;
}
else
{
}
else
{
buildIt
();
buildIt
();
...
@@ -40,23 +37,26 @@ const buildSettings = (themeColor, colorWeak) => {
...
@@ -40,23 +37,26 @@ const buildSettings = (themeColor, colorWeak) => {
if
(
!
window
.
less
)
{
if
(
!
window
.
less
)
{
return
;
return
;
}
}
setTimeout
(()
=>
{
window
.
less
window
.
less
.
modifyVars
({
.
modifyVars
({
'
@primary-color
'
:
themeColor
,
'
@primary-color
'
:
themeColor
,
'
@input-hover-border-color
'
:
themeColor
,
})
})
.
then
(()
=>
{
.
then
(()
=>
{
console
.
log
(
'
start to compile
'
);
window
[
'
antd_pro_less_color
'
]
=
themeColor
;
hideMessage
();
hideMessage
();
})
})
.
catch
(()
=>
{
.
catch
(()
=>
{
message
.
error
(
`Failed to update theme`
);
message
.
error
(
'
Failed to update theme
'
);
hideMessage
();
hideMessage
();
});
});
},
200
);
}
}
};
};
const
updateColorWeak
=
colorWeak
=>
{
document
.
body
.
className
=
colorWeak
?
'
colorWeak
'
:
''
;
};
export
default
{
export
default
{
namespace
:
'
setting
'
,
namespace
:
'
setting
'
,
state
:
defaultSetting
,
state
:
defaultSetting
,
...
@@ -71,7 +71,10 @@ export default {
...
@@ -71,7 +71,10 @@ export default {
}
}
});
});
const
{
themeColor
,
colorWeak
}
=
setting
;
const
{
themeColor
,
colorWeak
}
=
setting
;
buildSettings
(
themeColor
,
colorWeak
);
if
(
state
.
themeColor
!==
themeColor
)
{
updateTheme
(
themeColor
);
}
updateColorWeak
(
colorWeak
);
return
{
return
{
...
state
,
...
state
,
...
setting
,
...
setting
,
...
@@ -97,7 +100,10 @@ export default {
...
@@ -97,7 +100,10 @@ export default {
}
}
});
});
const
{
themeColor
,
colorWeak
}
=
payload
;
const
{
themeColor
,
colorWeak
}
=
payload
;
buildSettings
(
themeColor
,
colorWeak
);
if
(
state
.
themeColor
!==
themeColor
)
{
updateTheme
(
themeColor
);
}
updateColorWeak
(
colorWeak
);
window
.
history
.
replaceState
(
null
,
'
setting
'
,
urlParams
.
href
);
window
.
history
.
replaceState
(
null
,
'
setting
'
,
urlParams
.
href
);
return
{
return
{
...
state
,
...
state
,
...
...
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