ny
23 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
65
66
67
68
69
70
71
72
73
74
75
76
77
<!-- eslint-disable no-template-curly-in-string -->
<script lang="ts" setup>
import { computed, onMounted, ref, watch } from 'vue';
 
import { useGlobSetting } from '@jnpf/hooks';
import { encryptByBase64, isUrl } from '@jnpf/utils';
 
import { useAccessStore } from '@vben/stores';
 
import { APP_PREFIX } from '#/utils/constants';
import { getRealJnpfAppEnCode } from '#/utils/jnpf';
 
const props = defineProps({
  linkType: { type: String, default: '' },
  urlAddress: { type: String, default: '' },
  linkTarget: { type: String, default: 'self' },
  type: { type: [Number, String], default: 0 },
  propertyJson: { type: String },
});
const to = ref('');
const globSetting = useGlobSetting();
const accessStore = useAccessStore();
const appEnCode = getRealJnpfAppEnCode();
 
const getIsUrl = computed(() => {
  return isUrl(to.value);
});
const routerType = computed(() => {
  if (!props.linkType || !props.urlAddress) return 'div';
  if (getIsUrl.value) return 'a';
  return 'router-link';
});
 
watch(
  () => props.urlAddress,
  () => {
    if (props.linkType) init();
  },
  {
    deep: true,
  },
);
 
function init() {
  let path = `/${props.urlAddress}`;
  if (props.type == 6) {
    let moduleId = '';
    const propertyJson = props.propertyJson ? JSON.parse(props.propertyJson) : null;
    if (propertyJson) moduleId = propertyJson.moduleId || '';
    path = `${globSetting.dataVUrl || ''}${appEnCode ? `${APP_PREFIX}${appEnCode}/` : ''}view/${moduleId}?token=${accessStore.accessToken}`;
  }
  if (props.type == 7 || props.linkType == '2') {
    path =
      props.linkTarget === '_self'
        ? `/externalLink?href=${encodeURIComponent(encryptByBase64(props.urlAddress))}`
        : props.urlAddress
            .replaceAll('${dataV}', (globSetting.dataVUrl || '') + (appEnCode ? `${APP_PREFIX}${appEnCode}/` : ''))
            .replaceAll('${jnpfToken}', accessStore.accessToken || '')
            .replaceAll('${jnpfAppCode}', appEnCode || '');
  }
  to.value = path;
}
function linkProps(to) {
  if (getIsUrl.value) return { href: to, target: '_blank', rel: 'noopener' };
  return { to };
}
 
onMounted(() => {
  if (props.linkType) init();
});
</script>
 
<template>
  <component :is="routerType" v-bind="linkProps(to)">
    <slot></slot>
  </component>
</template>