node-sass 改成 sass,tpl 的 eval 加缓存

This commit is contained in:
wuduoyi 2020-11-03 11:34:23 +08:00
parent 6826b83256
commit 8c385ca1d0
6 changed files with 55 additions and 30 deletions

View File

@ -31,7 +31,7 @@ export default function (schema) {
open: !this.state.open
});
copyCode = () => {
copy(JSON.stringify(schema));
copy(JSON.stringify(schema, null, 2));
toast.success('页面配置JSON已复制到粘贴板');
};
close = () =>

View File

@ -1100,6 +1100,15 @@ const FIX_LABEL = {
* @param option
*/
const buildOneOption = (scope: string, name: string, option: any) => {
if (name.indexOf('<') !== -1) {
return;
}
if (name.indexOf('.0') != -1) {
return;
}
if (name.indexOf('.1') != -1) {
return;
}
const desc = option.desc.trim();
const uiControl = option.uiControl;
if (!desc) {
@ -1170,9 +1179,9 @@ const buildOneOption = (scope: string, name: string, option: any) => {
return vector(name, label, '单独设置', remark);
} else if (uiControlType === 'percentvector') {
// TODO: 可能需要特殊处理
return vector(name, label, '单独设置', remark);
// return vector(name, label, '单独设置', remark);
} else if (uiControlType === 'text') {
return text(name, label, remark, uiControl.default);
// return text(name, label, remark, uiControl.default);
} else {
console.warn('unknow type', name, uiControlType);
}
@ -1183,12 +1192,16 @@ export const buildGroupOptions = (
parentName: string,
options: any
) => {
const controls = [];
let controls = [];
for (const name in options) {
if (name.startsWith(parentName + '.')) {
const control = buildOneOption(scope, name, options[name]);
if (control) {
controls.push(control);
if (Array.isArray(control)) {
controls = controls.concat(control);
} else {
controls.push(control);
}
}
}
}
@ -1213,26 +1226,21 @@ export const buildOptions = (scope: string, options: any) => {
// 没啥用的
const uselessKeys = new Set(['id', 'z', 'zlevel']);
const controls = [];
let controls = [];
// 有些属性有深层结构,对它们进行特殊处理,使用 fieldSet 来自动折叠
const groupKeys = new Set();
for (const name in options) {
if (name.indexOf('<') !== -1) {
// TODO: 暂时跳过
continue;
}
if (name.indexOf('.') !== -1) {
groupKeys.add(name.split('.')[0]);
}
}
for (const name in options) {
// if (name !== 'padding') {
// if (!name.startsWith('label.padding')) {
// continue; // 用于开发时单独测试某个属性
// }
// 这些样式单独处理或忽略
if (
commonStyleKeys.has(name) ||
@ -1253,10 +1261,6 @@ export const buildOptions = (scope: string, options: any) => {
if (name === 'data' || name === 'tooltip') {
continue;
}
if (name.indexOf('<') !== -1) {
// TODO: 暂时不支持
continue;
}
if (groupKeys.has(name)) {
controls.push(
@ -1270,8 +1274,13 @@ export const buildOptions = (scope: string, options: any) => {
}
const control = buildOneOption(scope, name, options[name]);
if (control) {
controls.push(control);
if (Array.isArray(control)) {
controls = controls.concat(control);
} else {
controls.push(control);
}
} else {
console.warn('build control error', name);
}

View File

@ -10,7 +10,7 @@ const lineOptions = __inline('./option-parts/option.series-line.json');
const buildSerieOptions = (type: string, options: any) => {
return {
type: 'container',
visibleOn: `this.type === ${type}`,
visibleOn: `this.type == "${type}"`,
controls: buildOptions('', options)
};
};

View File

@ -51,7 +51,7 @@ fis.match('mod.js', {
});
fis.match('*.scss', {
parser: fis.plugin('node-sass', {
parser: fis.plugin('sass', {
sourceMap: true
}),
rExt: '.css'

View File

@ -27,8 +27,14 @@
"json",
"schema"
],
"author": "fex",
"license": "ISC",
"author": "baidu",
"license": "Apache-2.0",
"licenses": [
{
"type": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
}
],
"dependencies": {
"@types/file-saver": "^2.0.1",
"@types/papaparse": "^5.2.2",
@ -120,7 +126,7 @@
"css": "2.2.1",
"es6-symbol": "3.1.1",
"faker": "^4.1.0",
"fis-parser-node-sass": "^1.0.5",
"fis-parser-sass": "^1.0.0",
"fis-parser-svgr": "^1.0.0",
"fis3": "^3.4.41",
"fis3-deploy-skip-packed": "0.0.5",

View File

@ -1,6 +1,6 @@
import { createObject } from './helper';
import { register as registerBulitin, getFilters } from './tpl-builtin';
import { register as registerLodash } from './tpl-lodash';
import {createObject} from './helper';
import {register as registerBulitin, getFilters} from './tpl-builtin';
import {register as registerLodash} from './tpl-lodash';
export interface Enginer {
test: (tpl: string) => boolean;
@ -35,6 +35,9 @@ export function filter(
return tpl;
}
// 缓存一下提升性能
const EVAL_CACHE: {[key: string]: Function} = {};
let customEvalExpressionFn: (expression: string, data?: any) => boolean;
export function setCustomEvalExpression(
fn: (expression: string, data?: any) => boolean
@ -62,11 +65,18 @@ export function evalExpression(expression: string, data?: object): boolean {
expression = expression.replace(/debugger;?/, '');
}
const fn = new Function(
'data',
'utils',
`with(data) {${debug ? 'debugger;' : ''}return !!(${expression});}`
);
let fn;
if (expression in EVAL_CACHE) {
fn = EVAL_CACHE[expression];
} else {
fn = new Function(
'data',
'utils',
`with(data) {${debug ? 'debugger;' : ''}return !!(${expression});}`
);
EVAL_CACHE[expression] = fn;
}
data = data || {};
return fn.call(data, data, getFilters());
} catch (e) {