const layers = { 'toast': 4000, 'modal': 3000, 'dropdown': 2000, 'mask': 1000, 'fixed-layer': 500, 'profile': 101, 'default': 1, 'below': -1, 'bottomless-pit': -10000, 'coupon-hover': 20, 'coupon-getbtn': 30, 'bottom-tab':102, } /** * z-index统一管理 * @param layer [description] * @return [description] */ export function zIndex(layer: keyof typeof layers){ return layers[layer] } /** * px to rem,10rem = 750px * @param px * @param width=750 H5宽度 * @return [description] */ export function rem(px: number, visualWidth=750){ return `${(px/visualWidth*10).toFixed(4)}rem` } /** * @param rem * @return number */ export function remToRealPx(rem: number){ const fontSize = parseFloat(document.documentElement.style.fontSize) || 0; return rem * fontSize; } /** * px to rem,10rem = 750px * @param px * @param width=750 H5宽度 * @return [description] */ export function getRemWithoutUnit(px, visualWidth=750){ return `${(px/visualWidth*10).toFixed(4)}` } /** * 将hex转化为rgb色值 * @param hex 想要被转化的hex颜色格式 支持#ffffff及简写#fff * @returns [r,g,b]三个色值的数值数组 */ export function hexToRgb(hex: string) { const reg = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; if (!reg.test(hex)) { return null; } return hex.replace(reg ,(m, r, g, b) => '#' + r + r + g + g + b + b) .substring(1).match(/.{2}/g) .map(x => parseInt(x, 16)) }