超级简单的数据自动滚动el-table表格

今天看到一个需求:

库存预警滚动表格,表格中每行数据由编号、物料及物料名称、仓库及仓库名称、当前库存及库存数量、状态(包括正常(黑色)、不足(绿色)、溢出(红色))构成,表格数据会自动滚动。

先来看一下成果:

直接上代码:




<template>
  <div class="th">
    <el-table class="th" border>
      <!-- 手动固定一个表头 -->
      <el-table-column label="编号" align="center" />
      <el-table-column label="物料" align="center" />
      <el-table-column label="仓库" align="center" />
      <el-table-column label="当前库存" align="center" />
      <el-table-column label="状态" align="center" />
    </el-table>
    <!--设置鼠标移入移出,悬浮时表格暂停动画-->
    <div class="box" @mouseover="pauseAnimation" @mouseout="resumeAnimation">
      <el-table
        :data="data"
        class="table"
        border
        stripe
        :show-header="false"
     
      >
        <el-table-column align="center" label="" prop="id" />
        <el-table-column align="center" label="" prop="matrial" />
        <el-table-column align="center" label="" prop="store" />
        <el-table-column align="center" label="" prop="stock" />
        <el-table-column align="center" label="" prop="status">
          <template slot-scope="scope">
            <span :style="getStatusColor(scope.row.status)">{{ scope.row.status }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-table
        :data="data"
        class="table"
        border
        stripe
        :show-header="false"
  
      >
        <el-table-column align="center" label="" prop="id" />
        <el-table-column align="center" label="" prop="matrial" />
        <el-table-column align="center" label="" prop="store" />
        <el-table-column align="center" label="" prop="stock" />
        <el-table-column align="center" label="" prop="status">
          <template slot-scope="scope">
            <span :style="getStatusColor(scope.row.status)">{{ scope.row.status }}</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [
  { id: 1, matrial: "wood", store: "仓库1", stock: 50, status: "正常" },
  { id: 2, matrial: "wood", store: "仓库1", stock: 50, status: "不足" },
  { id: 3, matrial: "wood", store: "仓库1", stock: 50, status: "不足" },
  { id: 4, matrial: "wood", store: "仓库1", stock: 50, status: "溢出" },
  { id: 5, matrial: "wood", store: "仓库1", stock: 50, status: "正常" },
  { id: 6, matrial: "wood", store: "仓库1", stock: 50, status: "正常" },
  { id: 7, matrial: "wood", store: "仓库1", stock: 50, status: "不足" },
  { id: 8, matrial: "wood", store: "仓库1", stock: 50, status: "溢出" },
  { id: 9, matrial: "wood", store: "仓库1", stock: 50, status: "正常" },
  { id: 10, matrial: "wood", store: "仓库1", stock: 50, status: "正常" },
  { id: 11, matrial: "wood", store: "仓库1", stock: 50, status: "正常" },
  { id: 12, matrial: "wood", store: "仓库1", stock: 50, status: "正常" },
  { id: 13, matrial: "wood", store: "仓库1", stock: 50, status: "正常" },
],

    };
  },
  mounted(){
  
  },
  methods: {
    getStatusColor(status) {
      if (status === "正常") {
        return { color: "" };
      } else if (status === "不足") {
        return { color: "green" };
      } else if (status === "溢出") {
        return { color: "red" };
      }
    },
    pauseAnimation() {
    
      const tables = document.querySelectorAll(".table");
      tables.forEach((table) => {
        table.style.animationPlayState = "paused";
       
      });
    },
    resumeAnimation() {
   
      const tables = document.querySelectorAll(".table");
      tables.forEach((table) => {
        table.style.animationPlayState = "running";
      });
    },
  },
};
</script>

<style scoped>
.box {
  width: 700px;
  overflow: hidden;
  border: 1px solid #eaeef2;
  height: 400px;
}

.table {
  width: 700px;
  animation: table 10s infinite linear;
}

@keyframes table {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(-100%);
  }
}

.th {
  transform: translateY(60px);
  width: 700px;
}
</style>

 这样一个数据可视化的自动滚动表格就做好了,是不是很简单?

  • 7
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值