-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQrCode.vue
116 lines (108 loc) · 2.18 KB
/
QrCode.vue
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
<div class="qrcodeBtn" @mousedown.stop="showQrCode">
<span class="labelText">{{ labelText || "Mobile Read" }}</span>
<qrcode-vue
id="qrcodeContainer"
v-if="show"
ref="qrcodeContainer"
:value="qrcodeText"
:size="qrSize"
level="H"
></qrcode-vue>
</div>
</template>
<script>
import QrcodeVue from "qrcode.vue";
import { isRealNum } from "./util";
export default {
components: {
QrcodeVue,
},
data() {
return {
show: false, //show or hide
qrcodeText: "", // url
qrSize: 100, //square size
channelQR:''
};
},
props: {
labelText: {
type: String,
default: "",
},
size: {
type: [String, Number],
default: "",
},
channel: {
type: Boolean,
default: false,
},
},
mounted() {
// tranform size
let newV = this.size;
let realSize = "";
switch (newV) {
case "small":
realSize = 100;
break;
case "medium":
realSize = 150;
break;
case "big":
realSize = 200;
break;
default:
if (isRealNum(newV)) {
const min = Math.min(window.innerHeight, window.innerWidth);
newV = ~~newV;
if (newV < 10) {
realSize = 10;
} else if (newV > min) {
realSize = min;
} else {
realSize = newV;
}
} else {
realSize = 100;
}
break;
}
this.qrSize = realSize;
// handle channel
if(this.channel){
this.channelQR = (location.href.indexOf('?') > -1 ? '&channel=qrcode' : '?channel=qrcode')
}
document.documentElement.addEventListener("mousedown", () => {
this.show = false;
});
},
methods: {
showQrCode() {
this.show = !this.show;
if (this.show) {
this.$nextTick(() => {
this.qrcodeText = location.href + this.channelQR;
});
}
},
},
};
</script>
<style lang="stylus">
.qrcodeBtn {
position: relative;
user-select: none;
&:hover {
color: $accentColor;
cursor: pointer;
}
#qrcodeContainer {
position: absolute;
right: 0;
top: 50px;
}
}
</style>