tabbar.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <u-tabbar :value="curIndex" @change="changeMethods" :fixed="true" :inactiveColor="'#999'" :activeColor="'#14ECCC'"
  3. :placeholder="false" :safeAreaInsetBottom="true" :zIndex="92" :border="false">
  4. <u-tabbar-item v-for="(item,k) in list" :key="k" :text="$t(item.text)" :badge="item.badge">
  5. <image :class="'u-page__item__slot-icon icon-'+(item.code)" slot="active-icon" :src="item.selectedIconPath">
  6. </image>
  7. <image :class="'u-page__item__slot-icon icon-'+(item.code)" slot="inactive-icon" :src="item.iconPath">
  8. </image>
  9. </u-tabbar-item>
  10. </u-tabbar>
  11. </template>
  12. <script>
  13. /*
  14. * 自定义底部导航栏
  15. */
  16. export default {
  17. name: "tabbar",
  18. props: {
  19. index: {
  20. type: Number,
  21. default: 1,
  22. }
  23. },
  24. data() {
  25. return {
  26. curIndex: this.index - 1,
  27. list: [{
  28. pagePath: "/pages/index/index",
  29. iconPath: "/static/icons/home.png",
  30. selectedIconPath: "/static/icons/home-active.png",
  31. text: '首页',
  32. code: 'home',
  33. badge: 0
  34. },
  35. {
  36. pagePath: "/pages/live/index?live=1",
  37. iconPath: "/static/icons/imchat.png",
  38. selectedIconPath: "/static/icons/imchat-active.png",
  39. text: '蜜聊', // 直播
  40. code: 'live',
  41. badge: 0
  42. },
  43. {
  44. pagePath: "/pages/video/index",
  45. iconPath: "/static/icons/live.png",
  46. selectedIconPath: "/static/icons/live.png",
  47. text: '', // 短视频
  48. code: 'video',
  49. badge: 0
  50. },
  51. {
  52. pagePath: "/pages/message/index",
  53. iconPath: "/static/icons/message.png",
  54. selectedIconPath: "/static/icons/message-active.png",
  55. text: '消息',
  56. code: 'message',
  57. badge: 0
  58. },
  59. {
  60. pagePath: "/pages/user/index",
  61. iconPath: "/static/icons/my.png",
  62. selectedIconPath: "/static/icons/my-active.png",
  63. text: '我的',
  64. code: 'mine',
  65. badge: 0
  66. }
  67. ],
  68. };
  69. },
  70. mounted() {
  71. let _this = this
  72. console.log('导航')
  73. this.getCount()
  74. uni.$on('load-message', function() {
  75. console.log('重新加载')
  76. _this.getCount();
  77. })
  78. },
  79. methods: {
  80. //底部导航选择操作
  81. changeMethods(index) {
  82. this.curIndex = index
  83. let path = typeof(this.list[index]) != 'undefined' ? this.list[index].pagePath : ''
  84. let code = typeof(this.list[index]) != 'undefined' ? this.list[index].code : ''
  85. if (path) {
  86. if (code == 'live') {
  87. // this.$emit('showLive', true)
  88. uni.reLaunch({
  89. url: path
  90. })
  91. } else {
  92. uni.reLaunch({
  93. url: path
  94. })
  95. }
  96. }
  97. },
  98. // 未读消息
  99. async getCount() {
  100. // 消息
  101. const res = await this.$request.api('/message/unread')
  102. if (res.success == true) {
  103. console.log('更新未读消息')
  104. this.list[3].badge = (res.data >= 100) ? '99' : res.data
  105. this.$forceUpdate()
  106. }
  107. }
  108. }
  109. }
  110. </script>
  111. <style scoped>
  112. .u-page__item__slot-icon {
  113. width: 42rpx;
  114. height: 42rpx;
  115. }
  116. .u-tabbar__content {
  117. background-color: #303030;
  118. }
  119. .icon-video {
  120. width: 76rpx;
  121. height: 76rpx;
  122. padding-top: 6rpx;
  123. }
  124. .u-border-top {
  125. border-top-width: 0rpx !important;
  126. border-color: transparent !important;
  127. border-top-style: solid;
  128. }
  129. </style>