2020-10-24 18:21:41 +02:00
|
|
|
<template>
|
|
|
|
<a :href="to" :class="active ? activeClass : null" @click.prevent="nav" @contextmenu.prevent.stop="onContextmenu">
|
|
|
|
<slot></slot>
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { inject } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
|
|
|
import { router } from '@/router';
|
|
|
|
import { url } from '@/config';
|
2022-01-15 23:47:28 +01:00
|
|
|
import { popout as popout_ } from '@/scripts/popout';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { defaultStore } from '@/store';
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
to: string;
|
|
|
|
activeClass?: null | string;
|
|
|
|
behavior?: null | 'window' | 'browser' | 'modalWindow';
|
|
|
|
}>(), {
|
|
|
|
activeClass: null,
|
|
|
|
behavior: null,
|
|
|
|
});
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
const navHook = inject('navHook', null);
|
|
|
|
const sideViewHook = inject('sideViewHook', null);
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
const active = $computed(() => {
|
|
|
|
if (props.activeClass == null) return false;
|
|
|
|
const resolved = router.resolve(props.to);
|
|
|
|
if (resolved.path === router.currentRoute.value.path) return true;
|
|
|
|
if (resolved.name == null) return false;
|
|
|
|
if (router.currentRoute.value.name == null) return false;
|
|
|
|
return resolved.name === router.currentRoute.value.name;
|
|
|
|
});
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
function onContextmenu(ev) {
|
|
|
|
if (window.getSelection().toString() !== '') return;
|
|
|
|
os.contextMenu([{
|
|
|
|
type: 'label',
|
|
|
|
text: props.to,
|
|
|
|
}, {
|
|
|
|
icon: 'fas fa-window-maximize',
|
|
|
|
text: i18n.locale.openInWindow,
|
|
|
|
action: () => {
|
|
|
|
os.pageWindow(props.to);
|
|
|
|
}
|
|
|
|
}, sideViewHook ? {
|
|
|
|
icon: 'fas fa-columns',
|
|
|
|
text: i18n.locale.openInSideView,
|
|
|
|
action: () => {
|
|
|
|
sideViewHook(props.to);
|
|
|
|
}
|
|
|
|
} : undefined, {
|
|
|
|
icon: 'fas fa-expand-alt',
|
|
|
|
text: i18n.locale.showInPage,
|
|
|
|
action: () => {
|
|
|
|
router.push(props.to);
|
|
|
|
}
|
|
|
|
}, null, {
|
|
|
|
icon: 'fas fa-external-link-alt',
|
|
|
|
text: i18n.locale.openInNewTab,
|
|
|
|
action: () => {
|
|
|
|
window.open(props.to, '_blank');
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
icon: 'fas fa-link',
|
|
|
|
text: i18n.locale.copyLink,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(`${url}${props.to}`);
|
|
|
|
}
|
|
|
|
}], ev);
|
|
|
|
}
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
function window() {
|
|
|
|
os.pageWindow(props.to);
|
|
|
|
}
|
2020-11-03 02:43:50 +01:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
function modalWindow() {
|
|
|
|
os.modalPageWindow(props.to);
|
|
|
|
}
|
2021-04-11 14:09:35 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
function popout() {
|
|
|
|
popout_(props.to);
|
|
|
|
}
|
2020-11-03 02:43:50 +01:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
function nav() {
|
|
|
|
if (props.behavior === 'browser') {
|
|
|
|
location.href = props.to;
|
|
|
|
return;
|
|
|
|
}
|
2021-03-02 17:03:29 +01:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
if (props.behavior) {
|
|
|
|
if (props.behavior === 'window') {
|
|
|
|
return window();
|
|
|
|
} else if (props.behavior === 'modalWindow') {
|
|
|
|
return modalWindow();
|
|
|
|
}
|
|
|
|
}
|
2020-10-27 05:53:47 +01:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
if (navHook) {
|
|
|
|
navHook(props.to);
|
|
|
|
} else {
|
|
|
|
if (defaultStore.state.defaultSideView && sideViewHook && props.to !== '/') {
|
|
|
|
return sideViewHook(props.to);
|
|
|
|
}
|
2020-10-24 18:21:41 +02:00
|
|
|
|
2022-01-15 23:47:28 +01:00
|
|
|
if (router.currentRoute.value.path === props.to) {
|
|
|
|
window.scroll({ top: 0, behavior: 'smooth' });
|
|
|
|
} else {
|
|
|
|
router.push(props.to);
|
2020-10-24 18:21:41 +02:00
|
|
|
}
|
|
|
|
}
|
2022-01-15 23:47:28 +01:00
|
|
|
}
|
2020-10-24 18:21:41 +02:00
|
|
|
</script>
|