mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:39:05 +08:00
This commit is contained in:
parent
068c4240d1
commit
71c3324170
@ -2,7 +2,7 @@
|
||||
* 导出 Excel 功能
|
||||
*/
|
||||
|
||||
import {filter, isEffectiveApi, arraySlice} from 'amis-core';
|
||||
import {filter, isEffectiveApi, arraySlice, isObject} from 'amis-core';
|
||||
import './ColumnToggler';
|
||||
import {TableStore} from 'amis-core';
|
||||
import {saveAs} from 'file-saver';
|
||||
@ -425,6 +425,7 @@ export async function exportExcel(
|
||||
}
|
||||
} else if (type == 'link' || (type as any) === 'static-link') {
|
||||
const href = column.pristine.href;
|
||||
|
||||
const linkURL =
|
||||
(typeof href === 'string' && href
|
||||
? filter(href, rowData, '| raw')
|
||||
@ -443,6 +444,8 @@ export async function exportExcel(
|
||||
};
|
||||
} else if (type === 'mapping' || (type as any) === 'static-mapping') {
|
||||
let map = column.pristine.map;
|
||||
const valueField = column.pristine.valueField || 'value';
|
||||
const labelField = column.pristine.labelField || 'label';
|
||||
const source = column.pristine.source;
|
||||
if (source) {
|
||||
let sourceValue = source;
|
||||
@ -462,6 +465,29 @@ export async function exportExcel(
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(map)) {
|
||||
map = map.reduce((res, now) => {
|
||||
if (now == null) {
|
||||
return res;
|
||||
} else if (isObject(now)) {
|
||||
let keys = Object.keys(now);
|
||||
if (
|
||||
keys.length === 1 ||
|
||||
(keys.length == 2 && keys.includes('$$id'))
|
||||
) {
|
||||
// 针对amis-editor的特殊处理
|
||||
keys = keys.filter(key => key !== '$$id');
|
||||
// 单key 数组对象
|
||||
res[keys[0]] = now[keys[0]];
|
||||
} else if (keys.length > 1) {
|
||||
// 多key 数组对象
|
||||
res[now[valueField]] = now;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}, {});
|
||||
}
|
||||
|
||||
if (typeof value !== 'undefined' && map && (map[value] ?? map['*'])) {
|
||||
const viewValue =
|
||||
map[value] ??
|
||||
@ -470,7 +496,23 @@ export async function exportExcel(
|
||||
: value === false && map['0']
|
||||
? map['0']
|
||||
: map['*']); // 兼容平台旧用法:即 value 为 true 时映射 1 ,为 false 时映射 0
|
||||
let text = removeHTMLTag(viewValue);
|
||||
|
||||
let label = viewValue;
|
||||
if (isObject(viewValue)) {
|
||||
if (labelField === undefined || labelField === '') {
|
||||
if (!viewValue.hasOwnProperty('type')) {
|
||||
// 映射值是object
|
||||
// 没配置labelField
|
||||
// object 也没有 type,不能作为schema渲染
|
||||
// 默认取 label 字段
|
||||
label = viewValue['label'];
|
||||
}
|
||||
} else {
|
||||
label = viewValue[labelField || 'label'];
|
||||
}
|
||||
}
|
||||
|
||||
let text = removeHTMLTag(label);
|
||||
|
||||
/** map可能会使用比较复杂的html结构,富文本也无法完全支持,直接把里面的变量解析出来即可 */
|
||||
if (isPureVariable(text)) {
|
||||
|
Loading…
Reference in New Issue
Block a user