box.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="container">
  3. <!-- 首页 -->
  4. <Home v-if="show === 'home'" :msgTotal="msgTotal" />
  5. <!-- 工单管理 -->
  6. <Management v-if="show === 'management'" />
  7. <!-- 通讯录 -->
  8. <AddressBook v-if="show === 'addressBook'" />
  9. <!-- 待处理池 -->
  10. <Pending v-if="show === 'pending'" />
  11. <!-- 报修 -->
  12. <Repairs v-if="show === 'repairs'" />
  13. <!-- 我的报修 -->
  14. <MyRepairs v-if="show === 'myRepairs'" />
  15. <!-- 底部导航栏 -->
  16. <Tabbar :list="routes" :currentRouter="currentRouter" @changeRouter="handleChangeRouter" />
  17. </view>
  18. </template>
  19. <script>
  20. import Home from '../home/home.vue'
  21. import Management from '../management/management.vue'
  22. import AddressBook from '../addressBook/addressBook.vue'
  23. import Pending from '../pending/pending.vue'
  24. import Repairs from '../repairs/repairs.vue'
  25. import MyRepairs from '../myRepairs/myRepairs.vue'
  26. import Tabbar from '../components/tabbar.vue'
  27. export default {
  28. components: {
  29. Home,
  30. Management,
  31. AddressBook,
  32. Pending,
  33. Repairs,
  34. MyRepairs,
  35. Tabbar
  36. },
  37. data() {
  38. return {
  39. // 展示的路由
  40. routes: [],
  41. // 所有的路由
  42. list: [
  43. {
  44. text: '报修',
  45. imgUrl: '../../static/images/repairsImg/repairs.png',
  46. imgUrlActive: '../../static/images/repairsImg/repairs-active.png',
  47. show: 'repairs'
  48. },
  49. {
  50. text: '我的报修',
  51. imgUrl: '../../static/images/repairsImg/myRepairs.png',
  52. imgUrlActive: '../../static/images/repairsImg/myRepairs-active.png',
  53. show: 'myRepairs'
  54. },
  55. {
  56. text: '首页',
  57. imgUrl: '../../static/images/repairsImg/home.png',
  58. imgUrlActive: '../../static/images/repairsImg/home-active.png',
  59. show: 'home'
  60. },
  61. {
  62. text: '工单管理',
  63. imgUrl: '../../static/images/repairsImg/management.png',
  64. imgUrlActive: '../../static/images/repairsImg/management-active.png',
  65. show: 'management'
  66. },
  67. {
  68. text: '待处理池',
  69. imgUrl: '../../static/images/repairsImg/myRepairs.png',
  70. imgUrlActive: '../../static/images/repairsImg/myRepairs-active.png',
  71. show: 'pending'
  72. },
  73. {
  74. text: '通讯录',
  75. imgUrl: '../../static/images/repairsImg/addressBook.png',
  76. imgUrlActive: '../../static/images/repairsImg/addressBook-active.png',
  77. show: 'addressBook'
  78. }
  79. ],
  80. // box页面展示哪个组件
  81. show: '',
  82. // 当前显示组件的index
  83. currentRouter: 0,
  84. // 未读信息总数
  85. msgTotal: 0
  86. }
  87. },
  88. mounted() {
  89. // 获取权限路由
  90. const repairsUserInfo = uni.getStorageSync('repairsUserInfo')
  91. if (repairsUserInfo.routes) {
  92. this.routes = this.filterRoute(this.list, repairsUserInfo.routes)
  93. }
  94. // 获取当前激活的路由
  95. const currentIndexRepairs = uni.getStorageSync('currentIndexRepairs')
  96. if (currentIndexRepairs) {
  97. this.currentRouter = currentIndexRepairs
  98. this.show = this.routes[currentIndexRepairs].show
  99. uni.setNavigationBarTitle({
  100. title: this.routes[currentIndexRepairs].text
  101. })
  102. } else {
  103. this.currentRouter = 0
  104. this.show = this.routes[0].show
  105. uni.setNavigationBarTitle({
  106. title: this.routes[0].text
  107. })
  108. }
  109. },
  110. onShow() {
  111. // 获取未读信息条数
  112. this.getUnreadMsgCount()
  113. },
  114. onLoad() {
  115. uni.$on('goToRepairs', this.goToRepairs)
  116. uni.$on('goToMyRepairs', this.goToMyRepairs)
  117. },
  118. onUnload() {
  119. // 移除全局自定义事件监听器
  120. uni.$off()
  121. },
  122. methods: {
  123. // 获取未读信息条数数据
  124. async getUnreadMsgCount() {
  125. const res = await this.$myRequest_repairs({
  126. url: '/repairSystemMessages/queryMessageUnreadCount',
  127. data: {
  128. userId: uni.getStorageSync('repairsUserInfo').userId
  129. }
  130. })
  131. // console.log(res)
  132. if (res.code === '200') {
  133. this.msgTotal = res.data.count
  134. }
  135. },
  136. // 全局自定义事件
  137. goToRepairs(e) {
  138. // console.log(e)
  139. this.show = e.show
  140. uni.setNavigationBarTitle({
  141. title: e.title
  142. })
  143. },
  144. goToMyRepairs(e) {
  145. // console.log(e)
  146. this.show = e.show
  147. this.currentRouter = 1
  148. uni.setNavigationBarTitle({
  149. title: e.title
  150. })
  151. },
  152. // 底部导航栏切换回调
  153. handleChangeRouter(show, text, e) {
  154. uni.setStorageSync('currentIndexRepairs', e)
  155. this.show = show
  156. this.currentRouter = e
  157. uni.setNavigationBarTitle({
  158. title: text
  159. })
  160. },
  161. // 路由过滤方法
  162. filterRoute(arr1, arr2) {
  163. return arr1.filter((item) => {
  164. return arr2.includes(item.text)
  165. })
  166. }
  167. }
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. .container {
  172. width: 100vw;
  173. height: calc(100vh - 152rpx);
  174. }
  175. </style>