tabbar.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view class="tabbar-area">
  3. <view class="tabbar-bottom" :style="{ backgroundColor: backgroundColor, height: tabbarHeight + 'px' }">
  4. <view class="tabbar-bottom-item" ref="tabbarItem" v-for="(item, index) in tabbars" :key="index"
  5. @click="switchTab(item, index)">
  6. <image v-if="item.type != 'midButton'"
  7. :src="currentIndex == index ? item.selectedIconPath : item.iconPath"
  8. :class="['tabbar-bottom-item-icon']"></image>
  9. <text class="tabbar-bottom-item-text"
  10. :style="{ color: currentIndex == index ? textActiveColor : textColor }">{{ item.text }}</text>
  11. <text class="tabbar-bottom-item-count" v-if="item.count">{{ item.count >= 99 ? '99+' : item.count
  12. }}</text>
  13. </view>
  14. </view>
  15. <view class="midButton" @click="midButtonGo()">
  16. <image class="image" src="../../static/tabbar-icon/center.png" mode=""></image>
  17. </view>
  18. <view class="safe-bottom-area" style="background-color: #fff;">
  19. <uv-safe-bottom></uv-safe-bottom>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. let animationModule = null;
  25. // #ifdef APP-NVUE
  26. animationModule = weex.requireModule('animation')
  27. // #endif
  28. import { mapActions, mapState, mapMutations } from 'vuex'
  29. export default {
  30. props: {
  31. currentIndex: {
  32. type: Number,
  33. default: 0
  34. },
  35. backgroundColor: {
  36. type: String,
  37. default: '#fff'
  38. },
  39. textColor: {
  40. type: String,
  41. default: '#717171'
  42. },
  43. textActiveColor: {
  44. type: String,
  45. default: '#000'
  46. },
  47. tabbarHeight: {
  48. type: Number,
  49. default: 60
  50. },
  51. tabbars: {
  52. type: Array,
  53. default: () => ([])
  54. },
  55. midButton: {
  56. type: Boolean,
  57. default: true,
  58. }
  59. },
  60. computed: {
  61. ...mapState('switchingModule', ['status', 'picture', 'name', 'requestData']),
  62. },
  63. data() {
  64. return {}
  65. },
  66. mounted() {
  67. uni.hideTabBar()
  68. },
  69. methods: {
  70. ...mapMutations('switchingModule', ['setInformation','deleteInformation']),
  71. switchTab(item, index) {
  72. if (!item.pagePath) return;
  73. if (item.pagePath == '/pages/message/mailMessage') {
  74. uni.$emit('check_login', () => {
  75. uni.switchTab({
  76. url: item.pagePath,
  77. });
  78. })
  79. return;
  80. }
  81. uni.switchTab({
  82. url: item.pagePath,
  83. });
  84. // this.payAnimation()
  85. },
  86. midButtonGo() {
  87. console.log('点击了中间按钮');
  88. // 判断登录
  89. uni.$emit('check_login', () => {
  90. let falg = this.status == 1
  91. console.log(falg,'状态');
  92. if (falg) {
  93. // 如果缓存为true,直接跳转到星球页面
  94. uni.navigateTo({
  95. url: '/pages/isLand/homeLand'
  96. });
  97. return;
  98. }
  99. // 如果缓存不为true,则请求接口
  100. uni.request({
  101. url: this.$apiHost + "/AIpipei/getinfo",
  102. data: {
  103. uuid: getApp().globalData.uuid,
  104. },
  105. header: {
  106. "content-type": "application/json",
  107. sign: getApp().globalData.headerSign,
  108. },
  109. timeout: 60000,
  110. success: (res) => {
  111. if (res && res.data && res.data.info) {
  112. if (res.data.info.image && res.data.info.status == 1) {
  113. this.setInformation(res.data.info)
  114. // 跳转到星球页面
  115. uni.navigateTo({
  116. url: '/pages/isLand/homeLand'
  117. });
  118. } else {
  119. this.deleteInformation()
  120. // 跳转到我的星球页面
  121. uni.navigateTo({
  122. url: '/pages/my/myStar'
  123. });
  124. }
  125. } else {
  126. this.deleteInformation()
  127. // 跳转到我的星球页面
  128. uni.navigateTo({
  129. url: '/pages/my/myStar'
  130. });
  131. }
  132. },
  133. fail: (err) => {
  134. // 请求失败时也跳转到我的星球页面
  135. uni.navigateTo({
  136. url: '/pages/my/myStar'
  137. });
  138. },
  139. complete: () => {
  140. }
  141. });
  142. })
  143. },
  144. async payAnimation() {
  145. const active = [{
  146. dom: this.$refs.tabbarItem[this.currentIndex],
  147. styles: {
  148. transform: `scale(1.2)`
  149. },
  150. transformOrigin: 'center center',
  151. timingFunction: 'ease-in-out',
  152. duration: 100,
  153. },
  154. {
  155. dom: this.$refs.tabbarItem[this.currentIndex],
  156. styles: {
  157. transform: `scale(1)`
  158. },
  159. transformOrigin: 'center center',
  160. timingFunction: 'ease-in-out',
  161. duration: 100,
  162. }
  163. ]
  164. for (var i = 0; i < active.length; i++) {
  165. await this.animationActive(active[i])
  166. }
  167. },
  168. animationActive(active) {
  169. return new Promise((resolve, reject) => {
  170. animationModule.transition(active.dom, {
  171. styles: active.styles || {},
  172. duration: active.duration,
  173. timingFunction: active.timingFunction,
  174. delay: active.delay || 0,
  175. transformOrigin: active.transformOrigin,
  176. }, () => {
  177. resolve()
  178. })
  179. })
  180. },
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. .tabbar-area {
  186. position: fixed;
  187. bottom: 0rpx;
  188. width: 750rpx;
  189. height: 145rpx;
  190. background-color: transparent;
  191. padding-top: 25rpx;
  192. // padding-top: 48rpx;
  193. // #ifndef APP-NVUE
  194. box-sizing: border-box;
  195. // #endif
  196. display: flex;
  197. flex-direction: column;
  198. background: url("@/static/home/taber-bg.png") center top / 100% auto;
  199. z-index: 99;
  200. }
  201. .tabbar-bottom {
  202. width: 750rpx;
  203. flex: 1;
  204. // #ifndef APP-NVUE
  205. display: flex;
  206. // #endif
  207. flex-direction: row;
  208. align-items: center;
  209. justify-content: space-around;
  210. border-top-left-radius: 40rpx;
  211. border-top-right-radius: 40rpx;
  212. }
  213. .midButton {
  214. position: absolute;
  215. top: 10px;
  216. left: 330rpx;
  217. .image {
  218. height: 96rpx;
  219. width: 96rpx;
  220. }
  221. }
  222. .tabbar-bottom-item {
  223. // #ifndef APP-NVUE
  224. display: flex;
  225. // #endif
  226. align-items: center;
  227. justify-content: center;
  228. flex-direction: column;
  229. height: 120rpx;
  230. width: 100rpx;
  231. position: relative;
  232. }
  233. .tabbar-bottom-item-icon {
  234. height: 68rpx;
  235. width: 68rpx;
  236. position: relative;
  237. }
  238. .tabbar-bottom-item-text {
  239. font-size: 20rpx;
  240. color: rgb(113, 113, 113);
  241. }
  242. .tabbar-bottom-item-count {
  243. background-color: #ff4d4d;
  244. font-size: 20rpx;
  245. font-weight: bold;
  246. color: #ffffff;
  247. padding: 8rpx;
  248. position: absolute;
  249. top: 0rpx;
  250. right: 0rpx;
  251. border-radius: 100rpx;
  252. /* 半径为高度的一半 */
  253. // #ifndef APP-NVUE
  254. display: flex;
  255. // #endif
  256. justify-content: center;
  257. align-items: center;
  258. }
  259. .safe-bottom-area {
  260. width: 750rpx;
  261. background-color: #fff;
  262. }
  263. </style>