You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
5.1 KiB

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