RuoYi前后端不分离版选中导出Excel,封装公用方法
1、在ry-ui.js文件中添加下面的方法
exportSelectedIds: function (selectedIds) {
table.set();
var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
console.log(rows, 'rows')
if (rows.length == 0) {
$.modal.alertWarning("请至少选择一条记录");
return;
}
$.modal.confirm("确认要导出选中的" + rows.length + "条" + table.options.modalName + "吗?", function () {
var dataParam = { "ids": rows.join() }; // 选中的 ID
$.modal.loading("正在导出数据,请稍后...");
$.post(table.options.exportUrlIds, dataParam, function (result) {
if (result.code === web_status.SUCCESS) {
window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
} else if (result.code === web_status.WARNING) {
$.modal.alertWarning(result.msg);
} else {
$.modal.alertError(result.msg);
}
$.modal.closeLoading();
});
});
},
2、在需要导出的位置添加导出按钮html中
<a class="btn btn-warning" onclick="$.table.exportSelectedIds()" shiro:hasPermission="archive:info:export">
<i class="fa fa-download"></i> 导出选中
</a>
var options = {
exportUrl: prefix + "/export",
exportUrlIds: prefix + "/export/selected",//选中导出接口路径
}