wangzhibo
6 天以前 7bd866831780abcf5a59c4cbb7d1be456eea7c99
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
<template>
    <div class="cl-link">
        <a v-for="item in urls" :key="item" class="cl-link__item" :href="item" :target="target">
            <el-icon><icon-link /></el-icon>
            <span>{{ text || filename(item) }}</span>
        </a>
    </div>
</template>
 
<script lang="ts" setup>
defineOptions({
    name: 'cl-link'
});
 
import { computed } from 'vue';
import { isArray, isString, last } from 'lodash-es';
import { Link as IconLink } from '@element-plus/icons-vue';
 
const props = defineProps({
    modelValue: [String, Array],
    href: [String, Array],
    text: String,
    target: {
        type: String,
        default: '_blank'
    }
});
 
const urls = computed(() => {
    const urls: any = props.modelValue || props.href;
 
    if (isArray(urls)) {
        return urls;
    }
 
    if (isString(urls)) {
        return (urls || '').split(',').filter(Boolean);
    }
 
    return [];
});
 
function filename(url: string) {
    return last(url.split('/'));
}
</script>
 
<style lang="scss" scoped>
.cl-link {
    &__item {
        display: flex;
        align-items: center;
        color: var(--el-color-primary);
        padding: 0 5px;
        border-radius: 6px;
        margin: 2px;
        text-decoration: none;
 
        span {
            display: block;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
 
        .el-icon {
            margin-right: 4px;
        }
 
        &:hover {
            text-decoration: underline;
        }
    }
}
</style>