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