feat: amis 添加更多扩展功能

This commit is contained in:
liaoxuezhi 2024-09-18 11:07:23 +08:00
parent 08bf3af7b2
commit ac00c9910b
6 changed files with 17 additions and 12 deletions

View File

@ -39,7 +39,7 @@ export * from './store';
import * as utils from './utils/helper';
import {getEnv} from 'mobx-state-tree';
import {RegisterStore, RendererStore} from './store';
import {RegisterStore, registerStore, RendererStore} from './store';
import type {IColumn, IColumn2, IRow, IRow2} from './store';
import {
setDefaultLocale,
@ -133,6 +133,7 @@ export {
RendererEnv,
EnvContext,
RegisterStore,
registerStore,
FormItem,
FormItemWrap,
FormItemProps,

View File

@ -114,6 +114,7 @@ export {iRendererStore, IIRendererStore};
export const RegisterStore = function (store: any) {
allowedStoreList.push(store as any);
};
export const registerStore = RegisterStore;
export {
ServiceStore,

View File

@ -26,14 +26,14 @@ export class Evaluator {
contextStack: Array<(varname: string) => any> = [];
static defaultFilters: FilterMap = {};
static setDefaultFilters(filters: FilterMap) {
static extendDefaultFilters(filters: FilterMap) {
Evaluator.defaultFilters = {
...Evaluator.defaultFilters,
...filters
};
}
static defaultFunctions: FunctionMap = {};
static setDefaultFunctions(funtions: FunctionMap) {
static extendDefaultFunctions(funtions: FunctionMap) {
Evaluator.defaultFunctions = {
...Evaluator.defaultFunctions,
...funtions
@ -2385,6 +2385,10 @@ export class Evaluator {
}
}
// 兼容
(Evaluator as any).setDefaultFilters = Evaluator.extendDefaultFilters;
(Evaluator as any).setDefaultFunctions = Evaluator.extendDefaultFunctions;
export function getCookie(name: string) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);

View File

@ -33,12 +33,12 @@ export function registerFilter(
fn: (input: any, ...args: any[]) => any
): void {
filters[name] = fn;
Evaluator.setDefaultFilters(filters);
Evaluator.extendDefaultFilters(filters);
}
export function extendsFilters(value: FilterMap) {
Object.assign(filters, value);
Evaluator.setDefaultFilters(filters);
Evaluator.extendDefaultFilters(filters);
}
export function getFilters() {

View File

@ -1,17 +1,16 @@
import {Evaluator} from './evalutor';
import {FunctionMap, FunctionDocMap, FunctionDocItem} from './types';
export const functions: FunctionMap = {};
import {FunctionDocMap, FunctionDocItem} from './types';
export function registerFunction(
name: string,
fn: (input: any, ...args: any[]) => any
): void {
functions[`fn${name}`] = fn;
Evaluator.setDefaultFunctions(functions);
Evaluator.extendDefaultFunctions({
[`fn${name}`]: fn
});
}
export let functionDocs: FunctionDocMap = {};
export const functionDocs: FunctionDocMap = {};
export function registerFunctionDoc(groupName: string, item: FunctionDocItem) {
if (functionDocs[groupName]) {

View File

@ -53,5 +53,5 @@ export async function evaluateForAsync(
return new AsyncEvaluator(data, options).evalute(ast);
}
Evaluator.setDefaultFilters(getFilters());
Evaluator.extendDefaultFilters(getFilters());
AsyncEvaluator.setDefaultFilters(getFilters());