列表无缝滚动--vue + animated

html部分

<template>
  <div class="table_scroll_wrapper" :style="{width:component.width + 'px',height:component.height + 'px'}">
    <div class="table_scroll" :id="this.$attrs.index">
 <!--表头字段------>
      <div class="table_header" :style="{height: option.singleHeight + 'px', background: option.headerBackgroud}"><span v-for="(h, i) in JSON.parse(option.column)" :key="i">{{h}}</span></div>
 <!--内容------->
      <div class="body_wrap" ref="bodyWrap" :style="{height: component.height-option.singleHeight + 'px'}">
        <ul ref="ulWrap" class="ul_wrap" @mouseenter="mEnter" @mouseleave="mLeave">
          <li v-for="(item, index) in list" :key="index" :style="{height: option.singleHeight + 'px', background: index % 2 ? option.othBackground : ''}">
            <span v-for="(val, ind) in item.column" :key="ind" :style="{color: ind == option.nthColumn-1 ? option.ntdColor : ''}" @click="option.nthColumn == ind + 1 && handleClick(item)">{{val}}</span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

js部分

<script>
import $ from "jquery";
export default {
  name: "TableScroll",
  props: {
    option: Object,
    component: Object,
  },
  data() {
    return {
      screenId: 0,
      column: ['社区', '事件数(件)', '操作'],
      list: [
        {
          column: ['A社区', 'A社区', 'A社区'],
          pieData: [
            {name: "处理中", value: 100},
            {name: "已办结", value: 134}
          ],
          subtext: 234,
          text: '事件总数',
          endRate: '99%',
        },
        {
          column: ['B社区', 'B社区', 'B社区'],
          pieData: [
            {name: "处理中", value: 50},
            {name: "已办结", value: 30}
          ],
          subtext: 80,
          text: '事件总数',
          endRate: '99%',
        },
        {
          column: ['C社区', 'C社区', 'C社区'],
          pieData: [
            {name: "处理中", value: 400},
            {name: "已办结", value: 20}
          ],
          subtext: 420,
          text: '事件总数',
          endRate: '99%',
        },
        {
          column: ['D社区', 'D社区', 'D社区'],
          pieData: [
            {name: "处理中", value: 10},
            {name: "已办结", value: 34}
          ],
          subtext: 44,
          text: '事件总数',
          endRate: '99%',
        },
        {
          column: ['E社区', 'E社区', 'E社区'],
          pieData: [
            {name: "处理中", value: 100},
            {name: "已办结", value: 100}
          ],
          subtext: 200,
          text: '事件总数',
          endRate: '99%',
        },
        {
          column: ['F社区', 'F社区', 'F社区'],
          pieData: [
            {name: "处理中", value: 100},
            {name: "已办结", value: 14}
          ],
          subtext: 114,
          text: '事件总数',
          endRate: '99%',
        }
      ],
      timer: null,  
      marginTop: 0,
      activeIndex: 0,
      tableWindowProps: {
        pieData: [],
        text: '',
        subtext: 0,
        endRate: ''
      }  
    };
  },
  created(){
    this.marginTop = 0
  },
  mounted() {
    this.requestData();
  },
  methods: {
    requestData() {
      var url = this.$attrs.url;
      var tag = this.$attrs.data.tag;
      this.screenId = this.$attrs.data.screenId;
      this.$request
        .post(url, {
          screenId: this.screenId,
          tag,
        })
        .then((res) => {
          if (res.data.success) {
            const { list } = res.data.data;
            this.list = list;
            this.$nextTick(()=> {
              this.scrollTable()
            })
          }
        });
    },
    scrollTable(){
      const _this = this
      let visibleHeight = parseInt(this.$refs.bodyWrap.style.height.split('px')[0])
      let contentHeight = this.$refs.ulWrap.offsetHeight
      if(visibleHeight == contentHeight) return
      this.timer && clearInterval(this.timer)
      this.timer = setInterval(_this.listScroll, 2000)
    },
    listScroll() {
      var that = this;
      //如果是不同高度的列表。可以在计时器开始之前获取列表每项的高度存成数组,增加height[activeIndex]
      const { singleHeight} = this.option
      $("ul.ul_wrap",$(`#${that.$attrs.index}`))
        .stop()
        .animate(
          {
            marginTop: -singleHeight,
          },
          500,
          "linear",
          function () {
            $("ul.ul_wrap",$(`#${that.$attrs.index}`)).find("li").slice(0, 1).appendTo($("ul.ul_wrap",$(`#${that.$attrs.index}`)));
            $("ul.ul_wrap",$(`#${that.$attrs.index}`)).css("margin-top", 0);
            that.activeIndex += 1;
            if (that.activeIndex > that.list.length - 1) {
              that.activeIndex = 0;
            }
          }
        );
    },
    mEnter() {
      clearInterval(this.timer);
    },
    mLeave() {
      this.scrollTable()
    },
    handleClick(item){
      const windowState = this.$attrs.windowState;
      if (windowState !== "1") return;
      this.tableWindowProps.pieData = item.pieData
      this.tableWindowProps.subtext = item.subtext
      this.tableWindowProps.text = item.text
      this.tableWindowProps.endRate = item.endRate
      window.setTableScrollWindowData({
        ...this.tableWindowProps,
      });
      
    }
  },
};
</script>

样式部分

<style lang="scss" scoped>
.table_scroll_wrapper {
  color: #fff;
  .table_scroll{
    .table_header{
      display: flex;
      justify-content: space-around;
      align-items: center;
    }
    .body_wrap{
      overflow: hidden;
      & > ul{
        list-style: none;
        li{
          display: flex;
          justify-content: space-around;
          align-items: center;
        }
      }
    }
  }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ant-design-vue springboot开源集成框架提供了一种将ant-design-vue前端组件库与springboot后端框架集成的解决方案。ant-design-vue是一个优秀的前端UI框架,提供了丰富的组件和样式库,可以帮助开发者快速构建出美观且易于使用的用户界面。 在传统的前后端分离开发中,前端开发者需要自行选择UI框架,并通过RESTful接口与后端进行通信。而使用ant-design-vue springboot开源集成框架,可以直接使用ant-design-vue提供的组件,无需繁琐地搭建UI,同时可以通过框架提供的API与后端进行交互,简化了前后端的协作流程。 具体来说,ant-design-vue springboot开源集成框架基于springboot框架和vue.js框架,提供了一套配置文件和样板代码,用于快速搭建前后端集成项目。框架中已经集成了ant-design-vue的组件库,并提供了一些自定义的样式和组件,使得开发者可以更方便地使用ant-design-vue的组件来构建用户界面。 同时,框架还提供了一些配置选项和API,用于与后端进行通信。开发者可以通过配置选项设置后端接口的URL,然后在前端代码中直接调用框架提供的API方法来发送请求和接收响应。这样,前端与后端之间的数据传输将更加方便和高效。 总之,ant-design-vue springboot开源集成框架是一个优秀的解决方案,可以帮助开发者快速搭建出前后端集成的项目,并使用ant-design-vue提供的丰富组件来构建美观且易于使用的用户界面。有了这个框架的帮助,开发者可以更专注于业务逻辑的实现,提高开发效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值