mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 02:28:04 +08:00 
			
		
		
		
	* fix: 修复moveable中custom able旋转中心错误问题 * feat(runtime): fix issue #503, 增加page-change回调 * feat(core, runtime): 增加页面不存在时调用报错 * fix(runtime, core, utils): 提取addParamsToUrl公共方法且更改'page-change'逻辑 * fix(utils): 优化addParamToUrl方法
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
<template>
 | 
						|
  <magic-ui-page :config="pageConfig"></magic-ui-page>
 | 
						|
</template>
 | 
						|
 | 
						|
<script lang="ts">
 | 
						|
import { defineComponent, inject, nextTick, reactive, ref } from 'vue';
 | 
						|
 | 
						|
import type { Page } from '@tmagic/core';
 | 
						|
import Core from '@tmagic/core';
 | 
						|
import type { ChangeEvent } from '@tmagic/data-source';
 | 
						|
import type { MNode } from '@tmagic/schema';
 | 
						|
import { addParamToUrl, isPage, replaceChildNode } from '@tmagic/utils';
 | 
						|
 | 
						|
export default defineComponent({
 | 
						|
  name: 'App',
 | 
						|
 | 
						|
  setup() {
 | 
						|
    const app = inject<Core | undefined>('app');
 | 
						|
    const pageConfig = ref(app?.page?.data || {});
 | 
						|
 | 
						|
    app?.on('page-change', (page?: Page) => {
 | 
						|
      if (!page) {
 | 
						|
        throw new Error(`页面不存在`);
 | 
						|
      }
 | 
						|
      addParamToUrl({ page: page.data.id }, window);
 | 
						|
    });
 | 
						|
 | 
						|
    app?.dataSourceManager?.on('update-data', (nodes: MNode[], sourceId: string, changeEvent: ChangeEvent) => {
 | 
						|
      nodes.forEach((node) => {
 | 
						|
        if (isPage(node)) {
 | 
						|
          pageConfig.value = node;
 | 
						|
        } else {
 | 
						|
          replaceChildNode(reactive(node), [pageConfig.value as MNode]);
 | 
						|
        }
 | 
						|
      });
 | 
						|
 | 
						|
      if (!app) return;
 | 
						|
 | 
						|
      nextTick(() => {
 | 
						|
        app.emit('replaced-node', { nodes, sourceId, ...changeEvent });
 | 
						|
      });
 | 
						|
    });
 | 
						|
 | 
						|
    return {
 | 
						|
      pageConfig,
 | 
						|
    };
 | 
						|
  },
 | 
						|
});
 | 
						|
</script>
 |