Files
admin-govern/src/utils/common.ts

66 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-12-21 16:42:39 +08:00
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
* 使: <Icon name="name" size="size" color="color" />
* <待完善>
*/
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)
}