@easyv/admin-utils
Version:
easyv/twin 公共 utils 集合
389 lines (377 loc) • 12.4 kB
TypeScript
type ComponentConfig = any[];
interface APIDataConfig {
data: {
data_id: string;
path: string;
params: string;
method: Method;
body: string;
headers: string;
needCookie: boolean;
reqFromBack: boolean;
};
}
type ComponentDataConfigItem = {
data: any;
fields: ComponentDataField;
config?: APIDataConfig['data'] | SQLDataConfig['data'] | {
data_id: string;
};
callbackKeys?: string[];
};
interface SQLDataConfig {
data: {
data_id: string;
sql: string;
};
}
type ComponentDataField = {
name: string;
value: string;
desc: string;
}[];
type ComponentDataConfigs = {
[x in DataType]: ComponentDataConfigItem;
};
type DataType = 'static' | 'mysql' | 'mssql' | 'oracle' | 'csv' | 'api' | 'apiGateway' | 'postgresql' | 'clickhouse' | 'dtInsight';
type Method = 'get' | 'post' | 'put' | 'delete' | 'patch';
type Components = ComponentItem[];
interface ComponentItem {
id: number;
config: ComponentConfig;
}
type EventConfig = EventConfigOld | EventConfigNew;
interface EventConfigOld {
id: string;
name: string;
trigger: string;
conditionType: ConditionType;
conditions: ConditionConfig[];
reverse?: boolean;
action: string;
actionData: Record<string, unknown>;
animation: {
type: AnimationType;
timingFunction: TimingFunction;
duration: number;
delay: number;
};
component: string[];
componentConfig: Record<string, unknown>;
componentScope: ComponentScope;
scale: {
x: number;
y: number;
origin: string;
lock: boolean;
};
stateId: string;
translate: {
toX: number;
toY: number;
};
unmount: boolean;
}
type AnimationType = 'opacity' | 'slide' | 'zoom' | 'fade';
type ComponentScope = 'current' | 'global';
type ConditionType = 'all' | 'none';
type CompareType = '==' | '!=' | '<' | '>' | '<=' | '>=' | 'include' | 'exclude';
interface ConditionConfig {
id: string;
name: string;
type: 'field' | 'custom';
field: string;
expected: string;
compore: CompareType;
code: string;
}
type TimingFunction = 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out';
interface EventConfigNew {
id: string;
name: string;
trigger: string;
conditionType: ConditionType;
conditions: ConditionConfig[];
reverse: boolean;
actions: {
action: string;
actionData: Record<string, unknown>;
animation: {
type: AnimationType;
timingFunction: TimingFunction;
duration: number;
delay: number;
};
component: string[];
componentConfig: Record<string, unknown>;
componentScope: ComponentScope;
scale: {
x: number;
y: number;
origin: string;
lock: boolean;
};
stateId: string;
translate: {
toX: number;
toY: number;
};
unmount: boolean;
}[];
}
declare enum DataFrom {
DEFAULT = 0,
DATA_CONTAINER = 1
}
interface FilterItem {
id: number;
name: string;
enable: boolean;
content: string;
screenId: number;
callbackKeys: string[];
}
declare const themeKeys: string[];
type Filters = FilterItem[];
interface ThemeType {
id: number;
rank: number;
name: string;
type: Type;
config: {
bgColor: string;
textColor: string;
assistColor: string;
gridColor: string;
seriesGradient: SeriesGradient[];
palette: string[];
};
}
declare enum Type {
SYSTEM = 1,
USER = 2
}
type ThemeConfigType = ThemeType['config'];
interface SeriesGradient {
angle: number;
gradient: {
color: string;
offset?: number;
location?: number;
}[];
}
/**
* @description: 组件主题配色替换
* @param {components , theme}
* @return {}
*/
declare function updateThemeConfig({ components, theme, }: {
components: Components;
theme: ThemeConfigType;
}): {
id: number;
config: ComponentConfig;
}[];
declare function isObject(obj: object): boolean;
declare function isString(val: string): boolean;
/**
* @description 计算最佳scale
* */
declare function getScreenScale(): void;
/**
* @description 数组转对象
* */
declare function arrayToObj<T extends Record<string, any>>(data: T[], key?: string): Record<string, T>;
declare function getFindIndex<T extends Record<string, any>>(data: T[], key: string, type: 'min' | 'max'): number;
/**
* @description 获取数组内最大/最小
* */
declare function calculateSize<T extends Record<string, unknown>>(data: T[], keys: string, type: 'min' | 'max'): unknown;
/**
* @description 获取大屏基础信息
* */
declare function getScreenDimension(config: any): {
width: any;
height: any;
backgroundColor: any;
useBackground: any;
background: any;
};
declare function reduceConfig(config: any): any;
declare function getComponentDimension(config: any): {
left: any;
top: any;
width: any;
height: any;
lock: any;
} | {
width: number;
height: number;
left: number;
top: number;
lock?: undefined;
};
declare function getComponentConfig(config: any): any;
declare function updateArrayConfig(config: any, updates: any): (base?: ((newConfig: any) => any) | undefined, ...args: unknown[]) => (newConfig: any) => any;
declare function getConfig(config: any, type: any, device: any): any;
declare function mergeConfig(now: any, prev: any): any;
declare function mergeStyleConfig(current: any, styleConfig: any, isPasteStyle?: boolean): any;
declare function updateArrayWithObject(config: any, obj: any): any;
declare function transformConfig(config: any): any;
declare function transformToOldConfig(config: any): any;
/**
* @描述 根据规则过滤config plus
* @注释 config 是全部config,解决跨tab 控制
* */
declare function isFullConfigShow(config?: any[], rules?: any[], ruleType?: string, fullConfig?: any[]): boolean;
declare function isConfigShow(config?: any[], rules?: any[], ruleType?: string): boolean;
declare function isOldConfig(config?: any[]): any;
declare function getValueObjFromConfig(config: any, path: any): {
value: any;
} | {
_value: any;
};
declare function getValueFromConfig(config: any, path: any, field: any): any;
declare function getLayersWithCustomId(layers: any[] | undefined, onlyComponent: any): any;
declare function getStateOptions(states?: any[]): any;
declare function getComponentOptions({ screensById, panelsById, componentsById, screenId, stateId, mode, }: {
screensById: any;
panelsById: any;
componentsById: any;
screenId: any;
stateId: any;
mode?: string | undefined;
}): any;
declare function getPanelOptions({ screensById, panelsById, screenId, stateId, mode, }: {
screensById: any;
panelsById: any;
screenId: any;
stateId: any;
mode?: string | undefined;
}): any;
declare function getPanelWithStates({ panelsById, screensById, id, name }: {
panelsById: any;
screensById: any;
id: any;
name: any;
}): {
title?: undefined;
value?: undefined;
children?: undefined;
} | {
title: any;
value: string;
children: any;
} | {
title: any;
value: string;
children?: undefined;
};
declare function getEvents(component: any, layers: any, panels: any[] | undefined, components: any): any[];
declare function filterLayersWithEvents(layers: any, components: any, componentsWithInfo: any, panels: any): any;
declare function getId(id: any): any;
declare function getModelTypes(): string[];
declare function findExpandedKeys(data: any, keys: any, expanedKeys?: any[]): {
tempExpanedKeys: any[];
expanedFather: boolean;
};
declare function searchExpandedKeys(data: any, title: any, expanedKeys?: any[]): {
tempExpanedKeys: any[];
expanedFather: boolean;
};
declare function generateId(): string;
declare function deepFind(data: any[] | undefined, predicate: any, deepKey?: string): any;
declare function deepFindOne(data: any[] | undefined, predicate: any, deepKey?: string): any;
declare function deepMap(data: any[] | undefined, predicate: any, deepKey?: string): any;
declare function isPanel(id: any): boolean;
declare function isRef(id: any): boolean;
declare function isGroup(id: any): boolean;
declare function isState(id: any): boolean;
declare function isScreen(id: any): boolean;
declare function isContainer(id: any): boolean;
declare function isComContainerPage(pathname?: string): boolean;
declare function getComContainerId(pathname?: string): string | undefined;
declare function isComponent(id: any): boolean;
declare function raf(cb: any): (...args: any[]) => void;
declare function safeDiv(a: any, b: any): number;
declare function safeModulo(a: any, b: any): number;
declare function safeAdd(a: any, b: any): number;
declare function safeMul(n1: any, n2: any): number;
/** 计算算术表达式的值 */
declare function calcExpression(expression: any): any;
declare function mergeUrl(...parts: any[]): string;
declare function resolvePath(...paths: any[]): string;
declare function transformCover(cover: any): any;
declare function getOptionsList(server_api: any): Promise<any>;
interface FetchRequest {
url: string;
params?: Record<string, any>;
query?: Record<string, any>;
body?: string | FormData;
keys?: unknown[];
options?: {
headers?: HeadersInit; // Record<string, unknown>
credentials?: 'omit' | 'same-origin' | 'include';
signal?: AbortSignal;
hideError?: boolean;
error?: (...args) => void;
};
}
declare function request({ url, params, query, body, options, }: FetchRequest): Promise<Response>;
/**
* 彩色打印console
* @param {string} hint 提示内容
* @param {string} content 打印内容
* @param {"info"|"warn"|"error"|"trace"} type 打印类型(log,trace,warn,error)
*/
declare function colorLog(hint: string, content: string, type?: 'info' | 'warn' | 'error' | 'trace'): void;
/**
* @description 导出大屏/场景 资源扫描函数
* @param {sceneInfo}
*/
interface ContentType {
components: ComponentType[];
scenes: object[];
objs: ObjectType[];
project?: ProjectType;
}
interface ComponentType {
id: string;
name: string;
type: string;
objId: string;
states: any[];
data: any;
}
interface ObjectType {
id: string;
name: string;
type?: string;
commonConfig?: {
version: string;
};
states?: any[];
aliasTag?: string;
hierarchyConfig?: object;
}
interface ProjectType {
id: string;
name: string;
thumb: string;
}
declare function getEasyTwinResourcesFromSceneInfo({ content, contentFileUrl, scenesEntityVersions, }: {
content: ContentType | string;
scenesEntityVersions: {
objs: {
type: string;
version: string;
}[];
components: {
type: string;
version: string;
}[];
handleVersion: string;
};
contentFileUrl?: string;
}): Promise<string[]>;
export { type ComponentConfig, type ComponentDataConfigItem, type ComponentDataConfigs, type ComponentItem, type Components, DataFrom, type DataType, type EventConfig, type EventConfigNew, type EventConfigOld, type FilterItem, type Filters, type Method, type SeriesGradient, type ThemeConfigType, type ThemeType, Type, arrayToObj, calcExpression, calculateSize, colorLog, deepFind, deepFindOne, deepMap, filterLayersWithEvents, findExpandedKeys, generateId, getComContainerId, getComponentConfig, getComponentDimension, getComponentOptions, getConfig, getEasyTwinResourcesFromSceneInfo, getEvents, getFindIndex, getId, getLayersWithCustomId, getModelTypes, getOptionsList, getPanelOptions, getPanelWithStates, getScreenDimension, getScreenScale, getStateOptions, getValueFromConfig, getValueObjFromConfig, isComContainerPage, isComponent, isConfigShow, isContainer, isFullConfigShow, isGroup, isObject, isOldConfig, isPanel, isRef, isScreen, isState, isString, mergeConfig, mergeStyleConfig, mergeUrl, raf, reduceConfig, request, resolvePath, safeAdd, safeDiv, safeModulo, safeMul, searchExpandedKeys, themeKeys, transformConfig, transformCover, transformToOldConfig, updateArrayConfig, updateArrayWithObject, updateThemeConfig };