tabber.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <uv-tabbar :customStyle="customStyle" activeColor="#0061FF" inactiveColor="#A6A6A6" :value="activeIndex">
  3. <uv-tabbar-item v-for="(item, index) in allList" :key="item.id" :text="item.text" :icon="item.icon" @click="handleChange(index, item)"></uv-tabbar-item>
  4. </uv-tabbar>
  5. </template>
  6. <script setup>
  7. import { ref } from 'vue'
  8. import { onLoad } from '@dcloudio/uni-app'
  9. const allList = ref([])
  10. // 导航栏数组
  11. const tabList = ref([
  12. {
  13. id: 1,
  14. text: '访客预约',
  15. icon: 'account'
  16. },
  17. {
  18. id: 2,
  19. text: '到访代办',
  20. icon: 'file-text'
  21. },
  22. {
  23. id: 3,
  24. text: '预约记录',
  25. icon: 'clock'
  26. }
  27. ])
  28. const tabList2 = ref([
  29. {
  30. id: 1,
  31. text: '访客预约',
  32. icon: 'account'
  33. },
  34. {
  35. id: 3,
  36. text: '预约记录',
  37. icon: 'clock'
  38. }
  39. ])
  40. // 当前高亮索引
  41. const activeIndex = ref(0)
  42. // 导航栏样式
  43. const customStyle = {
  44. height: '120rpx'
  45. }
  46. onLoad(() => {
  47. const userType = uni.getStorageSync('userType')
  48. if (userType == 0) {
  49. allList.value = tabList2.value
  50. } else {
  51. allList.value = tabList.value
  52. }
  53. const i = uni.getStorageSync('Tab-activeIndex')
  54. i ? (activeIndex.value = i) : (activeIndex.value = 0)
  55. })
  56. // 切换导航栏回调
  57. const handleChange = (index, item) => {
  58. if (index != activeIndex.value) {
  59. activeIndex.value = index
  60. uni.setStorageSync('Tab-activeIndex', activeIndex.value)
  61. if (item.icon === 'account') {
  62. uni.redirectTo({
  63. url: '/pagesReservation/reservation/reservation'
  64. })
  65. } else if (item.icon === 'file-text') {
  66. uni.redirectTo({
  67. url: '/pagesReservation/backlog/backlog'
  68. })
  69. } else if (item.icon === 'clock') {
  70. uni.redirectTo({
  71. url: '/pagesReservation/record/record'
  72. })
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped></style>