Vue 实现批量审核功能实例完整代码(表格批量操作)(Vue开发一)

1 前端部分

效果如下图所示:
Vue 实现批量审核功能实例完整代码(表格批量操作)(Vue开发一)_第1张图片

1.1 html部分
              <el-form-item>
               <el-button type="success" 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: 'success'
                   })
            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 map) throws Exception {
            if (map.get("serverIds")!=null){
                String serverIds = (String) map.get("serverIds");
                List ids = Arrays.asList(serverIds.split(","));
                apiServerMapper.auditServers(ids);
            }
            return ResponseData.success("服务信息修改成功");
        }

转载请注明出处:https://blog.csdn.net/wangjie919/article/details/81103828

你可能感兴趣的:(vue,Spring,Boot)