CustomTabBar.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view class="custom-tabbar">
  3. <view class="tab-item" :class="{ active: currentIndex === 0 }" @click="switchTab(0)">
  4. <view class="tab-icon">
  5. <view class="icon-work"></view>
  6. </view>
  7. <text class="tab-text">工作台</text>
  8. </view>
  9. <view class="tab-item" :class="{ active: currentIndex === 1 }" @click="switchTab(1)">
  10. <view class="tab-icon">
  11. <view class="icon-order"></view>
  12. </view>
  13. <text class="tab-text">订单</text>
  14. </view>
  15. <view class="scan-zone">
  16. <view class="scan-btn" @click="handleScan">
  17. <view class="scan-icon"></view>
  18. </view>
  19. <text class="scan-label">扫码</text>
  20. </view>
  21. <view class="tab-item" :class="{ active: currentIndex === 2 }" @click="switchTab(2)">
  22. <view class="tab-icon">
  23. <view class="icon-device"></view>
  24. </view>
  25. <text class="tab-text">设备</text>
  26. </view>
  27. <view class="tab-item" :class="{ active: currentIndex === 3 }" @click="switchTab(3)">
  28. <view class="tab-icon">
  29. <view class="icon-my"></view>
  30. </view>
  31. <text class="tab-text">我的</text>
  32. </view>
  33. </view>
  34. </template>
  35. <script setup lang="ts">
  36. import { ref, onMounted } from 'vue';
  37. import { logger } from '@/utils/logger';
  38. const tabPages = [
  39. '/pages/index/index',
  40. '/pages/orders/list',
  41. '/pages/device/list',
  42. '/pages/my/my'
  43. ];
  44. const currentIndex = ref(0);
  45. onMounted(() => {
  46. const pages = getCurrentPages();
  47. const currentPage = pages[pages.length - 1];
  48. const currentPath = '/' + currentPage.route;
  49. const index = tabPages.indexOf(currentPath);
  50. if (index !== -1) {
  51. currentIndex.value = index;
  52. }
  53. });
  54. const switchTab = (index: number) => {
  55. if (currentIndex.value === index) return;
  56. currentIndex.value = index;
  57. uni.switchTab({
  58. url: tabPages[index]
  59. });
  60. };
  61. const handleScan = () => {
  62. uni.scanCode({
  63. scanType: ['qrCode', 'barCode'],
  64. success: (res) => {
  65. logger.log('扫码结果:', res.result);
  66. let deviceId = '';
  67. const urlPattern = /\/([A-Z0-9]+)(\?|$)/;
  68. const match = res.result.match(urlPattern);
  69. if (match && match[1]) {
  70. deviceId = match[1];
  71. } else {
  72. try {
  73. const qrData = JSON.parse(res.result);
  74. deviceId = qrData.deviceId || res.result;
  75. } catch {
  76. deviceId = res.result;
  77. }
  78. }
  79. if (deviceId) {
  80. uni.navigateTo({
  81. url: `/pages/device/detail?id=${deviceId}&mode=stock`
  82. });
  83. } else {
  84. uni.showToast({
  85. title: '无法识别设备',
  86. icon: 'none'
  87. });
  88. }
  89. },
  90. fail: () => {
  91. uni.showToast({
  92. title: '扫码取消',
  93. icon: 'none'
  94. });
  95. }
  96. });
  97. };
  98. </script>
  99. <style lang="scss" scoped>
  100. .custom-tabbar {
  101. position: fixed;
  102. bottom: 0;
  103. left: 0;
  104. right: 0;
  105. height: 100rpx;
  106. background: $bg-color-card;
  107. border-top: 1rpx solid rgba(0, 0, 0, 0.06);
  108. display: flex;
  109. align-items: flex-end;
  110. justify-content: space-around;
  111. padding-bottom: constant(safe-area-inset-bottom);
  112. padding-bottom: env(safe-area-inset-bottom);
  113. z-index: 999;
  114. }
  115. /* ======== Tab 项 ======== */
  116. .tab-item {
  117. display: flex;
  118. flex-direction: column;
  119. align-items: center;
  120. justify-content: center;
  121. flex: 1;
  122. height: 100%;
  123. color: $text-color-muted;
  124. transition: color 0.2s ease;
  125. }
  126. .tab-icon {
  127. width: 44rpx;
  128. height: 44rpx;
  129. display: flex;
  130. align-items: center;
  131. justify-content: center;
  132. position: relative;
  133. margin-bottom: 2rpx;
  134. }
  135. .tab-item.active {
  136. color: $primary-color;
  137. }
  138. .tab-text {
  139. font-size: 20rpx;
  140. font-weight: 400;
  141. line-height: 1.3;
  142. }
  143. .tab-item.active .tab-text {
  144. font-weight: 500;
  145. }
  146. /* ======== 图标:工作台(简约房子) ======== */
  147. .icon-work {
  148. width: 32rpx;
  149. height: 28rpx;
  150. position: relative;
  151. /* 房屋主体 */
  152. &::before {
  153. content: '';
  154. position: absolute;
  155. bottom: 0;
  156. left: 50%;
  157. transform: translateX(-50%);
  158. width: 24rpx;
  159. height: 15rpx;
  160. border: 2rpx solid currentColor;
  161. border-radius: 2rpx 2rpx 3rpx 3rpx;
  162. }
  163. /* 屋顶 — 旋转正方形取上半部 */
  164. &::after {
  165. content: '';
  166. position: absolute;
  167. top: 1rpx;
  168. left: 50%;
  169. transform: translateX(-50%) rotate(45deg);
  170. width: 18rpx;
  171. height: 18rpx;
  172. border-top: 2rpx solid currentColor;
  173. border-left: 2rpx solid currentColor;
  174. border-radius: 2rpx 0 0 0;
  175. }
  176. }
  177. /* ======== 图标:订单(简约票据) ======== */
  178. .icon-order {
  179. width: 26rpx;
  180. height: 30rpx;
  181. border: 2rpx solid currentColor;
  182. border-radius: 4rpx;
  183. position: relative;
  184. /* 折角 */
  185. &::before {
  186. content: '';
  187. position: absolute;
  188. top: -2rpx;
  189. right: -2rpx;
  190. width: 0;
  191. height: 0;
  192. border-left: 7rpx solid transparent;
  193. border-bottom: 7rpx solid currentColor;
  194. border-radius: 0 0 0 2rpx;
  195. }
  196. /* 文字横线 */
  197. &::after {
  198. content: '';
  199. position: absolute;
  200. top: 9rpx;
  201. left: 5rpx;
  202. right: 9rpx;
  203. height: 2rpx;
  204. background: currentColor;
  205. border-radius: 1rpx;
  206. box-shadow: 0 5rpx 0 currentColor, 0 10rpx 0 currentColor;
  207. }
  208. }
  209. /* ======== 图标:设备(简约显示器) ======== */
  210. .icon-device {
  211. width: 32rpx;
  212. height: 28rpx;
  213. position: relative;
  214. /* 屏幕 */
  215. &::before {
  216. content: '';
  217. position: absolute;
  218. top: 0;
  219. left: 50%;
  220. transform: translateX(-50%);
  221. width: 28rpx;
  222. height: 18rpx;
  223. border: 2rpx solid currentColor;
  224. border-radius: 4rpx;
  225. }
  226. /* 底座 */
  227. &::after {
  228. content: '';
  229. position: absolute;
  230. bottom: 0;
  231. left: 50%;
  232. transform: translateX(-50%);
  233. width: 18rpx;
  234. height: 4rpx;
  235. background: currentColor;
  236. border-radius: 0 0 2rpx 2rpx;
  237. }
  238. }
  239. /* ======== 图标:我的(简约人物) ======== */
  240. .icon-my {
  241. width: 28rpx;
  242. height: 32rpx;
  243. position: relative;
  244. /* 头部 */
  245. &::before {
  246. content: '';
  247. position: absolute;
  248. top: 0;
  249. left: 50%;
  250. transform: translateX(-50%);
  251. width: 13rpx;
  252. height: 13rpx;
  253. border: 2rpx solid currentColor;
  254. border-radius: 50%;
  255. }
  256. /* 身体 — 更大的弧线 */
  257. &::after {
  258. content: '';
  259. position: absolute;
  260. bottom: 0;
  261. left: 50%;
  262. transform: translateX(-50%);
  263. width: 26rpx;
  264. height: 12rpx;
  265. border: 2rpx solid currentColor;
  266. border-radius: 14rpx 14rpx 0 0;
  267. border-bottom: none;
  268. }
  269. }
  270. /* ======== 扫码按钮(绝对定位突出) ======== */
  271. .scan-zone {
  272. flex: 1;
  273. position: relative;
  274. display: flex;
  275. flex-direction: column;
  276. align-items: center;
  277. justify-content: flex-end;
  278. height: 100rpx;
  279. }
  280. .scan-btn {
  281. position: absolute;
  282. bottom: 64rpx;
  283. left: 50%;
  284. transform: translateX(-50%);
  285. width: 96rpx;
  286. height: 96rpx;
  287. border-radius: 50%;
  288. background: $primary-color;
  289. display: flex;
  290. align-items: center;
  291. justify-content: center;
  292. box-shadow: 0 6rpx 24rpx rgba(255, 193, 7, 0.45);
  293. transition: transform 0.15s ease, box-shadow 0.15s ease;
  294. &:active {
  295. transform: translateX(-50%) scale(0.93);
  296. box-shadow: 0 3rpx 12rpx rgba(255, 193, 7, 0.35);
  297. }
  298. }
  299. .scan-icon {
  300. width: 40rpx;
  301. height: 40rpx;
  302. position: relative;
  303. /* 四角 L 形:左上 + 右下 */
  304. &::before, &::after {
  305. content: '';
  306. position: absolute;
  307. width: 16rpx;
  308. height: 16rpx;
  309. }
  310. &::before {
  311. top: 0;
  312. left: 0;
  313. border-top: 5rpx solid #ffffff;
  314. border-left: 5rpx solid #ffffff;
  315. border-radius: 4rpx 0 0 0;
  316. }
  317. &::after {
  318. bottom: 0;
  319. right: 0;
  320. border-bottom: 5rpx solid #ffffff;
  321. border-right: 5rpx solid #ffffff;
  322. border-radius: 0 0 4rpx 0;
  323. }
  324. }
  325. .scan-label {
  326. font-size: 20rpx;
  327. color: $text-color-primary;
  328. font-weight: 400;
  329. padding-bottom: 8rpx;
  330. margin-top: 12rpx;
  331. }
  332. </style>