hans-tabbar.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="weui-tabbar" :class="extClass">
  3. <!-- 选中的时候往weui-tabbar__item加class:weui-bar__item_on -->
  4. <view @click="tabChange(index)" v-for="(item, index) in list" :key="index" class="weui-tabbar__item"
  5. :class="{'weui-bar__item_on':index === current}">
  6. <view style="position: relative;display:inline-block;">
  7. <image :src="current === index ? item.selectedIconPath : item.iconPath" class="weui-tabbar__icon">
  8. </image>
  9. </view>
  10. <view class="weui-tabbar__label">{{ item.text }}</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. // list: {
  18. // type: Array,
  19. // default: function() {
  20. // return []
  21. // }
  22. // }
  23. },
  24. data() {
  25. return {
  26. extClass: '',
  27. current: 0,
  28. list:[]
  29. };
  30. },
  31. created() {
  32. // "tabBar":{
  33. // "color":"#AAABAD",
  34. // "selectedColor":"#9797FF",
  35. // "backgroundColor":"#FFFFFF",
  36. // "borderStyle":"#eee",
  37. // "height":"75px",
  38. // "spacing":"6px",
  39. // "list":[
  40. // {
  41. // "pagePath":"pages/personal-page/personal/personal",
  42. // "text":"首页",
  43. // "iconPath":"./static/common/navigationBar/nHome.png",
  44. // "selectedIconPath":"static/common/navigationBar/nHomeB.png"
  45. // },
  46. // {
  47. // "pagePath":"pages/personal-page/plan/plan",
  48. // "text":"计划",
  49. // "iconPath":"static/common/navigationBar/nPlan.png",
  50. // "selectedIconPath":"static/common/navigationBar/nPlanB.png"
  51. // },{
  52. // "pagePath":"pages/game-page/game/game",
  53. // "text":"游戏",
  54. // "iconPath":"static/common/navigationBar/nGame.png",
  55. // "selectedIconPath":"static/common/navigationBar/nGameB.png"
  56. // },
  57. // {
  58. // "pagePath":"pages/game-page/game/game",
  59. // "text":"视频",
  60. // "iconPath":"static/common/navigationBar/nVideo.png",
  61. // "selectedIconPath":"static/common/navigationBar/nVideoB.png"
  62. // },
  63. // {
  64. // "pagePath":"pages/my-page/homepage/homepage",
  65. // "text":"我的",
  66. // "iconPath":"static/common/navigationBar/nMy.png",
  67. // "selectedIconPath":"static/common/navigationBar/nMyB.png"
  68. // }
  69. // ]
  70. // }
  71. this.list = [{
  72. "pagePath": "../../personal-page/personal/personal",
  73. "text": "首页",
  74. "iconPath": "/static/common/navigationBar/nHome.png",
  75. "selectedIconPath": "/static/common/navigationBar/nHomeB.png"
  76. },
  77. {
  78. "pagePath": "../../personal-page/plan/plan",
  79. "text": "计划",
  80. "iconPath": "/static/common/navigationBar/nPlan.png",
  81. "selectedIconPath": "/static/common/navigationBar/nPlanB.png"
  82. }, {
  83. "pagePath": "../../game-page/game/game",
  84. "text": "游戏",
  85. "iconPath": "/static/common/navigationBar/nGame.png",
  86. "selectedIconPath": "/static/common/navigationBar/nGameB.png"
  87. },
  88. {
  89. "pagePath": "../../game-page/game/game",
  90. "text": "视频",
  91. "iconPath": "/static/common/navigationBar/nVideo.png",
  92. "selectedIconPath": "/static/common/navigationBar/nVideoB.png"
  93. },
  94. {
  95. "pagePath": "../../my-page/homepage/homepage",
  96. "text": "我的",
  97. "iconPath": "/static/common/navigationBar/nMy.png",
  98. "selectedIconPath": "/static/common/navigationBar/nMyB.png"
  99. }
  100. ];
  101. const value = uni.getStorageSync('tabbarCurrentIndex');
  102. if (value) {
  103. this.current = value;
  104. }
  105. },
  106. methods: {
  107. tabChange(index) {
  108. if (index === this.current) {
  109. return;
  110. }
  111. this.current = index;
  112. this.$emit('tabChange', index)
  113. uni.setStorageSync('tabbarCurrentIndex', this.current);
  114. uni.reLaunch({
  115. url: this.list[this.current].pagePath,
  116. success: res => {},
  117. fail: () => {},
  118. complete: () => {}
  119. });
  120. console.log('tabChange');
  121. }
  122. }
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. .weui-tabbar {
  127. display: flex;
  128. position: relative;
  129. z-index: 500;
  130. height: 75px;
  131. background-color: #ffffff;
  132. justify-content: center;
  133. align-items: center;
  134. }
  135. .weui-tabbar:before {
  136. content: ' ';
  137. position: absolute;
  138. left: 0;
  139. top: 0;
  140. right: 0;
  141. height: 1px;
  142. border-top: 1rpx solid rgba(0, 0, 0, 0.1);
  143. color: rgba(0, 0, 0, 0.1);
  144. }
  145. .weui-tabbar__item {
  146. display: block;
  147. flex: 1;
  148. padding: 8px 0 4px;
  149. padding-bottom: calc(8px + constant(safe-area-inset-bottom));
  150. padding-bottom: calc(8px + env(safe-area-inset-bottom));
  151. font-size: 0;
  152. color: rgba(0, 0, 0, 0.5);
  153. text-align: center;
  154. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  155. }
  156. .weui-tabbar__item:first-child {
  157. padding-left: constant(safe-area-inset-left);
  158. padding-left: env(safe-area-inset-left);
  159. }
  160. .weui-tabbar__item:last-child {
  161. padding-right: constant(safe-area-inset-right);
  162. padding-right: env(safe-area-inset-right);
  163. }
  164. .weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon,
  165. .weui-tabbar__item.weui-bar__item_on .weui-tabbar__icon>i,
  166. .weui-tabbar__item.weui-bar__item_on .weui-tabbar__label {
  167. color: #9797FF;
  168. }
  169. .weui-tabbar__icon {
  170. display: inline-block;
  171. width: 28px;
  172. height: 28px;
  173. margin-bottom: 2px;
  174. }
  175. i.weui-tabbar__icon,
  176. .weui-tabbar__icon>i {
  177. font-size: 24px;
  178. color: rgba(0, 0, 0, 0.5);
  179. }
  180. .weui-tabbar__icon image {
  181. width: 100%;
  182. height: 100%;
  183. }
  184. .weui-tabbar__label {
  185. color: #bfbfbf;
  186. font-size: 10px;
  187. line-height: 1.4;
  188. }
  189. </style>