fix: 修复 export-excel 中 mapping 不支持 source 变量问题 Closes #5134

This commit is contained in:
wuduoyi 2023-05-29 18:46:05 +08:00
parent 79d87ca940
commit 9981be2d10
2 changed files with 21 additions and 17 deletions

View File

@ -4,6 +4,9 @@ export default {
type: 'crud',
headerToolbar: ['export-excel', 'export-csv'],
data: {
mapping_type: {
'*': '其他'
},
items: [
{
link: 'https://www.microsoft.com/',
@ -188,6 +191,12 @@ export default {
D: '极差'
}
},
{
name: 'grade',
label: 'CSS grade',
type: 'mapping',
source: '${mapping_type}'
},
{
name: 'date',
label: 'Date',

View File

@ -2,7 +2,7 @@
* Excel
*/
import {filter} from 'amis-core';
import {filter, isEffectiveApi} from 'amis-core';
import './ColumnToggler';
import {TableStore} from 'amis-core';
import {saveAs} from 'file-saver';
@ -359,27 +359,22 @@ export async function exportExcel(
hyperlink: absoluteURL
};
} else if (type === 'mapping' || (type as any) === 'static-mapping') {
// 拷贝自 Mapping.tsx
let map = column.pristine.map;
const source = column.pristine.source;
if (source) {
let sourceValue = source;
if (isPureVariable(source)) {
sourceValue = resolveVariableAndFilter(
source as string,
rowData,
'| raw'
);
}
const mapKey = JSON.stringify(source);
if (mapKey in remoteMappingCache) {
map = remoteMappingCache[mapKey];
} else {
const res = await env.fetcher(sourceValue, rowData);
if (res.data) {
remoteMappingCache[mapKey] = res.data;
map = res.data;
map = resolveVariableAndFilter(source as string, rowData, '| raw');
} else if (isEffectiveApi(source, data)) {
const mapKey = JSON.stringify(source);
if (mapKey in remoteMappingCache) {
map = remoteMappingCache[mapKey];
} else {
const res = await env.fetcher(sourceValue, rowData);
if (res.data) {
remoteMappingCache[mapKey] = res.data;
map = res.data;
}
}
}
}