index.vue
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<script lang="ts" setup>
import { Empty, Spin } from 'ant-design-vue';
import { BasicModal } from '/@/components/Modal';
import { useAwaitPopupWindowBindData } from '../../../hook/useAwaitPopupWindowBindData';
import { ElementsTypeEnum } from '../../../enum';
import { DataActionModeEnum } from '/@/enums/toolEnum';
import { useForm, BasicForm } from '/@/components/Form';
import { BottomFormSchemas, TopFormSchemas } from './config';
defineProps<{
getContainer: () => any;
}>();
const [topFormRegister, topFormActionType] = useForm({
schemas: TopFormSchemas,
showActionButtonGroup: false,
});
const [bottomFormRegister, bottomFormActionType] = useForm({
schemas: BottomFormSchemas,
showActionButtonGroup: false,
});
const {
visible,
spinning,
nodeData,
shadowComponent,
getComponentKey,
createComponentEl,
open,
handleSubmit,
handleCancel,
handleOnMounted,
} = useAwaitPopupWindowBindData({ type: ElementsTypeEnum.NODE, mode: DataActionModeEnum.CREATE });
const validate = async () => {
await topFormActionType.validate();
await bottomFormActionType.validate();
};
const getFieldsValue = () => {
const topValue = topFormActionType.getFieldsValue() || {};
const bottomValue = bottomFormActionType.getFieldsValue() || {};
return {
...topValue,
...bottomValue,
};
};
const resetFieldsValue = () => {
topFormActionType.resetFields();
bottomFormActionType.resetFields();
};
const handleModalOk = async () => {
await validate();
const data = getFieldsValue();
await handleSubmit(data);
resetFieldsValue();
};
defineExpose({ open });
</script>
<template>
<BasicModal
v-model:visible="visible"
:title="`添加规则节点: ${nodeData?.config?.name}`"
width="50%"
:get-container="getContainer"
@ok="handleModalOk"
@cancel="handleCancel"
>
<Spin :spinning="spinning">
<section v-if="shadowComponent" class="w-full h-full">
<BasicForm @register="topFormRegister" />
<component
class="rule-node-form"
:is="shadowComponent"
ref="createComponentEl"
:key="getComponentKey"
:config="nodeData"
@vue:mounted="handleOnMounted"
/>
<BasicForm @register="bottomFormRegister" />
</section>
<Empty v-if="!shadowComponent" description="未找到创建组件" />
</Spin>
</BasicModal>
</template>
<style lang="less" scoped>
.rule-node-form {
:deep(.ant-input-number) {
width: 100%;
min-width: none;
}
}
</style>