index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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: '#FF6702'
  75. // color: this.dataConfig.themeStyleConfig.tabVal?this.dataConfig.checkColor.color[0].item:this.themeColor
  76. };
  77. }
  78. },
  79. },
  80. created() {
  81. let routes = getCurrentPages(); //获取当前打开过的页面路由数组
  82. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  83. this.activeRouter = '/' + curRoute;
  84. },
  85. mounted() {
  86. if (this.activeRouter === '/pages/activity/small_page/index') {
  87. this.bottomNavigationList = this.dataConfig.menuList.list;
  88. } else {
  89. this.navigationInfo();
  90. }
  91. },
  92. data() {
  93. return {
  94. theme: app.globalData.theme,
  95. isCustom: '',
  96. bottomNavigationList: [],
  97. activeRouter: '',
  98. // themeColor:this.$options.filters.filterTheme(app.globalData.theme)
  99. }
  100. },
  101. methods: {
  102. navigationInfo() {
  103. getBottomNavigationApi().then(res => {
  104. let data = res.data;
  105. this.isCustom = data.isCustom; //是否使用自定义导航,1使用,0不使用
  106. this.$store.commit('BottomNavigationIsCustom', this.isCustom == 1 ? true : false);
  107. if (data.isCustom == 1) {
  108. uni.hideTabBar()
  109. this.bottomNavigationList = data.bottomNavigationList;
  110. } else {
  111. uni.showTabBar();
  112. }
  113. })
  114. },
  115. goRouter(item) {
  116. var pages = getCurrentPages();
  117. var page = (pages[pages.length - 1]).$page.fullPath;
  118. if (item.link == page) return
  119. if (['/pages/index/index', '/pages/order_addcart/order_addcart',
  120. '/pages/user/index', '/pages/discover_index/index', '/pages/goods_cate/index', '/pages/order/index'
  121. ].indexOf(item.link) > -1) {
  122. uni.switchTab({
  123. url: item.link,
  124. fail(err) {
  125. uni.redirectTo({
  126. url: item.link
  127. })
  128. }
  129. })
  130. } else {
  131. uni.navigateTo({
  132. url: item.link
  133. })
  134. }
  135. }
  136. }
  137. }
  138. </script>
  139. <style scoped lang="scss">
  140. .overlay {
  141. position: absolute;
  142. bottom: 0;
  143. left: 0;
  144. width: 100%;
  145. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  146. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  147. // display: flex;
  148. // justify-content: center;
  149. // align-items: center;
  150. // background-color: rgba(0, 0, 0, 0.5);
  151. }
  152. .unchecked {
  153. color: #333;
  154. font-size: 24rpx;
  155. }
  156. .page-footer {
  157. position: fixed;
  158. bottom: 0;
  159. z-index: 998;
  160. display: flex;
  161. align-items: center;
  162. justify-content: space-around;
  163. width: 100%;
  164. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  165. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  166. box-sizing: border-box;
  167. border-top: solid 1rpx #F3F3F3;
  168. background-color: #fff;
  169. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  170. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  171. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  172. .foot-item {
  173. display: flex;
  174. width: max-content;
  175. align-items: center;
  176. justify-content: center;
  177. flex-direction: column;
  178. position: relative;
  179. .count-num {
  180. position: absolute;
  181. display: flex;
  182. justify-content: center;
  183. align-items: center;
  184. width: 40rpx;
  185. height: 40rpx;
  186. top: 0rpx;
  187. right: -15rpx;
  188. color: #fff;
  189. font-size: 20rpx;
  190. background-color: #FD502F;
  191. border-radius: 50%;
  192. padding: 4rpx;
  193. }
  194. }
  195. .bg-box{
  196. width: 100%;
  197. height: 100%;
  198. }
  199. .foot-item image {
  200. height: 50rpx;
  201. width: 50rpx;
  202. text-align: center;
  203. margin: 0 auto;
  204. }
  205. .txtchecked {
  206. font-size: 24rpx;
  207. }
  208. .foot-item .txt {
  209. font-size: 24rpx;
  210. @include main-color(theme);
  211. }
  212. }
  213. </style>