美文网首页
小程序的选项卡结合左右滑动

小程序的选项卡结合左右滑动

作者: 倩仔6 | 来源:发表于2020-08-27 20:37 被阅读0次

这个是uni小程序的选项卡结合左右滑动

<template>
  <view class="body-view">
    <scroll-view
      class="top-menu-view"
      scroll-x="true"
      :scroll-left="scrollLeft"
    >
      <block v-for="(menuTab, index) in menuTabs" :key="index">
        <view
          class="menu-one-view"
          v-bind:id="'tabNum' + index"
          @click="swichMenu(index)"
        >
          <view :class="[num == index ? 'menu-one-act' : 'menu-one']">
            <view class="menu-one-txt">{{ menuTab.name }}</view>
            <view class="menu-one-bottom">
              <view class="menu-one-bottom-color"></view>
            </view>
          </view>
        </view>
      </block>
    </scroll-view>
    <swiper
      :current="num"
      class="swiper-box-list"
      duration="300"
      @change="swiperChange"
    >
      <block v-for="(swiperDate, index1) in swiperDateList" :key="index1">
        <swiper-item>
          <scroll-view
            class="swiper-one-list"
            scroll-y="true"
            @scrolltolower="loadMore(index1)"
            refresher-enabled="true"
            :refresher-triggered="triggered"
            @refresherrefresh="onRefresh"
          >
            <block>
              <view class="swiper-list-entity">
                <div class="tabCon">
                  {{ index1 }}
                  <!-- 这里面写循环数据 -->
                </div>
              </view>
            </block>
          </scroll-view>
        </swiper-item>
      </block>
    </swiper>
  </view>
</template>
<script>
import { comBxList } from "@/api/api"; //报修列表
export default {
  data() {
    return {
      scrollLeft: 0,
      listBx: [], //数据
      listCount: {}, //总个数
      bottomText: "",
      loginInfo: {},
      num: 0,
      pageSize: 10, //当前页面数量
      pageNum: 1, //当前页码
      menuTabs: [
        {
          name: "待接单",
        },
        {
          name: "待维修",
        },
        {
          name: "已修复",
        },
        {
          name: "已取消",
        },
      ],
      swiperDateList: [[], [], [], []],
      triggered: false,
      _freshing: false,
    };
  },

  created() {
    console.log(this.num, "num");
    var that = this;
    uni.getStorage({
      key: "logininfo",
      success: function(res) {
        that.loginInfo = res.data;
        // that.List();
      },
    });
  },
  methods: {
    swichMenu: async function(current) {
      console.log(current, "current", this.num, "this.num点击其中一个 menu");
      //点击其中一个 menu
      if (this.num == current) {
        return false;
      } else {
        this.num = current;
        this.setScrollLeft(current);
      }
    },
    swiperChange: async function(e) {
      let index = e.target.current;
      this.num = index;
      this.pageNum = 1;
      // this.List();
      this.setScrollLeft(index);
    },
    setScrollLeft: async function(tabIndex) {
      let leftWidthSum = 0;
      for (var i = 0; i <= tabIndex; i++) {
        let nowElement = await this.getWidth("tabNum" + i);
        leftWidthSum = leftWidthSum + nowElement.width;
      }
      let winWidth = uni.getSystemInfoSync().windowWidth;
      this.scrollLeft = leftWidthSum > winWidth ? leftWidthSum - winWidth : 0;
    },
    getWidth: function(id) {
      //得到元素的宽高
      return new Promise((res, rej) => {
        uni
          .createSelectorQuery()
          .select("#" + id)
          .fields(
            {
              size: true,
              scrollOffset: true,
            },
            (data) => {
              res(data);
            }
          )
          .exec();
      });
    },
  },
};
</script>
<style scoped>
page {
  width: 100%;
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  background: rgba(249, 249, 249, 1);
}

.body-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  width: 100%;
  align-items: flex-start;
  justify-content: center;
}

