index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <van-tabbar
  3. v-model="active"
  4. :placeholder="true"
  5. :route="true"
  6. fixed
  7. class="custom-tabbar"
  8. >
  9. <van-tabbar-item
  10. v-for="(item, index) in tabBarData"
  11. :key="index"
  12. :icon="item.icon"
  13. :to="item.to"
  14. >
  15. <template #icon="props">
  16. <img
  17. :src="getImageUrl(props.active ? item.iconActive : item.icon)"
  18. alt=""
  19. />
  20. </template>
  21. {{ item.title }}
  22. </van-tabbar-item>
  23. </van-tabbar>
  24. </template>
  25. <script setup lang="ts">
  26. import { ref, reactive, onMounted, watch } from "vue";
  27. import useUserStore from "@/store/modules/user";
  28. const active = ref(0);
  29. let tabBarData = reactive([]);
  30. watch(
  31. () => useUserStore().roles,
  32. () => {
  33. const roles = useUserStore().roles;
  34. if (roles.includes("leader")) {
  35. tabBarData = [
  36. {
  37. icon: "index",
  38. iconActive: "indexActive",
  39. title: "首页",
  40. to: {
  41. name: "LeaderIndex"
  42. }
  43. },
  44. {
  45. icon: "command",
  46. iconActive: "commandActive",
  47. title: "移动指挥",
  48. to: {
  49. name: "MobileControl"
  50. }
  51. },
  52. {
  53. icon: "contact",
  54. iconActive: "contactActive",
  55. title: "通讯录",
  56. to: {
  57. name: "AddressBook"
  58. }
  59. },
  60. {
  61. icon: "mine",
  62. iconActive: "mineActive",
  63. title: "我的",
  64. to: {
  65. name: "My"
  66. }
  67. }
  68. ];
  69. } else if (roles.includes("worker")) {
  70. tabBarData = [
  71. {
  72. icon: "index",
  73. iconActive: "indexActive",
  74. title: "首页",
  75. to: {
  76. name: "WorkerIndex"
  77. }
  78. },
  79. {
  80. icon: "command",
  81. iconActive: "commandActive",
  82. title: "事件管理",
  83. to: {
  84. name: "workerEvent"
  85. }
  86. },
  87. {
  88. icon: "contact",
  89. iconActive: "contactActive",
  90. title: "值班管理",
  91. to: {
  92. name: "Duty"
  93. }
  94. },
  95. {
  96. icon: "mine",
  97. iconActive: "mineActive",
  98. title: "我的",
  99. to: {
  100. name: "My"
  101. }
  102. }
  103. ];
  104. }
  105. },
  106. {
  107. immediate: true,
  108. deep: true
  109. }
  110. );
  111. const getImageUrl = name => {
  112. return new URL(`../../assets/images/tabBar/${name}.png`, import.meta.url)
  113. .href;
  114. };
  115. onMounted(() => {
  116. /*
  117. const mobile_control_status =
  118. localStorage.getItem("mobile_control_status") || "0";
  119. // 动态切换平时态或者应急态
  120. if (mobile_control_status === "1") {
  121. tabBarData[1] = {
  122. icon: "command",
  123. iconActive: "command",
  124. title: "移动指挥",
  125. to: {
  126. name: "MobileControl"
  127. }
  128. };
  129. }
  130. */
  131. });
  132. </script>
  133. <style lang="scss" scoped>
  134. .custom-tabbar {
  135. height: 55px !important;
  136. :deep(.van-tabbar) {
  137. height: 55px !important;
  138. }
  139. :deep(.van-tabbar-item) {
  140. height: 55px !important;
  141. }
  142. }
  143. </style>