perf: 代码优化 utils/index
This commit is contained in:
parent
dc117459ad
commit
8520fd3df2
@ -2,14 +2,10 @@ import dayjs from "dayjs"
|
|||||||
|
|
||||||
/** 格式化时间 */
|
/** 格式化时间 */
|
||||||
export const formatDateTime = (time: string | number | Date) => {
|
export const formatDateTime = (time: string | number | Date) => {
|
||||||
if (!time) {
|
return time ? dayjs(new Date(time)).format("YYYY-MM-DD HH:mm:ss") : "N/A"
|
||||||
return "N/A"
|
|
||||||
}
|
|
||||||
const date = new Date(time)
|
|
||||||
return dayjs(date).format("YYYY-MM-DD HH:mm:ss")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 将全局 CSS 变量导入 JS 中使用 */
|
/** 用 JS 获取全局 css 变量 */
|
||||||
export const getCssVariableValue = (cssVariableName: string) => {
|
export const getCssVariableValue = (cssVariableName: string) => {
|
||||||
let cssVariableValue = ""
|
let cssVariableValue = ""
|
||||||
try {
|
try {
|
||||||
@ -20,3 +16,12 @@ export const getCssVariableValue = (cssVariableName: string) => {
|
|||||||
}
|
}
|
||||||
return cssVariableValue
|
return cssVariableValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 用 JS 设置全局 CSS 变量 */
|
||||||
|
export const setCssVariableValue = (cssVariableName: string, cssVariableValue: string) => {
|
||||||
|
try {
|
||||||
|
document.documentElement.style.setProperty(cssVariableName, cssVariableValue)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user