Skip to content

通用导出

通用导出excel功能。仅对常用表格数据进行导出,复杂导出自行实现。

服务端接口

增加导出接口,使用post提交查询与导出参数

c#
[HttpPost("export")]
public async Task<FootCallResult<MachinePlayLogOutput>> ExportListAsync([FromBodyDeviceMachinePlayLogListInput input)
  => await GetListAsync(input); // 调用查询方法,参数多增加 FrontendExportInput类型的属性

导出入参需增加参数:ExportInput,其他参数与查询参数相同

c#
public class DeviceMachinePlayLogListInput : PageQueryInput
{
  ......
  /// <summary>
  /// 导出参数
  /// </summary>
  [NotFilterField]
  public FrontendExportInput ExportInput { get; set; }
}

增加导出提交

c#
// 提交导出请求
if (input.ExportInput?.IsExport == true)
{
  _excelExportCommonService.Submit(new SubmitRequest()
  {
    ExportName = "设备机台玩游戏记录".Translating(),
    ExportSetting = ExportFactory.CreateExportSetting(
      input.ExportInput,
      query.ToQueryString(),
      new List<Type>() { typeof(MachinePlayLogOutput) }).ToJsonString()
  });
  return new FootCallResult<MachinePlayLogOutput>() { Success = true };
}

前端接口

js
const onExport = async () => {
  try
  {
    let request = {
      ...conditions.value,
      sortField: searchEvent.value.sortField,
      sortType: searchEvent.value.sortType,
      exportInput: { columns: defineColumns.value } 
    }

    const res: HttpResult<any> = await jingjian.https.post(exportUrl, request);
    if (!res.success) throw new Error(res.msg);
    UIFactory.success(t('添加导出任务成功,请进入导出中心下载'))
  } 
  catch (error) 
  {
    UIFactory.error((<Error>error).message);
  } 
  finally 
  {
    loadingQuery.value = false;
  }
}

广州宝点数字化科技