表格拖动排序

            <el-table
        :data="tabListDataS"
        ref="singleTable"
        row-key="id"
        max-height="350"
      >
        <el-table-column
          prop="name"
          label="关注游戏名称"
          width="220"
        ></el-table-column>
        <el-table-column
          prop="sort"
          label="排序"
          type="index"
          width="120"
        ></el-table-column>
        <el-table-column
          label="操作"
          width="180"
        >
          <template #default="scope">
            <div>
              <img
                style="cursor: pointer"
                src="./gantt/icon/顺序备份5.svg"
                alt
              />
              <img
                v-if="scope.row.cancel === false"
                style="cursor: pointer; padding-left: 20px; padding-right: 20px"
                src="./gantt/icon/编组10备份13.svg"
                alt
                @click.prevent="deletRow(scope.row, scope.$index)"
                v-buriedPointClick="[GetRouter,173,'search']"
              />
            </div>
          </template>
        </el-table-column>
      </el-table>
import Sortable from "sortablejs";

  data() {
    return {
      tabListDataS: [],
    };
  },
    init() {
      this.$nextTick(() => {
        this.dragSort()
      })
    },
    //表格拖动排序
    dragSort() {
      const tbody = this.$refs.singleTable.$el.querySelector(
        ".el-table__body-wrapper tbody"
      );
      const selft = this;
      Sortable.create(tbody, {
        animation: 400, //动画参数
        onEnd({ newIndex, oldIndex }) {
          let tData = JSON.parse(JSON.stringify(selft.tabListDataS));
          const currRow = tData.splice(oldIndex, 1)[0];
          tData.splice(newIndex, 0, currRow);
          selft.tabListDataS = [];
          setTimeout(() => {
            selft.tabListDataS = tData;
          }, 5);
          let YData = tData.map((e) => {
            let Focus = { id: e.id, sort: e.sort };
            return Focus;
          });
          const tempArr = [];
          YData.forEach((e) => {
            tempArr.push(e.sort);
          });
          tempArr.sort((a, b) => a - b);
          tempArr.forEach((e, i) => {
            YData[i].sort = e;
          });
          // const Focus = {
          // updateList: YData,
          // userName: selft.userinformation.userName,
          // };
          userintelligencetagSort(YData)
            .then((res) => {
              if (res.code === 0) {
                ElMessage({
                  message: "排序成功!",
                  type: "success",
                });
                selft.$parent.updateList()
              } else {
                ElMessage({
                  message: res.message,
                  type: "warning",
                });
              }
            })
            .catch((err) => {
              ElMessage({
                message: err,
                type: "error",
              });
            });
        },
      });
    },

Sortablejs的用法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值