TabBar.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="placeholder safe-area" v-if="placeholder && fixed"></view>
  3. <view class="tab-bar-wrap safe-area" :style="[getTabBarWrapStyle]">
  4. <view class="tab-bar">
  5. <!-- 左侧:首页 -->
  6. <view class="menu" @click="go(menus[0].link)">
  7. <image v-if="getPath === menus[0].link" :src="getFileUrl(menus[0].img)" mode="aspectFill"></image>
  8. <image v-else :src="getFileUrl(menus[0].imgon)" mode="aspectFill"></image>
  9. <view class="text" :class="{ sele: getPath === menus[0].link }">{{ menus[0].title }}</view>
  10. </view>
  11. <!-- 中间:扫码点餐 - 点击先调起微信扫一扫 -->
  12. <view class="menu-center" @click="handleScanOrder">
  13. <view class="scan-btn">
  14. <image :src="getFileUrl(menus[1].img)" mode="aspectFill"></image>
  15. </view>
  16. <image :src="getFileUrl(menus[1].imgon)" mode="heightFix" class="qrT-img"></image>
  17. </view>
  18. <!-- 右侧:我的 -->
  19. <view class="menu" @click="go(menus[2].link)">
  20. <image v-if="getPath === menus[2].link" :src="getFileUrl(menus[2].img)" mode="aspectFill"></image>
  21. <image v-else :src="getFileUrl(menus[2].imgon)" mode="aspectFill"></image>
  22. <view class="text" :class="{ sele: getPath === menus[2].link }">{{ menus[2].title }}</view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script setup>
  28. import { computed, unref } from 'vue';
  29. import { getFileUrl } from '@/utils/file.js';
  30. import { SCAN_QR_CACHE } from '@/settings/enums.js';
  31. import { parseQrScanResult, isScanEntryAllowed } from '@/utils/qrScene.js';
  32. import { syncM2GenericPricingStorage } from '@/utils/m2GenericApiPath.js';
  33. import { useUserStore } from '@/store/user.js';
  34. import { TOKEN } from '@/settings/enums.js';
  35. import { runTableDiningStatusAndRedirect } from '@/utils/tableDiningLaunch.js';
  36. const menus = [
  37. { title: '首页', link: '/pages/index/index', img: 'img/tabbar/index1.png', imgon: 'img/tabbar/index2.png' },
  38. { title: '扫码点餐', link: '/pages/numberOfDiners/index', img: 'img/tabbar/qr2.png', imgon: 'img/tabbar/qr.png' },
  39. { title: '我的', link: '/pages/personal/index', img: 'img/tabbar/personal1.png', imgon: 'img/tabbar/personal2.png' }
  40. ];
  41. const props = defineProps({
  42. placeholder: { type: Boolean, default: false }, // 是否显示占位
  43. fixed: { type: Boolean, default: true } // 是否定位
  44. });
  45. const getTabBarWrapStyle = computed(() => ({
  46. position: props.fixed ? 'fixed' : 'relative'
  47. }));
  48. // 点击扫码点餐:未登录提示请登录;已登录扫码后跳转点餐页(m=1 或无 m 为美食,走 dining)
  49. function handleScanOrder() {
  50. const userStore = useUserStore();
  51. const token = userStore.getToken || uni.getStorageSync(TOKEN) || '';
  52. if (!token) {
  53. uni.showToast({ title: '请登录', icon: 'none' });
  54. return;
  55. }
  56. uni.scanCode({
  57. scanType: ['wxCode', 'qrCode', 'barCode'],
  58. success: async (res) => {
  59. const result = (res?.path || res?.result || '').trim();
  60. const { storeId, tableId, m } = parseQrScanResult(result);
  61. const payload = { raw: result, storeId, tableId, m };
  62. uni.setStorageSync(SCAN_QR_CACHE, JSON.stringify(payload));
  63. syncM2GenericPricingStorage(m);
  64. if (!isScanEntryAllowed(m)) {
  65. uni.showToast({ title: '请扫描正确的点餐二维码', icon: 'none' });
  66. return;
  67. }
  68. if (storeId) uni.setStorageSync('currentStoreId', storeId);
  69. if (tableId) uni.setStorageSync('currentTableId', tableId);
  70. if (!tableId) {
  71. uni.showToast({ title: '未识别到桌号,请扫描正确的桌号二维码', icon: 'none' });
  72. return;
  73. }
  74. uni.showLoading({ title: '加载中...', mask: true });
  75. try {
  76. await runTableDiningStatusAndRedirect(tableId);
  77. } finally {
  78. uni.hideLoading();
  79. }
  80. },
  81. fail: (err) => {
  82. const msg = err?.errMsg || '';
  83. if (msg && !msg.includes('cancel')) {
  84. if (msg.includes('auth') || msg.includes('camera') || msg.includes('scope')) {
  85. uni.showModal({
  86. title: '提示',
  87. content: '需要相机权限才能扫码,请在设置中开启',
  88. confirmText: '去设置',
  89. success: (res) => {
  90. if (res.confirm) uni.openSetting();
  91. }
  92. });
  93. } else {
  94. uni.showToast({ title: msg || '扫码失败', icon: 'none' });
  95. }
  96. }
  97. }
  98. });
  99. }
  100. // 底部 tabBar 跳转(需在 pages.json 中配置 tabBar.list)
  101. function go(url) {
  102. if (url === unref(getPath)) return;
  103. uni.switchTab({ url });
  104. }
  105. const getPath = computed(() => {
  106. const pages = getCurrentPages(); // 获取路由栈
  107. console.log('/' + pages[pages.length - 1].route);
  108. return '/' + pages[pages.length - 1].route;
  109. });
  110. </script>
  111. <style lang="scss" scoped>
  112. .placeholder {
  113. height: 140rpx;
  114. box-sizing: content-box;
  115. }
  116. .tab-bar-wrap {
  117. position: fixed;
  118. left: 0;
  119. right: 0;
  120. bottom: 0;
  121. z-index: 99;
  122. background-color: #ffffff;
  123. box-shadow: 0 -2rpx 16rpx 0 rgba(0, 0, 0, 0.08);
  124. .tab-bar {
  125. // padding: 16rpx 0;
  126. // padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
  127. display: flex;
  128. align-items: flex-end;
  129. justify-content: space-around;
  130. position: relative;
  131. padding-top: 20rpx;
  132. .menu {
  133. display: flex;
  134. flex-direction: column;
  135. align-items: center;
  136. justify-content: center;
  137. flex: 1;
  138. padding: 0 40rpx;
  139. padding-bottom: 0;
  140. transition: all 0.3s ease;
  141. image {
  142. width: 48rpx;
  143. height: 48rpx;
  144. transition: transform 0.3s ease;
  145. }
  146. .text {
  147. font-size: 22rpx;
  148. color: #999999;
  149. margin-top: 8rpx;
  150. transition: all 0.3s ease;
  151. font-weight: 400;
  152. }
  153. .text.sele {
  154. color: #333333;
  155. font-weight: 500;
  156. }
  157. &:active {
  158. opacity: 0.7;
  159. transform: scale(0.95);
  160. }
  161. }
  162. .menu-center {
  163. display: flex;
  164. flex-direction: column;
  165. align-items: center;
  166. justify-content: center;
  167. position: absolute;
  168. bottom: -20rpx;
  169. margin: 0 40rpx;
  170. // transform: translateY(-35rpx);
  171. transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  172. background-color: #fff;
  173. border-radius: 50%;
  174. padding: 20rpx;
  175. .scan-btn {
  176. width: 110rpx;
  177. height: 110rpx;
  178. border-radius: 50%;
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. margin-bottom: 6rpx;
  183. position: relative;
  184. transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  185. background: linear-gradient(35deg, #FCB73F 0%, #FC733D 100%);
  186. box-shadow: 0rpx 0rpx 11rpx 0rpx rgba(0, 0, 0, 0.16);
  187. image {
  188. width: 42rpx;
  189. height: 42rpx;
  190. filter: brightness(0) invert(1);
  191. transition: transform 0.3s ease;
  192. margin-bottom: 20rpx;
  193. }
  194. }
  195. .qrT-img {
  196. width: 85rpx;
  197. height: 22rpx;
  198. position: absolute;
  199. bottom: 36rpx;
  200. left: 50%;
  201. transform: translateX(-50%);
  202. }
  203. .text-center {
  204. font-size: 22rpx;
  205. color: #ff8844;
  206. margin-top: 4rpx;
  207. font-weight: 500;
  208. transition: all 0.3s ease;
  209. }
  210. &:active {
  211. transform: translateY(-35rpx) scale(0.92);
  212. .scan-btn {
  213. box-shadow: 0 4rpx 16rpx 0 rgba(255, 136, 68, 0.3),
  214. 0 1rpx 4rpx 0 rgba(255, 136, 68, 0.15);
  215. image {
  216. transform: scale(0.9);
  217. }
  218. }
  219. }
  220. }
  221. }
  222. }
  223. </style>