本文实例为大家分享了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<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("服务信息修改成功"); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。