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
78
79
| <template>
| <a v-for="item in urls" :key="item" class="cl-link" :href="item" :target="target">
| <el-icon><icon-link /></el-icon>{{ filename(item) }}
| </a>
| </template>
|
| <script lang="ts">
| import { defineComponent, computed } from "vue";
| import { isArray, isString, last } from "/@/cool/utils";
| import { Link } from "@element-plus/icons";
|
| export default defineComponent({
| name: "cl-link",
|
| components: {
| "icon-link": Link
| },
|
| props: {
| modelValue: [String, Array],
| href: [String, Array],
| text: {
| type: String,
| default: "查看"
| },
| target: {
| type: String,
| default: "_blank"
| }
| },
|
| setup(props) {
| 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("/"));
| }
|
| return {
| urls,
| filename
| };
| }
| });
| </script>
|
| <style lang="scss" scoped>
| .cl-link {
| display: inline-flex;
| align-items: center;
| text-align: left;
| background-color: $color-primary;
| color: #fff;
| padding: 0 5px;
| border-radius: 5px;
| font-size: 12px;
| margin: 2px;
|
| .el-icon {
| margin-right: 2px;
| }
|
| &:hover {
| text-decoration: underline;
| }
| }
| </style>
|
|