tab-bar.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="tab-bar">
  3. <view class="tab-item" @click="onTabClick(0)">
  4. <!-- <uni-icons type="home" size="20" color="#666"></uni-icons> -->
  5. <image src="/static/icons/remixicon/home-3-line.svg" class="icon" mode="widthFix" />
  6. <text class="tab-text">首页</text>
  7. </view>
  8. <view class="tab-item" @click="onTabClick(1)">
  9. <image src="/static/icons/remixicon/line-chart-line.svg" class="icon" mode="widthFix" />
  10. <!-- <uni-icons type="bars" size="20" color="#666"></uni-icons> -->
  11. <text class="tab-text">健康</text>
  12. </view>
  13. <view class="tab-item" @click="onTabClick(2)">
  14. <image src="/static/icons/remixicon/account-circle-line.svg" class="icon" mode="widthFix" />
  15. <!-- <uni-icons type="person" size="20" color="#666"></uni-icons> -->
  16. <text class="tab-text">用户</text>
  17. </view>
  18. </view>
  19. </template>
  20. <script setup lang="ts">
  21. import { isLoggedIn as checkLogin, getRole } from '../composables/useAuth'
  22. const onTabClick = (index: number) => {
  23. console.log('Tab clicked:', index)
  24. switch (index) {
  25. case 0: // 慢病首页
  26. try {
  27. const logged = checkLogin()
  28. const role = logged ? getRole() : null
  29. if (logged && role === 3) {
  30. uni.switchTab({ url: '/pages/patient/index/index' })
  31. } else {
  32. uni.switchTab({ url: '/pages/public/index/index' })
  33. }
  34. } catch (err) {
  35. console.error('tab click index redirect error', err)
  36. uni.switchTab({ url: '/pages/public/index/index' })
  37. }
  38. break
  39. case 1: // 健康数据
  40. try {
  41. // 本地判断:已登录且 role===3 则跳转到患者端健康页(使用 switchTab,因为该页属于 tab)
  42. // 未登录或非患者则降级到公共健康页
  43. // TODO: 后续支持根据其他角色(医生/患者家属等)跳转到各自的健康页
  44. const logged = checkLogin()
  45. const role = logged ? getRole() : null
  46. if (logged && role === 3) {
  47. uni.switchTab({ url: '/pages/patient/health/index' })
  48. } else {
  49. uni.switchTab({ url: '/pages/public/health/index' })
  50. }
  51. } catch (err) {
  52. console.error('tab click health redirect error', err)
  53. uni.switchTab({ url: '/pages/public/health/index' })
  54. }
  55. break
  56. case 2: // 个人中心
  57. try {
  58. const logged = checkLogin()
  59. const role = logged ? getRole() : null
  60. if (logged && role === 3) {
  61. uni.switchTab({ url: '/pages/patient/profile/index' })
  62. } else {
  63. uni.switchTab({ url: '/pages/public/profile/index' })
  64. }
  65. } catch (err) {
  66. console.error('tab click profile redirect error', err)
  67. uni.switchTab({ url: '/pages/public/profile/index' })
  68. }
  69. break
  70. }
  71. }
  72. </script>
  73. <style>
  74. .icon {
  75. width: 45rpx;
  76. height: 45rpx;
  77. display: inline-block;
  78. }
  79. .tab-bar {
  80. position: fixed;
  81. bottom: 0;
  82. left: 0;
  83. right: 0;
  84. height: 100rpx;
  85. background-color: #ffffffe7;
  86. display: flex;
  87. justify-content: space-around;
  88. align-items: center;
  89. border-top: 1rpx solid #eee;
  90. }
  91. .tab-item {
  92. display: flex;
  93. flex-direction: column;
  94. align-items: center;
  95. justify-content: center;
  96. flex: 1;
  97. height: 100%;
  98. }
  99. .tab-text {
  100. font-size: 24rpx;
  101. color: #666;
  102. }
  103. </style>