import type { App } from 'vue' import { adminBaseRoutePath } from '@/router/static' import router from '@/router/index' import { trimStart } from 'lodash-es' import * as elIcons from '@element-plus/icons-vue' import Icon from '@/components/icon/index.vue' export function registerIcons(app: App) { /* * 全局注册 Icon * 使用方式: * 详见<待完善> */ app.component('Icon', Icon) /* * 全局注册element Plus的icon */ const icons = elIcons as any for (const i in icons) { app.component(`el-icon-${icons[i].name}`, icons[i]) } } /** * 是否在后台应用内 * @param path 不传递则通过当前路由 path 检查 */ export const isAdminApp = (path = '') => { const regex = new RegExp(`^${adminBaseRoutePath}`) if (path) { return regex.test(path) } if (regex.test(getCurrentRoutePath())) { return true } return false } /** * 获取路由 path */ export const getCurrentRoutePath = () => { let path = router.currentRoute.value.path if (path == '/') path = trimStart(window.location.hash, '#') if (path.indexOf('?') !== -1) path = path.replace(/\?.*/, '') return path } /** * 获取资源完整地址 * @param relativeUrl 资源相对地址 * @param domain 指定域名 */ export const fullUrl = (relativeUrl: string, domain = '') => { return domain + relativeUrl } /** * 是否是外部链接 * @param path */ export function isExternal(path: string): boolean { return /^(https?|ftp|mailto|tel):/.test(path) }