index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 * as diningApi from '@/api/dining.js';
  10. import { useUserStore } from '@/store/user.js';
  11. const userStore = useUserStore();
  12. async function doRedirect() {
  13. const tableid = uni.getStorageSync('currentTableId') || '';
  14. if (!tableid) {
  15. uni.reLaunch({ url: '/pages/index/index' });
  16. return;
  17. }
  18. try {
  19. const res = await diningApi.GetTableDiningStatus(tableid);
  20. const raw = (res && typeof res === 'object') ? res : {};
  21. const inDining =
  22. raw?.inDining === true ||
  23. raw?.inDining === 'true' ||
  24. raw?.data?.inDining === true ||
  25. raw?.data?.inDining === 'true';
  26. const dinerCount =
  27. raw?.dinerCount ?? raw?.diner ?? raw?.data?.dinerCount ?? raw?.data?.diner ?? uni.getStorageSync('currentDiners') ?? 1;
  28. if (inDining) {
  29. uni.setStorageSync('currentDiners', dinerCount);
  30. if (!userStore.getToken) {
  31. uni.reLaunch({
  32. url: `/pages/numberOfDiners/index?inDining=1&tableid=${encodeURIComponent(tableid)}&diners=${encodeURIComponent(dinerCount)}`
  33. });
  34. return;
  35. }
  36. uni.reLaunch({
  37. url: `/pages/orderFood/index?tableid=${encodeURIComponent(tableid)}&diners=${encodeURIComponent(dinerCount)}`
  38. });
  39. return;
  40. }
  41. uni.reLaunch({ url: '/pages/numberOfDiners/index' });
  42. } catch (err) {
  43. console.warn('查询桌位就餐状态失败,进入选择人数页', err);
  44. uni.reLaunch({ url: '/pages/numberOfDiners/index' });
  45. }
  46. }
  47. onLoad(() => {
  48. doRedirect();
  49. });
  50. </script>
  51. <style scoped lang="scss">
  52. .launch-wrap {
  53. min-height: 100vh;
  54. display: flex;
  55. align-items: center;
  56. justify-content: center;
  57. background: #f7f9fa;
  58. }
  59. .launch-loading {
  60. font-size: 28rpx;
  61. color: #999;
  62. }
  63. </style>