Link.vue
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<template>
<component :is="type" v-bind="linkProps()" @click="handleClick">
<slot />
</component>
</template>
<script setup>
import { isExternal } from '@/utils/validate'
import useTagsViewStore from '@/store/modules/tagsView'
import { useRouter } from 'vue-router'
import useUserStore from '@/store/modules/user'
import { getCurrentInstance } from 'vue'
const userStore = useUserStore()
const tagsViewStore = useTagsViewStore()
const router = useRouter()
const { proxy } = getCurrentInstance()
const props = defineProps({
to: {
type: [String, Object],
required: true
},
route: {
type: Object,
required: true
}
})
const isExt = computed(() => {
return isExternal(props.to)
})
const type = computed(() => {
if (isExt.value) {
return 'a'
}
// return 'router-link'
return 'div'
})
function linkProps() {
if (isExt.value) {
return {
href: props.to,
target: '_blank',
rel: 'noopener'
}
}
return {
to: props.to
}
}
function handleClick() {
// 过期禁止点击
if (userStore.authenticationStatus == 5) {
return proxy.$modal.msgError('您的会员已过期!')
}
tagsViewStore.delCachedView(props.route)
.then(() => {
router.push(props.to)
})
}
</script>