2020-10-24 16:21:41 +00: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';
|
|
|
|
import { faExpandAlt, faColumns, faExternalLinkAlt, faLink, faWindowMaximize } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
|
|
|
import { router } from '@/router';
|
2020-12-27 09:13:50 +00:00
|
|
|
import { url } from '@/config';
|
2020-11-03 01:43:50 +00:00
|
|
|
import { popout } from '@/scripts/popout';
|
2020-12-19 01:55:52 +00:00
|
|
|
import { ColdDeviceStorage } from '@/store';
|
2020-10-24 16:21:41 +00: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 04:53:47 +00:00
|
|
|
behavior: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
},
|
2020-10-24 16:21:41 +00: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,
|
|
|
|
}, {
|
|
|
|
icon: faWindowMaximize,
|
2020-12-26 01:47:36 +00:00
|
|
|
text: this.$ts.openInWindow,
|
2020-10-24 16:21:41 +00:00
|
|
|
action: () => {
|
|
|
|
os.pageWindow(this.to);
|
|
|
|
}
|
2020-10-28 13:21:40 +00:00
|
|
|
}, this.sideViewHook ? {
|
2020-10-24 16:21:41 +00:00
|
|
|
icon: faColumns,
|
2020-12-26 01:47:36 +00:00
|
|
|
text: this.$ts.openInSideView,
|
2020-10-24 16:21:41 +00:00
|
|
|
action: () => {
|
|
|
|
this.sideViewHook(this.to);
|
|
|
|
}
|
|
|
|
} : undefined, {
|
|
|
|
icon: faExpandAlt,
|
2020-12-26 01:47:36 +00:00
|
|
|
text: this.$ts.showInPage,
|
2020-10-24 16:21:41 +00:00
|
|
|
action: () => {
|
|
|
|
this.$router.push(this.to);
|
|
|
|
}
|
|
|
|
}, null, {
|
|
|
|
icon: faExternalLinkAlt,
|
2020-12-26 01:47:36 +00:00
|
|
|
text: this.$ts.openInNewTab,
|
2020-10-24 16:21:41 +00:00
|
|
|
action: () => {
|
|
|
|
window.open(this.to, '_blank');
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
icon: faLink,
|
2020-12-26 01:47:36 +00:00
|
|
|
text: this.$ts.copyLink,
|
2020-10-24 16:21:41 +00:00
|
|
|
action: () => {
|
2020-10-30 09:22:14 +00:00
|
|
|
copyToClipboard(`${url}${this.to}`);
|
2020-10-24 16:21:41 +00:00
|
|
|
}
|
|
|
|
}], e);
|
|
|
|
},
|
|
|
|
|
2020-11-03 01:43:50 +00:00
|
|
|
window() {
|
|
|
|
os.pageWindow(this.to);
|
|
|
|
},
|
|
|
|
|
|
|
|
popout() {
|
|
|
|
popout(this.to);
|
|
|
|
},
|
|
|
|
|
2020-10-24 16:21:41 +00:00
|
|
|
nav() {
|
2020-11-03 01:43:50 +00:00
|
|
|
if (this.to.startsWith('/my/messaging')) {
|
2020-12-19 01:55:52 +00:00
|
|
|
if (ColdDeviceStorage.get('chatOpenBehavior') === 'window') return this.window();
|
|
|
|
if (ColdDeviceStorage.get('chatOpenBehavior') === 'popout') return this.popout();
|
2020-11-03 01:43:50 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 04:53:47 +00:00
|
|
|
if (this.behavior) {
|
|
|
|
if (this.behavior === 'window') {
|
2020-11-03 01:43:50 +00:00
|
|
|
return this.window();
|
2020-10-27 04:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 16:21:41 +00:00
|
|
|
if (this.navHook) {
|
|
|
|
this.navHook(this.to);
|
|
|
|
} else {
|
2020-12-19 01:55:52 +00:00
|
|
|
if (this.$store.state.defaultSideView && this.sideViewHook && this.to !== '/') {
|
2020-11-03 01:43:50 +00:00
|
|
|
return this.sideViewHook(this.to);
|
2020-10-24 16:21:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:30:16 +00:00
|
|
|
if (this.$router.currentRoute.value.path === this.to) {
|
|
|
|
window.scroll({ top: 0, behavior: 'smooth' });
|
|
|
|
} else {
|
|
|
|
this.$router.push(this.to);
|
|
|
|
}
|
2020-10-24 16:21:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|