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
15c8853a
Commit
15c8853a
authored
Jul 15, 2018
by
ιεΈ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimization: Robust code
parent
b0be02b1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
30 deletions
+58
-30
config/config.js
config/config.js
+12
-3
src/components/ActiveChart/index.js
src/components/ActiveChart/index.js
+2
-1
src/components/Charts/Pie/index.js
src/components/Charts/Pie/index.js
+2
-1
src/components/Charts/TagCloud/index.js
src/components/Charts/TagCloud/index.js
+2
-1
src/components/SettingDarwer/index.js
src/components/SettingDarwer/index.js
+4
-4
src/models/setting.js
src/models/setting.js
+1
-1
src/pages/layouts/BasicLayout.js
src/pages/layouts/BasicLayout.js
+25
-16
src/pages/layouts/LoadingPage.js
src/pages/layouts/LoadingPage.js
+10
-3
No files found.
config/config.js
View file @
15c8853a
...
@@ -165,12 +165,18 @@ export default {
...
@@ -165,12 +165,18 @@ export default {
component
:
'
./Account/Center/Center
'
,
component
:
'
./Account/Center/Center
'
,
routes
:
[
routes
:
[
{
path
:
'
/account/center
'
,
redirect
:
'
/account/center/articles
'
},
{
path
:
'
/account/center
'
,
redirect
:
'
/account/center/articles
'
},
{
path
:
'
/account/center/articles
'
,
component
:
'
./Account/Center/Articles
'
},
{
path
:
'
/account/center/articles
'
,
component
:
'
./Account/Center/Articles
'
,
},
{
{
path
:
'
/account/center/applications
'
,
path
:
'
/account/center/applications
'
,
component
:
'
./Account/Center/Applications
'
,
component
:
'
./Account/Center/Applications
'
,
},
},
{
path
:
'
/account/center/projects
'
,
component
:
'
./Account/Center/Projects
'
},
{
path
:
'
/account/center/projects
'
,
component
:
'
./Account/Center/Projects
'
,
},
],
],
},
},
{
{
...
@@ -179,7 +185,10 @@ export default {
...
@@ -179,7 +185,10 @@ export default {
component
:
'
./Account/Settings/Info
'
,
component
:
'
./Account/Settings/Info
'
,
routes
:
[
routes
:
[
{
path
:
'
/account/settings
'
,
redirect
:
'
/account/settings/base
'
},
{
path
:
'
/account/settings
'
,
redirect
:
'
/account/settings/base
'
},
{
path
:
'
/account/settings/base
'
,
component
:
'
./Account/Settings/BaseView
'
},
{
path
:
'
/account/settings/base
'
,
component
:
'
./Account/Settings/BaseView
'
,
},
{
{
path
:
'
/account/settings/security
'
,
path
:
'
/account/settings/security
'
,
component
:
'
./Account/Settings/SecurityView
'
,
component
:
'
./Account/Settings/SecurityView
'
,
...
...
src/components/ActiveChart/index.js
View file @
15c8853a
...
@@ -30,10 +30,11 @@ export default class ActiveChart extends Component {
...
@@ -30,10 +30,11 @@ export default class ActiveChart extends Component {
componentWillUnmount
()
{
componentWillUnmount
()
{
clearTimeout
(
this
.
timer
);
clearTimeout
(
this
.
timer
);
cancelAnimationFrame
(
this
.
requestRef
);
}
}
loopData
=
()
=>
{
loopData
=
()
=>
{
requestAnimationFrame
(()
=>
{
this
.
requestRef
=
requestAnimationFrame
(()
=>
{
this
.
timer
=
setTimeout
(()
=>
{
this
.
timer
=
setTimeout
(()
=>
{
this
.
setState
(
this
.
setState
(
{
{
...
...
src/components/Charts/Pie/index.js
View file @
15c8853a
...
@@ -22,7 +22,7 @@ export default class Pie extends Component {
...
@@ -22,7 +22,7 @@ export default class Pie extends Component {
window
.
addEventListener
(
window
.
addEventListener
(
'
resize
'
,
'
resize
'
,
()
=>
{
()
=>
{
requestAnimationFrame
(()
=>
this
.
resize
());
this
.
requestRef
=
requestAnimationFrame
(()
=>
this
.
resize
());
},
},
{
passive
:
true
}
{
passive
:
true
}
);
);
...
@@ -38,6 +38,7 @@ export default class Pie extends Component {
...
@@ -38,6 +38,7 @@ export default class Pie extends Component {
}
}
componentWillUnmount
()
{
componentWillUnmount
()
{
window
.
cancelAnimationFrame
(
this
.
requestRef
);
window
.
removeEventListener
(
'
resize
'
,
this
.
resize
);
window
.
removeEventListener
(
'
resize
'
,
this
.
resize
);
this
.
resize
.
cancel
();
this
.
resize
.
cancel
();
}
}
...
...
src/components/Charts/TagCloud/index.js
View file @
15c8853a
...
@@ -35,11 +35,12 @@ class TagCloud extends Component {
...
@@ -35,11 +35,12 @@ class TagCloud extends Component {
componentWillUnmount
()
{
componentWillUnmount
()
{
this
.
isUnmount
=
true
;
this
.
isUnmount
=
true
;
window
.
cancelAnimationFrame
(
this
.
requestRef
);
window
.
removeEventListener
(
'
resize
'
,
this
.
resize
);
window
.
removeEventListener
(
'
resize
'
,
this
.
resize
);
}
}
resize
=
()
=>
{
resize
=
()
=>
{
requestAnimationFrame
(()
=>
{
this
.
requestRef
=
requestAnimationFrame
(()
=>
{
this
.
renderChart
();
this
.
renderChart
();
});
});
};
};
...
...
src/components/SettingDarwer/index.js
View file @
15c8853a
...
@@ -24,7 +24,8 @@ class SettingDarwer extends PureComponent {
...
@@ -24,7 +24,8 @@ class SettingDarwer extends PureComponent {
const
{
const
{
setting
:
{
themeColor
,
colorWeak
},
setting
:
{
themeColor
,
colorWeak
},
}
=
this
.
props
;
}
=
this
.
props
;
if
(
themeColor
!==
'
#1890FF
'
)
{
// Determine if the component is remounted
if
(
themeColor
!==
'
#1890FF
'
&&
themeColor
!==
window
[
'
antd_pro_less_color
'
])
{
window
.
less
.
refresh
().
then
(()
=>
{
window
.
less
.
refresh
().
then
(()
=>
{
this
.
colorChange
(
themeColor
);
this
.
colorChange
(
themeColor
);
});
});
...
@@ -32,9 +33,6 @@ class SettingDarwer extends PureComponent {
...
@@ -32,9 +33,6 @@ class SettingDarwer extends PureComponent {
if
(
colorWeak
===
'
open
'
)
{
if
(
colorWeak
===
'
open
'
)
{
document
.
body
.
className
=
'
colorWeak
'
;
document
.
body
.
className
=
'
colorWeak
'
;
}
}
requestAnimationFrame
(()
=>
{
this
.
togglerContent
();
});
}
}
getLayOutSetting
=
()
=>
{
getLayOutSetting
=
()
=>
{
...
@@ -139,6 +137,7 @@ class SettingDarwer extends PureComponent {
...
@@ -139,6 +137,7 @@ class SettingDarwer extends PureComponent {
'
@input-hover-border-color
'
:
color
,
'
@input-hover-border-color
'
:
color
,
})
})
.
then
(()
=>
{
.
then
(()
=>
{
window
[
'
antd_pro_less_color
'
]
=
color
;
hideMessage
();
hideMessage
();
})
})
.
catch
(()
=>
{
.
catch
(()
=>
{
...
@@ -152,6 +151,7 @@ class SettingDarwer extends PureComponent {
...
@@ -152,6 +151,7 @@ class SettingDarwer extends PureComponent {
const
{
collapse
,
silderTheme
,
themeColor
,
layout
,
colorWeak
}
=
setting
;
const
{
collapse
,
silderTheme
,
themeColor
,
layout
,
colorWeak
}
=
setting
;
return
(
return
(
<
Drawer
<
Drawer
firstEnter
=
{
true
}
visible
=
{
collapse
}
visible
=
{
collapse
}
width
=
{
273
}
width
=
{
273
}
onClose
=
{
this
.
togglerContent
}
onClose
=
{
this
.
togglerContent
}
...
...
src/models/setting.js
View file @
15c8853a
const
defaultSetting
=
{
const
defaultSetting
=
{
collapse
:
tru
e
,
collapse
:
fals
e
,
silderTheme
:
'
dark
'
,
silderTheme
:
'
dark
'
,
themeColor
:
'
#1890FF
'
,
themeColor
:
'
#1890FF
'
,
layout
:
'
sidemenu
'
,
layout
:
'
sidemenu
'
,
...
...
src/pages/layouts/BasicLayout.js
View file @
15c8853a
...
@@ -63,13 +63,15 @@ const query = {
...
@@ -63,13 +63,15 @@ const query = {
};
};
class
BasicLayout
extends
React
.
PureComponent
{
class
BasicLayout
extends
React
.
PureComponent
{
state
=
{
rendering
:
true
,
};
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
const
{
menuData
}
=
this
.
props
;
const
{
menuData
}
=
this
.
props
;
this
.
getPageTitle
=
memoizeOne
(
this
.
getPageTitle
);
this
.
getPageTitle
=
memoizeOne
(
this
.
getPageTitle
);
this
.
breadcrumbNameMap
=
getBreadcrumbNameMap
(
menuData
);
this
.
breadcrumbNameMap
=
getBreadcrumbNameMap
(
menuData
);
}
}
getContext
()
{
getContext
()
{
const
{
location
}
=
this
.
props
;
const
{
location
}
=
this
.
props
;
return
{
return
{
...
@@ -77,7 +79,6 @@ class BasicLayout extends React.PureComponent {
...
@@ -77,7 +79,6 @@ class BasicLayout extends React.PureComponent {
breadcrumbNameMap
:
this
.
breadcrumbNameMap
,
breadcrumbNameMap
:
this
.
breadcrumbNameMap
,
};
};
}
}
getPageTitle
=
pathname
=>
{
getPageTitle
=
pathname
=>
{
let
currRouterData
=
null
;
let
currRouterData
=
null
;
// match params path
// match params path
...
@@ -142,7 +143,16 @@ class BasicLayout extends React.PureComponent {
...
@@ -142,7 +143,16 @@ class BasicLayout extends React.PureComponent {
payload
:
collapsed
,
payload
:
collapsed
,
});
});
};
};
componentDidMount
()
{
this
.
renderRef
=
requestAnimationFrame
(()
=>
{
this
.
setState
({
rendering
:
false
,
});
});
}
componentWillUnmount
()
{
cancelAnimationFrame
(
this
.
renderRef
);
}
render
()
{
render
()
{
const
{
const
{
isMobile
,
isMobile
,
...
@@ -170,20 +180,19 @@ class BasicLayout extends React.PureComponent {
...
@@ -170,20 +180,19 @@ class BasicLayout extends React.PureComponent {
<
/Layout
>
<
/Layout
>
<
/Layout
>
<
/Layout
>
);
);
return
(
return
(
<
DocumentTitle
title
=
{
this
.
getPageTitle
(
pathname
)}
>
<
React
.
Fragment
>
<
ContainerQuery
query
=
{
query
}
>
<
DocumentTitle
title
=
{
this
.
getPageTitle
(
pathname
)
}
>
{
params
=>
(
<
ContainerQuery
query
=
{
query
}
>
<
Context
.
Provider
value
=
{
this
.
getContext
()}
>
{
params
=>
(
<
div
className
=
{
classNames
(
params
)}
>
<
Context
.
Provider
value
=
{
this
.
getContext
(
)}
>
{
layout
}
<
div
className
=
{
classNames
(
params
)}
>
{
layout
}
<
/div
>
<
SettingDarwer
/
>
<
/Context.Provider
>
<
/div
>
)}
<
/Context.Provider
>
<
/ContainerQuery
>
)}
<
/DocumentTitle
>
<
/ContainerQuery
>
{
this
.
state
.
rendering
?
null
:
<
SettingDarwer
/>
}
<
/
DocumentTitle
>
<
/
React.Fragment
>
);
);
}
}
}
}
...
...
src/pages/layouts/LoadingPage.js
View file @
15c8853a
...
@@ -10,14 +10,21 @@ const menuData = config['routes'];
...
@@ -10,14 +10,21 @@ const menuData = config['routes'];
// Conversion router to menu.
// Conversion router to menu.
function
formatter
(
data
,
parentPath
=
''
,
parentAuthority
,
parentName
)
{
function
formatter
(
data
,
parentPath
=
''
,
parentAuthority
,
parentName
)
{
return
data
.
map
(
item
=>
{
return
data
.
map
(
item
=>
{
const
id
=
parentName
?
`
${
parentName
}
.
${
item
.
name
}
`
:
`menu.
${
item
.
name
}
`
;
let
locale
=
'
menu
'
;
if
(
parentName
&&
item
.
name
)
{
locale
=
`
${
parentName
}
.
${
item
.
name
}
`
;
}
else
if
(
item
.
name
)
{
locale
=
`menu.
${
item
.
name
}
`
;
}
else
if
(
parentName
)
{
locale
=
parentName
;
}
const
result
=
{
const
result
=
{
...
item
,
...
item
,
locale
:
id
,
locale
,
authority
:
item
.
authority
||
parentAuthority
,
authority
:
item
.
authority
||
parentAuthority
,
};
};
if
(
item
.
routes
)
{
if
(
item
.
routes
)
{
const
children
=
formatter
(
item
.
routes
,
`
${
parentPath
}${
item
.
path
}
/`
,
item
.
authority
,
id
);
const
children
=
formatter
(
item
.
routes
,
`
${
parentPath
}${
item
.
path
}
/`
,
item
.
authority
,
locale
);
// Reduce memory usage
// Reduce memory usage
result
.
children
=
children
;
result
.
children
=
children
;
}
}
...
...
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