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