Open
Description
gin-vue-admin 版本
2.8.0
Node 版本
22.14.0
Golang 版本
1.24.2
是否依旧存在
可以
bug描述
当前excel的导出,会导出全部数据。不能根据查询条件,或者表格内已勾选的数据导出
修改建议
前端
web\src\components\exportExcel\exportExcel.vue
<script setup>
// ... 省略部分代码 ...
const props = defineProps({
// ... 省略已有props ...
selectedIds: {
type: Array,
default: () => []
}
})
// ... 省略部分代码 ...
const exportExcelFunc = async () => {
// ... 省略部分代码 ...
const paramsCopy = JSON.parse(JSON.stringify(props.condition))
// ... 省略已有参数处理 ...
if (props.selectedIds && props.selectedIds.length > 0) {
paramsCopy.selectedIds = props.selectedIds.join(',')
}
// ... 省略部分代码 ...
}
</script>
后端
server\service\system\sys_export_template.go
func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID string, values url.Values) (file *bytes.Buffer, name string, err error) {
// ... 省略部分代码 ...
db = db.Select(selects).Table(template.TableName)
// 新增:处理 selectedIds 参数
selectedIdsStr := values.Get("selectedIds")
if selectedIdsStr != "" {
ids := strings.Split(selectedIdsStr, ",")
db = db.Where("id IN ?", ids)
} else {
// 处理软删除过滤和条件(原有逻辑)
// ... 原有代码 ...
}
// ... 省略后续代码 ...
}
父组件使用时
<ExportExcel template-id="WarehouseManag_ApplicationsItems" :selected-ids="multipleSelection.map(item => item.ID)" />