You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
2.9 KiB
138 lines
2.9 KiB
<!--扫描组件-->
|
|
<template>
|
|
<page-meta root-font-size="18px"></page-meta>
|
|
<view>
|
|
<view class="conbox">
|
|
<textarea v-model="scanMsg" trim="all" inputmode='none' maxlength="1000" :focus="boxfocus"
|
|
:placeholder="placeholderValue" :auto-focus='true' @focus="getfocus" @blur="losefocus"
|
|
@input="handelScanMsg"></textarea>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
<script module="input" lang="renderjs">
|
|
import {
|
|
analyseScanInfo
|
|
} from '@/common/scan.js';
|
|
export default {
|
|
emits:["getScanResult"],
|
|
name: "winComScan",
|
|
props: {
|
|
placeholder: {
|
|
type: String,
|
|
default: '请扫描标签'
|
|
},
|
|
clearResult: {
|
|
type: Boolean,
|
|
default: true
|
|
},
|
|
boxFocus: {
|
|
type: Boolean,
|
|
default: true
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
scanMsg: "",
|
|
items: null,
|
|
boxfocus: this.boxFocus,
|
|
placeholderValue: ''
|
|
}
|
|
},
|
|
mounted() {
|
|
// if (this.$el.querySelector('textarea') != null) {
|
|
// this.$el.querySelector('textarea').setAttribute('inputmode', 'none')
|
|
// }
|
|
},
|
|
watch: {
|
|
placeholder() {
|
|
this.placeholderValue = '请扫描' + this.placeholder;
|
|
}
|
|
},
|
|
created() {
|
|
this.placeholderValue = '请扫描' + this.placeholder;
|
|
},
|
|
methods: {
|
|
setValue(val) {
|
|
this.scanMsg = val
|
|
},
|
|
clearScanValue() {
|
|
this.scanMsg = ''
|
|
},
|
|
iconclick(type) {
|
|
console.log(type)
|
|
},
|
|
confirm() {
|
|
this.handelScanMsg();
|
|
},
|
|
handelScanMsg(e) {
|
|
//获取最后一个回车
|
|
// let a = e.detail.value[e.detail.value.length - 1];
|
|
let that = this;
|
|
//点击了回车
|
|
if (that.scanMsg.indexOf('\n') != -1) {
|
|
if (that.scanMsg == "")
|
|
return;
|
|
setTimeout(() => {
|
|
//去除回车和空格
|
|
let content = that.scanMsg.replace(/[\r\n]/g, "").replace(/[, ]/g, "");
|
|
let scanResult = analyseScanInfo(content);
|
|
if (scanResult.sucess) {
|
|
if (that.clearResult) {
|
|
that.clear();
|
|
}
|
|
that.$emit("getScanResult", scanResult);
|
|
} else {
|
|
uni.showToast({
|
|
title: scanResult.message,
|
|
icon: 'error',
|
|
duration: 2000
|
|
})
|
|
}
|
|
});
|
|
}
|
|
},
|
|
getfocus() {
|
|
let that = this;
|
|
that.boxfocus = true;
|
|
this.$nextTick(r => {
|
|
that.boxfocus = true;
|
|
});
|
|
},
|
|
losefocus() {
|
|
let that = this;
|
|
that.boxfocus = false;
|
|
this.$nextTick(r => {
|
|
that.boxfocus = false;
|
|
});
|
|
},
|
|
blurfocus() {
|
|
this.boxfocus = false;
|
|
},
|
|
clear() {
|
|
let that = this;
|
|
that.clearScanValue();
|
|
// this.$refs.scanInput.onClear(); //删除input的内容
|
|
that.boxfocus = true;
|
|
},
|
|
iconClick(type) {
|
|
this.$emit("clearResult", this.scanMsgk);
|
|
},
|
|
getValue() {
|
|
return this.scanMsg
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
<!-- <script module="input" lang="renderjs">
|
|
export default {
|
|
mounted() {
|
|
if (this.$el.querySelector('textarea') != null) {
|
|
this.$el.querySelector('textarea').setAttribute('inputmode', 'none')
|
|
}
|
|
|
|
}
|
|
}
|
|
</script> -->
|
|
<style scoped lang="scss">
|
|
|
|
</style>
|
|
|