mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:48:13 +08:00
fix: 修复 export-excel 中 mapping 不支持 source 变量问题 Closes #5134
This commit is contained in:
parent
79d87ca940
commit
9981be2d10
@ -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',
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user