index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <!-- 启动页:根据 table-dining-status 接口结果跳转,避免先展示错误页面 -->
  3. <view class="launch-wrap">
  4. <view class="launch-loading">正在加载...</view>
  5. </view>
  6. </template>
  7. <script setup>
  8. import { onLoad } from '@dcloudio/uni-app';
  9. import { isScanEntryAllowed } from '@/utils/qrScene.js';
  10. import { SCAN_QR_CACHE } from '@/settings/enums.js';
  11. import { syncM2GenericPricingStorage } from '@/utils/m2GenericApiPath.js';
  12. import {
  13. getScanEntryIdsFromOptions,
  14. runTableDiningStatusAndRedirect,
  15. trim
  16. } from '@/utils/tableDiningLaunch.js';
  17. async function doRedirect(options = {}) {
  18. let { tableid, storeId: optStore, m } = getScanEntryIdsFromOptions(options);
  19. if (trim(m) === '') {
  20. try {
  21. const c = uni.getStorageSync(SCAN_QR_CACHE);
  22. if (c) m = trim(JSON.parse(c).m ?? '');
  23. } catch (_) {}
  24. }
  25. syncM2GenericPricingStorage(m);
  26. if (!isScanEntryAllowed(m)) {
  27. uni.showToast({ title: '请扫描正确的点餐二维码', icon: 'none' });
  28. uni.reLaunch({ url: '/pages/index/index' });
  29. return;
  30. }
  31. /** 本次启动参数里的桌号(新扫太阳码)优先于本地缓存,避免仍用上一桌 */
  32. const fromScan = trim(tableid);
  33. const stored = trim(uni.getStorageSync('currentTableId') || '');
  34. const tableidResolved = fromScan || stored;
  35. if (!tableidResolved) {
  36. console.log('[launch] 无 tableid,跳转首页');
  37. uni.reLaunch({ url: '/pages/index/index' });
  38. return;
  39. }
  40. if (fromScan) {
  41. uni.setStorageSync('currentTableId', tableidResolved);
  42. if (optStore) uni.setStorageSync('currentStoreId', optStore);
  43. } else if (!stored) {
  44. uni.setStorageSync('currentTableId', tableidResolved);
  45. if (optStore) uni.setStorageSync('currentStoreId', optStore);
  46. }
  47. console.log('[launch] 调用 GetTableDiningStatus, tableid:', tableidResolved);
  48. await runTableDiningStatusAndRedirect(tableidResolved);
  49. }
  50. onLoad((options) => {
  51. doRedirect(options);
  52. });
  53. </script>
  54. <style scoped lang="scss">
  55. .launch-wrap {
  56. min-height: 100vh;
  57. display: flex;
  58. align-items: center;
  59. justify-content: center;
  60. background: #f7f9fa;
  61. }
  62. .launch-loading {
  63. font-size: 28rpx;
  64. color: #999;
  65. }
  66. </style>