添加扫一扫功能,兼容h5、小程序、app

master
chen 2022-03-28 10:55:35 +08:00
parent 1ef8bfb99c
commit 2002b246ac
3 changed files with 2714 additions and 4 deletions

View File

@ -20,7 +20,7 @@
},
onShow: function() {
if(uni.getStorageSync('phone_active')){
// token
// token
this.$toolAll.tools.refreshToken();
}
},

View File

@ -13,6 +13,8 @@
</view>
</template>
<script>
// qrcode.js qrcode.js
var qrcode = require('@/jsFile/qrcode.js');
export default {
name:'foot-tab',
props:{
@ -105,7 +107,8 @@
};
},
mounted() {
// qrcode
console.log(qrcode,111)
},
methods:{
choosefoot(index){
@ -119,7 +122,20 @@
uni.reLaunch({url:'/pages/project/projectList'})
break;
case 2:
// uni.reLaunch({url:'/pages/tabbar/project-list/project-list'})
// #ifdef APP-PLUS, MP-WEIXIN
uni.scanCode({
onlyFromCamera:false, //
scanType: ['qrCode'], // barCode qrCode datamatrixData Matrix pdf417PDF417
autoDecodeCharset:true, //
success: function (res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
}
});
// #endif
// #ifdef H5
this.scanCode();
// #endif
break;
case 3:
uni.reLaunch({url:'/pages/feedback/feedback'})
@ -135,7 +151,95 @@
// })
// }
}
}
},
scanCode() {
let that = this
// uniapi
uni.chooseImage({
sizeType: ['original'],
count: 1,
success: (res)=> {
qrcode.decode(this.getObjectURL(res.tempFiles[0]))
qrcode.callback = (codeRes) => {
if (codeRes.indexOf('error') >= 0) {
//
console.log('不合法二维码:' + codeRes);
} else {
//
let r = this.decodeStr(codeRes)
// this.qrCodeRes = r
console.log(r);
}
}
// const tempFilePaths = res.tempFilePaths[0] //
// qrcode.decode(tempFilePaths); //
// qrcode.callback = function(res1) {
// // error decoding QR Code
// if (res1 == "error decoding QR Code") {
// uni.showToast({
// title: "",
// duration: 2000,
// icon: 'none'
// })
// } else {
// //
// console.log(res1)
// }
// }
}
});
},
//
getObjectURL(file) {
var url = null
if (window.createObjectURL !== undefined) { // basic
url = window.createObjectURL(file)
} else if (window.URL !== undefined) { // mozilla(firefox)
url = window.URL.createObjectURL(file)
} else if (window.webkitURL !== undefined) { // webkit or chrome
url = window.webkitURL.createObjectURL(file)
}
return url
},
//
decodeStr(str) {
var out, i, len, c;
var char2, char3;
out = "";
len = str.length;
i = 0;
while (i < len) {
c = str.charCodeAt(i++);
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
// 0xxxxxxx
out += str.charAt(i - 1);
break;
case 12:
case 13:
// 110x xxxx 10xx xxxx
char2 = str.charCodeAt(i++);
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = str.charCodeAt(i++);
char3 = str.charCodeAt(i++);
out += String.fromCharCode(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
}
}
return out;
},
}
}
</script>

2606
jsFile/qrcode.js Normal file

File diff suppressed because it is too large Load Diff