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

效果如下图所示:

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


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" :data="listData" :highlight-current-row="true" size="small" @selection-change="selsChange" @row-click="handleChange"> <el-table-column type="selection"></el-table-column> <el-table-column prop="applcd" label="微服务编码" show-overflow-tooltip sortable fixed="left"></el-table-column> <el-table-column prop="servcd" label="服务编码" show-overflow-tooltip sortable fixed="left"></el-table-column> </el-table>

代码说明:

1)为table添加属性

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

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

<el-table-column type="selection"></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 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.success("服务信息修改成功"); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b3e0ac74758860a34ae458d10c95a5c6.html