|
@@ -2,6 +2,8 @@
|
|
|
import initConfig from '@/initConfig.js';
|
|
import initConfig from '@/initConfig.js';
|
|
|
// #ifdef MP-WEIXIN
|
|
// #ifdef MP-WEIXIN
|
|
|
import { SCAN_QR_CACHE } from '@/settings/enums.js';
|
|
import { SCAN_QR_CACHE } from '@/settings/enums.js';
|
|
|
|
|
+import * as diningApi from '@/api/dining.js';
|
|
|
|
|
+import { useUserStore } from '@/store/user.js';
|
|
|
// #endif
|
|
// #endif
|
|
|
|
|
|
|
|
/** 从 scene 或 query 中解析:二维码 s=店铺id,t=桌号id */
|
|
/** 从 scene 或 query 中解析:二维码 s=店铺id,t=桌号id */
|
|
@@ -24,6 +26,44 @@ function parseSceneToStoreTable(sceneStr) {
|
|
|
return { storeId, tableId };
|
|
return { storeId, tableId };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 查询桌位就餐状态,若 inDining 为 true 则跳转点餐页或选择人数页(未登录时)
|
|
|
|
|
+ * @param {Object} opts - { fromTabBar: boolean } 来自 TabBar 扫码时,inDining 为 false 需 switchTab 到 numberOfDiners
|
|
|
|
|
+ */
|
|
|
|
|
+async function checkTableDiningStatus(opts = {}) {
|
|
|
|
|
+ const tableid = uni.getStorageSync('currentTableId') || '';
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await diningApi.GetTableDiningStatus(tableid);
|
|
|
|
|
+ const raw = (res && typeof res === 'object') ? res : {};
|
|
|
|
|
+ const inDining =
|
|
|
|
|
+ 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;
|
|
|
|
|
+ if (!inDining) {
|
|
|
|
|
+ if (opts.fromTabBar) uni.switchTab({ url: '/pages/numberOfDiners/index' });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ uni.setStorageSync('currentDiners', dinerCount);
|
|
|
|
|
+ const userStore = useUserStore();
|
|
|
|
|
+ if (!userStore.getToken) {
|
|
|
|
|
+ uni.reLaunch({
|
|
|
|
|
+ url: `/pages/numberOfDiners/index?inDining=1&tableid=${encodeURIComponent(tableid)}&diners=${encodeURIComponent(dinerCount)}`
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ uni.reLaunch({
|
|
|
|
|
+ url: `/pages/orderFood/index?tableid=${encodeURIComponent(tableid)}&diners=${encodeURIComponent(dinerCount)}`
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ console.warn('查询桌位就餐状态失败', err);
|
|
|
|
|
+ if (opts.fromTabBar) uni.switchTab({ url: '/pages/numberOfDiners/index' });
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export default {
|
|
export default {
|
|
|
onLaunch: function (e) {
|
|
onLaunch: function (e) {
|
|
|
// 只有小程序执行
|
|
// 只有小程序执行
|
|
@@ -46,6 +86,8 @@ export default {
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.warn('缓存二维码启动参数失败', err);
|
|
console.warn('缓存二维码启动参数失败', err);
|
|
|
}
|
|
}
|
|
|
|
|
+ // 冷启动时由 pages/launch/index 根据接口结果跳转;TabBar 扫码后由 App 统一调用接口并跳转
|
|
|
|
|
+ uni.$on('checkTableDiningStatus', () => checkTableDiningStatus({ fromTabBar: true }));
|
|
|
// #endif
|
|
// #endif
|
|
|
},
|
|
},
|
|
|
onShow: function (res) {
|
|
onShow: function (res) {
|