随笔 - 435  文章 - 0  评论 - 111  阅读 - 62万 

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 });
      };
复制代码

 

posted on   Gu  阅读(256)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
点击右上角即可分享
微信分享提示