forked from un-pany/v3-admin-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
34 lines (30 loc) · 1006 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import dayjs from "dayjs"
import { removeConfigLayout } from "@/utils/cache/local-storage"
/** 格式化时间 */
export const formatDateTime = (time: string | number | Date) => {
return time ? dayjs(new Date(time)).format("YYYY-MM-DD HH:mm:ss") : "N/A"
}
/** 用 JS 获取全局 css 变量 */
export const getCssVariableValue = (cssVariableName: string) => {
let cssVariableValue = ""
try {
// 没有拿到值时,会返回空串
cssVariableValue = getComputedStyle(document.documentElement).getPropertyValue(cssVariableName)
} catch (error) {
console.error(error)
}
return cssVariableValue
}
/** 用 JS 设置全局 CSS 变量 */
export const setCssVariableValue = (cssVariableName: string, cssVariableValue: string) => {
try {
document.documentElement.style.setProperty(cssVariableName, cssVariableValue)
} catch (error) {
console.error(error)
}
}
/** 重置项目配置 */
export const resetConfigLayout = () => {
removeConfigLayout()
location.reload()
}