index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <!-- 底部导航 -->
  3. <view class="page-footer">
  4. <view class="foot-item" :class="item.pagePath == activeRouter?'active':''" v-for="(item,index) in footerList" :key="index" @click="goRouter(item)">
  5. <block v-if="item.pagePath == activeRouter">
  6. <image :src="item.selectedIconPath"></image>
  7. <view class="txt">{{item.text}}</view>
  8. </block>
  9. <block v-else>
  10. <image :src="item.iconPath"></image>
  11. <view class="txt">{{item.text}}</view>
  12. </block>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. mapGetters
  19. } from "vuex";
  20. export default {
  21. name: 'footers',
  22. props:{
  23. isWork: {
  24. type: Number,
  25. default: 0
  26. }
  27. },
  28. computed: mapGetters(["storeNum"]),
  29. created() {
  30. let routes = getCurrentPages(); //获取当前打开过的页面路由数组
  31. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  32. this.activeRouter = '/' + curRoute
  33. },
  34. mounted() {},
  35. data() {
  36. return {
  37. activeRouter:'',
  38. footerList:[
  39. {
  40. pagePath: (this.storeNum || this.isWork)?"/pages/admin/work/index":"/pages/admin/work/store",
  41. iconPath: require("../../static/footer1-1.png"),
  42. selectedIconPath: require("../../static/footer1-2.png"),
  43. text: "工作台"
  44. },
  45. {
  46. pagePath: "/pages/admin/goods/index",
  47. iconPath: require("../../static/footer2-1.png"),
  48. selectedIconPath: require("../../static/footer2-2.png"),
  49. text: "商品"
  50. },
  51. {
  52. pagePath: "/pages/admin/orderList/index",
  53. iconPath: require("../../static/footer3-1.png"),
  54. selectedIconPath: require("../../static/footer3-2.png"),
  55. text: "订单"
  56. },
  57. {
  58. pagePath: "/pages/admin/user/list",
  59. iconPath: require("../../static/footer4-1.png"),
  60. selectedIconPath: require("../../static/footer4-2.png"),
  61. text: "用户"
  62. }
  63. ]
  64. }
  65. },
  66. methods: {
  67. goRouter(item) {
  68. var pages = getCurrentPages();
  69. var page = (pages[pages.length - 1]).$page.fullPath;
  70. if (item.pagePath == page) return
  71. uni.redirectTo({
  72. url: item.pagePath,
  73. animationType: 'none' // 关闭默认的滑动效果
  74. });
  75. }
  76. }
  77. }
  78. </script>
  79. <style scoped lang="scss">
  80. .page-footer {
  81. position: fixed;
  82. bottom: 0;
  83. left:0;
  84. z-index: 20;
  85. display: flex;
  86. align-items: center;
  87. justify-content: space-around;
  88. width: 100%;
  89. height: calc(100rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  90. height: calc(100rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  91. box-sizing: border-box;
  92. border-top: solid 1rpx #F3F3F3;
  93. background-color: #fff;
  94. // box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  95. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  96. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  97. .foot-item {
  98. display: flex;
  99. width: max-content;
  100. align-items: center;
  101. justify-content: center;
  102. flex-direction: column;
  103. position: relative;
  104. padding: 0 20rpx;
  105. &.active {
  106. color: #2A7EFB
  107. }
  108. }
  109. .foot-item image {
  110. height: 40rpx;
  111. width: 40rpx;
  112. text-align: center;
  113. margin: 0 auto;
  114. }
  115. .foot-item .txt {
  116. font-size: 20rpx;
  117. margin-top: 6rpx;
  118. }
  119. }
  120. </style>