common.tsx
1.15 KB
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
35
36
37
export function setFavicon (logoPath: string) {
const link = document.createElement('link');
link.rel = 'icon';
link.href = logoPath;
document.head.appendChild(link);
}
// deepSeek版本 base 基础版本(红色模版, 红色机器人 不带联通logo)
export const currentV = () => {
return 'base';
};
// 十六进制颜色 转换成 rgba
export const hexToRgba = (hex: string | null | undefined, alpha: any) => {
let r: string | number = 0, g: string | number = 0, b: string | number = 0;
// 3 digits
if (hex?.length == 4) {
r = "0x" + hex?.[1] + hex?.[1];
g = "0x" + hex?.[2] + hex?.[2];
b = "0x" + hex?.[3] + hex?.[3];
// 6 digits
} else if (hex?.length == 7) {
r = "0x" + hex?.[1] + hex?.[2];
g = "0x" + hex?.[3] + hex?.[4];
b = "0x" + hex?.[5] + hex?.[6];
}
return "rgba(" + +r + "," + +g + "," + +b + "," + alpha + ")";
}
// // 使用示例
// const hexColor = "#ff5733"; // 16进制颜色
// const opacity = 0.5; // 透明度(0.0 到 1.0)
// const rgbaColor = hexToRgba(hexColor, opacity);
// console.log(rgbaColor); // 输出: "rgba(255, 87, 51, 0.5)"