.top-menu-view {
  display: flex;
  white-space: nowrap;
  width: 100%;
  background-color: #f3f3f3;
  height: 112rpx;
  justify-content: center;
  color: #3c3c3c;
  /* 在这里设置导航条高度 */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

.top-menu-view .menu-one-view {
  display: inline-block;
  white-space: nowrap;
  height: 100%;
  width: 25%;
  /* width: 50%; */
  /* flex: 1; */
}

.top-menu-view .menu-one-view .menu-one {
  /* 在这里写 单个按钮样式 */
  margin-left: 25rpx;
  margin-right: 25rpx;
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-menu-view .menu-one-view .menu-one .menu-one-txt {
  height: 40rpx;
  font-size: 28rpx;
  font-weight: 400;
  color: rgba(154, 154, 154, 1);
  line-height: 40rpx;
}

.top-menu-view .menu-one-view .menu-one .menu-one-bottom {
  position: absolute;
  bottom: 0;
  width: 100%;
}

.top-menu-view
  .menu-one-view
  .menu-one
  .menu-one-bottom
  .menu-one-bottom-color {
  width: 60%;
  height: 4rpx;
}

.top-menu-view .menu-one-view .menu-one-act {
  /* 在这里写 单个按钮样式 */
  margin-left: 25rpx;
  margin-right: 25rpx;
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-menu-view .menu-one-view .menu-one-act .menu-one-txt {
  height: 40rpx;
  font-size: 28rpx;
  font-weight: 400;
  color: #2e2e2e;
  line-height: 40rpx;
}

.top-menu-view .menu-one-view .menu-one-act .menu-one-bottom {
  position: absolute;
  bottom: 0;
  width: 100%;
  display: flex;
  justify-content: center;
}

.top-menu-view
  .menu-one-view
  .menu-one-act
  .menu-one-bottom
  .menu-one-bottom-color {
  width: 60%;
  height: 6rpx;
  background: #2e2e2e;
}

.swiper-box-list {
  flex: 1;
  width: 100%;
  height: auto;
  background-color: #ffffff;
  margin-top: 112rpx;
}

.swiper-one-list {
  height: 100%;
  width: 100%;
}

.swiper-one-list .swiper-list-entity {
  width: 100%;
  /* height: 112rpx; */
  /* text-align: center; */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}

.tabCon {
  width: 90%;
  padding: 0 5%;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(34, 34, 34, 1);
  line-height: 34px;
  flex: 1;
}
</style>

相关文章

  • 小程序的选项卡结合左右滑动

    这个是uni小程序的选项卡结合左右滑动

  • 小程序左右滑动

    左右滑动还是我们写小程序页面时经常遇到的一个布局,所以今天就摘出来写一个小demo,后面遇到就不用再想了,主要是比...

  • 微信小程序——左右滑动切换页面

    微信小程序——左右滑动切换页面事件 微信小程序的左右滑动触屏事件,主要有三个事件:touchstart,touch...

  • 2019-11-11

    防止小程序左右超出,导致左右滑动的问题: 防止小程序弹出层中,背景滚动的问题: 在元素中添加这个: 具体看以下链接...

  • 微信小程序(三)

    昨晚再一次体验到了程序员的加班,开始慢慢习惯了-.-今天谈一谈关于滚动Tab选项卡:左右可滑动切换的效果,效果最终...

  • 微信小程序滚动Tab选项卡:左右可滑动切换

    最终效果如上。问题:1、tab标题总共8个,所以一屏无法全部显示。2、tab内容区左右滑动切换时,tab标题随即做...

  • 小程序Tab选项卡滑动切换

    从事前端的同学们一定不会对选项卡陌生,不管是自己原生写的,还是各个UI框架里带的,我想大家都使用过很多选项卡,对选...

  • 左右滑动+选项卡切换视图

    需求 左右可滑动+选项卡切换视图,相信大多数人都做过这样的需求,就我接触到的做个整理. 根据不同情况我会分两种情况...

  • 小程序组件 scroll-view

    小程序组件 scroll-view 中分别有上下竖向滑动和左右横向滑动之分,在这次项目中刚好需要用到横向滑动,但在...

  • 微信小程序开发教程(基础篇)10-滑动操作

    微信小程序开发教程(基础篇)9-事件 在实际的移动应用程序交互方式中,最常见的就是滑动操作。像左右滑动切换页面,手...

网友评论

      本文标题:小程序的选项卡结合左右滑动

      本文链接:https://www.haomeiwen.com/subject/edyhsktx.html