25 lines
646 B
JavaScript
25 lines
646 B
JavaScript
export default {
|
|
$colorUtils: {
|
|
Hex2RGBA(color, alpha = 1) {
|
|
let hex = 0;
|
|
if (color.charAt(0) == "#") {
|
|
if (color.length == 4) {
|
|
//检测诸如#FFF简写格式
|
|
color = "#" + color.charAt(1).repeat(2) +
|
|
color.charAt(2).repeat(2) +
|
|
color.charAt(3).repeat(2);
|
|
}
|
|
hex = parseInt(color.slice(1), 16);
|
|
}
|
|
let r = hex >> 16 & 0xFF;
|
|
let g = hex >> 8 & 0xFF;
|
|
let b = hex & 0xFF;
|
|
return `rgba(${r},${g},${b},${alpha})`;
|
|
},
|
|
RGBtoHex(r, g, b) {
|
|
let hex = r << 16 | g << 8 | b;
|
|
return "#" + hex.toString(16);
|
|
}
|
|
}
|
|
}
|