...
|
...
|
@@ -11,7 +11,7 @@ const { |
|
|
JUMP_WITH_URL,
|
|
|
SET_SCANTYPE,
|
|
|
JUMP_WITH_OBJECT_NEWFLAG,
|
|
|
PROCESS_SCAN_STRING,
|
|
|
UPDATE_ALERT_INFO,
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
let showTip = false;
|
...
|
...
|
@@ -43,64 +43,116 @@ function showAlert(title = '二维码扫描', message1, message2, confirmInfo = |
|
|
function scanSkn(scanString) {
|
|
|
let strs= new Array();
|
|
|
strs = scanString.split(":");
|
|
|
let sknAlertInfo = {
|
|
|
show: true,
|
|
|
title:'二维码扫描',
|
|
|
message1: '商品skn无法识别:',
|
|
|
message2: scanString,
|
|
|
confirmInfo: '确定',
|
|
|
};
|
|
|
if (strs.length < 2) {
|
|
|
showAlert('二维码扫描','商品skn无法识别:', scanString,);
|
|
|
return false;
|
|
|
return sknAlertInfo;
|
|
|
}
|
|
|
let sknID = strs[1];
|
|
|
if (sknID === '') {
|
|
|
showAlert('二维码扫描','商品skn无法识别:', scanString,);
|
|
|
return;
|
|
|
return sknAlertInfo;
|
|
|
}
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithUrl(sknID, ScanTypeInfo.YHScanType_Skn);
|
|
|
return true;
|
|
|
return {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: '',
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function scanBear(scanString) {
|
|
|
let strs= new Array();
|
|
|
let bearAlertInfo = {
|
|
|
show: true,
|
|
|
title:'二维码扫描',
|
|
|
message1: '小熊二维码无法识别:',
|
|
|
message2: {scanString},
|
|
|
confirmInfo: '确定',
|
|
|
};
|
|
|
strs = scanString.split(":");
|
|
|
if (strs.length < 2) {
|
|
|
showAlert('二维码扫描','小熊二维码无法识别:', scanString,);
|
|
|
return false;
|
|
|
return bearAlertInfo;
|
|
|
}
|
|
|
let bearID = strs[1];
|
|
|
if (bearID === '') {
|
|
|
showAlert('二维码扫描','小熊二维码无法识别:', scanString,);
|
|
|
return false;
|
|
|
return bearAlertInfo;
|
|
|
}
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithUrl(bearID, ScanTypeInfo.YHScanType_Bear);
|
|
|
return true;
|
|
|
return {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: '',
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function scanBooth(scanString) {
|
|
|
let strs= new Array();
|
|
|
strs = scanString.split(":");
|
|
|
let boothAlertInfo = {
|
|
|
show: true,
|
|
|
title:'二维码扫描',
|
|
|
message1: '品牌店铺号无法识别:',
|
|
|
message2: scanString,
|
|
|
confirmInfo: '确定',
|
|
|
};
|
|
|
if (strs.length < 2) {
|
|
|
showAlert('二维码扫描','品牌店铺号无法识别:', scanString,);
|
|
|
return false;
|
|
|
return boothAlertInfo;
|
|
|
}
|
|
|
let boothID = strs[1];
|
|
|
if (boothID === '') {
|
|
|
showAlert('二维码扫描','品牌店铺号无法识别:', scanString,);
|
|
|
return false;
|
|
|
return boothAlertInfo;
|
|
|
}
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithUrl(boothID, ScanTypeInfo.YHScanType_Booth);
|
|
|
return true;
|
|
|
return {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: '',
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function scanExpress(expressString) {
|
|
|
let expressAlertInfo = {
|
|
|
show: true,
|
|
|
title:'二维码扫描',
|
|
|
message1: '快递单号无法识别:',
|
|
|
message2: expressString,
|
|
|
confirmInfo: '确定',
|
|
|
};
|
|
|
if (scanString === '') {
|
|
|
showAlert('二维码扫描','快递单号无法识别:', expressString,);
|
|
|
return false;
|
|
|
return expressAlertInfo;
|
|
|
}
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithUrl(expressString, ScanTypeInfo.YHScanType_Express);
|
|
|
return true;
|
|
|
return {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: '',
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function scanYohoBuy(scanString) {
|
|
|
let dataString = '';
|
|
|
let isNew = false;
|
|
|
let strs= new Array();
|
|
|
let yohoBuyAlertInfo = {
|
|
|
show: true,
|
|
|
title:'二维码扫描',
|
|
|
message1: '',
|
|
|
message2: scanString,
|
|
|
confirmInfo: '确定',
|
|
|
};
|
|
|
if (scanString.indexOf('yohobuy:') !== -1) {
|
|
|
strs = scanString.split("yohobuy:");
|
|
|
if (strs.length == 1) {
|
...
|
...
|
@@ -127,15 +179,26 @@ function scanYohoBuy(scanString) { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
var obj = JSON.parse(dataString); //由JSON字符串转换为JSON对象
|
|
|
var obj;
|
|
|
try {
|
|
|
obj = JSON.parse(dataString); //由JSON字符串转换为JSON对象
|
|
|
} catch(err) {
|
|
|
return yohoBuyAlertInfo;
|
|
|
}
|
|
|
console.log(obj);
|
|
|
if (!obj) {
|
|
|
showAlert('二维码扫描','', dataString,);
|
|
|
return false;
|
|
|
return yohoBuyAlertInfo;
|
|
|
} else {
|
|
|
//回传
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithObjectNewFlag(obj, isNew);
|
|
|
}
|
|
|
return true;
|
|
|
return {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: '',
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function handleUrlForSknId(scanString) {
|
...
|
...
|
@@ -195,14 +258,26 @@ function scanAddressLink (scanString) { |
|
|
let sknId = handleUrlForSknId(scanString);
|
|
|
if (sknId !== '') {
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithUrl(sknId, ScanTypeInfo.YHScanType_Skn);
|
|
|
return true;
|
|
|
return {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: scanString,
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
}
|
|
|
|
|
|
//判断yoho 品牌链接二维码
|
|
|
let brandId = handleUrlForBrandId(scanString);
|
|
|
if (brandId !== '') {
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithUrl(brandId, ScanTypeInfo.YHScanType_Brand);
|
|
|
return true;
|
|
|
return {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: scanString,
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
}
|
|
|
|
|
|
//判断PC登录二维码
|
...
|
...
|
@@ -212,18 +287,22 @@ function scanAddressLink (scanString) { |
|
|
if (!isConnected) {
|
|
|
if (!showTip) {
|
|
|
showTip = true;
|
|
|
Alert.alert('提示', '无网络连接,刷新试试', [
|
|
|
{text: '取消', onPress: () => {
|
|
|
showTip = false;
|
|
|
}},
|
|
|
{text: '刷新', onPress: () => {
|
|
|
showTip = false;
|
|
|
}}
|
|
|
]);
|
|
|
return false;
|
|
|
return {
|
|
|
show: true,
|
|
|
title:'提示',
|
|
|
message1: '无网络连接,刷新试试',
|
|
|
message2: '',
|
|
|
confirmInfo: '取消',
|
|
|
};;
|
|
|
};
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithUrl(pcLoginCode, ScanTypeInfo.YHScanType_PCLogin);
|
|
|
return true;
|
|
|
return {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: '',
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
}
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -231,51 +310,80 @@ function scanAddressLink (scanString) { |
|
|
//扫描信息全局变量
|
|
|
let scanQRString = scanComonURL(scanString);
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithUrl(scanQRString, ScanTypeInfo.YHScanType_CommonUrl);
|
|
|
return true;
|
|
|
return {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: '',
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
function processScanString(url,scanType) {
|
|
|
let prefixRegex = '^skn:|^booth:|^bear:|^yohobuy:|^yohobuy=|^http://|^https://';
|
|
|
let isHasPrefix = url.match(prefixRegex);//prefixRegex.search(url);
|
|
|
let alertInfo = {
|
|
|
show: false,
|
|
|
title:'',
|
|
|
message1: '',
|
|
|
message2: '',
|
|
|
confirmInfo: '',
|
|
|
};
|
|
|
if(isHasPrefix === -1 && scanType !== 4 && !showTip){
|
|
|
showAlert('二维码扫描','无法识别的二维码:', url,);
|
|
|
return false;
|
|
|
alertInfo = {
|
|
|
show: true,
|
|
|
title:'二维码扫描',
|
|
|
message1: '无法识别的二维码:',
|
|
|
message2: url,
|
|
|
confirmInfo: '确定',
|
|
|
};
|
|
|
};
|
|
|
|
|
|
switch (scanType) {
|
|
|
case ScanTypeInfo.YHScanType_Skn://YHScanType_Skn
|
|
|
scanSkn(url);
|
|
|
alertInfo = scanSkn(url);
|
|
|
break;
|
|
|
case ScanTypeInfo.YHScanType_Bear:
|
|
|
scanBear(url);
|
|
|
alertInfo =scanBear(url);
|
|
|
break;
|
|
|
case ScanTypeInfo.YHScanType_Booth:
|
|
|
scanBooth(url);
|
|
|
alertInfo = scanBooth(url);
|
|
|
break;
|
|
|
case ScanTypeInfo.YHScanType_Express:
|
|
|
scanExpress(url);
|
|
|
alertInfo = scanExpress(url);
|
|
|
break;
|
|
|
case ScanTypeInfo.YHScanType_Default: {
|
|
|
if (url.indexOf('skn:') !== -1) {
|
|
|
scanSkn(url);
|
|
|
console.log('skn');
|
|
|
alertInfo = scanSkn(url);
|
|
|
} else if (url.indexOf('booth:') !== -1) {
|
|
|
scanBooth(url);
|
|
|
console.log('booth');
|
|
|
alertInfo = scanBooth(url);
|
|
|
} else if (url.indexOf('bear:') !== -1) {
|
|
|
scanBear(url);
|
|
|
} else if (url.indexOf('yohobuy:') !== -1 || url.indexOf('yohobuy=') !== -1) {
|
|
|
scanYohoBuy(url);
|
|
|
console.log('bear');
|
|
|
alertInfo = scanBear(url);
|
|
|
} else if (url.indexOf('yohobuy:') !== -1 || url.indexOf('yohobuy=') !== -1 || url.indexOf('yohobuy=') !== -1) {
|
|
|
console.log('yohobuy');
|
|
|
alertInfo = scanYohoBuy(url);
|
|
|
} else if (url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1) {
|
|
|
scanAddressLink(url);
|
|
|
console.log('http&s');
|
|
|
alertInfo = scanAddressLink(url);
|
|
|
} else {
|
|
|
showAlert('二维码扫描','无法识别的二维码:', url,);
|
|
|
return false;
|
|
|
alertInfo = {
|
|
|
show: true,
|
|
|
title:'二维码扫描',
|
|
|
message1: '无法识别的二维码:',
|
|
|
message2: url,
|
|
|
confirmInfo: '确定',
|
|
|
};
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
|
|
|
}
|
|
|
return alertInfo;
|
|
|
};
|
|
|
|
|
|
export function setScanType(scanType) {
|
...
|
...
|
@@ -285,6 +393,13 @@ export function setScanType(scanType) { |
|
|
};
|
|
|
}
|
|
|
|
|
|
export function updateAlertInfo(info) {
|
|
|
return {
|
|
|
type: UPDATE_ALERT_INFO,
|
|
|
payload: info,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function processURL(scanString) {
|
|
|
return (dispatch, getState) => {
|
|
|
|
...
|
...
|
@@ -292,21 +407,15 @@ export function processURL(scanString) { |
|
|
if(!scanString) {
|
|
|
return;
|
|
|
}
|
|
|
let useableScanString = processScanString(scanString,qrcode.scanType);
|
|
|
if (useableScanString) {
|
|
|
return;
|
|
|
}
|
|
|
dispatch({
|
|
|
type: PROCESS_SCAN_STRING,
|
|
|
payload: useableScanString
|
|
|
});
|
|
|
let alertInfo = processScanString(scanString,qrcode.scanType);
|
|
|
dispatch(updateAlertInfo(alertInfo));
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
export function jumpWithUrl(url, JumpType) {
|
|
|
if (!url) {
|
|
|
__DEV__ && console.log('Illegal url');
|
|
|
console.log('Illegal url');
|
|
|
return;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -316,16 +425,3 @@ export function jumpWithUrl(url, JumpType) { |
|
|
payload: url
|
|
|
};
|
|
|
} |
|
|
|
|
|
export function jumpWithObjectNewFlag(jsonObj, isNew) {
|
|
|
if (!url) {
|
|
|
__DEV__ && console.log('Illegal object');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_QRCodeHelper.jumpWithObjectNewFlag({jsonObj, isNew});
|
|
|
return {
|
|
|
type: JUMP_WITH_OBJECT_NEWFLAG,
|
|
|
payload: url
|
|
|
};
|
|
|
} |
...
|
...
|
|