|
|
@@ -89,17 +89,27 @@ const handleScan = () => {
|
|
|
onlyFromCamera: true,
|
|
|
scanType: ['qrCode', 'barCode'],
|
|
|
success: (res: any) => {
|
|
|
- const result = (res.result || '').trim();
|
|
|
- if (!result) {
|
|
|
- uni.showToast({ title: '未识别到设备ID', icon: 'none' });
|
|
|
+ // 与 haha-mp 一致的 deviceId 提取逻辑
|
|
|
+ let deviceId = '';
|
|
|
+ try {
|
|
|
+ const urlPattern = /\/([A-Z0-9]+)(\?|$)/;
|
|
|
+ const match = res.result.match(urlPattern);
|
|
|
+ if (match && match[1]) {
|
|
|
+ deviceId = match[1];
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ const qrData = JSON.parse(res.result);
|
|
|
+ if (qrData.deviceId) deviceId = qrData.deviceId;
|
|
|
+ } catch (e) {
|
|
|
+ deviceId = res.result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!deviceId) throw new Error('无法解析设备ID');
|
|
|
+ } catch (error) {
|
|
|
+ uni.showToast({ title: '二维码格式错误', icon: 'none' });
|
|
|
return;
|
|
|
}
|
|
|
- // 提取设备ID(支持直接扫描设备SN或URL中的设备ID参数)
|
|
|
- let deviceId = result;
|
|
|
- if (result.includes('deviceId=')) {
|
|
|
- const match = result.match(/deviceId=([^&\s]+)/);
|
|
|
- if (match) deviceId = match[1];
|
|
|
- }
|
|
|
+
|
|
|
uni.showActionSheet({
|
|
|
itemList: ['设备补货', '库存盘点'],
|
|
|
success: (sheetRes) => {
|