common.tsx 1.15 KB
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)"