init
This commit is contained in:
32
utils/util.js
Normal file
32
utils/util.js
Normal file
@@ -0,0 +1,32 @@
|
||||
function formatDateTime(date) {
|
||||
const year = date.getFullYear()
|
||||
const month = date.getMonth() + 1
|
||||
const day = date.getDate()
|
||||
const hour = date.getHours()
|
||||
const minute = date.getMinutes()
|
||||
const second = date.getSeconds()
|
||||
|
||||
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
|
||||
}
|
||||
|
||||
function formatNumber(n) {
|
||||
n = n.toString()
|
||||
return n[1] ? n : `0${n}`
|
||||
}
|
||||
|
||||
function maskToken(token) {
|
||||
if (!token) {
|
||||
return '未登录'
|
||||
}
|
||||
|
||||
if (token.length <= 10) {
|
||||
return token
|
||||
}
|
||||
|
||||
return `${token.slice(0, 4)}...${token.slice(-4)}`
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatDateTime,
|
||||
maskToken
|
||||
}
|
||||
Reference in New Issue
Block a user