金诚优选前端代码
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.

67 lines
1.5 KiB

  1. <template>
  2. <view>
  3. <lf-tabbar-box :value="currentTabBar"
  4. v-if="isShowTabBar"
  5. :close-animate-on-raisede="false">
  6. <lf-tabbar-item v-for="item in tabbars"
  7. :key="item.name"
  8. :name="item.name"
  9. :icon="item.icon"
  10. :dot="item.dot"
  11. :info="item.info"
  12. :path="item.path"
  13. :raisede="item.raisede"
  14. :style="{'width': 100 / tabbars.length +'%'}"
  15. @click="handleClick"
  16. icon-prefix="icon">
  17. {{ item.text }}
  18. </lf-tabbar-item>
  19. </lf-tabbar-box>
  20. </view>
  21. </template>
  22. <script>
  23. import lfTabbarBox from "./lf-tabbar-box.vue"
  24. import lfTabbarItem from "./lf-tabbar-item.vue"
  25. import { mapGetters } from "vuex";
  26. export default {
  27. name: 'lf-tabbar',
  28. components: {
  29. lfTabbarBox,
  30. lfTabbarItem
  31. },
  32. props: {
  33. type: {
  34. type: String, // 默认跳转方式redirect,可选switch
  35. default: 'redirect'
  36. }
  37. },
  38. computed: {
  39. ...mapGetters(['currentTabBar', 'tabbars', 'isShowTabBar'])
  40. },
  41. created(){
  42. // 组件被创建时检查当前在哪个页面,然后校验currentTabBar是否与之匹配
  43. let pages = getCurrentPages();
  44. let page = pages[pages.length - 1].route;
  45. let tabbar_name = '';
  46. this.tabbars.map(item => {
  47. if(item.path == '/'+ page){
  48. tabbar_name = item.name;
  49. }
  50. })
  51. if(tabbar_name != this.currentTabBar){
  52. this.$store.commit('setCurrentTabBar', tabbar_name);
  53. }
  54. },
  55. methods: {
  56. handleClick (options) {
  57. this.$store.commit('setCurrentTabBar', options.name);
  58. this.$url(options.path, {type: this.type});
  59. }
  60. }
  61. }
  62. </script>
  63. <style>
  64. </style>