mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 02:28:04 +08:00 
			
		
		
		
	feat(data-source,runtime): 数据源编译组件时新增一个参数控制是否要编辑子元素
编译时只需要关注组件本身的配置,子组件有自己的依赖,不需要由父组件来控制,但是在编辑器中就需要,因为为了不改动到编辑器中的dsl,编译后的配置是不会保存起来的,所以容器编译时需要把子组件也一同编译
This commit is contained in:
		
							parent
							
								
									a3b41caf06
								
							
						
					
					
						commit
						c68d4e05de
					
				@ -162,9 +162,16 @@ class DataSourceManager extends EventEmitter {
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public compiledNode(node: MNode, sourceId?: Id) {
 | 
			
		||||
    if (node.condResult === false) return node;
 | 
			
		||||
    if (node.visible === false) return node;
 | 
			
		||||
  public compiledNode({ items, ...node }: MNode, sourceId?: Id, deep = false) {
 | 
			
		||||
    const newNode = cloneDeep(node);
 | 
			
		||||
 | 
			
		||||
    if (items) {
 | 
			
		||||
      newNode.items =
 | 
			
		||||
        Array.isArray(items) && deep ? items.map((item) => this.compiledNode(item, sourceId, deep)) : items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (node.condResult === false) return newNode;
 | 
			
		||||
    if (node.visible === false) return newNode;
 | 
			
		||||
 | 
			
		||||
    return compiledNode(
 | 
			
		||||
      (value: any) => {
 | 
			
		||||
@ -201,7 +208,7 @@ class DataSourceManager extends EventEmitter {
 | 
			
		||||
 | 
			
		||||
        return value;
 | 
			
		||||
      },
 | 
			
		||||
      cloneDeep(node),
 | 
			
		||||
      newNode,
 | 
			
		||||
      this.app.dsl?.dataSourceDeps || {},
 | 
			
		||||
      sourceId,
 | 
			
		||||
    );
 | 
			
		||||
@ -229,7 +236,7 @@ class DataSourceManager extends EventEmitter {
 | 
			
		||||
 | 
			
		||||
      return compiledNode(
 | 
			
		||||
        (value: string) => template(value)(createIteratorContentData(itemData, dsId, fields)),
 | 
			
		||||
        cloneDeep(item),
 | 
			
		||||
        item,
 | 
			
		||||
        {
 | 
			
		||||
          [dsId]: {
 | 
			
		||||
            [item.id]: {
 | 
			
		||||
 | 
			
		||||
@ -15,7 +15,7 @@
 | 
			
		||||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
import { cloneDeep, union } from 'lodash-es';
 | 
			
		||||
import { union } from 'lodash-es';
 | 
			
		||||
 | 
			
		||||
import type { AppCore } from '@tmagic/schema';
 | 
			
		||||
import { getDepNodeIds, getNodes } from '@tmagic/utils';
 | 
			
		||||
@ -62,9 +62,11 @@ export const createDataSourceManager = (app: AppCore, useMock?: boolean, initial
 | 
			
		||||
      dataSourceManager.emit(
 | 
			
		||||
        'update-data',
 | 
			
		||||
        getNodes(nodeIds, dsl.items).map((node) => {
 | 
			
		||||
          const newNode = cloneDeep(node);
 | 
			
		||||
          newNode.condResult = dataSourceManager.compliedConds(newNode);
 | 
			
		||||
          return dataSourceManager.compiledNode(newNode);
 | 
			
		||||
          if (app.platform !== 'editor') {
 | 
			
		||||
            node.condResult = dataSourceManager.compliedConds(node);
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          return dataSourceManager.compiledNode(node);
 | 
			
		||||
        }),
 | 
			
		||||
        sourceId,
 | 
			
		||||
        changeEvent,
 | 
			
		||||
 | 
			
		||||
@ -114,7 +114,7 @@ const operations = {
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  update({ config, root }: UpdateData) {
 | 
			
		||||
    replaceChildNode(app.dataSourceManager?.compiledNode(config) || config, root.items);
 | 
			
		||||
    replaceChildNode(app.dataSourceManager?.compiledNode(config, undefined, true) || config, root.items);
 | 
			
		||||
    updateConfig(cloneDeep(root));
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -88,7 +88,7 @@ export default defineComponent({
 | 
			
		||||
      update({ config, parentId }: UpdateData) {
 | 
			
		||||
        if (!root.value || !app) throw new Error('error');
 | 
			
		||||
 | 
			
		||||
        const newNode = app.dataSourceManager?.compiledNode(config) || config;
 | 
			
		||||
        const newNode = app.dataSourceManager?.compiledNode(config, undefined, true) || config;
 | 
			
		||||
        replaceChildNode(reactive(newNode), [root.value], parentId);
 | 
			
		||||
 | 
			
		||||
        const nodeInstance = app.page?.getNode(config.id);
 | 
			
		||||
 | 
			
		||||
@ -85,7 +85,7 @@ window.magic?.onRuntimeReady({
 | 
			
		||||
  update({ config, parentId }: UpdateData) {
 | 
			
		||||
    if (!root.value || !app) throw new Error('error');
 | 
			
		||||
 | 
			
		||||
    const newNode = app.dataSourceManager?.compiledNode(config) || config;
 | 
			
		||||
    const newNode = app.dataSourceManager?.compiledNode(config, undefined, true) || config;
 | 
			
		||||
    replaceChildNode(reactive(newNode), [root.value], parentId);
 | 
			
		||||
 | 
			
		||||
    const nodeInstance = app.page?.getNode(config.id);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user