index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. <van-badge :content="item.num" max="99" :show-zero="false">
  17. <img
  18. :src="getImageUrl(props.active ? item.iconActive : item.icon)"
  19. alt=""
  20. />
  21. </van-badge>
  22. </template>
  23. <div>{{ item.title }}</div>
  24. </van-tabbar-item>
  25. </van-tabbar>
  26. </template>
  27. <script setup lang="ts">
  28. import { ref, reactive, onMounted, watch } from "vue";
  29. import useUserStore from "@/store/modules/user";
  30. import { getUnreadMsgCount } from "@/api/InformationReception/InformationReception";
  31. const active = ref(0);
  32. let tabBarData = ref([]);
  33. const getImageUrl = name => {
  34. return new URL(`../../assets/images/tabBar/${name}.png`, import.meta.url)
  35. .href;
  36. };
  37. // 设置定时器,刷新统计数
  38. const fetchInterval = process.env.NODE_ENV === 'development' ? 60000 : 10000; // 每60秒刷新一次(刷新太频繁影响调试)
  39. let intervalId: any | null = null;
  40. const startFetchingData = () => {
  41. if (!intervalId) {
  42. intervalId = setInterval(() => {
  43. fetchData();
  44. }, fetchInterval);
  45. }
  46. };
  47. const stopFetchingData = () => {
  48. if (intervalId) {
  49. clearInterval(intervalId);
  50. intervalId = null;
  51. }
  52. };
  53. const fetchData = async () => {
  54. getUnreadMsgCount({"msg_types": "事件管理,值班管理"}).then((res)=>{
  55. tabBarData.value.forEach((v)=>{
  56. let obj = res.data.find(item=>item.name === v.title);
  57. if(obj) {
  58. v.num = ""+obj.num;
  59. }
  60. })
  61. })
  62. }
  63. watch(
  64. () => useUserStore().roles,
  65. () => {
  66. const roles = useUserStore().roles;
  67. if (roles.includes("leader")) {
  68. tabBarData.value = [
  69. {
  70. icon: "index",
  71. iconActive: "indexActive",
  72. title: "首页",
  73. num: '0',
  74. to: {
  75. name: "LeaderIndex"
  76. }
  77. },
  78. {
  79. icon: "command",
  80. iconActive: "commandActive",
  81. title: "移动指挥",
  82. num: '0',
  83. to: {
  84. name: "MobileControl"
  85. }
  86. },
  87. {
  88. icon: "threepro",
  89. iconActive: "threeproActive",
  90. title: "三防责任人",
  91. num: '0',
  92. to: {
  93. name: "ThreePreventionResponsiblePerson"
  94. }
  95. },
  96. // {
  97. // icon: "contact",
  98. // iconActive: "contactActive",
  99. // title: "通讯录",
  100. // to: {
  101. // name: "AddressBook"
  102. // }
  103. // },
  104. // {
  105. // icon: "mine",
  106. // iconActive: "mineActive",
  107. // title: "我的",
  108. // to: {
  109. // name: "My"
  110. // }
  111. // }
  112. ];
  113. } else if (roles.includes("worker")) {
  114. tabBarData.value = [
  115. {
  116. icon: "index",
  117. iconActive: "indexActive",
  118. title: "首页",
  119. num: '0',
  120. to: {
  121. name: "WorkerIndex"
  122. }
  123. },
  124. {
  125. icon: "command",
  126. iconActive: "commandActive",
  127. num: '0',
  128. title: "事件管理",
  129. to: {
  130. name: "workerEvent"
  131. }
  132. },
  133. {
  134. icon: "contact",
  135. iconActive: "contactActive",
  136. num: '0',
  137. title: "值班管理",
  138. to: {
  139. name: "Duty"
  140. }
  141. },
  142. // {
  143. // icon: "mine",
  144. // iconActive: "mineActive",
  145. // title: "我的",
  146. // to: {
  147. // name: "My"
  148. // }
  149. // }
  150. ];
  151. fetchData();
  152. }
  153. },
  154. {
  155. immediate: true,
  156. deep: true
  157. }
  158. );
  159. onMounted(() => {
  160. startFetchingData();
  161. });
  162. onUnmounted(() => {
  163. stopFetchingData();
  164. });
  165. </script>
  166. <style lang="scss" scoped>
  167. .custom-tabbar {
  168. height: 55px !important;
  169. :deep(.van-tabbar) {
  170. height: 55px !important;
  171. }
  172. :deep(.van-tabbar-item) {
  173. height: 55px !important;
  174. }
  175. :deep(.van-tabbar-item__icon) {
  176. .van-badge {
  177. margin-top: 0;
  178. }
  179. .van-badge--top-right {
  180. top: 7px
  181. }
  182. }
  183. }
  184. </style>