Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9977c0a

Browse files
author
knight.chen
committed
fix(vue-renderer): ignore hidden in live mode
1 parent 844f4c2 commit 9977c0a

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

packages/vue-renderer/src/core/hoc.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,37 @@ import { SlotNode } from '@alilc/lowcode-designer';
44
import {
55
ComponentPublicInstance,
66
h,
7-
ref,
87
Fragment,
9-
computed,
108
reactive,
119
onUnmounted,
1210
defineComponent,
1311
} from 'vue';
1412
import { leafProps } from './base';
1513
import { useRendererContext } from '../context';
16-
import { ensureArray, parseSchema } from '../utils';
14+
import { ensureArray } from '../utils';
1715
import { PropSchemaMap, SlotSchemaMap, useLeaf } from './use';
1816

1917
export const Hoc = defineComponent({
2018
name: 'Hoc',
2119
props: leafProps,
2220
setup(props) {
23-
const hidden = ref(!!props.schema.hidden);
24-
const condition = ref<unknown>(props.schema.condition ?? true);
25-
2621
const { triggerCompGetCtx } = useRendererContext();
27-
const { node, locked, buildSchema, buildProps, buildSlost, buildLoop } =
22+
const { node, locked, buildSchema, buildProps, buildSlost, buildLoop, buildShow } =
2823
useLeaf(props);
2924

25+
const { show, hidden, condition } = buildShow(props.schema);
3026
const { loop, updateLoop, updateLoopArg, buildLoopScope } = buildLoop(props.schema);
27+
3128
const compProps: PropSchemaMap = reactive({});
3229
const compSlots: SlotSchemaMap = reactive({});
3330
const result = buildSchema();
3431
Object.assign(compProps, result.props);
3532
Object.assign(compSlots, result.slots);
3633

37-
const show = computed(() => {
38-
if (hidden.value) return false;
39-
const { value: showCondition } = condition;
40-
if (typeof showCondition === 'boolean') return showCondition;
41-
return !!parseSchema(showCondition, props.scope);
42-
});
43-
4434
// hoc
4535
if (node) {
4636
const disposeFunctions: Array<CallableFunction | undefined> = [];
4737
onUnmounted(() => disposeFunctions.forEach((dispose) => dispose?.()));
48-
disposeFunctions.push(
49-
node.onVisibleChange((visible) => void (hidden.value = !visible))
50-
);
5138
disposeFunctions.push(
5239
node.onChildrenChange(() => {
5340
const schema = node.export(TransformStage.Render);
@@ -59,9 +46,12 @@ export const Hoc = defineComponent({
5946
const { key, prop, newValue, oldValue } = info;
6047
if (key === '___isLocked___') {
6148
locked.value = newValue;
49+
} else if (key === '___hidden___') {
50+
// 设计器控制组件渲染
51+
hidden(newValue);
6252
} else if (key === '___condition___') {
6353
// 条件渲染更新 v-if
64-
condition.value = newValue;
54+
condition(newValue);
6555
} else if (key === '___loop___') {
6656
// 循环数据更新 v-for
6757
updateLoop(newValue);

packages/vue-renderer/src/core/live.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
1-
import { computed, defineComponent, Fragment, h, ref } from 'vue';
1+
import { defineComponent, Fragment, h } from 'vue';
22
import { useLeaf } from './use';
33
import { leafProps } from './base';
4-
import { parseSchema } from '../utils';
54

65
export const Live = defineComponent({
76
props: leafProps,
87
setup(props) {
9-
const hidden = ref(!!props.schema.hidden);
10-
const condition = ref<unknown>(props.schema.condition ?? true);
11-
12-
const { buildSchema, buildProps, buildLoop, buildSlost } = useLeaf(props);
8+
const { buildSchema, buildProps, buildLoop, buildSlost, buildShow } = useLeaf(props);
139

10+
const { show } = buildShow(props.schema);
1411
const { loop, loopArgs } = buildLoop(props.schema);
1512
const { props: compProps, slots: compSlots } = buildSchema();
1613

17-
const show = computed(() => {
18-
if (hidden.value) return false;
19-
const { value: showCondition } = condition;
20-
if (typeof showCondition === 'boolean') return showCondition;
21-
return !!parseSchema(showCondition, props.scope);
22-
});
23-
2414
return {
2515
show,
2616
loop,

packages/vue-renderer/src/core/use.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,28 @@ export function useLeaf(props: LeafProps) {
555555
};
556556
};
557557

558+
const buildShow = (schema: NodeSchema) => {
559+
const hidden = isDesignMode ? ref(schema.hidden ?? false) : ref(false);
560+
const condition = ref<unknown>(schema.condition ?? true);
561+
562+
const show = computed(() => {
563+
if (hidden.value) return false;
564+
const { value: showCondition } = condition;
565+
if (typeof showCondition === 'boolean') return showCondition;
566+
return !!parseSchema(showCondition, props.scope);
567+
});
568+
569+
return {
570+
show,
571+
hidden: (val: boolean) => {
572+
hidden.value = val;
573+
},
574+
condition: (val: unknown) => {
575+
condition.value = val;
576+
},
577+
};
578+
};
579+
558580
/**
559581
* 装饰默认插槽,当插槽为空时,渲染插槽占位符,便于拖拽
560582
*
@@ -628,6 +650,7 @@ export function useLeaf(props: LeafProps) {
628650
return {
629651
node,
630652
locked,
653+
buildShow,
631654
renderComp,
632655
buildLoop,
633656
buildProps,

0 commit comments

Comments
 (0)