mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-20 05:29:58 +08:00
feat(core,data-source,dep,editor,schema): 新增组件禁用代码块/数据源的配置开关
This commit is contained in:
parent
c984c1a0cf
commit
2f4a7a33b8
@ -31,6 +31,8 @@ import {
|
||||
type DataSourceItemConfig,
|
||||
type EventActionItem,
|
||||
type EventConfig,
|
||||
NODE_DISABLE_CODE_BLOCK_KEY,
|
||||
NODE_DISABLE_DATA_SOURCE_KEY,
|
||||
} from '@tmagic/schema';
|
||||
import { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX } from '@tmagic/utils';
|
||||
|
||||
@ -216,10 +218,17 @@ export default class EventHelper extends EventEmitter {
|
||||
// 组件动作
|
||||
await this.compActionHandler(compActionItem, fromCpt, args);
|
||||
} else if (actionItem.actionType === ActionType.CODE) {
|
||||
if (fromCpt.data[NODE_DISABLE_CODE_BLOCK_KEY]) {
|
||||
return;
|
||||
}
|
||||
const codeActionItem = actionItem as CodeItemConfig;
|
||||
// 执行代码块
|
||||
await this.app.runCode(codeActionItem.codeId, codeActionItem.params || {}, args, flowState);
|
||||
} else if (actionItem.actionType === ActionType.DATA_SOURCE) {
|
||||
if (fromCpt.data[NODE_DISABLE_DATA_SOURCE_KEY]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dataSourceActionItem = actionItem as DataSourceItemConfig;
|
||||
|
||||
const [dsId, methodName] = dataSourceActionItem.dataSourceMethod;
|
||||
|
@ -20,7 +20,7 @@ import { EventEmitter } from 'events';
|
||||
|
||||
import { DataSource } from '@tmagic/data-source';
|
||||
import type { EventConfig, MNode } from '@tmagic/schema';
|
||||
import { HookCodeType, HookType } from '@tmagic/schema';
|
||||
import { HookCodeType, HookType, NODE_DISABLE_CODE_BLOCK_KEY } from '@tmagic/schema';
|
||||
|
||||
import type { default as TMagicApp } from './App';
|
||||
import type Page from './Page';
|
||||
@ -167,8 +167,8 @@ class Node extends EventEmitter {
|
||||
this.once('created', (instance: any) => {
|
||||
this.once('destroy', () => {
|
||||
this.instance = null;
|
||||
if (typeof this.data.destroy === 'function') {
|
||||
this.data.destroy(this);
|
||||
if (this.data[NODE_DISABLE_CODE_BLOCK_KEY] !== true) {
|
||||
this.runHookCode('destroy');
|
||||
}
|
||||
|
||||
this.listenLifeSafe();
|
||||
@ -178,7 +178,9 @@ class Node extends EventEmitter {
|
||||
this.setInstance(instance);
|
||||
}
|
||||
|
||||
this.runHookCode('created');
|
||||
if (this.data[NODE_DISABLE_CODE_BLOCK_KEY] !== true) {
|
||||
this.runHookCode('created');
|
||||
}
|
||||
});
|
||||
|
||||
this.once('mounted', (instance: any) => {
|
||||
@ -193,7 +195,9 @@ class Node extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
this.runHookCode('mounted');
|
||||
if (this.data[NODE_DISABLE_CODE_BLOCK_KEY] !== true) {
|
||||
this.runHookCode('mounted');
|
||||
}
|
||||
};
|
||||
handler();
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ import EventEmitter from 'events';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
|
||||
import type { DataSourceSchema, default as TMagicApp, DisplayCond, Id, MNode } from '@tmagic/core';
|
||||
import { compiledNode, getDefaultValueFromFields, NODE_CONDS_KEY } from '@tmagic/core';
|
||||
import { compiledNode, getDefaultValueFromFields, NODE_CONDS_KEY, NODE_DISABLE_DATA_SOURCE_KEY } from '@tmagic/core';
|
||||
|
||||
import { SimpleObservedData } from './observed-data/SimpleObservedData';
|
||||
import { DataSource, HttpDataSource } from './data-sources';
|
||||
@ -225,7 +225,12 @@ class DataSourceManager extends EventEmitter {
|
||||
* @param {boolean} deep 是否编译子项(items),默认为false
|
||||
* @returns {MNode} 编译后的组件dsl
|
||||
*/
|
||||
public compiledNode({ items, ...node }: MNode, sourceId?: Id, deep = false) {
|
||||
public compiledNode(n: MNode, sourceId?: Id, deep = false) {
|
||||
if (n[NODE_DISABLE_DATA_SOURCE_KEY]) {
|
||||
return n;
|
||||
}
|
||||
|
||||
const { items, ...node } = n;
|
||||
const newNode = cloneDeep(node);
|
||||
|
||||
if (items) {
|
||||
@ -250,7 +255,10 @@ class DataSourceManager extends EventEmitter {
|
||||
* @param {{ [NODE_CONDS_KEY]?: DisplayCond[] }} node 显示条件组配置
|
||||
* @returns {boolean} 是否显示
|
||||
*/
|
||||
public compliedConds(node: { [NODE_CONDS_KEY]?: DisplayCond[] }) {
|
||||
public compliedConds(node: { [NODE_CONDS_KEY]?: DisplayCond[]; [NODE_DISABLE_DATA_SOURCE_KEY]?: boolean }) {
|
||||
if (node[NODE_DISABLE_DATA_SOURCE_KEY]) {
|
||||
return true;
|
||||
}
|
||||
return compliedConditions(node, this.data);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { NODE_NO_CODE_BLOCK_KEY, NODE_NO_DATA_SOURCE_KEY } from '@tmagic/schema';
|
||||
import { NODE_DISABLE_CODE_BLOCK_KEY, NODE_DISABLE_DATA_SOURCE_KEY } from '@tmagic/schema';
|
||||
import { isObject } from '@tmagic/utils';
|
||||
|
||||
import type Target from './Target';
|
||||
@ -195,11 +195,11 @@ export default class Watcher {
|
||||
DepTargetType.DATA_SOURCE_COND,
|
||||
DepTargetType.DATA_SOURCE_METHOD,
|
||||
];
|
||||
if (node[NODE_NO_DATA_SOURCE_KEY] && dataSourceTargetTypes.includes(target.type)) {
|
||||
if (node[NODE_DISABLE_DATA_SOURCE_KEY] && dataSourceTargetTypes.includes(target.type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node[NODE_NO_CODE_BLOCK_KEY] && target.type === DepTargetType.CODE_BLOCK) {
|
||||
if (node[NODE_DISABLE_CODE_BLOCK_KEY] && target.type === DepTargetType.CODE_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NODE_CONDS_KEY } from '@tmagic/core';
|
||||
import { NODE_CONDS_KEY, NODE_DISABLE_CODE_BLOCK_KEY, NODE_DISABLE_DATA_SOURCE_KEY } from '@tmagic/core';
|
||||
import { tMagicMessage } from '@tmagic/design';
|
||||
import type { FormConfig, FormState, TabConfig, TabPaneConfig } from '@tmagic/form';
|
||||
|
||||
@ -123,6 +123,20 @@ export const advancedTabConfig: TabPaneConfig = {
|
||||
title: '高级',
|
||||
lazy: true,
|
||||
items: [
|
||||
{
|
||||
name: NODE_DISABLE_CODE_BLOCK_KEY,
|
||||
text: '禁用代码块',
|
||||
type: 'switch',
|
||||
defaultValue: false,
|
||||
extra: '开启后,配置的代码块将不会被执行',
|
||||
},
|
||||
{
|
||||
name: NODE_DISABLE_DATA_SOURCE_KEY,
|
||||
text: '禁用数据源',
|
||||
type: 'switch',
|
||||
defaultValue: false,
|
||||
extra: '开启后,组件内配置的数据源相关配置将不会被编译,显隐条件将失效',
|
||||
},
|
||||
{
|
||||
name: 'created',
|
||||
text: 'created',
|
||||
|
@ -47,8 +47,8 @@ export enum NodeType {
|
||||
}
|
||||
|
||||
export const NODE_CONDS_KEY = 'displayConds';
|
||||
export const NODE_NO_DATA_SOURCE_KEY = '__tmagic_node_no_data_source';
|
||||
export const NODE_NO_CODE_BLOCK_KEY = '__tmagic_node_no_code_block';
|
||||
export const NODE_DISABLE_DATA_SOURCE_KEY = '_tmagic_node_disabled_data_source';
|
||||
export const NODE_DISABLE_CODE_BLOCK_KEY = '_tmagic_node_disabled_code_block';
|
||||
|
||||
export type Id = string | number;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user