index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view>
  3. <addressbook v-if="PageCur=='addressbook'"></addressbook>
  4. <message v-if="PageCur=='message'"></message>
  5. <workbench v-if="PageCur=='workbench'"></workbench>
  6. <apps v-if="PageCur=='apps'"></apps>
  7. <person v-if="PageCur=='my'"></person>
  8. <view class="cu-bar tabbar bg-white shadow foot">
  9. <!--<view class="action" @click="NavChange" data-cur="addressbook">
  10. <view :class="PageCur=='addressbook'?'text-blue':'text-gray'">
  11. <text class="lg" :class="PageCur=='addressbook'?'cuIcon-addressbook':'cuIcon-addressbook'"></text>
  12. <text>通讯录</text>
  13. </view>
  14. </view>-->
  15. <view class="action" @click="NavChange" data-cur="message">
  16. <view :class="PageCur=='message'?'text-blue':'text-gray'">
  17. <text class="lg" :class="PageCur=='message'?'cuIcon-messagefill':'cuIcon-message'">
  18. <text class='cu-tag badge'>{{notificationCount}}</text>
  19. </text>
  20. <text>消息</text>
  21. </view>
  22. </view>
  23. <view class="action text-gray add-action" @click="NavChange" data-cur="workbench">
  24. <button class="cu-btn shadow" :class="PageCur=='workbench'?'cuIcon-homefill bg-blue':'cuIcon-home bg-grey'"></button>
  25. 工作台
  26. </view>
  27. <!--<view class="action" @click="NavChange" data-cur="apps">
  28. <view :class="PageCur=='apps'?'text-blue':'text-gray'">
  29. <text class="lg" :class="PageCur=='apps'?'cuIcon-circlefill':'cuIcon-circle'"></text>
  30. <text>应用</text>
  31. </view>
  32. </view>-->
  33. <view class="action" @click="NavChange" data-cur="my">
  34. <view :class="PageCur=='my'?'text-blue':'text-gray'">
  35. <text class="lg" :class="PageCur=='my'?'cuIcon-profilefill':'cuIcon-profile'"></text>
  36. <text>我的</text>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import { mapState, mapActions } from 'vuex';
  44. import addressbook from '@/pages/addressbook/addressbook.vue';
  45. import person from '@/pages/user/person/person.vue';
  46. import message from '@/pages/message/message.vue';
  47. import workbench from '@/pages/workbench/workbench.vue';
  48. import apps from '@/pages/apps/apps.vue';
  49. import { EventBus } from '@/store/eventBus.js';
  50. export default {
  51. components: {
  52. addressbook,
  53. person,
  54. message,
  55. workbench,
  56. apps
  57. },
  58. data() {
  59. return {
  60. PageCur: 'workbench',
  61. notificationCount: 0
  62. };
  63. },
  64. computed: {
  65. ...mapState({
  66. messageDataList: state => state.messageDataList // 映射 Vuex state 到组件的计算属性
  67. })
  68. },
  69. mounted() {
  70. EventBus.$on('dataFromMessage', (data) => {
  71. this.handleMessageData(data); // 处理接收到的数据
  72. });
  73. },
  74. methods: {
  75. NavChange: function(e) {
  76. let newPageCur = e.currentTarget.dataset.cur;
  77. // 清空当前导航项
  78. this.PageCur = '';
  79. // 使用 setTimeout 确保下一帧将新值设回去,强制页面更新
  80. setTimeout(() => {
  81. this.PageCur = newPageCur;
  82. }, 0);
  83. },
  84. handleMessageData(data) {
  85. // 处理 message.vue 传递过来的参数
  86. this.notificationCount = data
  87. }
  88. }
  89. };
  90. </script>
  91. <style>
  92. .cu-tag.badge {
  93. right: 4px;
  94. }
  95. </style>