1
0
mirror of synced 2026-03-23 11:18:36 +08:00

feat(vue-runtime-help): 只有dsl中的组件才触发生命周期hook

This commit is contained in:
roymondchen
2024-08-02 14:07:27 +08:00
parent 831cdfb2d6
commit 69f3cb2f12
3 changed files with 22 additions and 70 deletions

View File

@@ -1,5 +1,5 @@
{
"version": "0.0.7",
"version": "0.1.0",
"name": "@tmagic/vue-runtime-help",
"type": "module",
"sideEffects": false,
@@ -32,11 +32,11 @@
"vue-demi": "^0.14.7"
},
"peerDependencies": {
"@tmagic/core": ">=1.4.8",
"@tmagic/data-source": ">=1.4.8",
"@tmagic/schema": ">=1.4.8",
"@tmagic/stage": ">=1.4.8",
"@tmagic/utils": ">=1.4.8",
"@tmagic/core": ">=1.4.16",
"@tmagic/data-source": ">=1.4.16",
"@tmagic/schema": ">=1.4.16",
"@tmagic/stage": ">=1.4.16",
"@tmagic/utils": ">=1.4.16",
"@vue/composition-api": ">=1.7.2",
"typescript": "*",
"vue": ">=2.0.0 || >=3.0.0"

View File

@@ -16,10 +16,11 @@
* limitations under the License.
*/
import { computed, inject, onBeforeUnmount, onMounted } from 'vue-demi';
import { inject, onBeforeUnmount, onMounted } from 'vue-demi';
import type Core from '@tmagic/core';
import type { MNode } from '@tmagic/schema';
import { IS_DSL_NODE_KEY } from '@tmagic/utils';
interface UseAppOptions<T extends MNode = MNode> {
config: T;
@@ -28,13 +29,11 @@ interface UseAppOptions<T extends MNode = MNode> {
};
}
const isDslNode = (config: MNode) => typeof config[IS_DSL_NODE_KEY] === 'undefined' || config[IS_DSL_NODE_KEY] === true;
export default ({ methods, config }: UseAppOptions) => {
const app: Core | undefined = inject('app');
const node = app?.page?.getNode(config.id || '');
const style = computed(() => (app ? app.transformStyle(config.style || {}) : config.style));
const emitData = {
config,
...methods,
@@ -53,6 +52,8 @@ export default ({ methods, config }: UseAppOptions) => {
return displayCfg !== false;
};
const node = isDslNode(config) ? app?.page?.getNode(config.id || '') : undefined;
if (node) {
node.emit('created', emitData);
@@ -68,7 +69,6 @@ export default ({ methods, config }: UseAppOptions) => {
return {
app,
node,
style,
display,
};