tabbar.vue 5.9 KB

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