3x-ui/web/html/common/qrcode_modal.html

104 lines
3.9 KiB
HTML
Raw Normal View History

2023-02-09 22:18:06 +03:00
{{define "qrcodeModal"}}
<a-modal id="qrcode-modal" v-model="qrModal.visible" :title="qrModal.title"
2023-03-24 16:17:14 +03:00
:closable="true"
2023-12-04 21:17:38 +03:00
:class="themeSwitcher.currentTheme"
2023-03-24 16:17:14 +03:00
:footer="null"
width="300px">
2023-05-08 17:44:22 +03:00
<a-tag color="green" style="margin-bottom: 10px;display: block;text-align: center;">
{{ i18n "pages.inbounds.clickOnQRcode" }}
</a-tag>
<template v-if="app.subSettings.enable && qrModal.subId">
<a-divider>Subscription</a-divider>
<canvas @click="copyToClipboard('qrCode-sub',genSubLink(qrModal.client.subId))" id="qrCode-sub" style="width: 100%; height: 100%;"></canvas>
</template>
<a-divider>{{ i18n "pages.inbounds.client" }}</a-divider>
<template v-for="(row, index) in qrModal.qrcodes">
2023-12-04 21:17:38 +03:00
<a-tag color="green" style="margin: 10px 0; display: block; text-align: center;">[[ row.remark ]]</a-tag>
<canvas @click="copyToClipboard('qrCode-'+index, row.link)" :id="'qrCode-'+index" style="width: 100%; height: 100%;"></canvas>
</template>
2023-02-09 22:18:06 +03:00
</a-modal>
<script>
const qrModal = {
title: '',
clientIndex: 0,
2023-02-09 22:18:06 +03:00
inbound: new Inbound(),
dbInbound: new DBInbound(),
client: null,
qrcodes: [],
2023-02-09 22:18:06 +03:00
clipboard: null,
visible: false,
subId: '',
show: function (title = '', dbInbound = new DBInbound(), clientIndex = 0) {
2023-02-09 22:18:06 +03:00
this.title = title;
this.clientIndex = clientIndex;
2023-02-09 22:18:06 +03:00
this.dbInbound = dbInbound;
this.inbound = dbInbound.toInbound();
settings = JSON.parse(this.inbound.settings);
this.client = settings.clients[clientIndex];
remark = [this.dbInbound.remark, ( this.client ? this.client.email : '')].filter(Boolean).join('-');
address = this.dbInbound.address;
this.subId = '';
this.qrcodes = [];
if (this.inbound.tls && !ObjectUtil.isArrEmpty(this.inbound.stream.tls.settings.domains)) {
this.inbound.stream.tls.settings.domains.forEach((domain) => {
remarkText = [remark, domain.remark].filter(Boolean).join('-');
this.qrcodes.push({
remark: remarkText,
link: this.inbound.genLink(domain.domain, remarkText, clientIndex)
});
});
2023-02-09 22:18:06 +03:00
} else {
this.qrcodes.push({
remark: remark,
link: this.inbound.genLink(address, remark, clientIndex)
});
2023-02-09 22:18:06 +03:00
}
this.visible = true;
},
close: function () {
this.visible = false;
},
};
const qrModalApp = new Vue({
2023-05-12 20:23:05 +03:00
delimiters: ['[[', ']]'],
2023-02-09 22:18:06 +03:00
el: '#qrcode-modal',
data: {
qrModal: qrModal,
},
2023-03-17 19:07:49 +03:00
methods: {
2023-05-31 00:17:07 +03:00
copyToClipboard(elmentId, content) {
this.qrModal.clipboard = new ClipboardJS('#' + elmentId, {
text: () => content,
2023-03-17 19:07:49 +03:00
});
this.qrModal.clipboard.on('success', () => {
app.$message.success('{{ i18n "copied" }}')
this.qrModal.clipboard.destroy();
});
},
2023-05-31 00:17:07 +03:00
setQrCode(elmentId, content) {
new QRious({
2023-05-31 00:17:07 +03:00
element: document.querySelector('#' + elmentId),
size: 260,
value: content,
});
},
genSubLink(subID) {
2023-12-08 19:18:51 +03:00
return app.subSettings.subURI+subID+'?name='+subID;
2023-03-17 19:07:49 +03:00
}
},
updated() {
2023-05-31 00:17:07 +03:00
if (qrModal.client && qrModal.client.subId) {
qrModal.subId = qrModal.client.subId;
2023-05-31 00:17:07 +03:00
this.setQrCode("qrCode-sub", this.genSubLink(qrModal.subId));
}
2023-05-31 00:17:07 +03:00
qrModal.qrcodes.forEach((element, index) => {
this.setQrCode("qrCode-" + index, element.link);
});
}
2023-02-09 22:18:06 +03:00
});
</script>
{{end}}