From 839d5888920b18ea3650016256ec00d082fea8dc Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 28 Jun 2022 19:51:14 +0800 Subject: [PATCH] fix: export of relation blocks (#546) --- .../relation-repository/relation-repository.ts | 4 ++++ packages/core/sdk/src/APIClient.ts | 7 +++++-- .../export/src/client/useExportAction.ts | 18 +++++++++--------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/core/database/src/relation-repository/relation-repository.ts b/packages/core/database/src/relation-repository/relation-repository.ts index 84f593e3d..fbdb28b86 100644 --- a/packages/core/database/src/relation-repository/relation-repository.ts +++ b/packages/core/database/src/relation-repository/relation-repository.ts @@ -40,6 +40,10 @@ export abstract class RelationRepository { this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel); } + get collection() { + return this.db.getCollection(this.targetModel.name); + } + targetKey() { return this.associationField.targetKey; } diff --git a/packages/core/sdk/src/APIClient.ts b/packages/core/sdk/src/APIClient.ts index 8847744e6..9add8fe42 100644 --- a/packages/core/sdk/src/APIClient.ts +++ b/packages/core/sdk/src/APIClient.ts @@ -226,7 +226,7 @@ export class APIClient { } else { config['method'] = 'post'; } - return async (params?: ActionParams) => { + return async (params?: ActionParams, opts?: any) => { const { values, filter, ...others } = params || {}; config['params'] = others; if (filter) { @@ -239,7 +239,10 @@ export class APIClient { if (config.method !== 'get') { config['data'] = values || {}; } - return await this.request(config); + return await this.request({ + ...config, + ...opts, + }); }; }, }; diff --git a/packages/plugins/export/src/client/useExportAction.ts b/packages/plugins/export/src/client/useExportAction.ts index 729f94f06..1c405452a 100644 --- a/packages/plugins/export/src/client/useExportAction.ts +++ b/packages/plugins/export/src/client/useExportAction.ts @@ -4,12 +4,12 @@ import { useBlockRequestContext, useCollection, useCollectionManager, - useCompile, + useCompile } from '@nocobase/client'; import { useTranslation } from 'react-i18next'; export const useExportAction = () => { - const { service } = useBlockRequestContext(); + const { service, resource } = useBlockRequestContext(); const apiClient = useAPIClient(); const actionSchema = useFieldSchema(); const compile = useCompile(); @@ -30,18 +30,18 @@ export const useExportAction = () => { } es.defaultTitle = uiSchema?.title; }); - const { data } = await apiClient.request({ - url: `/${name}:exportXlsx`, - method: 'get', - responseType: 'blob', - params: { + const { data } = await resource.exportXlsx( + { title: compile(title), columns: JSON.stringify(compile(exportSettings)), appends: service.params[0]?.appends?.join(), filter: JSON.stringify(service.params[0]?.filter), }, - }); - + { + method: 'get', + responseType: 'blob', + }, + ); let blob = new Blob([data], { type: 'application/x-xls' }); const a = document.createElement('a'); const blobUrl = window.URL.createObjectURL(blob);