Files
trihuy-russian/web/html/common/qrcode_modal.html
T

115 lines
4.1 KiB
HTML
Raw Normal View History

2023-02-09 22:48:06 +03:30
{{define "qrcodeModal"}}
<a-modal id="qrcode-modal" v-model="qrModal.visible" :title="qrModal.title"
2024-03-11 16:14:24 +03:30
:dialog-style="{ top: '20px' }"
:closable="true"
:class="themeSwitcher.currentTheme"
:footer="null"
width="300px">
2023-05-08 19:14:22 +04:30
<a-tag color="green" style="margin-bottom: 10px;display: block;text-align: center;">
{{ i18n "pages.inbounds.clickOnQRcode" }}
</a-tag>
2023-05-22 17:31:41 +03:30
<template v-if="app.subSettings.enable && qrModal.subId">
2024-02-21 14:17:52 +03:30
<a-divider>{{ i18n "pages.settings.subSettings"}}</a-divider>
<canvas @click="copyToClipboard('qrCode-sub',genSubLink(qrModal.client.subId))"
id="qrCode-sub"
2024-02-22 22:50:38 +03:30
class="qr-bg">
2024-02-21 14:17:52 +03:30
</canvas>
<a-divider>{{ i18n "pages.settings.subSettings"}} Json</a-divider>
<canvas @click="copyToClipboard('qrCode-subJson',genSubJsonLink(qrModal.client.subId))"
id="qrCode-subJson"
style="width: 100%; height: 100%; display: flex; border-radius: 1rem;">
</canvas>
2023-05-22 17:31:41 +03:30
</template>
2024-01-26 22:07:15 +03:30
<a-divider>{{ i18n "pages.inbounds.client" }}</a-divider>
<template v-for="(row, index) in qrModal.qrcodes">
2024-02-22 22:50:38 +03:30
<a-tag color="green" style="margin: 10px 0; display: block; text-align: center;">[[ row.remark ]]</a-tag>
2024-02-21 14:17:52 +03:30
<canvas @click="copyToClipboard('qrCode-'+index, row.link)"
:id="'qrCode-'+index"
2024-02-22 22:50:38 +03:30
class="qr-bg"></canvas>
2023-05-22 17:31:41 +03:30
</template>
2023-02-09 22:48:06 +03:30
</a-modal>
<script>
const qrModal = {
title: '',
dbInbound: new DBInbound(),
2023-05-22 17:31:41 +03:30
client: null,
qrcodes: [],
2023-02-09 22:48:06 +03:30
clipboard: null,
visible: false,
2023-05-22 17:31:41 +03:30
subId: '',
2024-01-26 22:07:15 +03:30
show: function (title = '', dbInbound, client) {
2023-02-09 22:48:06 +03:30
this.title = title;
this.dbInbound = dbInbound;
this.inbound = dbInbound.toInbound();
2023-12-08 18:45:21 +01:00
this.client = client;
2023-05-23 03:15:34 +03:30
this.subId = '';
2023-05-22 17:31:41 +03:30
this.qrcodes = [];
2024-02-18 00:46:49 +03:30
if (this.inbound.protocol == Protocols.WIREGUARD){
this.inbound.genInboundLinks(dbInbound.remark).split('\r\n').forEach((l,index) =>{
this.qrcodes.push({
remark: "Peer " + (index+1),
link: l
});
2023-05-22 17:31:41 +03:30
});
2024-02-18 00:46:49 +03:30
} else {
this.inbound.genAllLinks(this.dbInbound.remark, app.remarkModel, client).forEach(l => {
this.qrcodes.push({
remark: l.remark,
link: l.link
});
});
}
2023-02-09 22:48:06 +03:30
this.visible = true;
},
close: function () {
this.visible = false;
},
};
const qrModalApp = new Vue({
2023-05-12 21:53:05 +04:30
delimiters: ['[[', ']]'],
2023-02-09 22:48:06 +03:30
el: '#qrcode-modal',
data: {
qrModal: qrModal,
},
2023-03-17 19:37:49 +03:30
methods: {
2023-05-31 01:47:07 +04:30
copyToClipboard(elmentId, content) {
this.qrModal.clipboard = new ClipboardJS('#' + elmentId, {
2023-05-22 17:31:41 +03:30
text: () => content,
2023-03-17 19:37:49 +03:30
});
this.qrModal.clipboard.on('success', () => {
app.$message.success('{{ i18n "copied" }}')
this.qrModal.clipboard.destroy();
});
2023-05-22 17:31:41 +03:30
},
2023-05-31 01:47:07 +04:30
setQrCode(elmentId, content) {
2023-05-22 17:31:41 +03:30
new QRious({
2023-05-31 01:47:07 +04:30
element: document.querySelector('#' + elmentId),
size: 260,
value: content,
});
2023-05-22 17:31:41 +03:30
},
genSubLink(subID) {
2023-12-13 19:55:20 +03:30
return app.subSettings.subURI+subID;
2024-02-21 14:17:52 +03:30
},
genSubJsonLink(subID) {
return app.subSettings.subJsonURI+subID;
2023-03-17 19:37:49 +03:30
}
},
2023-05-22 17:31:41 +03:30
updated() {
2023-05-31 01:47:07 +04:30
if (qrModal.client && qrModal.client.subId) {
2023-05-22 17:31:41 +03:30
qrModal.subId = qrModal.client.subId;
2023-05-31 01:47:07 +04:30
this.setQrCode("qrCode-sub", this.genSubLink(qrModal.subId));
2024-02-21 14:17:52 +03:30
this.setQrCode("qrCode-subJson", this.genSubJsonLink(qrModal.subId));
2023-05-22 17:31:41 +03:30
}
2023-05-31 01:47:07 +04:30
qrModal.qrcodes.forEach((element, index) => {
this.setQrCode("qrCode-" + index, element.link);
2023-05-22 17:31:41 +03:30
});
}
2023-02-09 22:48:06 +03:30
});
</script>
2024-02-22 22:50:38 +03:30
{{end}}