tpl url 处理 51378 的情况

This commit is contained in:
liaoxuezhi 2019-11-01 15:00:14 +08:00
parent eba8b0379b
commit f522fe3436
1 changed files with 9 additions and 4 deletions

View File

@ -2,7 +2,7 @@ import {reigsterTplEnginer, filter} from './tpl';
import moment from 'moment'; import moment from 'moment';
import {PlainObject} from '../types'; import {PlainObject} from '../types';
import isPlainObject = require('lodash/isPlainObject'); import isPlainObject = require('lodash/isPlainObject');
import {createObject, isObject, setVariable} from './helper'; import {createObject, isObject, setVariable, qsstringify} from './helper';
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
@ -387,9 +387,14 @@ export const tokenize = (str: string, data: object, defaultFilter: string = '| h
return str; return str;
} }
return str.replace(/(\\)?\$(?:([a-z0-9_\.]+|&)|{([^}{]+?)})/gi, (_, escape) => return str
escape ? _.substring(1) : resolveVariableAndFilter(_, data, defaultFilter) .replace(/(\\)?\$(?:([a-z0-9_\.]+|&)|{([^}{]+?)})/gi, (_, escape) =>
); escape ? _.substring(1) : resolveVariableAndFilter(_, data, defaultFilter)
)
.replace(/\$\$/g, (_, index: number, source: string) => {
const prefix = source[index - 1];
return prefix === '=' ? encodeURIComponent(JSON.stringify(data)) : qsstringify(data);
});
}; };
function resolveMapping(value: any, data: PlainObject) { function resolveMapping(value: any, data: PlainObject) {