|
@@ -134,31 +134,56 @@ function handleScanOrder() {
|
|
|
uni.showToast({ title: '请登录', icon: 'none' });
|
|
uni.showToast({ title: '请登录', icon: 'none' });
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- uni.scanCode({
|
|
|
|
|
- scanType: ['qrCode'],
|
|
|
|
|
- success: (res) => {
|
|
|
|
|
- // 普通二维码用 result;小程序码用 path(含 scene)
|
|
|
|
|
- const result = (res?.path || res?.result || '').trim();
|
|
|
|
|
- const { storeId, tableId } = parseScanResult(result);
|
|
|
|
|
- if (!tableId) {
|
|
|
|
|
- console.warn('[扫码] 未解析到桌号,原始内容:', result, '解析结果:', { storeId, tableId });
|
|
|
|
|
- }
|
|
|
|
|
- const payload = { raw: result, storeId, tableId };
|
|
|
|
|
- uni.setStorageSync(SCAN_QR_CACHE, JSON.stringify(payload));
|
|
|
|
|
- if (storeId) uni.setStorageSync('currentStoreId', storeId);
|
|
|
|
|
- if (tableId) uni.setStorageSync('currentTableId', tableId);
|
|
|
|
|
- const diners = uni.getStorageSync('currentDiners') || '1';
|
|
|
|
|
- uni.setStorageSync('currentDiners', diners);
|
|
|
|
|
- uni.reLaunch({
|
|
|
|
|
- url: `/pages/orderFood/index?tableid=${encodeURIComponent(tableId || '')}&diners=${encodeURIComponent(diners)}`
|
|
|
|
|
|
|
+ // scanCode 真机需相机权限,先申请再扫码
|
|
|
|
|
+ uni.authorize({
|
|
|
|
|
+ scope: 'scope.camera',
|
|
|
|
|
+ success: () => runScan(),
|
|
|
|
|
+ fail: () => {
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title: '提示',
|
|
|
|
|
+ content: '需要相机权限才能扫描桌号二维码,请在设置中开启',
|
|
|
|
|
+ confirmText: '去设置',
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ uni.openSetting({
|
|
|
|
|
+ success: (settingRes) => {
|
|
|
|
|
+ if (settingRes?.authSetting?.['scope.camera']) runScan();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
- },
|
|
|
|
|
- fail: (err) => {
|
|
|
|
|
- if (err?.errMsg && !String(err.errMsg).includes('cancel')) {
|
|
|
|
|
- uni.showToast({ title: '扫码失败', icon: 'none' });
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ function runScan() {
|
|
|
|
|
+ uni.scanCode({
|
|
|
|
|
+ scanType: ['qrCode', 'barCode'],
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ const result = (res?.path || res?.result || '').trim();
|
|
|
|
|
+ const { storeId, tableId } = parseScanResult(result);
|
|
|
|
|
+ const payload = { raw: result, storeId, tableId };
|
|
|
|
|
+ uni.setStorageSync(SCAN_QR_CACHE, JSON.stringify(payload));
|
|
|
|
|
+ if (storeId) uni.setStorageSync('currentStoreId', storeId);
|
|
|
|
|
+ if (tableId) uni.setStorageSync('currentTableId', tableId);
|
|
|
|
|
+ const diners = uni.getStorageSync('currentDiners') || '1';
|
|
|
|
|
+ uni.setStorageSync('currentDiners', diners);
|
|
|
|
|
+ if (!tableId) {
|
|
|
|
|
+ uni.showToast({ title: '未识别到桌号,请扫描正确的桌号二维码', icon: 'none' });
|
|
|
|
|
+ console.warn('[扫码] 未解析到桌号,原始内容:', result);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ uni.reLaunch({
|
|
|
|
|
+ url: `/pages/orderFood/index?tableid=${encodeURIComponent(tableId)}&diners=${encodeURIComponent(diners)}`
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (err) => {
|
|
|
|
|
+ if (err?.errMsg && !String(err.errMsg).includes('cancel')) {
|
|
|
|
|
+ uni.showToast({ title: err?.errMsg || '扫码失败', icon: 'none' });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 底部 tabBar 跳转(需在 pages.json 中配置 tabBar.list)
|
|
// 底部 tabBar 跳转(需在 pages.json 中配置 tabBar.list)
|