|
@@ -43,25 +43,6 @@
|
|
</view>
|
|
</view>
|
|
<u-empty mode="data" :text="emptyText" v-if="showEmpty&&!showResult"></u-empty>
|
|
<u-empty mode="data" :text="emptyText" v-if="showEmpty&&!showResult"></u-empty>
|
|
|
|
|
|
- <view class="scan" v-show="showScan">
|
|
|
|
- <!-- <view class="loop_line"></view> -->
|
|
|
|
- <u-icon class="close" name="close-circle" color="#fff" size="30" @click="closeScan"></u-icon>
|
|
|
|
- <view class="video-container">
|
|
|
|
- <video class="video" id="video_nav_id" :controls="false"></video>
|
|
|
|
- </view>
|
|
|
|
- <view class="camera-container" v-if="videoInputDevices.length">
|
|
|
|
- <label>摄像头:</label>
|
|
|
|
- <select v-model="currentVideoInputDevice">
|
|
|
|
- <option
|
|
|
|
- v-for="(videoInputDevice, index) in videoInputDevices"
|
|
|
|
- :key="index"
|
|
|
|
- :value="videoInputDevice"
|
|
|
|
- >
|
|
|
|
- {{ videoInputDevice.label }}
|
|
|
|
- </option>
|
|
|
|
- </select>
|
|
|
|
- </view>
|
|
|
|
- </view>
|
|
|
|
|
|
|
|
<tabbar :tabbarIndexProps='0' />
|
|
<tabbar :tabbarIndexProps='0' />
|
|
</view>
|
|
</view>
|
|
@@ -86,11 +67,6 @@ import { LOG } from "@zxing/library/esm/core/datamatrix/encoder/constants";
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
exchangeCode:'',
|
|
exchangeCode:'',
|
|
- codeReader: null,
|
|
|
|
- videoInputDevices: [],
|
|
|
|
- currentVideoInputDevice: {},
|
|
|
|
- decodeResult: undefined,
|
|
|
|
- showScan:false,
|
|
|
|
checkGoods:{},
|
|
checkGoods:{},
|
|
showResult:false,
|
|
showResult:false,
|
|
emptyText:'',
|
|
emptyText:'',
|
|
@@ -105,24 +81,14 @@ import { LOG } from "@zxing/library/esm/core/datamatrix/encoder/constants";
|
|
|
|
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
- var video = document.getElementById('video_nav_id').getElementsByTagName('video')[0]
|
|
|
|
- video.setAttribute('id','video-1')
|
|
|
|
- video.setAttribute('class','video_calss')
|
|
|
|
- this.codeReader = new BrowserMultiFormatReader();
|
|
|
|
},
|
|
},
|
|
onShow() {
|
|
onShow() {
|
|
|
|
|
|
},
|
|
},
|
|
beforeDestroy() {
|
|
beforeDestroy() {
|
|
- this.codeReader.reset(); //关闭摄像头
|
|
|
|
|
|
+
|
|
},
|
|
},
|
|
watch: {
|
|
watch: {
|
|
- currentVideoInputDevice: function () {
|
|
|
|
- this.decodeFromInputVideo();
|
|
|
|
- },
|
|
|
|
- decodeResult: function () {
|
|
|
|
- this.successDecode();
|
|
|
|
- },
|
|
|
|
exchangeCode:{
|
|
exchangeCode:{
|
|
handler(val){
|
|
handler(val){
|
|
if(val.length>=8){
|
|
if(val.length>=8){
|
|
@@ -159,66 +125,17 @@ import { LOG } from "@zxing/library/esm/core/datamatrix/encoder/constants";
|
|
console.log('check',err);
|
|
console.log('check',err);
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- closeScan(){
|
|
|
|
- this.showScan = false;
|
|
|
|
- },
|
|
|
|
async openScan() {
|
|
async openScan() {
|
|
- uni.$u.route('/center/scan');
|
|
|
|
- return
|
|
|
|
- const _this = this;
|
|
|
|
- // console.log('codeReader', this.codeReader);
|
|
|
|
- // camera.setDisplayOrientation(90);
|
|
|
|
- this.showScan = true;
|
|
|
|
- _this.codeReader
|
|
|
|
- .getVideoInputDevices() //老版本listVideoInputDevices()
|
|
|
|
- .then((videoInputDevices) => {
|
|
|
|
- if (videoInputDevices && videoInputDevices.length) {
|
|
|
|
- if (videoInputDevices.length > 1) {
|
|
|
|
- videoInputDevices.reverse();
|
|
|
|
- } //防止先唤出前摄像头
|
|
|
|
- _this.videoInputDevices = videoInputDevices;
|
|
|
|
- _this.currentVideoInputDevice = videoInputDevices[0];
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- .catch(() => {});
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- decodeFromInputVideo() {
|
|
|
|
- const _this = this;
|
|
|
|
- _this.codeReader.reset();
|
|
|
|
- // 多次
|
|
|
|
- try {
|
|
|
|
- _this.codeReader.decodeFromVideoDevice(_this.currentVideoInputDevice.deviceId, 'video-1',(res,err) => {
|
|
|
|
- if(res) {
|
|
|
|
- _this.decodeResult = res.text;
|
|
|
|
- }
|
|
|
|
- if (err) {
|
|
|
|
- // alert(err)
|
|
|
|
- if (err instanceof ChecksumException) {
|
|
|
|
- alert("A code was found, but it's read value was not valid.")
|
|
|
|
- console.log(
|
|
|
|
- "A code was found, but it's read value was not valid."
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- if (err instanceof FormatException) {
|
|
|
|
- alert("A code was found, but it was in a invalid format.")
|
|
|
|
- console.log("A code was found, but it was in a invalid format.");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }catch(err){
|
|
|
|
- uni.showToast({title: `初始化失败${err}`,icon: 'none'});
|
|
|
|
- }
|
|
|
|
|
|
+ // uni.$u.route('/center/scan');
|
|
|
|
+ uni.navigateTo({
|
|
|
|
+ url:'/center/scan',
|
|
|
|
+ fail(e) {
|
|
|
|
+ console.log('navigateTo',e);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
|
|
- successDecode() {
|
|
|
|
- const _this = this;
|
|
|
|
- let result = JSON.parse(_this.decodeResult);
|
|
|
|
- this.exchangeCode = result.qrcode;
|
|
|
|
- this.closeScan();
|
|
|
|
- this.getCheckGoods();
|
|
|
|
- // alert(_this.decodeResult);
|
|
|
|
- },
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|