| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /**
- * 扫码/太阳码进入后:调桌位就餐状态并 reLaunch 到点餐或选人数页。
- * 供 launch、首页(太阳码直达首页)、TabBar 等共用。
- */
- import * as diningApi from '@/api/dining.js';
- import { parseSceneToStoreTable, isScanEntryAllowed } from '@/utils/qrScene.js';
- function trim(v) {
- return v == null ? '' : String(v).trim();
- }
- function tryDecodeURIComponent(s) {
- if (s == null || s === '') return '';
- try {
- return decodeURIComponent(String(s).trim());
- } catch (_) {
- return String(s).trim();
- }
- }
- /**
- * 从页面 onLoad 参数解析 tableId、storeId、m(与 pages/launch 一致;兼容 query 嵌套与平铺)
- */
- export function getScanEntryIdsFromOptions(options) {
- if (!options || typeof options !== 'object') return { tableid: '', storeId: '', m: '' };
- const flat = { ...options, ...(options.query && typeof options.query === 'object' ? options.query : {}) };
- let m = trim(flat.m ?? flat.mode ?? '');
- const directTable =
- flat.tableId ?? flat.tableid ?? flat.table_id ?? flat.t ?? '';
- if (directTable) {
- const directStore = flat.storeId ?? flat.storeid ?? flat.s ?? '';
- return { tableid: String(directTable).trim(), storeId: String(directStore || '').trim(), m };
- }
- const sceneEnc = flat.scene ?? flat.q ?? '';
- const scene = sceneEnc ? tryDecodeURIComponent(sceneEnc) : '';
- if (scene) {
- const { storeId: s, tableId: t, m: sm } = parseSceneToStoreTable(scene);
- return { tableid: trim(t), storeId: trim(s), m: m || trim(sm) || '' };
- }
- return { tableid: '', storeId: '', m };
- }
- /**
- * 查询 /store/dining/table-dining-status 后跳转(与 launch 页逻辑一致)
- * @param {string} tableidResolved 桌台主键 id
- */
- export async function runTableDiningStatusAndRedirect(tableidResolved) {
- const tid = trim(tableidResolved);
- if (!tid) {
- uni.reLaunch({ url: '/pages/index/index' });
- return;
- }
- try {
- const res = await diningApi.GetTableDiningStatus(tid);
- const raw = res && typeof res === 'object' ? res : {};
- const inDining =
- res === true ||
- res === 'true' ||
- raw?.inDining === true ||
- raw?.inDining === 'true' ||
- raw?.data?.inDining === true ||
- raw?.data?.inDining === 'true';
- const dinerCount =
- raw?.dinerCount ??
- raw?.diner ??
- raw?.data?.dinerCount ??
- raw?.data?.diner ??
- uni.getStorageSync('currentDiners') ??
- 1;
- const dinersStr = String(dinerCount);
- if (inDining) {
- uni.setStorageSync('currentDiners', dinersStr);
- uni.reLaunch({
- url: `/pages/orderFood/index?tableid=${encodeURIComponent(tid)}&diners=${encodeURIComponent(dinersStr)}`
- });
- } else {
- uni.reLaunch({
- url: `/pages/numberOfDiners/index?inDining=1&tableid=${encodeURIComponent(tid)}&diners=${encodeURIComponent(dinersStr)}`
- });
- }
- } catch (err) {
- console.warn('[tableDiningLaunch] 查询桌位就餐状态失败,进入选择人数页', err);
- const fallbackDiners = uni.getStorageSync('currentDiners') || '1';
- uni.reLaunch({
- url: `/pages/numberOfDiners/index?inDining=1&tableid=${encodeURIComponent(tid)}&diners=${encodeURIComponent(fallbackDiners)}`
- });
- }
- }
|