2020-10-24 19:21:41 +03:00
|
|
|
<template>
|
|
|
|
<a :href="to" :class="active ? activeClass : null" @click.prevent="nav" @contextmenu.prevent.stop="onContextmenu">
|
|
|
|
<slot></slot>
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
2021-11-11 19:02:25 +02:00
|
|
|
import * as os from '@/os';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
|
|
|
import { router } from '@/router';
|
|
|
|
import { url } from '@/config';
|
|
|
|
import { popout } from '@/scripts/popout';
|
|
|
|
import { ColdDeviceStorage } from '@/store';
|
2020-10-24 19:21:41 +03:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
inject: {
|
|
|
|
navHook: {
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
sideViewHook: {
|
|
|
|
default: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
to: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
activeClass: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
},
|
2020-10-27 06:53:47 +02:00
|
|
|
behavior: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
},
|
2020-10-24 19:21:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
active() {
|
|
|
|
if (this.activeClass == null) return false;
|
|
|
|
const resolved = router.resolve(this.to);
|
|
|
|
if (resolved.path == this.$route.path) return true;
|
|
|
|
if (resolved.name == null) return false;
|
|
|
|
if (this.$route.name == null) return false;
|
|
|
|
return resolved.name == this.$route.name;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
onContextmenu(e) {
|
|
|
|
if (window.getSelection().toString() !== '') return;
|
|
|
|
os.contextMenu([{
|
|
|
|
type: 'label',
|
|
|
|
text: this.to,
|
|
|
|
}, {
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-window-maximize',
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.openInWindow,
|
2020-10-24 19:21:41 +03:00
|
|
|
action: () => {
|
|
|
|
os.pageWindow(this.to);
|
|
|
|
}
|
2020-10-28 15:21:40 +02:00
|
|
|
}, this.sideViewHook ? {
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-columns',
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.openInSideView,
|
2020-10-24 19:21:41 +03:00
|
|
|
action: () => {
|
|
|
|
this.sideViewHook(this.to);
|
|
|
|
}
|
|
|
|
} : undefined, {
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-expand-alt',
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.showInPage,
|
2020-10-24 19:21:41 +03:00
|
|
|
action: () => {
|
|
|
|
this.$router.push(this.to);
|
|
|
|
}
|
|
|
|
}, null, {
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-external-link-alt',
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.openInNewTab,
|
2020-10-24 19:21:41 +03:00
|
|
|
action: () => {
|
|
|
|
window.open(this.to, '_blank');
|
|
|
|
}
|
|
|
|
}, {
|
2021-04-20 17:22:59 +03:00
|
|
|
icon: 'fas fa-link',
|
2020-12-26 03:47:36 +02:00
|
|
|
text: this.$ts.copyLink,
|
2020-10-24 19:21:41 +03:00
|
|
|
action: () => {
|
2020-10-30 11:22:14 +02:00
|
|
|
copyToClipboard(`${url}${this.to}`);
|
2020-10-24 19:21:41 +03:00
|
|
|
}
|
|
|
|
}], e);
|
|
|
|
},
|
|
|
|
|
2020-11-03 03:43:50 +02:00
|
|
|
window() {
|
|
|
|
os.pageWindow(this.to);
|
|
|
|
},
|
|
|
|
|
2021-04-11 15:09:35 +03:00
|
|
|
modalWindow() {
|
|
|
|
os.modalPageWindow(this.to);
|
|
|
|
},
|
|
|
|
|
2020-11-03 03:43:50 +02:00
|
|
|
popout() {
|
|
|
|
popout(this.to);
|
|
|
|
},
|
|
|
|
|
2020-10-24 19:21:41 +03:00
|
|
|
nav() {
|
2021-03-02 18:03:29 +02:00
|
|
|
if (this.behavior === 'browser') {
|
|
|
|
location.href = this.to;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-27 06:53:47 +02:00
|
|
|
if (this.behavior) {
|
|
|
|
if (this.behavior === 'window') {
|
2020-11-03 03:43:50 +02:00
|
|
|
return this.window();
|
2021-04-11 15:09:35 +03:00
|
|
|
} else if (this.behavior === 'modalWindow') {
|
|
|
|
return this.modalWindow();
|
2020-10-27 06:53:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 19:21:41 +03:00
|
|
|
if (this.navHook) {
|
|
|
|
this.navHook(this.to);
|
|
|
|
} else {
|
2020-12-19 03:55:52 +02:00
|
|
|
if (this.$store.state.defaultSideView && this.sideViewHook && this.to !== '/') {
|
2020-11-03 03:43:50 +02:00
|
|
|
return this.sideViewHook(this.to);
|
2020-10-24 19:21:41 +03:00
|
|
|
}
|
|
|
|
|
2020-11-07 05:30:16 +02:00
|
|
|
if (this.$router.currentRoute.value.path === this.to) {
|
|
|
|
window.scroll({ top: 0, behavior: 'smooth' });
|
|
|
|
} else {
|
|
|
|
this.$router.push(this.to);
|
|
|
|
}
|
2020-10-24 19:21:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|