Skip to content

Commit abeba11

Browse files
committed
Added new functions and formatted
1 parent 49e77a8 commit abeba11

2 files changed

Lines changed: 90 additions & 71 deletions

File tree

pages/index.vue

Lines changed: 90 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,104 @@
11
<template>
22
<div>
3-
<HeaderNavbar/>
4-
<a-card hoverable style="width: 400px; margin:0 auto; margin-top: 5%;">
5-
<template #cover>
6-
<img
7-
alt="example"
8-
class="w-[400px] h-[300px] pointer-events-none select-none"
9-
:src="newQrCodeImg || require('../assets/imgs/default.png')"
10-
/>
11-
<br>
12-
<div class="flex w-[90%] text-center items-center justify-center flex-col">
13-
<a-input @keypress.enter="generateNewQrCode" class="ml-[10%]" v-model:value="text" size="large" placeholder="Enter text for convert to qr-code" title="Qr-code"/>
14-
<button @click="generateNewQrCode" class="px-[6px] py-[8px] rounded bg-blue-400 text-[16px] font-semibold text-white mt-4 ml-[10%] hover:-translate-y-2 hover:bg-black">Generate QR-CODE</button>
15-
</div>
16-
<br>
17-
</template>
18-
<template #actions>
19-
<p class="text-[16px] text-blue-400" @click="downloadSVG(newQrCodeImg)">SVG</p>
20-
<p class="text-[16px] text-blue-400" @click="downloadPNG(newQrCodeImg)">PNG</p>
21-
<p class="text-[16px] text-blue-400" @click="downloadJPG(newQrCodeImg)">JPG</p>
22-
</template>
23-
</a-card>
3+
<HeaderNavbar />
4+
<a-card hoverable style="width: 400px; margin: 0 auto; margin-top: 5%">
5+
<template #cover>
6+
<img
7+
alt="example"
8+
class="w-[400px] h-[300px] pointer-events-none select-none"
9+
:src="newQrCodeImg || require('../assets/imgs/default.png')"
10+
/>
11+
<br />
12+
<div
13+
class="flex w-[90%] text-center items-center justify-center flex-col"
14+
>
15+
<a-input
16+
@keypress.enter="generateNewQrCode"
17+
class="ml-[10%]"
18+
v-model:value="text"
19+
size="large"
20+
placeholder="Enter text for convert to qr-code"
21+
title="Qr-code"
22+
/>
23+
<button
24+
@click="generateNewQrCode"
25+
class="px-[6px] py-[8px] rounded bg-blue-400 text-[16px] font-semibold text-white mt-4 ml-[10%] hover:-translate-y-2 hover:bg-black"
26+
>
27+
Generate QR-CODE
28+
</button>
29+
</div>
30+
<br />
31+
</template>
32+
<template #actions>
33+
<p class="text-[16px] text-blue-400" @click="downloadSVG(newQrCodeImg)">
34+
SVG
35+
</p>
36+
<p class="text-[16px] text-blue-400" @click="downloadPNG(newQrCodeImg)">
37+
PNG
38+
</p>
39+
<p class="text-[16px] text-blue-400" @click="downloadJPG(newQrCodeImg)">
40+
JPG
41+
</p>
42+
</template>
43+
</a-card>
2444
</div>
2545
</template>
2646

2747
<script>
28-
import { notification } from 'ant-design-vue'
29-
import { downloadPNG, downloadSVG, downloadJPG } from '@/utils/download.js'
30-
export default{
31-
name: 'indexPage',
48+
import { notification } from "ant-design-vue";
49+
export default {
50+
name: "indexPage",
3251
data() {
3352
return {
34-
text: '',
35-
newQrCodeImg: null
36-
}
53+
text: "",
54+
newQrCodeImg: null,
55+
};
3756
},
3857
3958
methods: {
40-
generateNewQrCode(){
41-
if(this.text.length > 0){
42-
this.newQrCodeImg = this.$config.secretText + this.text
59+
generateNewQrCode() {
60+
if (this.text.length > 0) {
61+
this.newQrCodeImg = this.$config.secretText + this.text;
4362
// this.$store.state.newQrCodeUrl = this.newQrCodeImg
44-
notification['success']({
45-
message: 'Generated new QR-CODE successfully',
46-
duration: 3
47-
});
48-
this.text = ''
49-
}else{
50-
notification['error']({
51-
message: 'You need enter some text or anything in input!',
52-
duration: 5
53-
});
63+
notification["success"]({
64+
message: "Generated new QR-CODE successfully",
65+
duration: 3,
66+
});
67+
this.text = "";
68+
} else {
69+
notification["error"]({
70+
message: "You need enter some text or anything in input!",
71+
duration: 5,
72+
});
5473
}
55-
}
74+
},
75+
76+
downloadPNG(imgURL) {
77+
const url = window.URL.createObjectURL(new Blob([imgURL]));
78+
const link = document.createElement("a");
79+
link.href = url;
80+
link.setAttribute("download", "qrCode.png"); //or any other extension
81+
document.body.appendChild(link);
82+
link.click();
83+
},
84+
85+
downloadSVG(imgURL) {
86+
const url = window.URL.createObjectURL(new Blob([imgURL]));
87+
const link = document.createElement("a");
88+
link.href = url;
89+
link.setAttribute("download", "qrCode.svg"); //or any other extension
90+
document.body.appendChild(link);
91+
link.click();
92+
},
93+
94+
downloadJPG(imgURL) {
95+
const url = window.URL.createObjectURL(new Blob([imgURL]));
96+
const link = document.createElement("a");
97+
link.href = url;
98+
link.setAttribute("download", "qrCode.jpg"); //or any other extension
99+
document.body.appendChild(link);
100+
link.click();
101+
},
56102
},
57-
}
58-
</script>
103+
};
104+
</script>

utils/download.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)