1
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
type RGBA = { r : number, g : number, b : number, a : number }
|
||||
export function hexToRgb(sColors : string) : RGBA | null {
|
||||
if (sColors == "") {
|
||||
return null
|
||||
}
|
||||
let reg = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{8})$/;
|
||||
let sColor : string = sColors.toLowerCase();
|
||||
|
||||
if (sColor != '' && reg.test(sColor)) {
|
||||
if (sColor.length == 4) {
|
||||
let sColorNew = "#";
|
||||
for (let i = 1; i < 4; i += 1) {
|
||||
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
|
||||
}
|
||||
sColor = sColorNew;
|
||||
}
|
||||
|
||||
//处理六位的颜色值
|
||||
let sColorChange : number[] = [];
|
||||
sColorChange.push(parseInt(sColor.substring(1, 3), 16));
|
||||
sColorChange.push(parseInt(sColor.substring(3, 5), 16));
|
||||
sColorChange.push(parseInt(sColor.substring(5, 7), 16));
|
||||
if (sColor.length == 9) {
|
||||
sColorChange.push(parseInt(sColor.substring(7, 9), 16) / 255);
|
||||
}
|
||||
return {
|
||||
r: sColorChange[0],
|
||||
g: sColorChange[1],
|
||||
b: sColorChange[2],
|
||||
a: sColorChange.length == 4 ? sColorChange[3] : 1
|
||||
} as RGBA
|
||||
} else if (/^(rgb|RGB|rgba|RGBA)/.test(sColor)) {
|
||||
let arr : string[] = sColor.replace(/(?:\(|\)|rgba|rgb|RGB|RGBA)*/g, "").split(",")
|
||||
let p : number[] = arr.map((val : string) : number => parseInt(val));
|
||||
|
||||
if (p.length < 3) {
|
||||
return {
|
||||
r: 0,
|
||||
g: 0,
|
||||
b: 0,
|
||||
a: 1
|
||||
} as RGBA
|
||||
}
|
||||
if (p.length == 3) {
|
||||
p.add(1)
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
r: p[0],
|
||||
g: p[1],
|
||||
b: p[2],
|
||||
a: arr.length==3?p[3]:parseFloat(arr[3])
|
||||
} as RGBA
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { XTIPS_TYPE, XTIPS_TYPE_PRIVATE } from "../interface.uts"
|
||||
export const defaultConfig = {
|
||||
iconColor: 'rgb(5,121,255)',
|
||||
contentBgColor: 'rgba(255,255,255,1)',
|
||||
maskBgColor: 'rgba(0,0,0,0)',
|
||||
iconSize: 20,
|
||||
iconCode: 'F449',
|
||||
title: '',
|
||||
titleSize: 16,
|
||||
titleColor: 'rgb(5,121,255)',
|
||||
duration: 2000,
|
||||
size: 130,
|
||||
close: () => { },
|
||||
|
||||
maskDisableClik: false,
|
||||
position:'top',
|
||||
offset:50
|
||||
|
||||
} as XTIPS_TYPE_PRIVATE
|
||||
|
||||
export const defaultStatusIcon = new Map<string, string>([
|
||||
['warn', 'ECA1'],
|
||||
['error', 'EB97'],
|
||||
['success', 'EB79'],
|
||||
['info', 'F449'],
|
||||
])
|
||||
|
||||
export function configCover(opts : XTIPS_TYPE) : XTIPS_TYPE_PRIVATE {
|
||||
let iconColor = opts.iconColor != null ? (opts.iconColor!) : defaultConfig.iconColor;
|
||||
let contentBgColor = opts.contentBgColor != null ? (opts.contentBgColor!) : defaultConfig.contentBgColor;
|
||||
let maskBgColor = opts.maskBgColor != null ? (opts.maskBgColor!) : defaultConfig.maskBgColor;
|
||||
let iconSize = opts.iconSize != null ? (opts.iconSize!) : defaultConfig.iconSize;
|
||||
let iconCode : string = opts.iconCode != null ? (opts.iconCode!) : defaultConfig.iconCode;
|
||||
if (defaultStatusIcon.has(iconCode)) {
|
||||
iconCode = defaultStatusIcon.get(iconCode)!
|
||||
}
|
||||
let title = opts.title != null ? (opts.title!) : defaultConfig.title;
|
||||
let titleSize = opts.titleSize != null ? (opts.titleSize!) : defaultConfig.titleSize;
|
||||
let titleColor = opts.titleColor != null ? (opts.titleColor!) : defaultConfig.titleColor;
|
||||
let duration = opts.duration != null ? (opts.duration!) : defaultConfig.duration;
|
||||
let close = opts.close != null ? (opts.close!) : defaultConfig.close;
|
||||
let size = opts.size != null ? (opts.size!) : defaultConfig.size;
|
||||
let position = opts.position != null ? (opts.position!) : defaultConfig.position;
|
||||
let offset = opts.offset != null ? (opts.offset!) : defaultConfig.offset;
|
||||
let maskDisableClik = false;
|
||||
|
||||
// #ifdef APP-ANDROID || APP-HARMONY
|
||||
maskDisableClik = opts.maskDisableClik == null ? defaultConfig.maskDisableClik : (opts.maskDisableClik!);
|
||||
// #endif
|
||||
// #ifdef WEB
|
||||
maskDisableClik = opts.maskDisableClik == null ? (defaultConfig.maskDisableClik) : (opts.maskDisableClik);
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-IOS
|
||||
maskDisableClik = opts.maskDisableClik == null ? (!defaultConfig.maskDisableClik) : (!opts.maskDisableClik);
|
||||
// #endif
|
||||
|
||||
return {
|
||||
iconColor,
|
||||
contentBgColor,
|
||||
maskBgColor,
|
||||
iconSize,
|
||||
iconCode, title, titleSize, titleColor, duration, close, size, maskDisableClik,position,offset
|
||||
} as XTIPS_TYPE_PRIVATE
|
||||
}
|
||||
Reference in New Issue
Block a user