forked from p96170835/amis
修复条件过滤器无法返回数字类型
This commit is contained in:
parent
8de3fac68f
commit
d371d93545
|
@ -101,17 +101,17 @@ export const filterDate = (
|
|||
const from = m[1]
|
||||
? filterDate(m[1], data, format, utc)
|
||||
: mm(
|
||||
/(minute|min|hour|second)s?/.test(m[4])
|
||||
? [
|
||||
date.getFullYear(),
|
||||
date.getMonth(),
|
||||
date.getDate(),
|
||||
date.getHours(),
|
||||
date.getMinutes(),
|
||||
date.getSeconds()
|
||||
]
|
||||
: [date.getFullYear(), date.getMonth(), date.getDate()]
|
||||
);
|
||||
/(minute|min|hour|second)s?/.test(m[4])
|
||||
? [
|
||||
date.getFullYear(),
|
||||
date.getMonth(),
|
||||
date.getDate(),
|
||||
date.getHours(),
|
||||
date.getMinutes(),
|
||||
date.getSeconds()
|
||||
]
|
||||
: [date.getFullYear(), date.getMonth(), date.getDate()]
|
||||
);
|
||||
|
||||
return m[2] === '-'
|
||||
? from.subtract(step, timeUnitMap[m[4]] as moment.DurationInputArg2)
|
||||
|
@ -348,7 +348,14 @@ export const filters: {
|
|||
* @param data 数据域
|
||||
*/
|
||||
function getStrOrVariable(arg: string, data: any) {
|
||||
return /^('|")(.*)\1$/.test(arg) ? RegExp.$2 : resolveVariable(arg, data);
|
||||
|
||||
return /^('|")(.*)\1$/.test(arg)
|
||||
? RegExp.$2
|
||||
: /^-?\d+$/.test(arg)
|
||||
? parseInt(arg, 10)
|
||||
: /^(-?\d+)\.\d+?$/.test(arg)
|
||||
? parseFloat(arg)
|
||||
: resolveVariable(arg, data);
|
||||
}
|
||||
|
||||
function getConditionValue(
|
||||
|
@ -485,44 +492,44 @@ export const resolveVariableAndFilter = (
|
|||
return ret == null && !~originalKey.indexOf('default')
|
||||
? ''
|
||||
: paths.reduce((input, filter) => {
|
||||
let params = filter
|
||||
.replace(
|
||||
/([^\\])\\([\:\\])/g,
|
||||
(_, affix, content) =>
|
||||
`${affix}__${content === ':' ? 'colon' : 'slash'}__`
|
||||
let params = filter
|
||||
.replace(
|
||||
/([^\\])\\([\:\\])/g,
|
||||
(_, affix, content) =>
|
||||
`${affix}__${content === ':' ? 'colon' : 'slash'}__`
|
||||
)
|
||||
.split(':')
|
||||
.map(item =>
|
||||
item.replace(/__(slash|colon)__/g, (_, type) =>
|
||||
type === 'colon' ? ':' : '\\'
|
||||
)
|
||||
.split(':')
|
||||
.map(item =>
|
||||
item.replace(/__(slash|colon)__/g, (_, type) =>
|
||||
type === 'colon' ? ':' : '\\'
|
||||
)
|
||||
);
|
||||
let key = params.shift() as string;
|
||||
);
|
||||
let key = params.shift() as string;
|
||||
|
||||
if (
|
||||
~[
|
||||
'isTrue',
|
||||
'isFalse',
|
||||
'isMatch',
|
||||
'isEquals',
|
||||
'notMatch',
|
||||
'notEquals'
|
||||
].indexOf(key)
|
||||
) {
|
||||
if (prevConInputChanged) {
|
||||
return input;
|
||||
} else {
|
||||
const result = filters[key].call(data, input, ...params);
|
||||
prevConInputChanged = result !== input;
|
||||
return result;
|
||||
}
|
||||
if (
|
||||
~[
|
||||
'isTrue',
|
||||
'isFalse',
|
||||
'isMatch',
|
||||
'isEquals',
|
||||
'notMatch',
|
||||
'notEquals'
|
||||
].indexOf(key)
|
||||
) {
|
||||
if (prevConInputChanged) {
|
||||
return input;
|
||||
} else {
|
||||
// 后面再遇到非类三元filter就重置了吧,不影响再后面的其他三元filter
|
||||
prevConInputChanged = false;
|
||||
const result = filters[key].call(data, input, ...params);
|
||||
prevConInputChanged = result !== input;
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
// 后面再遇到非类三元filter就重置了吧,不影响再后面的其他三元filter
|
||||
prevConInputChanged = false;
|
||||
}
|
||||
|
||||
return (filters[key] || filters.raw).call(data, input, ...params);
|
||||
}, ret);
|
||||
return (filters[key] || filters.raw).call(data, input, ...params);
|
||||
}, ret);
|
||||
};
|
||||
|
||||
export const tokenize = (
|
||||
|
@ -559,8 +566,8 @@ function resolveMapping(
|
|||
return typeof value === 'string' && isPureVariable(value)
|
||||
? resolveVariableAndFilter(value, data, defaultFilter)
|
||||
: typeof value === 'string' && ~value.indexOf('$')
|
||||
? tokenize(value, data, defaultFilter)
|
||||
: value;
|
||||
? tokenize(value, data, defaultFilter)
|
||||
: value;
|
||||
}
|
||||
|
||||
export function dataMapping(to: any, from: PlainObject): any {
|
||||
|
@ -584,13 +591,13 @@ export function dataMapping(to: any, from: PlainObject): any {
|
|||
} else if (key === '&') {
|
||||
const v =
|
||||
isPlainObject(value) &&
|
||||
(keys = Object.keys(value)) &&
|
||||
keys.length === 1 &&
|
||||
from[keys[0].substring(1)] &&
|
||||
Array.isArray(from[keys[0].substring(1)])
|
||||
(keys = Object.keys(value)) &&
|
||||
keys.length === 1 &&
|
||||
from[keys[0].substring(1)] &&
|
||||
Array.isArray(from[keys[0].substring(1)])
|
||||
? from[keys[0].substring(1)].map((raw: object) =>
|
||||
dataMapping(value[keys[0]], createObject(from, raw))
|
||||
)
|
||||
dataMapping(value[keys[0]], createObject(from, raw))
|
||||
)
|
||||
: resolveMapping(value, from);
|
||||
|
||||
if (Array.isArray(v) || typeof v === 'string') {
|
||||
|
|
Loading…
Reference in New Issue