fix: export of relation blocks (#546)

This commit is contained in:
chenos 2022-06-28 19:51:14 +08:00 committed by GitHub
parent fdb7b4c664
commit 839d588892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 11 deletions

View File

@ -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;
}

View File

@ -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,
});
};
},
};

View File

@ -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);