HttpApi项目,vben28\nswag\refresh.bat 更新前端接口
[HttpPost("export")] [SwaggerOperation(summary: "导出客户列表", Tags = new[] { "Customers" })] [ProducesResponseType(typeof(FileContentResult), (int)HttpStatusCode.OK)] public Task<ActionResult> ExportAsync(PageCustomerInput input) { return _customerAppService.ExportAsync(input); }
application.Contract 项目
public interface ICustomerAppService : IApplicationService { 。。。 Task<ActionResult> ExportAsync(PageCustomerInput input); }
public class ExportCustomerOutput { [ExporterHeader(DisplayName = "客户编号")] public string Code { get; set; } [ExporterHeader(DisplayName = "客户名称")] public string Name { get; set; } }
application 项目
/// <summary> /// 导出列表 /// </summary> [Authorize(BasicManagementPermissions.SystemManagement.UserExport)] public async Task<ActionResult> ExportAsync(PageCustomerInput input) { var list = await _customerManager.GetListAsync(input.PageSize, input.SkipCount, input.Filter); var result = ObjectMapper.Map<List<CustomerDto>, List<ExportCustomerOutput>>(list); var bytes = await _excelExporter.ExportAsByteArray<ExportCustomerOutput>(result); return new XlsxFileResult(bytes: bytes, fileDownloadName: $"导出列表{Clock.Now:yyyyMMdd}"); }
public ERPApplicationAutoMapperProfile() { CreateMap<CustomerDto, ExportCustomerOutput>(); }
前端页面 index.ts
const [openFullLoading, closeFullLoading] = useLoading({ tip: 'Loading...', }); export function exportAsync({ request }) { openFullLoading(); const customerServiceProxy = new CustomersServiceProxy(); customerServiceProxy.export(request).then((res) => { const a = document.createElement('a'); a.href = URL.createObjectURL(res.data); a.download = '用户列表导出.xlsx'; a.click(); closeFullLoading(); }); }
index.vue
<script lang="ts"> ... import { tableColumns, searchFormSchema, pageAsync, deleteAsync,exportAsync } from './Index'; const handleExport = () => { const { getFieldsValue } = getForm(); let request = getFieldsValue(); exportAsync({ request }); };
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?