index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <!-- 底部导航 -->
  3. <view :data-theme="theme">
  4. <view v-if="bottomNavigationList.length">
  5. <view class="page-footer" id="target" :style="[isSmallPage?boxStyle:'']">
  6. <view :style="[bgColor]" class="acea-row row-middle row-around bg-box">
  7. <view class="foot-item" v-for="(item,index) in bottomNavigationList" :key="index"
  8. @click="goRouter(item)">
  9. <block v-if="item.link.split('?')[0] == activeRouter">
  10. <image :src="item.checked"></image>
  11. <view v-if="isSmallPage" class="txtchecked" :style="[checkColor]">{{item.name}}</view>
  12. <view v-else class="txt">{{item.name}}</view>
  13. </block>
  14. <block v-else>
  15. <image :src="item.unchecked"></image>
  16. <view class="unchecked" :style="[isSmallPage?fontColor:'']">{{item.name}}</view>
  17. </block>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import {
  26. mapState,
  27. mapGetters
  28. } from "vuex"
  29. import {
  30. getBottomNavigationApi
  31. } from '@/api/api.js';
  32. let app = getApp();
  33. export default {
  34. name: 'pageFooter',
  35. props: {
  36. dataConfig: {
  37. type: Object,
  38. default: () => {}
  39. },
  40. isSmallPage: {
  41. type: Boolean,
  42. default: () => false
  43. }
  44. },
  45. computed: {
  46. //外部盒子
  47. boxStyle() {
  48. if (this.dataConfig) {
  49. return {
  50. borderRadius: this.dataConfig.bgStyle.val ? this.dataConfig.bgStyle.val + 'px' : '0',
  51. padding: '0' + ' ' + this.dataConfig.lrConfig.val + 'px' + ' ' + 0
  52. }
  53. }
  54. },
  55. bgColor(){
  56. if(this.dataConfig){
  57. return {
  58. background: `linear-gradient(${this.dataConfig.bgColor.color[0].item}, ${this.dataConfig.bgColor.color[1].item})`,
  59. }
  60. }
  61. },
  62. //标签文字颜色
  63. fontColor() {
  64. if (this.dataConfig) {
  65. return {
  66. color: this.dataConfig.fontColor.color[0].item
  67. };
  68. }
  69. },
  70. //选中颜色
  71. checkColor() {
  72. if (this.dataConfig) {
  73. return {
  74. color: this.dataConfig.themeStyleConfig.tabVal?this.dataConfig.checkColor.color[0].item:this.themeColor
  75. };
  76. }
  77. },
  78. },
  79. created() {
  80. let routes = getCurrentPages(); //获取当前打开过的页面路由数组
  81. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  82. this.activeRouter = '/' + curRoute;
  83. },
  84. mounted() {
  85. if (this.activeRouter === '/pages/activity/small_page/index') {
  86. this.bottomNavigationList = this.dataConfig.menuList.list;
  87. } else {
  88. this.navigationInfo();
  89. }
  90. },
  91. data() {
  92. return {
  93. theme: app.globalData.theme,
  94. isCustom: '',
  95. bottomNavigationList: [],
  96. activeRouter: '',
  97. themeColor:this.$options.filters.filterTheme(app.globalData.theme)
  98. }
  99. },
  100. methods: {
  101. navigationInfo() {
  102. getBottomNavigationApi().then(res => {
  103. let data = res.data;
  104. this.isCustom = data.isCustom; //是否使用自定义导航,1使用,0不使用
  105. this.$store.commit('BottomNavigationIsCustom', this.isCustom == 1 ? true : false);
  106. if (data.isCustom == 1) {
  107. uni.hideTabBar()
  108. this.bottomNavigationList = data.bottomNavigationList;
  109. } else {
  110. uni.showTabBar();
  111. }
  112. })
  113. },
  114. goRouter(item) {
  115. var pages = getCurrentPages();
  116. var page = (pages[pages.length - 1]).$page.fullPath;
  117. if (item.link == page) return
  118. if (['/pages/index/index', '/pages/order_addcart/order_addcart',
  119. '/pages/user/index', '/pages/discover_index/index', '/pages/goods_cate/index'
  120. ].indexOf(item.link) > -1) {
  121. uni.switchTab({
  122. url: item.link,
  123. fail(err) {
  124. uni.redirectTo({
  125. url: item.link
  126. })
  127. }
  128. })
  129. } else {
  130. uni.navigateTo({
  131. url: item.link
  132. })
  133. }
  134. }
  135. }
  136. }
  137. </script>
  138. <style scoped lang="scss">
  139. .overlay {
  140. position: absolute;
  141. bottom: 0;
  142. left: 0;
  143. width: 100%;
  144. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  145. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  146. // display: flex;
  147. // justify-content: center;
  148. // align-items: center;
  149. // background-color: rgba(0, 0, 0, 0.5);
  150. }
  151. .unchecked {
  152. color: #333;
  153. font-size: 24rpx;
  154. }
  155. .page-footer {
  156. position: fixed;
  157. bottom: 0;
  158. z-index: 998;
  159. display: flex;
  160. align-items: center;
  161. justify-content: space-around;
  162. width: 100%;
  163. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  164. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  165. box-sizing: border-box;
  166. border-top: solid 1rpx #F3F3F3;
  167. background-color: #fff;
  168. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  169. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  170. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  171. .foot-item {
  172. display: flex;
  173. width: max-content;
  174. align-items: center;
  175. justify-content: center;
  176. flex-direction: column;
  177. position: relative;
  178. .count-num {
  179. position: absolute;
  180. display: flex;
  181. justify-content: center;
  182. align-items: center;
  183. width: 40rpx;
  184. height: 40rpx;
  185. top: 0rpx;
  186. right: -15rpx;
  187. color: #fff;
  188. font-size: 20rpx;
  189. background-color: #FD502F;
  190. border-radius: 50%;
  191. padding: 4rpx;
  192. }
  193. }
  194. .bg-box{
  195. width: 100%;
  196. height: 100%;
  197. }
  198. .foot-item image {
  199. height: 50rpx;
  200. width: 50rpx;
  201. text-align: center;
  202. margin: 0 auto;
  203. }
  204. .txtchecked {
  205. font-size: 24rpx;
  206. }
  207. .foot-item .txt {
  208. font-size: 24rpx;
  209. @include main-color(theme);
  210. }
  211. }
  212. </style>