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); this.targetCollection = this.sourceCollection.context.database.modelCollection.get(this.targetModel);
} }
get collection() {
return this.db.getCollection(this.targetModel.name);
}
targetKey() { targetKey() {
return this.associationField.targetKey; return this.associationField.targetKey;
} }

View File

@ -226,7 +226,7 @@ export class APIClient {
} else { } else {
config['method'] = 'post'; config['method'] = 'post';
} }
return async (params?: ActionParams) => { return async (params?: ActionParams, opts?: any) => {
const { values, filter, ...others } = params || {}; const { values, filter, ...others } = params || {};
config['params'] = others; config['params'] = others;
if (filter) { if (filter) {
@ -239,7 +239,10 @@ export class APIClient {
if (config.method !== 'get') { if (config.method !== 'get') {
config['data'] = values || {}; config['data'] = values || {};
} }
return await this.request(config); return await this.request({
...config,
...opts,
});
}; };
}, },
}; };

View File

@ -4,12 +4,12 @@ import {
useBlockRequestContext, useBlockRequestContext,
useCollection, useCollection,
useCollectionManager, useCollectionManager,
useCompile, useCompile
} from '@nocobase/client'; } from '@nocobase/client';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
export const useExportAction = () => { export const useExportAction = () => {
const { service } = useBlockRequestContext(); const { service, resource } = useBlockRequestContext();
const apiClient = useAPIClient(); const apiClient = useAPIClient();
const actionSchema = useFieldSchema(); const actionSchema = useFieldSchema();
const compile = useCompile(); const compile = useCompile();
@ -30,18 +30,18 @@ export const useExportAction = () => {
} }
es.defaultTitle = uiSchema?.title; es.defaultTitle = uiSchema?.title;
}); });
const { data } = await apiClient.request({ const { data } = await resource.exportXlsx(
url: `/${name}:exportXlsx`, {
method: 'get',
responseType: 'blob',
params: {
title: compile(title), title: compile(title),
columns: JSON.stringify(compile(exportSettings)), columns: JSON.stringify(compile(exportSettings)),
appends: service.params[0]?.appends?.join(), appends: service.params[0]?.appends?.join(),
filter: JSON.stringify(service.params[0]?.filter), filter: JSON.stringify(service.params[0]?.filter),
}, },
}); {
method: 'get',
responseType: 'blob',
},
);
let blob = new Blob([data], { type: 'application/x-xls' }); let blob = new Blob([data], { type: 'application/x-xls' });
const a = document.createElement('a'); const a = document.createElement('a');
const blobUrl = window.URL.createObjectURL(blob); const blobUrl = window.URL.createObjectURL(blob);