zhangxiao
2024-08-21 523e69a7f649b513aa8d3788c79d52fc26c894d2
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
export default {
    /**
     * 获取主要色
     * @returns
     */
    getPrimary(): string {
        const rootStyles = getComputedStyle(document.body);
        return rootStyles.getPropertyValue("--primary-6").trim();
    },
    /**
     * 获取主要色
     * @returns
     */
    getCustom(key: string): string {
        const rootStyles = getComputedStyle(document.body);
        return rootStyles.getPropertyValue(key).trim();
    },
    /**
     * 自定义变量
     * @param data
     */
    setCustom(data: Record<string, string>): void {
        for (const key in data) {
            document.documentElement.style.setProperty(key, data[key]);
        }
    },
    /**
     * 设置主要色
     * @param color
     */
    setPrimary(color: string): void {
        document.documentElement.style.setProperty("--primary-6", color);
    }
};