// 将rgb颜色转成hex export const RGBToHex = (color = '') => { const rgb = color.split(','); const r = parseInt(rgb[0].split('(')[1]); const g = parseInt(rgb[1]); const b = parseInt(rgb[2].split(')')[0]); const hex = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); return hex; }; // 将hex颜色转成rgb export const HexToRGBA = (hex = '', opacity) => { const red = parseInt(`0x${hex.slice(1, 3)}`); const green = parseInt(`0x${hex.slice(3, 5)}`); const blue = parseInt(`0x${hex.slice(5, 7)}`); const RGBA = `rgba(${red},${green},${blue},${opacity})`; return { red, green, blue, rgba: RGBA }; };