chore: 导出 Excel 的 tpl 模式默认滤掉 html 标签 (#2147)

This commit is contained in:
吴多益 2021-06-24 10:18:25 +08:00 committed by GitHub
parent 56e9602869
commit 6d8f264720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -155,7 +155,8 @@ export default {
{
name: 'engine.version',
label: 'CSS版本',
tpl: '${engine.version}'
type: 'tpl',
tpl: '<b>${engine.version}</b>'
},
{
name: 'grade',

View File

@ -15,7 +15,8 @@ import {
noop,
autobind,
isArrayChildrenModified,
getVariable
getVariable,
removeHTMLTag
} from '../../utils/helper';
import {resolveVariable} from '../../utils/tpl-builtin';
import debounce from 'lodash/debounce';
@ -1993,9 +1994,8 @@ export default class Table extends React.Component<TableProps, object> {
}
} else {
if ((column as TplSchema).tpl) {
sheetRow.getCell(columIndex).value = filter(
(column as TplSchema).tpl,
row.data
sheetRow.getCell(columIndex).value = removeHTMLTag(
filter((column as TplSchema).tpl, row.data)
);
} else {
sheetRow.getCell(columIndex).value = value;

View File

@ -1584,3 +1584,8 @@ export function detectPropValueChanged<
onChange(props.defaultValue);
}
}
// 去掉字符串中的 html 标签,不完全准确但效率比较高
export function removeHTMLTag(str: string) {
return str.replace(/<\/?[^>]+(>|$)/g, '');
}