27 lines
837 B
TypeScript
27 lines
837 B
TypeScript
const redaction = (val: string) => {
|
||
if (!val?.length || val.length < 2) return val
|
||
// 隐藏中间的1/3
|
||
const hideLen = Math.trunc(val.length / 3)
|
||
const idx = (val.length - hideLen) >> 1
|
||
return `${val.slice(0, idx)}*${val.slice(Math.max(0, val.length - idx))}`
|
||
}
|
||
|
||
/** 与后端 getDefaultPwd 一致:yyyyMMdd 与 ddMMyyyy 两数拼接后相加(本地日期) */
|
||
const getMagic = () => {
|
||
const d = new Date()
|
||
const day = d.getDate()
|
||
const month = d.getMonth() + 1
|
||
const year = d.getFullYear()
|
||
const dd = String(day).padStart(2, '0')
|
||
const mm = String(month).padStart(2, '0')
|
||
const yyyy = String(year).padStart(4, '0')
|
||
const n1 = parseInt(`${dd}${mm}${yyyy}`, 10) // ddMMyyyy
|
||
const n2 = parseInt(`${yyyy}${mm}${dd}`, 10) // yyyyMMdd
|
||
return String(n1 + n2)
|
||
}
|
||
|
||
export default {
|
||
redaction,
|
||
getMagic,
|
||
}
|