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.
 
 
 
 
 
 

117 lines
2.4 KiB

<!--扫描组件-->
<template>
<page-meta root-font-size="16px"></page-meta>
<view class="conbox">
<!-- v-model="scanMsg" -->
<!-- :suffixIcon="scanMsg.length>0?'clear':''" -->
<uni-easyinput ref='scanInput' :inputBorder="false" :focus="boxfocus" v-model="scanMsg"
:class="`myinput ${boxfocus == true ?'inputfocus':''}`" @focus="getfocus" @blur="blurfocus"
@iconClick="iconclick" @confirm="handelScanMsg" @input="input" :placeholder="placeholder"
placeholderStyle="font-size:16px" style='font-size: 18px;'>
</uni-easyinput>
</view>
</template>
<script>
import {
analyseScanInfo
} from '@/common/scan.js';
export default {
name: "comscan",
props: {
placeholder: {
type: String,
default: '请扫描标签'
},
clearResult: {
type: Boolean,
default: true
},
boxFocus: {
type: Boolean,
default: true
},
// scanMsg: {
// type: String,
// default: ''
// }
},
data() {
return {
scanMsg: "",
items: null,
boxfocus: this.boxFocus,
}
},
created() {
},
methods: {
setValue(val) {
this.scanMsg = val
},
input(val) {
if (val === '') {
this.$emit("clearEvent", '');
// uni.showToast({
// title: `点击了删除'}`,
// icon: 'none',
// })
}
},
iconclick(type) {
console.log(type)
},
handelScanMsg(val) {
setTimeout(() => {
if (val != "") {
let that = this;
that.scanMsg = val;
console.log('1.扫描到的内容:', val);
let scanResult = analyseScanInfo(val);
console.log('2.解析后的内容:', scanResult);
if (scanResult.sucess) {
if (that.clearResult) {
that.clear();
}
that.boxfocus = true;
that.$emit("scanResult", scanResult);
} else {
uni.showToast({
title: scanResult.message,
icon: 'error',
duration: 2000
})
}
}
}, 100)
},
getfocus() {
this.boxfocus = true;
this.$nextTick(r => {
this.boxfocus = true;
});
},
blurfocus() {
this.boxfocus = false;
},
clear() {
let that = this;
// that.scanMsg = '';
this.$refs.scanInput.onClear(); //删除input的内容
that.boxfocus = true;
},
iconClick(type) {
this.$emit("clearResult", this.scanMsgk);
},
getValue() {
return this.scanMsg
}
}
}
</script>
<style scoped lang="scss">
</style>