index.vue
9.4 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<script setup lang="ts">
import { Spin, Tooltip } from 'ant-design-vue';
import { Background, BackgroundVariant } from '@vue-flow/background';
import { Controls } from '@vue-flow/controls';
import { Panel, PanelPosition, VueFlow } from '@vue-flow/core';
import { computed, onMounted, Ref, ref, unref } from 'vue';
import './style';
import {
BasicConnectionArrow,
BasicConnectionLine,
BasicEdge,
MenuSidebar,
} from './src/components';
import type { FlowElRef } from './types/flow';
import { useDragCreate } from './hook/useDragCreate';
import { createFlowContext } from './hook/useFlowContext';
import { CreateNodeModal } from './src/components/CreateNodeModal';
import { useRuleFlow } from './hook/useRuleFlow';
import { CreateEdgeModal } from './src/components/CreateEdgeModal';
import { useFullScreen } from './hook/useFullScreen';
import { useSaveAndRedo } from './hook/useSaveAndRedo';
import { NodeData } from './types/node';
import { Icon } from '/@/components/Icon';
import { UpdateNodeDrawer } from './src/components/UpdateNodeDrawer';
import { UpdateEdgeDrawer } from './src/components/UpdateEdgeDrawer';
import { CreateRuleChainModal } from './src/components/CreateRuleChainModal';
import { useRouter } from 'vue-router';
// import { getRuleChinsList } from '/@/api/ruleengine/ruleengineApi';
// import { ApiSelect } from '/@/components/Form';
// import DownImage from '/@/assets/svg/down-svg.svg';
const getId = Number(Math.random().toString().substring(2)).toString(16);
const rootElRef = ref<Nullable<HTMLDivElement>>(null);
const createNodeModalActionType = ref<Nullable<InstanceType<typeof CreateNodeModal>>>(null);
const createEdgeModalActionType = ref<Nullable<InstanceType<typeof CreateEdgeModal>>>(null);
const updateNodeDrawerActionType = ref<Nullable<InstanceType<typeof UpdateNodeDrawer>>>(null);
const updateEdgeDrawerActionType = ref<Nullable<InstanceType<typeof UpdateEdgeDrawer>>>(null);
const createRuleChainModalActionType =
ref<Nullable<InstanceType<typeof CreateRuleChainModal>>>(null);
const flowElRef = ref<Nullable<FlowElRef>>(null);
const elements = ref([]);
const useSaveAndRedoActionType = useSaveAndRedo();
const {
loading,
changeMarker,
ruleChainDetail,
getCurrentPageMetaData,
triggerChange,
handleApplyChange,
handleRedoChange,
handleRemoveDebug,
getCurrentRuleChainDetail,
} = useSaveAndRedoActionType;
const { flowActionType } = useRuleFlow({
id: getId,
ruleChainDetail,
useSaveAndRedoActionType,
modalActionType: {
createNodeModalActionType,
createEdgeModalActionType,
updateEdgeDrawerActionType,
updateNodeDrawerActionType,
createRuleChainModalActionType,
},
});
const { handleOnDragOver, handleOnDrop } = useDragCreate({
el: flowElRef,
createNodeModalActionType,
flowActionType,
triggerChange,
});
const { handleFullScreen, getFullScreenIcon } = useFullScreen(
rootElRef as unknown as Ref<Nullable<HTMLDivElement>>
);
const handleGetContainer = () => unref(rootElRef)!;
const getDeleteDisplayState = computed(() => unref(flowActionType.getSelectedElements).length);
const getDebugMarker = computed(() =>
flowActionType.getNodes.value.some((item) => (item.data as NodeData).data?.debugMode)
);
const handleDeleteSelectionElements = () => {
flowActionType.removeNodes(unref(flowActionType.getSelectedNodes));
flowActionType.removeEdges(unref(flowActionType.getSelectedEdges));
useSaveAndRedoActionType.triggerChange?.();
};
const ROUTER = useRouter();
// const isShowSelect = ref<boolean>(false);
const handleBack = () => {
ROUTER.go(-1);
};
// const handleDown = () => {
// isShowSelect.value = !unref(isShowSelect);
// };
// const handleSelectChange = (e) => {
// ROUTER.replace(`${e}`);
// };
onMounted(() => {
getCurrentPageMetaData(flowActionType);
getCurrentRuleChainDetail();
});
createFlowContext({
createEdgeModalActionType,
createNodeModalActionType,
updateEdgeDrawerActionType,
updateNodeDrawerActionType,
createRuleChainModalActionType,
flowActionType,
triggerChange,
});
</script>
<template>
<main ref="rootElRef" class="w-full h-full flex relative" @drop="handleOnDrop">
<!-- <Sidebar /> -->
<MenuSidebar />
<Spin :spinning="loading" wrapperClassName="w-full h-ful rule-chain-designer-loading-container">
<VueFlow
:id="getId"
ref="flowElRef"
v-model="elements"
class="w-full h-full"
@dragover="handleOnDragOver"
>
<template #connection-line="props">
<BasicConnectionLine v-bind="props" />
</template>
<template #edge-custom="props">
<BasicEdge v-bind="props" />
</template>
<BasicConnectionArrow />
<Background :variant="BackgroundVariant.Lines" :gap="25" pattern-color="#cfcfcf" />
<Controls :position="PanelPosition.BottomLeft" />
<Panel position="bottom-right" class="controls">
<section class="flex gap-4">
<button
:style="{ transform: `translateY(${getDeleteDisplayState ? 0 : '72px'})` }"
class="button-box-shadow w-14 h-14 flex justify-center items-center bg-orange-600 rounded-full transition-transform transform"
@click="handleDeleteSelectionElements"
>
<Icon class="!text-3xl !text-light-50" icon="mdi:delete" />
</button>
<button
:class="getDebugMarker ? '!bg-orange-600 !opacity-100' : 'opacity-50'"
class="button-box-shadow w-14 h-14 flex justify-center items-center bg-gray-400 rounded-full opacity-50"
@click="handleRemoveDebug(flowActionType)"
>
<Icon class="!text-3xl !text-light-50" icon="carbon:debug" />
</button>
<button
:class="changeMarker ? '!bg-orange-600 !opacity-100' : 'opacity-50'"
class="button-box-shadow w-14 h-14 flex justify-center items-center bg-gray-400 rounded-full"
@click="handleApplyChange(flowActionType)"
>
<Icon class="!text-3xl !text-light-50" icon="mdi:tick" />
</button>
<button
:class="changeMarker ? '!bg-orange-600 !opacity-100' : 'opacity-50'"
class="button-box-shadow w-14 h-14 flex justify-center items-center bg-gray-400 rounded-full"
@click="handleRedoChange(flowActionType)"
>
<Icon class="!text-3xl !text-light-50" icon="ic:baseline-close" />
</button>
</section>
</Panel>
<Panel position="top-right" class="flex">
<Tooltip title="返回">
<button
class="w-10 h-10 bg-gray-300 flex justify-center items-center rounded-full dark:bg-dark-50"
@click="handleBack"
><Icon icon="ant-design:rollback-outlined" class="cursor-pointer svg:text-xl" />
</button>
</Tooltip>
<button
class="w-10 h-10 bg-gray-300 mx-1 flex justify-center items-center rounded-full dark:bg-dark-50"
@click="handleFullScreen"
>
<Icon class="!text-2xl dark:text-light-50" :icon="getFullScreenIcon" />
</button>
</Panel>
<!-- <Panel position="top-left">
<h1 class="ml-10">{{ ruleChainDetail?.name }}</h1>
</Panel> -->
<!-- <Panel position="top-center" class="flex flex-col items-center">
<button
class="w-10 h-10 bg-gray-300 mx-1 flex justify-center items-center rounded-full dark:bg-dark-50"
@click="handleDown"
>
<img :src="DownImage" alt="avatar" />
</button>
<div v-if="isShowSelect" class="mt-1">
<ApiSelect
class="!mx-2 flex-auto w-40"
:api="
async (params) => {
const options = await getRuleChinsList(params);
return options?.data
.map((item) => ({ label: item.name, value: item.id.id }))
.filter((item) => item.label !== ruleChainDetail?.name);
}
"
:showSearch="true"
:filterOption="(inputValue: string, option: Record<'label' | 'value', string>) =>
option.label.includes(inputValue)"
placeholder="请选择规则链"
:params="{
page: 0,
pageSize: 100,
sortProperty: 'createdTime',
sortOrder: 'DESC',
}"
@change="handleSelectChange"
/>
</div>
</Panel> -->
</VueFlow>
</Spin>
<CreateNodeModal ref="createNodeModalActionType" :get-container="handleGetContainer" />
<CreateEdgeModal ref="createEdgeModalActionType" :get-container="handleGetContainer" />
<UpdateEdgeDrawer ref="updateEdgeDrawerActionType" />
<UpdateNodeDrawer ref="updateNodeDrawerActionType" />
<CreateRuleChainModal ref="createRuleChainModalActionType" />
</main>
</template>
<style scoped>
.button-box-shadow {
box-shadow: 0 3px 5px -1px #0003, 0 6px 10px 0 #00000024, 0 1px 18px 0 #0000001f;
}
</style>
<style lang="less">
.rule-chain-designer-loading-container {
.ant-spin-container {
@apply w-full h-full;
}
// :deep(.top .center) {
// margin: 0 !important;
// }
}
</style>