28 lines
828 B
TypeScript
Raw Normal View History

import dayjs from "dayjs"
/** 格式化时间 */
export const formatDateTime = (time: string | number | Date) => {
2023-06-01 16:09:58 +08:00
return time ? dayjs(new Date(time)).format("YYYY-MM-DD HH:mm:ss") : "N/A"
}
2022-05-25 21:53:38 +08:00
2023-06-01 16:09:58 +08:00
/** 用 JS 获取全局 css 变量 */
2022-05-25 21:53:38 +08:00
export const getCssVariableValue = (cssVariableName: string) => {
let cssVariableValue = ""
try {
// 没有拿到值时,会返回空串
cssVariableValue = getComputedStyle(document.documentElement).getPropertyValue(cssVariableName)
} catch (error) {
console.error(error)
}
return cssVariableValue
}
2023-06-01 16:09:58 +08:00
/** 用 JS 设置全局 CSS 变量 */
export const setCssVariableValue = (cssVariableName: string, cssVariableValue: string) => {
try {
document.documentElement.style.setProperty(cssVariableName, cssVariableValue)
} catch (error) {
console.error(error)
}
}