Chart 优化 & 添加新的 tpl filter (#1199)

* 弄着玩

* 优化 chart

* 还原一下代码
This commit is contained in:
liaoxuezhi 2020-12-18 02:54:47 +08:00 committed by GitHub
parent 27642497ff
commit 6b2ccdba41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 2 deletions

View File

@ -1,9 +1,11 @@
export default {
type: 'page',
type: 'page',
title: '标题',
remark: {
title: '标题',
body: '这是一段描述问题,注意到了没,还可以设置标题。而且只有点击了才弹出来。',
body:
'这是一段描述问题,注意到了没,还可以设置标题。而且只有点击了才弹出来。',
icon: 'question-mark',
placement: 'right',
trigger: 'click',

View File

@ -54,10 +54,15 @@ export interface ChartSchema extends BaseSchema {
initFetchOn?: SchemaExpression;
/**
* echart的config
* echart的config trackExpression
*/
config?: any;
/**
* Echart config
*/
trackExpression?: string;
/**
*
*/
@ -214,6 +219,13 @@ export class Chart extends React.Component<ChartProps> {
}
} else if (props.config !== prevProps.config) {
this.renderChart(props.config || {});
} else if (
props.config &&
props.trackExpression &&
filter(props.trackExpression, props.data) !==
filter(prevProps.trackExpression, prevProps.data)
) {
this.renderChart(props.config || {});
}
}

View File

@ -145,6 +145,32 @@ export const filters: {
return ret;
},
raw: input => input,
now: () => new Date(),
toDate: (input: any, inputFormat = '') => {
const data = moment(input, inputFormat);
data.add();
return data.isValid() ? data.toDate() : undefined;
},
dateModify: (
input: any,
modifier: 'add' | 'subtract' | 'endOf' | 'startOf' = 'add',
amount = 0,
unit = 'days'
) => {
if (!(input instanceof Date)) {
input = new Date();
}
if (modifier === 'endOf' || modifier === 'startOf') {
return moment(input)
[modifier === 'endOf' ? 'endOf' : 'startOf'](amount || 'day')
.toDate();
}
return moment(input)
[modifier === 'add' ? 'add' : 'subtract'](amount, unit)
.toDate();
},
date: (input, format = 'LLL', inputFormat = 'X') =>
moment(input, inputFormat).format(format),
number: input => {
@ -214,6 +240,15 @@ export const filters: {
last: input => input && (input.length ? input[input.length - 1] : null),
minus: (input, step = 1) => (parseInt(input, 10) || 0) - parseInt(step, 10),
plus: (input, step = 1) => (parseInt(input, 10) || 0) + parseInt(step, 10),
sum: (input, field) =>
Array.isArray(input)
? input.reduce(
(sum, item) =>
sum + (parseFloat(field ? pickValues(field, item) : item) || 0),
0
)
: input,
abs: (input: any) => (typeof input === 'number' ? Math.abs(input) : input),
pick: (input, path = '&') =>
Array.isArray(input) && !/^\d+$/.test(path)
? input.map((item, index) =>