import { USE_M2_GENERIC_PRICING_API } from '@/settings/enums.js'; /** 与 qrScene 一致:m=2 为通用价目扫码 */ export function isGenericPricingM2(m) { const s = String(m ?? '').trim(); if (s === '2') return true; const n = Number(s); return !Number.isNaN(n) && n === 2; } export function syncM2GenericPricingStorage(m) { try { uni.setStorageSync(USE_M2_GENERIC_PRICING_API, isGenericPricingM2(m) ? '1' : '0'); } catch (_) {} } export function isM2GenericPricingApiActive() { try { return uni.getStorageSync(USE_M2_GENERIC_PRICING_API) === '1'; } catch (_) { return false; } } /** * 仅改写文档 4.1 点餐域、4.2 购物车/下单/SSE;其余 URL 不变。 * @param {string} fullUrl path 可含 query */ export function rewriteM2DocumentedApiPath(fullUrl) { if (!fullUrl || typeof fullUrl !== 'string' || !isM2GenericPricingApiActive()) return fullUrl; const qIndex = fullUrl.indexOf('?'); const path = qIndex >= 0 ? fullUrl.slice(0, qIndex) : fullUrl; const query = qIndex >= 0 ? fullUrl.slice(qIndex) : ''; // 4.2 订单域:/store/order/cart*、create、sse if (path.startsWith('/store/order/cart')) { return path.replace(/^\/store\/order\/cart/, '/store/generic-order/cart') + query; } if (path === '/store/order/create') { return '/store/generic-order/create' + query; } if (path.startsWith('/store/order/sse/')) { return path.replace(/^\/store\/order\/sse\//, '/store/generic-order/sse/') + query; } // 4.1 点餐域:白名单路径 /store/dining/ -> /store/generic-dining/ if (!path.startsWith('/store/dining/')) return fullUrl; const rest = path.slice('/store/dining/'.length); const allowed = rest === 'page-info' || rest === 'search' || rest === 'cuisines' || rest.startsWith('cuisine/') || rest === 'order/confirm' || rest === 'coupons/available' || rest === 'coupon/receive' || rest === 'order/lock' || rest === 'order/unlock' || rest === 'order/check-lock' || rest === 'order/settlement' || rest === 'order/settlement/lock' || rest === 'order/settlement/unlock'; if (!allowed) return fullUrl; return `/store/generic-dining/${rest}${query}`; }