first
This commit is contained in:
62
commons/utils/unionScan.js
Normal file
62
commons/utils/unionScan.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 统一扫码, 支持登录、 码牌绑定、 打印机、 等
|
||||
*
|
||||
* @author terrfly
|
||||
* @site https://www.jeepay.vip
|
||||
* @date 2022/11/22 10:38
|
||||
*/
|
||||
|
||||
import { $parseQrCodeUrl } from '@/http/apiManager.js'
|
||||
|
||||
const model = {
|
||||
|
||||
// 扫码结果类型
|
||||
QR_TYPE_LOGIN: 'QR_TYPE_LOGIN', // 登录
|
||||
QR_TYPE_QRC: 'QR_TYPE_QRC', // 码牌
|
||||
QR_TYPE_PRINTER: 'QR_TYPE_PRINTER', // 打印机
|
||||
QR_TYPE_OTHER: 'QR_TYPE_OTHER', // 其他
|
||||
|
||||
|
||||
returnFunc: (type, bizValue, originQrVal) => {
|
||||
return { type: type, bizValue: bizValue, originQrVal: originQrVal}
|
||||
},
|
||||
|
||||
// 解析 码牌
|
||||
parseQrc: (originQrVal) => {
|
||||
return $parseQrCodeUrl(originQrVal).then( ({bizData}) => {
|
||||
return model.returnFunc(model.QR_TYPE_QRC, bizData, originQrVal)
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
// 返回 类型 和 扫码的值
|
||||
// 参数: 是否解析qrc , 默认不解析
|
||||
scan: (isParseQRC = false) => {
|
||||
|
||||
return uni.scanCode().then(({ result }) => {
|
||||
|
||||
// 登录类型
|
||||
if(result.startsWith("JEEPAY_LOGIN_QR_")){
|
||||
return model.returnFunc(model.QR_TYPE_LOGIN, result.substring(16), result)
|
||||
}
|
||||
|
||||
|
||||
if(isParseQRC){
|
||||
return model.parseQrc(result).then( (res) => {
|
||||
return res;
|
||||
}).catch(() => {
|
||||
return model.returnFunc(model.QR_TYPE_OTHER, result, result)
|
||||
})
|
||||
}else{
|
||||
|
||||
return model.returnFunc(model.QR_TYPE_OTHER, result, result)
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default model
|
||||
|
||||
Reference in New Issue
Block a user