2026-05-09 10:34:51 +08:00

27 lines
837 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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,
}