Skip to content

Commit 4c7815a

Browse files
committed
feat: fallback for old mobile devices
Create dedicated component based on HTML Media Capture. Instead of continiously scanning a camera stream, mobile devices can take a single picture to be uploaded. Also allows classic file upload which can also serve desktop devices. See #63 #56
1 parent 465a4cf commit 4c7815a

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/components/QrcodeCapture.vue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<template lang="html">
2+
<input
3+
@change="onChangeInput"
4+
type="file"
5+
name="image"
6+
accept="image/*"
7+
capture="environment"
8+
multiple>
9+
</template>
10+
11+
<script>
12+
import { scan } from '../misc/scanner.js'
13+
import { imageDataFromFile } from '../misc/image-data.js'
14+
import CommonAPI from '../mixins/CommonAPI.vue'
15+
16+
export default {
17+
18+
mixins: [ CommonAPI ],
19+
20+
methods: {
21+
onChangeInput (event) {
22+
const files = [...event.target.files]
23+
const resultPromises = files.map(this.processFile)
24+
25+
resultPromises.forEach(this.onDetect)
26+
27+
console.log(Promise.all(resultPromises))
28+
},
29+
30+
async processFile (file) {
31+
const imageData = await imageDataFromFile(file)
32+
const scanResult = await scan(imageData)
33+
34+
return { source: 'file', ...scanResult }
35+
},
36+
},
37+
38+
}
39+
</script>

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import QrcodeReader from './components/QrcodeReader.vue'
2+
import QrcodeCapture from './components/QrcodeCapture.vue'
23
// import QrcodeDropZone from './components/QrcodeDropZone.vue'
34

45
// Install the components
56
export function install (Vue) {
67
Vue.component('qrcode-reader', QrcodeReader)
8+
Vue.component('qrcode-capture', QrcodeCapture)
9+
// Vue.component('qrcode-drop-zone', QrcodeDropZone)
710
}
811

912
// Expose the components
1013
export {
1114
QrcodeReader,
15+
QrcodeCapture,
1216
// QrcodeDropZone,
1317
}
1418

0 commit comments

Comments
 (0)