Vue实现表格批量审核功能实例代码

网络编程 2021-07-04 15:50www.168986.cn编程入门
这篇文章主要为大家详细介绍了Vue实现表格批量审核功能实例代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Vue实现表格批量审核功能的具体代码,供大家参考,具体内容如下

1 前端部分

效果如下图所示


1.1 html部分

 <el-form-item>
   <el-button type="suess" icon="el-icon-search" @click="auditServer()" :disabled="this.sels.length === 0">批量审核</el-button>
    <el-button @click="toggleSelection()">取消选择</el-button>
    </el-form-item>
    </br>
    <el-table border :fit="true" ref="multipleTable" height="520" :data="listData" :highlight-current-row="true" size="small" @selection-change="selsChange" @row-click="handleChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="applcd" label="微服务编码" show-overflow-tooltip width="130px" sortable fixed="left"></el-table-column>
        <el-table-column prop="servcd" label="服务编码" show-overflow-tooltip width="130px" sortable fixed="left"></el-table-column>
 </el-table>

代码说明

1)为table添加属性

@selection-change="selsChange" @row-click="handleChange"

2)添加一列 指定type为selection,表示该表格可选择

<el-table-column type="selection" width="55"></el-table-column>

3)当没有选择服务时,按钮不可选;

:disabled="this.sels.length === 0"

1.2 js部分

export default {
 data () {
  return {

   sels:[],


 methods: {


  selsChange(sels) {
    this.sels = sels
  },

  handleChange(row, event, column) {
    this.$refs.multipleTable.toggleRowSelection(row)
  },
  auditServer () {
   var servids = this.sels.map(item => item.servid).join(",")
   var params = {
    serverIds:servids
   }
     debugger
     auditServer(params).then(
     function (res) {
     debugger
      if(res.code === 200){
      this.$message({
           message: res.data,
           type: 'suess'
          })
      this.dialogFormVisible = false
      }else{
      this.$message({
         message: '错误信息'+res.message,
         type: 'error'
        });
      }
        this.loadData()
     }.bind(this)
    )
  },

  toggleSelection(){
  this.$refs.multipleTable.clearSelection();
  }
 }
}

2 后端部分

2.1 mapper.xml

批量修改的Mybatis实现方式,注意sql语句的书写

<!--审核服务信息-->
  <update id="auditServers" parameterType="java.util.List">
    update sdcp_serv
    SET ISAUDITED ='1'
    where servid in
    <foreach collection="list" index="index" item="item"
         separator="," open="(" close=")">
      #{item,jdbcType=VARCHAR}
    </foreach>
</update>

2.2 mapper.java(对应的接口)

int auditServers(List<String> servids);

2.3 controller

/  
  @Description: 批量审核服务信息 
  @param @param map
  @param @return
  @param @throws Exception  参数 
  @return Object  返回类型  
 / 
    @RequestMapping(value = "/auditServers", method = RequestMethod.POST)
    public Object auditServers(@RequestBody Map<String, Object> map) throws Exception {
      if (map.get("serverIds")!=null){
        String serverIds = (String) map.get("serverIds");
        List<String> ids = Arrays.asList(serverIds.split(","));
        apiServerMapper.auditServers(ids);
      }
      return ResponseData.suess("服务信息修改成功");
 }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by