当前位置: 首页 > article >正文

vue3 eltable 数据向上移动/向下移动

分为两种情况:

(一)在后台写接口,手动更改排序字段

@Override
    public void updateUpSorNum(long id) {
        RepairBaseDescripDO repairBaseDescripDO = repairBaseDescripMapper.selectById(id);
        int AfterNum = 0;
        int beforeNum = 0;
        beforeNum = repairBaseDescripDO.getSortNum();
        AfterNum = repairBaseDescripDO.getSortNum() + 1;
        QueryWrapper<RepairBaseDescripDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sort_num",AfterNum).eq("head_id",repairBaseDescripDO.getHeadId());
        RepairBaseDescripDO repairBaseDescripDo = repairBaseDescripMapper.selectOne(queryWrapper);
        if (repairBaseDescripDo != null){
            repairBaseDescripDO.setSortNum(repairBaseDescripDo.getSortNum());
        }else {
            throw exception(ALL,"这条数据是最顶级,不能继续向上移动");
        }
        repairBaseDescripDo.setSortNum(beforeNum);
        repairBaseDescripMapper.updateById(repairBaseDescripDo);
        repairBaseDescripMapper.updateById(repairBaseDescripDO);
    }

    @Override
    public void updateDownSorNum(long id) {
        RepairBaseDescripDO repairBaseDescripDO = repairBaseDescripMapper.selectById(id);
        int AfterNum = 0;
        int beforeNum = 0;
        beforeNum = repairBaseDescripDO.getSortNum();
        AfterNum = repairBaseDescripDO.getSortNum() - 1;
        QueryWrapper<RepairBaseDescripDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sort_num",AfterNum).eq("head_id",repairBaseDescripDO.getHeadId());
        RepairBaseDescripDO repairBaseDescripDo = repairBaseDescripMapper.selectOne(queryWrapper);
        if (repairBaseDescripDo != null){
            repairBaseDescripDO.setSortNum(repairBaseDescripDo.getSortNum());
        }else {
            throw exception(ALL,"这条数据是最末级,不能继续向下移动");
        }
        repairBaseDescripDo.setSortNum(beforeNum);
        repairBaseDescripMapper.updateById(repairBaseDescripDo);
        repairBaseDescripMapper.updateById(repairBaseDescripDO);
    }

(二)在前端移动索引后保存时按照顺序存到数据库

