mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-01 00:57:01 +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) { |   public compiledNode({ items, ...node }: MNode, sourceId?: Id, deep = false) { | ||||||
|     if (node.condResult === false) return node; |     const newNode = cloneDeep(node); | ||||||
|     if (node.visible === false) return 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( |     return compiledNode( | ||||||
|       (value: any) => { |       (value: any) => { | ||||||
| @ -201,7 +208,7 @@ class DataSourceManager extends EventEmitter { | |||||||
| 
 | 
 | ||||||
|         return value; |         return value; | ||||||
|       }, |       }, | ||||||
|       cloneDeep(node), |       newNode, | ||||||
|       this.app.dsl?.dataSourceDeps || {}, |       this.app.dsl?.dataSourceDeps || {}, | ||||||
|       sourceId, |       sourceId, | ||||||
|     ); |     ); | ||||||
| @ -229,7 +236,7 @@ class DataSourceManager extends EventEmitter { | |||||||
| 
 | 
 | ||||||
|       return compiledNode( |       return compiledNode( | ||||||
|         (value: string) => template(value)(createIteratorContentData(itemData, dsId, fields)), |         (value: string) => template(value)(createIteratorContentData(itemData, dsId, fields)), | ||||||
|         cloneDeep(item), |         item, | ||||||
|         { |         { | ||||||
|           [dsId]: { |           [dsId]: { | ||||||
|             [item.id]: { |             [item.id]: { | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ | |||||||
|  * See the License for the specific language governing permissions and |  * See the License for the specific language governing permissions and | ||||||
|  * limitations under the License. |  * limitations under the License. | ||||||
|  */ |  */ | ||||||
| import { cloneDeep, union } from 'lodash-es'; | import { union } from 'lodash-es'; | ||||||
| 
 | 
 | ||||||
| import type { AppCore } from '@tmagic/schema'; | import type { AppCore } from '@tmagic/schema'; | ||||||
| import { getDepNodeIds, getNodes } from '@tmagic/utils'; | import { getDepNodeIds, getNodes } from '@tmagic/utils'; | ||||||
| @ -62,9 +62,11 @@ export const createDataSourceManager = (app: AppCore, useMock?: boolean, initial | |||||||
|       dataSourceManager.emit( |       dataSourceManager.emit( | ||||||
|         'update-data', |         'update-data', | ||||||
|         getNodes(nodeIds, dsl.items).map((node) => { |         getNodes(nodeIds, dsl.items).map((node) => { | ||||||
|           const newNode = cloneDeep(node); |           if (app.platform !== 'editor') { | ||||||
|           newNode.condResult = dataSourceManager.compliedConds(newNode); |             node.condResult = dataSourceManager.compliedConds(node); | ||||||
|           return dataSourceManager.compiledNode(newNode); |           } | ||||||
|  | 
 | ||||||
|  |           return dataSourceManager.compiledNode(node); | ||||||
|         }), |         }), | ||||||
|         sourceId, |         sourceId, | ||||||
|         changeEvent, |         changeEvent, | ||||||
|  | |||||||
| @ -114,7 +114,7 @@ const operations = { | |||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   update({ config, root }: UpdateData) { |   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)); |     updateConfig(cloneDeep(root)); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -88,7 +88,7 @@ export default defineComponent({ | |||||||
|       update({ config, parentId }: UpdateData) { |       update({ config, parentId }: UpdateData) { | ||||||
|         if (!root.value || !app) throw new Error('error'); |         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); |         replaceChildNode(reactive(newNode), [root.value], parentId); | ||||||
| 
 | 
 | ||||||
|         const nodeInstance = app.page?.getNode(config.id); |         const nodeInstance = app.page?.getNode(config.id); | ||||||
|  | |||||||
| @ -85,7 +85,7 @@ window.magic?.onRuntimeReady({ | |||||||
|   update({ config, parentId }: UpdateData) { |   update({ config, parentId }: UpdateData) { | ||||||
|     if (!root.value || !app) throw new Error('error'); |     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); |     replaceChildNode(reactive(newNode), [root.value], parentId); | ||||||
| 
 | 
 | ||||||
|     const nodeInstance = app.page?.getNode(config.id); |     const nodeInstance = app.page?.getNode(config.id); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user