Element——table排序,上移下移功能。及按钮上一条下一条功能

需求:table排序,可操作排序上移下移功能。判断第一行上移禁用和最后一行下移禁用,排序根据后端返回的字段

javascript 复制代码
 <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column type="index" label="序号" align="center" min-width="50">
        <template slot-scope="scope">
          <span>{{ scope.$index + (pageNum - 1) * pageSize + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="name"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="排序">
         <template slot-scope="scope">
			<el-button
                  type="text"
                  disabled={index === 0}
                  @click={e => this.sortFunction(e, row, "1")}
                >
                  上移
                </el-button>
                <el-button
                  type="text"
                  disabled={index === this.tableData.length - 1}
                  @click={e => this.sortFunction(e, row, "2")}
                >
                  下移
                </el-button>
            </el-table-column>
      </el-table-column>
      <el-table-column prop="address" label="操作" min-width="200" align="center">
        <template slot-scope="scope">
          <el-button
            >编辑
          </el-button>

          <el-button  @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
javascript 复制代码
sortFunction(e, row, type) {
      changeSort({//排序接口
        sortType: type,
        templateConfigId: row.templateConfigId
      }).then(res => {
        if (res.code === 200) {
          this.getList();//获取表格接口
        }
      });
    },

按钮上一条下一条功能

javascript 复制代码
            <div class="right-bottom">
              <el-button
                class="end-upon btns"
                :disabled="uponindex === 0"
                :class="isEndBtn === true ? 'isActive' : ''"
                @click="endUponClick()"
                >上一条</el-button
              >
              <el-button
                class="end-next btns"
                :disabled="isDisabled"
                :class="isNextBtn === true ? 'isActive' : ''"
                @click="endNextClick()"
                >下一条</el-button
              >
            </div>
javascript 复制代码
//上一条按钮
    endUponClick() {
      //存老的值 oldName
      let oldName = this.activeName;//this.activeName 当前选中的那一条数据
      let addNum = this.activeName - 1;
      this.tabsList.forEach((item, index) => {
        if (addNum === 0) {
          this.isEndBtn = true;
          this.isBtnDisabled = true;
          this.isNextBtn = false;
          this.$message({
            message: '此项为第一条数据',
            type: 'warning'
          });
        }
        if (addNum === item.sort) {
          this.activeName = addNum;
          if (item.testStatus === '2') {
            this.onSetShow = true;
          } else {
            this.onSetShow = false;
          }
          //当前选中的那一条
          this.tabsList.forEach(v => {
            if (oldName === v.sort) {
              this.contentCode = v.contentCode;
              this.debugContent = v.debugContent;
              this.testStatus = v.testStatus;
              this.dataRecordResultList = v.dataRecordResult;
            }
          });
          this.isEndBtn = true;
          this.isNextBtn = false;
          this.activeName = addNum;
          this.updateInfo(this.dataRecordResultList);
        }
      });
    },

//下一条按钮
    endNextClick() {
      //存老的值 oldName
      let oldName = this.activeName;//this.activeName 当前选中的那一条数据
      let addNum = this.activeName + 1;
      let lengthNum = this.tabsList.length + 1;
      this.tabsList.forEach((item, index) => {
        if (addNum === lengthNum) {
          this.isNextBtn = true;
          this.isEndBtn = false;
          this.isBtnDisabled = true;
          this.$message({
            message: '此项为最后一条数据',
            type: 'warning'
          });
        } else {
          if (addNum === item.sort) {
            this.activeName = addNum;
            if (item.testStatus === '2') {
              this.onSetShow = true;
            } else {
              this.onSetShow = false;
            }
            //当前选中的那一条
            this.tabsList.forEach(v => {
              if (oldName === v.sort) {
                this.contentCode = v.contentCode;
                this.debugContent = v.debugContent;
                this.testStatus = v.testStatus;
                this.dataRecordResultList = v.dataRecordResult;
              }
            });
            this.isNextBtn = true;
            this.isEndBtn = false;
            this.activeName = addNum;
            this.updateInfo(this.dataRecordResultList);
          }
        }
      });
    },
相关推荐
风骏时光牛马28 分钟前
生成一个移动端标题,只需要一个标题,不需要其他的任何文本。
前端
IT_陈寒1 小时前
Redis雪崩把我坑惨了,这是5年经验的教训
前端·人工智能·后端
SameX1 小时前
HarmonyOS ArkUI List 的侧滑删除 用 ListItem 的 swipeAction + endIcon 的做法
前端
usdoc文档预览3 小时前
USDOC系列之PPT文件在线编辑-VUE前端实现在线浏览器在线编辑PPT文档
前端·vue.js·编辑器·office365·ppt在线编辑·office文件在线编辑·文件在线编辑
用户2705077725243 小时前
Agent 调工具卡住?3 种超时与取消策略实测对比
前端
LuHang4 小时前
我一行代码没写,把领导派的活做成了公司内部系统😭
前端
明月_清风5 小时前
Meta 开源了一个 AI Native 组件库:Astryx,150+ React 组件,专为 AI Agent 而设计
前端·人工智能·ai编程
用户850869276155 小时前
秒杀系统中 Shell 脚本并发控制 Bug:究竟哪里出了
前端
程序员大阳7 小时前
HTML+CSS+JS对话式实战(3)-活动管理页实现查询、新增、删除API后端接口
javascript·css·html·实战·删除·查询·新增
炫酷的大高个7 小时前
6 亿播放的闪身步,我用前端算出 15 倍重心差
前端·javascript