-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract QR-Button as component, fix button display
Signed-off-by: Knut Ahlers <[email protected]>
- Loading branch information
Showing
3 changed files
with
99 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<template> | ||
<button | ||
v-if="!$root.customize.disableQRSupport" | ||
id="secret-url-qrcode" | ||
ref="qrButton" | ||
class="btn btn-secondary" | ||
:disabled="!qrDataURL" | ||
> | ||
<i class="fas fa-qrcode" /> | ||
</button> | ||
</template> | ||
<script> | ||
import { Popover } from 'bootstrap' | ||
import qrcode from 'qrcode' | ||
export default { | ||
data() { | ||
return { | ||
qrDataURL: null, | ||
} | ||
}, | ||
methods: { | ||
generateQR() { | ||
if (this.$root.customize.disableQRSupport) { | ||
return | ||
} | ||
qrcode.toDataURL(this.qrContent, { width: 200 }) | ||
.then(url => { | ||
this.qrDataURL = url | ||
}) | ||
}, | ||
}, | ||
mounted() { | ||
this.generateQR() | ||
}, | ||
name: 'AppQRButton', | ||
props: { | ||
qrContent: { | ||
required: true, | ||
type: String, | ||
}, | ||
}, | ||
watch: { | ||
qrContent() { | ||
this.generateQR() | ||
}, | ||
qrDataURL(to) { | ||
if (this.popover) { | ||
this.popover.dispose() | ||
} | ||
this.popover = new Popover(this.$refs.qrButton, { | ||
content: () => { | ||
const img = document.createElement('img') | ||
img.src = to | ||
return img | ||
}, | ||
html: true, | ||
placement: 'left', | ||
trigger: 'focus', | ||
}) | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters