Line 0
Link Here
|
|
|
1 |
<template> |
2 |
<a |
3 |
v-if="callback" |
4 |
@click="typeof callback === 'string' ? redirect() : callback(this)" |
5 |
:class="cssClass" |
6 |
style="cursor: pointer" |
7 |
> |
8 |
<font-awesome-icon v-if="icon" :icon="icon" /> {{ title }} |
9 |
</a> |
10 |
<router-link v-else :to="to" :class="cssClass" |
11 |
><font-awesome-icon v-if="icon" :icon="icon" /> {{ title }}</router-link |
12 |
> |
13 |
</template> |
14 |
|
15 |
<script> |
16 |
export default { |
17 |
props: { |
18 |
to: { |
19 |
type: [String, Object], |
20 |
}, |
21 |
icon: { |
22 |
type: String, |
23 |
required: false, |
24 |
}, |
25 |
title: { |
26 |
type: String, |
27 |
}, |
28 |
callback: { |
29 |
type: [String, Function], |
30 |
required: false, |
31 |
}, |
32 |
cssClass: { |
33 |
type: String, |
34 |
default: "btn btn-default", |
35 |
required: false, |
36 |
}, |
37 |
}, |
38 |
methods: { |
39 |
redirect(url) { |
40 |
const redirectParams = url ? url : this.to; |
41 |
if (typeof redirectParams === "string") |
42 |
window.location.href = this.formatUrl(redirectParams); |
43 |
if (typeof redirectParams === "object") { |
44 |
const url = this.handleQuery(redirectParams); |
45 |
window.open(this.formatUrl(url), "_blank"); |
46 |
} |
47 |
}, |
48 |
formatUrl(url) { |
49 |
if (url.includes("http://") || url.includes("https://")) return url; |
50 |
if (url.includes("cgi-bin/koha")) |
51 |
return `//${window.location.host}/${url}`; |
52 |
return `//${url}`; |
53 |
}, |
54 |
handleQuery(query) { |
55 |
let url = this.to.path; |
56 |
if (this.to.hasOwnProperty("query")) { |
57 |
url += |
58 |
"?" + |
59 |
Object.keys(this.to.query) |
60 |
.map( |
61 |
queryParam => |
62 |
`${queryParam}=${this.to.query[queryParam]}` |
63 |
) |
64 |
.join("&"); |
65 |
} |
66 |
return url; |
67 |
}, |
68 |
}, |
69 |
name: "Link", |
70 |
}; |
71 |
</script> |