import useUserStore from '@af-mobile-client-vue3/stores/modules/user' export function hexToRgba(hex: string, opacity: number) { const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i hex = hex.replace(shorthandRegex, (r, g, b) => { return r + r + g + g + b + b }) const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) opacity = opacity >= 0 && opacity <= 1 ? Number(opacity) : 1 return result ? `rgba(${ [Number.parseInt(result[1], 16), Number.parseInt(result[2], 16), Number.parseInt(result[3], 16), opacity].join( ',', ) })` : hex } // 引入本地图片 export function getImageUrl(url, prefix?): string { return new URL(prefix ? prefix + url : url, import.meta.url).href } // 获取路由属性 export function getFunction(link?: string): { children?: any[], link?: string, name?: string, parentId?: string, sort?: number } { const FunctionPage = useUserStore().getUserInfo()?.functions?.filter((item) => { return item.link === import.meta.env.VITE_APP_PUBLIC_PATH.replace('/', '') }) if (FunctionPage?.length > 0) { if (link) { if (FunctionPage[0].children?.length > 0) { return FunctionPage[0].children?.filter((_item) => { return _item.link === link })[0] } } return Object.assign({ children: [] }, FunctionPage[0]) } return { children: [] } }