Skip to content

[Bug]:当前excel的导出,会导出全部数据。不能根据查询条件,或者表格内已勾选的数据导出 #2011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mononokeGit opened this issue Apr 16, 2025 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@mononokeGit
Copy link

mononokeGit commented Apr 16, 2025

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)" />

@mononokeGit mononokeGit added the bug Something isn't working label Apr 16, 2025
@mononokeGit mononokeGit changed the title [Bug]: [Bug]:当前excel的导出,会导出全部数据。不能根据查询条件,或者表格内已勾选的数据导出 Apr 16, 2025
@mononokeGit
Copy link
Author

如上修改以后不需要在意是否支持软删除数据过滤

@pixelmaxQm
Copy link
Collaborator

此改动存在问题,当用户主键不为id时,此改动会导致模板报错。

@pixelmaxQm
Copy link
Collaborator

查询条件可以通过模板配置支持

@tangta15
Copy link

tangta15 commented May 7, 2025

我也发现同样的问题, 过滤条件会被忽略掉 params参数没有被正确解析为url.Values
func (sysExportTemplateService *SysExportTemplateService) ExportExcel(templateID string, params url.Values) (file *bytes.Buffer, name string, err error) {
// ... 原有代码 ...
if len(template.JoinTemplate) > 0 {
for _, join := range template.JoinTemplate {
db = db.Joins(join.JOINS + " " + join.Table + " ON " + join.ON)
}
}
db = db.Select(selects).Table(template.TableName)
filterDeleted := false

// 新增:处理 开始
valuesStr := params.Get("params")

values, err := url.ParseQuery(valuesStr)

if err != nil {
	return nil, "", err
}

// 新增:处理 结束

// ... 原有代码 ...

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants