mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-10-14 17:33:01 +08:00
feat(data-source, editor, schema, react-runtime-help, vue-components): 新增条件成立时隐藏的配置功能
This commit is contained in:
parent
81aa8f151d
commit
51f95aef6f
@ -22,7 +22,13 @@ import EventEmitter from 'events';
|
|||||||
import { cloneDeep } from 'lodash-es';
|
import { cloneDeep } from 'lodash-es';
|
||||||
|
|
||||||
import type { DataSourceSchema, default as TMagicApp, DisplayCond, Id, MNode } from '@tmagic/core';
|
import type { DataSourceSchema, default as TMagicApp, DisplayCond, Id, MNode } from '@tmagic/core';
|
||||||
import { compiledNode, getDefaultValueFromFields, NODE_CONDS_KEY, NODE_DISABLE_DATA_SOURCE_KEY } from '@tmagic/core';
|
import {
|
||||||
|
compiledNode,
|
||||||
|
getDefaultValueFromFields,
|
||||||
|
NODE_CONDS_KEY,
|
||||||
|
NODE_CONDS_RESULT_KEY,
|
||||||
|
NODE_DISABLE_DATA_SOURCE_KEY,
|
||||||
|
} from '@tmagic/core';
|
||||||
|
|
||||||
import { SimpleObservedData } from './observed-data/SimpleObservedData';
|
import { SimpleObservedData } from './observed-data/SimpleObservedData';
|
||||||
import { DataSource, HttpDataSource } from './data-sources';
|
import { DataSource, HttpDataSource } from './data-sources';
|
||||||
@ -238,8 +244,9 @@ class DataSourceManager extends EventEmitter {
|
|||||||
Array.isArray(items) && deep ? items.map((item) => this.compiledNode(item, sourceId, deep)) : items;
|
Array.isArray(items) && deep ? items.map((item) => this.compiledNode(item, sourceId, deep)) : items;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.condResult === false) return newNode;
|
if (node.condResult === false || (typeof node.condResult === 'undefined' && node[NODE_CONDS_RESULT_KEY])) {
|
||||||
if (node.visible === false) return newNode;
|
return newNode;
|
||||||
|
}
|
||||||
|
|
||||||
// 编译函数这里作为参数,方便后续支持自定义编译
|
// 编译函数这里作为参数,方便后续支持自定义编译
|
||||||
return compiledNode(
|
return compiledNode(
|
||||||
@ -255,11 +262,24 @@ class DataSourceManager extends EventEmitter {
|
|||||||
* @param {{ [NODE_CONDS_KEY]?: DisplayCond[] }} node 显示条件组配置
|
* @param {{ [NODE_CONDS_KEY]?: DisplayCond[] }} node 显示条件组配置
|
||||||
* @returns {boolean} 是否显示
|
* @returns {boolean} 是否显示
|
||||||
*/
|
*/
|
||||||
public compliedConds(node: { [NODE_CONDS_KEY]?: DisplayCond[]; [NODE_DISABLE_DATA_SOURCE_KEY]?: boolean }) {
|
public compliedConds(
|
||||||
|
node: {
|
||||||
|
[NODE_CONDS_KEY]?: DisplayCond[];
|
||||||
|
[NODE_CONDS_RESULT_KEY]?: boolean;
|
||||||
|
[NODE_DISABLE_DATA_SOURCE_KEY]?: boolean;
|
||||||
|
},
|
||||||
|
data = this.data,
|
||||||
|
) {
|
||||||
if (node[NODE_DISABLE_DATA_SOURCE_KEY]) {
|
if (node[NODE_DISABLE_DATA_SOURCE_KEY]) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return compliedConditions(node, this.data);
|
|
||||||
|
const result = compliedConditions(node, data);
|
||||||
|
|
||||||
|
if (!node[NODE_CONDS_RESULT_KEY]) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return !result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -271,7 +291,11 @@ class DataSourceManager extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
public compliedIteratorItemConds(
|
public compliedIteratorItemConds(
|
||||||
itemData: any,
|
itemData: any,
|
||||||
node: { [NODE_CONDS_KEY]?: DisplayCond[] },
|
node: {
|
||||||
|
[NODE_CONDS_KEY]?: DisplayCond[];
|
||||||
|
[NODE_CONDS_RESULT_KEY]?: boolean;
|
||||||
|
[NODE_DISABLE_DATA_SOURCE_KEY]?: boolean;
|
||||||
|
},
|
||||||
dataSourceField: string[] = [],
|
dataSourceField: string[] = [],
|
||||||
) {
|
) {
|
||||||
const [dsId, ...keys] = dataSourceField;
|
const [dsId, ...keys] = dataSourceField;
|
||||||
@ -279,7 +303,7 @@ class DataSourceManager extends EventEmitter {
|
|||||||
if (!ds) return true;
|
if (!ds) return true;
|
||||||
|
|
||||||
const ctxData = createIteratorContentData(itemData, ds.id, keys, this.data);
|
const ctxData = createIteratorContentData(itemData, ds.id, keys, this.data);
|
||||||
return compliedConditions(node, ctxData);
|
return this.compliedConds(node, ctxData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public compliedIteratorItems(itemData: any, nodes: MNode[], dataSourceField: string[] = []): MNode[] {
|
public compliedIteratorItems(itemData: any, nodes: MNode[], dataSourceField: string[] = []): MNode[] {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
|
||||||
/*
|
/*
|
||||||
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
||||||
*
|
*
|
||||||
@ -17,7 +16,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { NODE_CONDS_KEY, NODE_DISABLE_CODE_BLOCK_KEY, NODE_DISABLE_DATA_SOURCE_KEY } from '@tmagic/core';
|
import {
|
||||||
|
NODE_CONDS_KEY,
|
||||||
|
NODE_CONDS_RESULT_KEY,
|
||||||
|
NODE_DISABLE_CODE_BLOCK_KEY,
|
||||||
|
NODE_DISABLE_DATA_SOURCE_KEY,
|
||||||
|
} from '@tmagic/core';
|
||||||
import { tMagicMessage } from '@tmagic/design';
|
import { tMagicMessage } from '@tmagic/design';
|
||||||
import type { FormConfig, FormState, TabConfig, TabPaneConfig } from '@tmagic/form';
|
import type { FormConfig, FormState, TabConfig, TabPaneConfig } from '@tmagic/form';
|
||||||
|
|
||||||
@ -163,8 +167,20 @@ export const advancedTabConfig: TabPaneConfig = {
|
|||||||
|
|
||||||
export const displayTabConfig: TabPaneConfig = {
|
export const displayTabConfig: TabPaneConfig = {
|
||||||
title: '显示条件',
|
title: '显示条件',
|
||||||
display: (_vm: FormState, { model }: any) => model.type !== 'page',
|
display: (_state: FormState, { model }: any) => model.type !== 'page',
|
||||||
items: [
|
items: [
|
||||||
|
{
|
||||||
|
name: NODE_CONDS_RESULT_KEY,
|
||||||
|
type: 'select',
|
||||||
|
text: '条件成立时',
|
||||||
|
defaultValue: false,
|
||||||
|
options: [
|
||||||
|
{ text: '显示', value: false },
|
||||||
|
{ text: '隐藏', value: true },
|
||||||
|
],
|
||||||
|
extra: (_state, { model }) =>
|
||||||
|
`条件成立时${model[NODE_CONDS_RESULT_KEY] ? '隐藏' : '显示'},不成立时${model[NODE_CONDS_RESULT_KEY] ? '显示' : '隐藏'};<br />同一条件组内的所有条件配置同时成立时表示该条件组成立,任意一个条件组成立时表示条件成立(条件组内为且的关系,条件组间为或的关系);<br />条件为空时表示成立;`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'display-conds',
|
type: 'display-conds',
|
||||||
name: NODE_CONDS_KEY,
|
name: NODE_CONDS_KEY,
|
||||||
|
@ -47,6 +47,8 @@ export enum NodeType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const NODE_CONDS_KEY = 'displayConds';
|
export const NODE_CONDS_KEY = 'displayConds';
|
||||||
|
export const NODE_CONDS_RESULT_KEY = 'displayCondsResultReverse';
|
||||||
|
|
||||||
export const NODE_DISABLE_DATA_SOURCE_KEY = '_tmagic_node_disabled_data_source';
|
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 const NODE_DISABLE_CODE_BLOCK_KEY = '_tmagic_node_disabled_code_block';
|
||||||
|
|
||||||
@ -130,6 +132,7 @@ export interface MComponent {
|
|||||||
/** 组件根Dom的style */
|
/** 组件根Dom的style */
|
||||||
style?: StyleSchema;
|
style?: StyleSchema;
|
||||||
[NODE_CONDS_KEY]?: DisplayCond[];
|
[NODE_CONDS_KEY]?: DisplayCond[];
|
||||||
|
[NODE_CONDS_RESULT_KEY]?: boolean;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,11 +56,10 @@ const IteratorContainer: React.FC<IteratorContainerProps> = ({
|
|||||||
|
|
||||||
const MagicUiComp = app?.resolveComponent('container');
|
const MagicUiComp = app?.resolveComponent('container');
|
||||||
|
|
||||||
const iteratorContainerNode = app?.getNode<TMagicIteratorContainer>(
|
const iteratorContainerNode = app?.getNode<TMagicIteratorContainer>(id || config.id || '', {
|
||||||
id || config.id || '',
|
|
||||||
iteratorContainerId,
|
iteratorContainerId,
|
||||||
iteratorIndex,
|
iteratorIndex,
|
||||||
);
|
});
|
||||||
|
|
||||||
iteratorContainerNode?.resetNodes();
|
iteratorContainerNode?.resetNodes();
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import { useContext, useEffect, useState } from 'react';
|
|||||||
|
|
||||||
import type TMagicApp from '@tmagic/core';
|
import type TMagicApp from '@tmagic/core';
|
||||||
import type { Id, MNodeInstance, Node as TMagicNode } from '@tmagic/core';
|
import type { Id, MNodeInstance, Node as TMagicNode } from '@tmagic/core';
|
||||||
import { isDslNode } from '@tmagic/core';
|
import { isDslNode, NODE_CONDS_RESULT_KEY } from '@tmagic/core';
|
||||||
|
|
||||||
import AppContent from '../AppContent';
|
import AppContent from '../AppContent';
|
||||||
|
|
||||||
@ -96,8 +96,13 @@ export const useApp = ({ methods = {}, config, iteratorContainerId, iteratorInde
|
|||||||
}
|
}
|
||||||
|
|
||||||
const display = <T extends MNodeInstance>(config: T) => {
|
const display = <T extends MNodeInstance>(config: T) => {
|
||||||
if (config.visible === false) return false;
|
if (
|
||||||
if (config.condResult === false) return false;
|
config.visible === false ||
|
||||||
|
config.condResult === false ||
|
||||||
|
(typeof config.condResult === 'undefined' && config[NODE_CONDS_RESULT_KEY])
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const displayCfg = config.display;
|
const displayCfg = config.display;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { defineComponent, h, inject, type PropType, provide } from 'vue-demi';
|
import { defineComponent, h, inject, type PropType, provide } from 'vue-demi';
|
||||||
|
|
||||||
import type TMagicApp from '@tmagic/core';
|
import type TMagicApp from '@tmagic/core';
|
||||||
import { Id, IS_DSL_NODE_KEY, MComponent } from '@tmagic/core';
|
import { Id, IS_DSL_NODE_KEY, MComponent, NODE_CONDS_RESULT_KEY } from '@tmagic/core';
|
||||||
import { useComponent, useComponentStatus, useNode, type UserRenderFunction } from '@tmagic/vue-runtime-help';
|
import { useComponent, useComponentStatus, useNode, type UserRenderFunction } from '@tmagic/vue-runtime-help';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@ -56,10 +56,13 @@ export default defineComponent({
|
|||||||
const { style, className } = componentStatusStore;
|
const { style, className } = componentStatusStore;
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (props.config.visible === false) return null;
|
if (
|
||||||
if (props.config.condResult === false) return null;
|
props.config.visible === false ||
|
||||||
|
props.config.condResult === false ||
|
||||||
if (typeof props.config.display === 'function' && props.config.display({ app, node }) === false) {
|
// 没有配置条件时,不会编译出condResult,所以这里是undefined
|
||||||
|
(typeof props.config.condResult === 'undefined' && props.config[NODE_CONDS_RESULT_KEY]) ||
|
||||||
|
(typeof props.config.display === 'function' && props.config.display({ app, node }) === false)
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user