Add basic components for Product CRUD
more specifically at this point, for product lookup via scanner
This commit is contained in:
parent
6db418ec19
commit
4fa08c68ec
7 changed files with 248 additions and 1 deletions
56
src/components/scanner-input/ByjoveScannerInput.vue
Normal file
56
src/components/scanner-input/ByjoveScannerInput.vue
Normal file
|
@ -0,0 +1,56 @@
|
|||
<template>
|
||||
<div class="scanner-input">
|
||||
<b-input v-model="quickEntry"
|
||||
placeholder="Scan/Enter Code"
|
||||
icon="search"
|
||||
@keypress.native="quickKey">
|
||||
</b-input>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'ByjoveScannerInput',
|
||||
data() {
|
||||
return {
|
||||
quickEntry: '',
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
window.addEventListener('keypress', this.globalKey)
|
||||
},
|
||||
beforeDestroy() {
|
||||
window.removeEventListener('keypress', this.globalKey)
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
globalKey(event) {
|
||||
if (event.target.tagName == 'BODY') {
|
||||
|
||||
// mimic keyboard wedge
|
||||
if (event.charCode >= 48 && event.charCode <= 57) { // numeric (qwerty)
|
||||
this.$nextTick(() => {
|
||||
this.quickEntry += event.key
|
||||
})
|
||||
|
||||
} else if (event.keyCode == 13) { // enter
|
||||
this.submitQuickEntry()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
quickKey(event) {
|
||||
if (event.keyCode == 13) { // enter
|
||||
this.submitQuickEntry()
|
||||
}
|
||||
},
|
||||
|
||||
submitQuickEntry() {
|
||||
if (this.quickEntry) {
|
||||
this.$emit('submit', this.quickEntry)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
28
src/components/scanner-input/index.js
Normal file
28
src/components/scanner-input/index.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Import vue component
|
||||
import ByjoveScannerInput from './ByjoveScannerInput.vue'
|
||||
|
||||
// Declare install function executed by Vue.use()
|
||||
export function install(Vue) {
|
||||
if (install.installed) return;
|
||||
install.installed = true;
|
||||
Vue.component('ByjoveScannerInput', ByjoveScannerInput);
|
||||
}
|
||||
|
||||
// Create module definition for Vue.use()
|
||||
const plugin = {
|
||||
install,
|
||||
};
|
||||
|
||||
// Auto-install when vue is found (eg. in browser via <script> tag)
|
||||
let GlobalVue = null;
|
||||
if (typeof window !== 'undefined') {
|
||||
GlobalVue = window.Vue;
|
||||
} else if (typeof global !== 'undefined') {
|
||||
GlobalVue = global.Vue;
|
||||
}
|
||||
if (GlobalVue) {
|
||||
GlobalVue.use(plugin);
|
||||
}
|
||||
|
||||
// To allow use as module (npm/webpack/etc.) export component
|
||||
export default ByjoveScannerInput
|
Loading…
Add table
Add a link
Reference in a new issue