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
99d3ed39
Commit
99d3ed39
authored
Apr 20, 2022
by
崔佳豪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: useTime
parent
bc78773b
Pipeline
#48272
skipped with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
useTime.js
src/pages/user/login/js/useTime.js
+30
-0
No files found.
src/pages/user/login/js/useTime.js
0 → 100644
View file @
99d3ed39
import
{
useEffect
,
useState
}
from
'react'
;
/**
* 自定义hook
* 登录页时间
* @returns {object} 返回时间信息,包含time、dayofweek、date
*/
const
useTime
=
()
=>
{
const
[
currentDate
,
setCurrentDate
]
=
useState
({});
useEffect
(()
=>
{
let
loginTimeInterval
=
null
;
if
(
loginTimeInterval
)
clearInterval
(
loginTimeInterval
),
(
loginTimeInterval
=
null
);
loginTimeInterval
=
setInterval
(()
=>
{
const
date
=
new
Date
();
const
weekday
=
[
'周日'
,
'周一'
,
'周二'
,
'周三'
,
'周四'
,
'周五'
,
'周六'
];
const
time
=
`
${
date
.
getHours
()
<
10
?
`0
${
date
.
getHours
()}
`
:
date
.
getHours
()}
:
${
date
.
getMinutes
()
<
10
?
`0
${
date
.
getMinutes
()}
`
:
date
.
getMinutes
()
}
:
${
date
.
getSeconds
()
<
10
?
`0
${
date
.
getSeconds
()}
`
:
date
.
getSeconds
()}
`
;
setCurrentDate
({
time
,
dayofweek
:
weekday
[
date
.
getDay
()],
date
:
date
.
pattern
(
'yyyy/MM/dd'
),
});
},
1000
);
return
()
=>
{
loginTimeInterval
&&
clearInterval
(
loginTimeInterval
);
};
},
[]);
return
currentDate
;
};
export
default
useTime
;
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