App.vue
6.41 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
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { FlowEditor, normalizeGraphData } from '@flow-editor'
import type {
FlowEditorRef,
FlowEditorInputGraphData,
ToolbarButtonDefinition,
} from '@flow-editor'
const editorRef = ref<FlowEditorRef | null>(null)
const currentVersionLabel = ref('基线版本')
const latestAction = ref('等待初始化')
const flowData = ref<FlowEditorInputGraphData>({
nodes: [],
edges: [],
})
const toolbarButtonHandler = (buttons: ToolbarButtonDefinition[]) => {
const hiddenKeys = new Set(['grid', 'miniMap', 'delete', 'undo', 'redo'])
return buttons.filter((button) => !hiddenKeys.has(button.key))
}
const hasLoadedRemoteBootstrap = computed(() => {
const normalizedGraph = normalizeGraphData(flowData.value)
return normalizedGraph.nodes.length > 0 || normalizedGraph.edges.length > 0
})
function onRef(instance: FlowEditorRef) {
editorRef.value = instance
}
function centerCanvas() {
editorRef.value?.commander.fitView()
latestAction.value = '已执行居中/适应画布'
}
function saveFlowDraft() {
latestAction.value = '当前为迁移阶段演示版,已模拟保存成功'
ElMessage.success('当前为迁移阶段演示版,已模拟保存成功')
}
function openPreviewPanel() {
editorRef.value?.openPreview()
latestAction.value = '已打开流程预览'
}
async function loadBootstrapData() {
// 这里保留旧项目的接口语义,方便把 Playwright 拦截能力平移到新项目。
const requestJson = async <T,>(url: string, fallback: T): Promise<T> => {
try {
const response = await fetch(url)
if (!response.ok) {
return fallback
}
const payload = (await response.json()) as { data?: T }
return payload.data ?? fallback
} catch {
return fallback
}
}
const [versionList, graph] = await Promise.all([
requestJson<Array<{ note?: string }>>('/admin/index.php?m=mod&a=flow_version', [
{ note: '基线版本' },
]),
requestJson<FlowEditorInputGraphData>('/admin/index.php?m=srv&a=flow_nodes', {
nodes: [],
edges: [],
}),
])
currentVersionLabel.value = versionList[0]?.note || '基线版本'
flowData.value = graph
editorRef.value?.read(graph)
}
function bindTestContract() {
window.__FLOW_EDITOR_TEST_API__ = {
getEditorContract: () => {
const instance = editorRef.value
return {
hasEditor: Boolean(instance),
hasCommander: Boolean(instance?.commander),
hasDelete: typeof instance?.commander?.delete === 'function',
hasUndo: typeof instance?.commander?.undo === 'function',
hasRedo: typeof instance?.commander?.redo === 'function',
hasOpenModel: typeof instance?.openModel === 'function',
hasCloseModel: typeof instance?.closeModel === 'function',
hasAddNode: typeof instance?.addNode === 'function',
hasUpdateModel: typeof instance?.updateModel === 'function',
hasGraphRead: typeof instance?.read === 'function',
}
},
}
}
onMounted(async () => {
bindTestContract()
await loadBootstrapData()
bindTestContract()
})
</script>
<template>
<div class="app">
<header class="page-header">
<div>
<p class="page-eyebrow">流程编辑器重构迁移</p>
<h1>新项目基线页</h1>
</div>
<div class="version-card">
<span>当前启用版本</span>
<strong>{{ currentVersionLabel }}</strong>
</div>
</header>
<main class="page-main">
<FlowEditor
:data="flowData"
:grid="false"
:mini-map="false"
:on-ref="onRef"
:toolbar-button-handler="toolbarButtonHandler"
>
<template #toolbar-extra>
<button
type="button"
class="toolbar-button toolbar-button--accent"
@click="centerCanvas"
>
居中
</button>
<button
type="button"
class="toolbar-button toolbar-button--accent"
@click="saveFlowDraft"
>
保存
</button>
<button
type="button"
class="toolbar-button toolbar-button--accent"
data-testid="open-preview-panel"
@click="openPreviewPanel"
>
预览测试
</button>
</template>
</FlowEditor>
<aside class="status-panel">
<h2>迁移状态</h2>
<p>当前目标:先建立新项目最小壳层与测试护栏,再逐步补齐 LogicFlow 实现。</p>
<p>接口基线:{{ hasLoadedRemoteBootstrap ? '已接入初始化 mock 语义' : '使用本地兜底空图数据' }}</p>
<p>最近动作:{{ latestAction }}</p>
</aside>
</main>
</div>
</template>
<style scoped>
.app {
min-height: 100vh;
padding: 24px;
background:
radial-gradient(circle at top left, rgba(43, 104, 168, 0.14), transparent 32%),
linear-gradient(180deg, #f5f7fb 0%, #eef2f8 100%);
color: #18314f;
font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}
.page-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
margin-bottom: 20px;
}
.page-header h1 {
margin: 6px 0 0;
font-size: 28px;
}
.page-eyebrow {
margin: 0;
font-size: 12px;
letter-spacing: 0.14em;
color: #52749b;
}
.version-card {
min-width: 180px;
padding: 14px 16px;
border: 1px solid rgba(24, 49, 79, 0.1);
border-radius: 16px;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 18px 40px rgba(34, 61, 96, 0.08);
}
.version-card span {
display: block;
margin-bottom: 6px;
font-size: 12px;
color: #52749b;
}
.version-card strong {
font-size: 18px;
}
.page-main {
display: grid;
grid-template-columns: minmax(0, 1fr) 320px;
gap: 20px;
}
.status-panel {
padding: 18px;
border: 1px solid rgba(24, 49, 79, 0.08);
border-radius: 20px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 18px 32px rgba(34, 61, 96, 0.08);
}
.status-panel h2 {
margin: 0 0 12px;
font-size: 18px;
}
.status-panel p {
margin: 0 0 10px;
line-height: 1.6;
}
.toolbar-button {
border: none;
border-radius: 999px;
background: #ffffff;
color: #18314f;
}
.toolbar-button--accent {
background: linear-gradient(135deg, #2b68a8 0%, #3f8ec6 100%);
color: #ffffff;
}
@media (max-width: 960px) {
.page-main {
grid-template-columns: 1fr;
}
.page-header {
flex-direction: column;
}
}
</style>