<ContentWrap>
      <el-form ref="formRef" :model="formData" :rules="formRules" :inline-message="true">
      <el-table
        :data="formData.mouldData"
        border
        stripe
        highlight-current-row
        :row-class-name="tableRowClassName"
        :cell-style="{ 'text-align': 'center' }"
        @row-click="handleRowClick"
        :header-cell-style="{
          background: '#b7babd',
          color: '#1e1f22',
          height: '35px',
          'text-align': 'center'
        }"
        style="width: 100%;max-height:45vh;overflow-y: auto"
        max-height="600"

      >
        <el-table-column label="序号" label-width="100px" type="index" />
        <el-table-column label="评价项目">
          <template #header> 评价项目</template>
          <template #default="scope">
            <el-form-item
              size="small"
              :prop="'mouldData.[' + scope.$index + '].evaluationProject'"
              :rules="formRules.evaluationProject"
              style="margin-top: 15px"
              v-show="scope.row.show"
            >
              <el-input v-model="scope.row.evaluationProject" size="large" @input="handleInput(scope.row)"/>
            </el-form-item>
            <span v-show="!scope.row.show">{{ scope.row.evaluationProject }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px" v-if="viewStats == '编辑'">
          <template #default="scope">
            <el-button
              v-if="scope.row.rowState == 0"
              link
              type="primary"
              @click="handleOpenFormClick(scope.$index, scope.row, '保存')"
            >
              确认
            </el-button>
            <el-button
              v-if="scope.row.rowState == 0"
              link
              type="primary"
              @click="handleOpenFormClick(scope.$index, scope.row, '取消')"
            >
              取消
            </el-button>
            <el-button
              v-if="scope.row.rowState != 0"
              type="primary"
              link
              @click="handleOpenFormClick(scope.$index, scope.row, '编辑')"
            >编辑
            </el-button>
            <el-button
              v-if="scope.row.rowState != 0"
              link
              type="primary"
              @click="handleOpenFormClick(scope.$index, scope.row, '删除')"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      </el-form>

const init = async () => {
  formData.value.mouldData = []
  versionArray.value = []
  // 获取所有版本号列表
  versionArray.value = versionList
   // 查所有数据列表并根据状态来决定是否是可以编辑的
  let data = await gettableAPi.getTableList(versionType.value)
  if (data) {
    formData.value.mouldData = data
    isFirst.value = false
    // const state = mouldData.value[0]['state']
    const state = formData.value.mouldData[0]?.state
    switch (state) {
      case '0':
        viewStats.value = '编辑'
        showUpgradeMouldButton.value = false
        break
      case '1':
        viewStats.value = '查看'
        showUpgradeMouldButton.value = true // 可升级
        break
      case '3':
        viewStats.value = '查看'
        showUpgradeMouldButton.value = false
        break
      default:
        viewStats.value = '查看'
        showUpgradeMouldButton.value = false
        break
    }
  }
}
const formData = ref({ mouldData: [] }) // 模板数据

// 降序
const handleDescendingOrder = () => {
  console.log('row', rowIndex.value)
  if (rowIndex.value == formData.value.mouldData.length - 1) {
    message.warning('已经是最后一条了')
    return
  }
  let data = formData.value.mouldData
  let temp = formData.value.mouldData[rowIndex.value]
  data[rowIndex.value] = data[rowIndex.value + 1]
  data[rowIndex.value + 1] = temp
  rowIndex.value = rowIndex.value + 1
  formData.value.mouldData = data
}


// 升序
const handleAscendingOrder = () => {
  if (rowIndex.value === 0) {
    message.warning('已经是第一条了')
    return
  }
  console.log('row', rowIndex.value)
  let data = formData.value.mouldData
  let temp = formData.value.mouldData[rowIndex.value]
  data[rowIndex.value] = data[rowIndex.value - 1]
  data[rowIndex.value - 1] = temp
  rowIndex.value = rowIndex.value - 1
  formData.value.mouldData = data
}


http://www.kler.cn/a/298875.html

相关文章:

  • Java文字识别OCR API-手写文字识别-生僻字识别-应用场景
  • ajax中get和post的区别,datatype返回的数据类型有哪些?web开发中数据提交的几种方式,有什么区别。
  • GIS 文件格式 及 常规应用总结
  • 重温设计模式--享元模式
  • 绕组识别标签规范
  • 探索AI代理在《我的世界》中的奇妙之旅:代理IP的角色与影响
  • 在 JavaScript 中,=== 和 ==的区别
  • Python Web 框架篇:Flask、Django、FastAPI介绍及其核心技术
  • gdb中使用python脚本
  • 合宙4G模组Air780EX——产品规格书
  • 通信工程学习:什么是FMC固定移动融合
  • Anthropic 的 Claude AI 如何可能超过 OpenAI 的 ChatGPT?
  • [网络编程]通过java用TCP实现网络编程
  • 景联文科技:专业数据标注公司,推动AI技术革新
  • 【Android】ViewPager基本用法总结
  • 不同工况下的迁移轴承故障诊断,融合SE注意力机制的Resnet18迁移学习,附MATLAB代码...
  • LeetCode53. 最大子数组和(2024秋季每日一题 15)
  • 基于UDP的简易网络通信程序
  • Shell入门
  • Flutter集成Firebase中的Remote Config
  • Ai+若依(集成easyexcel实现excel表格增强)
  • Sky Takeaway
  • WEBSERVER完整体系
  • Java 创建对象方法的演变
  • ARM----时钟
  • Mybatis--SqlSessionFactory 、SqlSession