android-midscene-automation 1.1.7 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +12 -0
- package/package.json +1 -1
- package/server/appium-auto-save.test.ts +12 -0
- package/server/appium-config.test.ts +14 -1
- package/server/appium-recorder/flow-layout.test.ts +52 -0
- package/server/config.ts +13 -2
- package/src/App.vue +3 -0
- package/src/appium-recorder/AppiumPage.vue +7 -1
- package/src/appium-recorder/components/AiRecognitionSettings.vue +1 -1
- package/src/appium-recorder/components/FlowCanvas.vue +160 -52
- package/src/appium-recorder/components/FlowNodeCard.vue +54 -23
- package/src/appium-recorder/components/FlowRoundedEdge.vue +30 -63
- package/src/appium-recorder/components/FlowStepEditor.vue +45 -10
- package/src/appium-recorder/components/LongPressSettings.vue +1 -1
- package/src/appium-recorder/components/RecordedSteps.vue +7 -1
- package/src/appium-recorder/flow-appearance.ts +37 -0
- package/src/appium-recorder/flow-graph.ts +43 -27
- package/src/components/config/AppiumConfigPanel.vue +32 -11
- package/src/components/config/FlowAppearanceSettings.vue +122 -49
- package/src/config/use-appium-auto-save.ts +2 -0
- package/src/config/use-model-config.ts +4 -1
- package/src/style.css +39 -25
- package/src/types.ts +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed,
|
|
2
|
+
import { computed, inject, onBeforeUnmount, onMounted, shallowRef } from 'vue';
|
|
3
|
+
import { flowLayoutDirectionKey, normalizeFlowLayoutDirection } from '../flow-appearance';
|
|
3
4
|
import { Handle, Position } from '@vue-flow/core';
|
|
4
5
|
import { CopyDocument, Delete, Edit, Plus, VideoPlay, View, WarningFilled, Connection, RefreshLeft } from '@element-plus/icons-vue';
|
|
5
6
|
import type { AppiumRecordedStep } from '../types';
|
|
@@ -16,6 +17,7 @@ const props = defineProps<{
|
|
|
16
17
|
nodeId: string;
|
|
17
18
|
data: FlowGraphNodeData;
|
|
18
19
|
steps: AppiumRecordedStep[];
|
|
20
|
+
expanded: boolean;
|
|
19
21
|
readonly?: boolean;
|
|
20
22
|
searchHighlighted?: boolean;
|
|
21
23
|
}>();
|
|
@@ -33,7 +35,15 @@ const emit = defineEmits<{
|
|
|
33
35
|
resize: [payload: { id: string; height: number }];
|
|
34
36
|
}>();
|
|
35
37
|
|
|
38
|
+
const layoutDirection = inject(flowLayoutDirectionKey, computed(() => normalizeFlowLayoutDirection(undefined)));
|
|
39
|
+
const horizontal = computed(() => layoutDirection.value === 'horizontal');
|
|
40
|
+
|
|
36
41
|
const rootRef = shallowRef<HTMLElement | null>(null);
|
|
42
|
+
const cardRef = shallowRef<HTMLButtonElement | null>(null);
|
|
43
|
+
const cardHeight = shallowRef(0);
|
|
44
|
+
const handleStyle = computed(() => horizontal.value && props.data.kind === 'step'
|
|
45
|
+
? { top: `${(cardHeight.value || props.data.cardMinHeight) / 2}px` }
|
|
46
|
+
: undefined);
|
|
37
47
|
let resizeObserver: ResizeObserver | null = null;
|
|
38
48
|
|
|
39
49
|
const insertTitle = computed(() => {
|
|
@@ -64,27 +74,23 @@ function handleStepClick() {
|
|
|
64
74
|
emit('nodeClick', props.data.index);
|
|
65
75
|
}
|
|
66
76
|
|
|
67
|
-
|
|
77
|
+
onMounted(() => {
|
|
68
78
|
if (!rootRef.value || props.data.kind !== 'step') return;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
resizeObserver = new ResizeObserver(([entry]) => {
|
|
80
|
+
if (!entry) return;
|
|
81
|
+
// 横向端点跟随卡片,展开的编辑区域不参与端点居中。
|
|
82
|
+
cardHeight.value = cardRef.value?.offsetHeight ?? 0;
|
|
83
|
+
emit('resize', {
|
|
84
|
+
id: props.nodeId,
|
|
85
|
+
height: entry.borderBoxSize[0]?.blockSize ?? rootRef.value!.offsetHeight,
|
|
86
|
+
});
|
|
72
87
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
onMounted(() => {
|
|
76
|
-
resizeObserver = new ResizeObserver(reportSize);
|
|
77
|
-
if (rootRef.value) resizeObserver.observe(rootRef.value);
|
|
78
|
-
void nextTick(reportSize);
|
|
88
|
+
resizeObserver.observe(rootRef.value);
|
|
79
89
|
});
|
|
80
90
|
|
|
81
91
|
onBeforeUnmount(() => {
|
|
82
92
|
resizeObserver?.disconnect();
|
|
83
93
|
});
|
|
84
|
-
|
|
85
|
-
watch(() => props.data, () => {
|
|
86
|
-
void nextTick(reportSize);
|
|
87
|
-
});
|
|
88
94
|
</script>
|
|
89
95
|
|
|
90
96
|
<template>
|
|
@@ -98,10 +104,11 @@ watch(() => props.data, () => {
|
|
|
98
104
|
@touchstart.stop
|
|
99
105
|
>
|
|
100
106
|
<Handle
|
|
101
|
-
id="
|
|
107
|
+
id="input"
|
|
102
108
|
type="target"
|
|
103
|
-
:position="Position.Top"
|
|
104
|
-
class="appium-flow-handle
|
|
109
|
+
:position="horizontal ? Position.Left : Position.Top"
|
|
110
|
+
class="appium-flow-handle"
|
|
111
|
+
:style="handleStyle"
|
|
105
112
|
/>
|
|
106
113
|
|
|
107
114
|
<div v-if="data.kind === 'start'" class="appium-flow-start-card nodrag nopan">
|
|
@@ -160,7 +167,7 @@ watch(() => props.data, () => {
|
|
|
160
167
|
:class="[
|
|
161
168
|
`appium-flow-step-shell--${data.flowKind}`,
|
|
162
169
|
{
|
|
163
|
-
'appium-flow-step-shell--expanded':
|
|
170
|
+
'appium-flow-step-shell--expanded': expanded,
|
|
164
171
|
'appium-flow-step-shell--selected': data.selected,
|
|
165
172
|
'appium-flow-step-shell--delete-selected': data.selected && data.deleteMode,
|
|
166
173
|
'appium-flow-step-shell--copying': data.copyMode,
|
|
@@ -169,6 +176,7 @@ watch(() => props.data, () => {
|
|
|
169
176
|
]"
|
|
170
177
|
>
|
|
171
178
|
<button
|
|
179
|
+
ref="cardRef"
|
|
172
180
|
type="button"
|
|
173
181
|
class="appium-flow-step-card nodrag nopan"
|
|
174
182
|
:style="{ minHeight: `${data.cardMinHeight}px` }"
|
|
@@ -251,7 +259,7 @@ watch(() => props.data, () => {
|
|
|
251
259
|
</span></el-tooltip>
|
|
252
260
|
</span>
|
|
253
261
|
<FlowStepEditor
|
|
254
|
-
v-if="!props.readonly &&
|
|
262
|
+
v-if="!props.readonly && expanded"
|
|
255
263
|
class="appium-flow-step-editor nodrag nopan"
|
|
256
264
|
:step="data.step"
|
|
257
265
|
:steps="steps"
|
|
@@ -262,15 +270,38 @@ watch(() => props.data, () => {
|
|
|
262
270
|
</div>
|
|
263
271
|
|
|
264
272
|
<Handle
|
|
265
|
-
id="
|
|
273
|
+
id="output"
|
|
266
274
|
type="source"
|
|
267
|
-
:position="Position.Bottom"
|
|
268
|
-
class="appium-flow-handle
|
|
275
|
+
:position="horizontal ? Position.Right : Position.Bottom"
|
|
276
|
+
class="appium-flow-handle"
|
|
277
|
+
:style="handleStyle"
|
|
269
278
|
/>
|
|
270
279
|
</div>
|
|
271
280
|
</template>
|
|
272
281
|
|
|
273
282
|
<style scoped>
|
|
283
|
+
.appium-flow-step-shell--expanded {
|
|
284
|
+
overflow: hidden;
|
|
285
|
+
border: 1px solid var(--ui-border);
|
|
286
|
+
border-radius: var(--ui-radius-control);
|
|
287
|
+
background: var(--ui-surface);
|
|
288
|
+
box-shadow: var(--ui-shadow-card);
|
|
289
|
+
}
|
|
290
|
+
.appium-flow-step-shell--expanded.appium-flow-step-shell--selected { border-color: var(--ui-primary); }
|
|
291
|
+
.appium-flow-step-shell--expanded > .appium-flow-step-card {
|
|
292
|
+
width: 100%;
|
|
293
|
+
border: 0;
|
|
294
|
+
border-radius: 0;
|
|
295
|
+
box-shadow: none;
|
|
296
|
+
}
|
|
297
|
+
.appium-flow-step-shell--expanded > .appium-flow-step-editor {
|
|
298
|
+
width: 100%;
|
|
299
|
+
margin-top: 0;
|
|
300
|
+
border: 0;
|
|
301
|
+
border-top: 1px solid var(--ui-border);
|
|
302
|
+
border-radius: 0;
|
|
303
|
+
}
|
|
304
|
+
|
|
274
305
|
.appium-flow-step-shell--delete-selected .appium-flow-step-card { background: #b83232; border-color: #a52a2a; }
|
|
275
306
|
.appium-flow-step-shell--delete-selected .appium-flow-step-card__content strong,
|
|
276
307
|
.appium-flow-step-shell--delete-selected .appium-flow-step-card__content em { color: #fff; }
|
|
@@ -1,82 +1,49 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, inject } from 'vue';
|
|
3
|
-
import { BaseEdge,
|
|
4
|
-
import { flowLineStyleKey, normalizeFlowLineStyle } from '../flow-appearance';
|
|
3
|
+
import { BaseEdge, type EdgeProps } from '@vue-flow/core';
|
|
4
|
+
import { flowLineStyleKey, normalizeFlowLineStyle, flowLayoutDirectionKey, normalizeFlowLayoutDirection } from '../flow-appearance';
|
|
5
5
|
import type { FlowGraphNodeData } from '../flow-graph';
|
|
6
6
|
|
|
7
7
|
const props = defineProps<EdgeProps>();
|
|
8
8
|
const lineStyle = inject(flowLineStyleKey, computed(() => normalizeFlowLineStyle(undefined)));
|
|
9
|
+
const layoutDirection = inject(flowLayoutDirectionKey, computed(() => normalizeFlowLayoutDirection(undefined)));
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type Point = {
|
|
13
|
-
x: number;
|
|
14
|
-
y: number;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function linePath(points: Point[]) {
|
|
18
|
-
if (points.length < 2) return '';
|
|
19
|
-
const [start, ...rest] = points;
|
|
20
|
-
return [
|
|
21
|
-
`M ${start.x} ${start.y}`,
|
|
22
|
-
...rest.map((point) => `L ${point.x} ${point.y}`),
|
|
23
|
-
].join(' ');
|
|
24
|
-
}
|
|
11
|
+
type Point = { x: number; y: number };
|
|
25
12
|
|
|
26
13
|
const path = computed(() => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
`M ${props.sourceX} ${props.sourceY}`,
|
|
34
|
-
`L ${props.sourceX} ${bendY}`,
|
|
35
|
-
`C ${props.sourceX} ${controlY} ${props.targetX} ${controlY} ${props.targetX} ${props.targetY}`,
|
|
36
|
-
].join(' ');
|
|
37
|
-
}
|
|
38
|
-
return getBezierPath({
|
|
39
|
-
sourceX: props.sourceX, sourceY: props.sourceY, sourcePosition: props.sourcePosition,
|
|
40
|
-
targetX: props.targetX, targetY: props.targetY, targetPosition: props.targetPosition,
|
|
41
|
-
})[0];
|
|
42
|
-
}
|
|
43
|
-
const source = { x: props.sourceX, y: props.sourceY };
|
|
44
|
-
const target = { x: props.targetX, y: props.targetY };
|
|
14
|
+
// 逻辑 y 轴始终沿流程前进,输出时再换成画布坐标。
|
|
15
|
+
const horizontal = layoutDirection.value === 'horizontal';
|
|
16
|
+
const source = horizontal ? { x: props.sourceY, y: props.sourceX } : { x: props.sourceX, y: props.sourceY };
|
|
17
|
+
const target = horizontal ? { x: props.targetY, y: props.targetX } : { x: props.targetX, y: props.targetY };
|
|
18
|
+
const point = ({ x, y }: Point) => horizontal ? `${y} ${x}` : `${x} ${y}`;
|
|
19
|
+
const linePath = (points: Point[]) => points.map((p, i) => `${i ? 'L' : 'M'} ${point(p)}`).join(' ');
|
|
45
20
|
const deltaX = target.x - source.x;
|
|
46
21
|
const deltaY = target.y - source.y;
|
|
22
|
+
const merge = props.data?.merge && deltaY > 0;
|
|
47
23
|
|
|
48
|
-
if (
|
|
49
|
-
//
|
|
50
|
-
const
|
|
51
|
-
|
|
24
|
+
if (lineStyle.value === 'curved') {
|
|
25
|
+
// 长汇入线先沿分支前进,留足弯曲空间后再汇合,避开中间卡片。
|
|
26
|
+
const bend = { x: source.x, y: merge ? Math.max(source.y, target.y - 160) : source.y };
|
|
27
|
+
const gap = target.y - bend.y;
|
|
28
|
+
const reach = gap > 0 ? Math.min(gap * 0.8, Math.max(gap * 0.5, Math.abs(deltaX) * 0.25)) : Math.max(40, Math.abs(gap) * 0.5);
|
|
29
|
+
return [
|
|
30
|
+
`M ${point(source)}`,
|
|
31
|
+
...(bend.y !== source.y ? [`L ${point(bend)}`] : []),
|
|
32
|
+
`C ${point({ x: bend.x, y: bend.y + reach })} ${point({ x: target.x, y: target.y - reach })} ${point(target)}`,
|
|
33
|
+
].join(' ');
|
|
52
34
|
}
|
|
53
35
|
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
return linePath([
|
|
58
|
-
source,
|
|
59
|
-
{ x: source.x, y: branchY },
|
|
60
|
-
{ x: target.x, y: branchY },
|
|
61
|
-
target,
|
|
62
|
-
]);
|
|
36
|
+
if (merge) {
|
|
37
|
+
const joinY = target.y - 24;
|
|
38
|
+
return linePath([source, { x: source.x, y: joinY }, { x: target.x, y: joinY }, target]);
|
|
63
39
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return
|
|
40
|
+
if ((props.targetNode.data as FlowGraphNodeData | undefined)?.kind === 'branch') {
|
|
41
|
+
const branchY = source.y + (deltaY >= 0 ? 1 : -1) * Math.min(Math.max(Math.abs(deltaY) * 0.45, 18), 34);
|
|
42
|
+
return linePath([source, { x: source.x, y: branchY }, { x: target.x, y: branchY }, target]);
|
|
67
43
|
}
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
? source.y + verticalGap
|
|
72
|
-
: source.y - verticalGap;
|
|
73
|
-
|
|
74
|
-
return linePath([
|
|
75
|
-
source,
|
|
76
|
-
{ x: source.x, y: splitY },
|
|
77
|
-
{ x: target.x, y: splitY },
|
|
78
|
-
target,
|
|
79
|
-
]);
|
|
44
|
+
if (Math.abs(deltaX) < 2) return linePath([source, target]);
|
|
45
|
+
const splitY = source.y + (deltaY >= 0 ? 1 : -1) * Math.min(Math.max(Math.abs(deltaY) * 0.38, 28), 56);
|
|
46
|
+
return linePath([source, { x: source.x, y: splitY }, { x: target.x, y: splitY }, target]);
|
|
80
47
|
});
|
|
81
48
|
</script>
|
|
82
49
|
|
|
@@ -163,7 +163,7 @@ function patchSelector(patch: Partial<AppiumSelector>) {
|
|
|
163
163
|
|
|
164
164
|
<template>
|
|
165
165
|
<div class="appium-flow-editor">
|
|
166
|
-
<el-form label-position="
|
|
166
|
+
<el-form class="appium-flow-editor__form" label-position="left" label-width="104px" size="small">
|
|
167
167
|
<LongPressSettings v-if="step.type === 'longPress'" :step="step" :disabled="disabled" @update="patchStep" />
|
|
168
168
|
<el-form-item v-if="['waitActivity', 'launchApp', 'stopApp', 'clearAppData'].includes(step.type)" :label="step.type === 'waitActivity' ? '目标 Activity' : '目标 APP 包名'">
|
|
169
169
|
<el-input :model-value="step.value || ''" :disabled="disabled" @update:model-value="patchStep({ value: String($event) })" />
|
|
@@ -458,19 +458,55 @@ function patchSelector(patch: Partial<AppiumSelector>) {
|
|
|
458
458
|
</template>
|
|
459
459
|
|
|
460
460
|
<style scoped>
|
|
461
|
+
.appium-flow-editor { --node-editor-gap: 12px; padding: 12px; }
|
|
462
|
+
.appium-flow-editor__form { display: grid; gap: var(--node-editor-gap); }
|
|
463
|
+
/* 高度动画会逐帧触发整张流程重排,子选项直接展开以保持编辑响应。 */
|
|
464
|
+
.appium-flow-editor :deep(.el-collapse-item__wrap) { transition: none; }
|
|
465
|
+
.appium-flow-editor :deep(.appium-flow-editor__section) { display: grid; gap: var(--node-editor-gap); }
|
|
466
|
+
.appium-flow-editor :deep(.el-collapse .el-collapse-item__content) {
|
|
467
|
+
display: grid;
|
|
468
|
+
gap: var(--node-editor-gap);
|
|
469
|
+
padding: 12px;
|
|
470
|
+
}
|
|
461
471
|
.appium-flow-editor__fallback {
|
|
462
472
|
display: grid;
|
|
463
|
-
gap:
|
|
464
|
-
margin-top: 8px;
|
|
473
|
+
gap: var(--node-editor-gap);
|
|
465
474
|
padding-top: 12px;
|
|
466
475
|
border-top: 1px solid var(--el-border-color-lighter);
|
|
467
476
|
}
|
|
468
477
|
|
|
469
|
-
.appium-flow-editor :deep(.el-form-item)
|
|
470
|
-
|
|
471
|
-
.appium-flow-
|
|
472
|
-
|
|
478
|
+
.appium-flow-editor :deep(.el-form-item),
|
|
479
|
+
.appium-flow-editor :deep(.ai-recognition-settings .el-form-item) { min-width: 0; margin: 0; }
|
|
480
|
+
.appium-flow-editor :deep(.el-form-item.is-error) { margin-bottom: 8px; }
|
|
481
|
+
.appium-flow-editor :deep(.el-form-item:has(> .el-form-item__label)) {
|
|
482
|
+
display: grid;
|
|
483
|
+
grid-template-columns: 100px minmax(0, 1fr);
|
|
484
|
+
align-items: start;
|
|
485
|
+
column-gap: 8px;
|
|
486
|
+
}
|
|
487
|
+
.appium-flow-editor :deep(.el-form-item > .el-form-item__label) {
|
|
488
|
+
justify-content: flex-start;
|
|
489
|
+
width: auto !important;
|
|
490
|
+
height: auto;
|
|
491
|
+
min-height: 28px;
|
|
492
|
+
margin: 0;
|
|
493
|
+
padding: 5px 0;
|
|
494
|
+
color: var(--ui-text-secondary);
|
|
495
|
+
font-size: 12px;
|
|
496
|
+
line-height: 18px;
|
|
497
|
+
overflow-wrap: anywhere;
|
|
473
498
|
}
|
|
499
|
+
.appium-flow-editor :deep(.el-form-item > .el-form-item__content) { min-width: 0; margin-left: 0 !important; }
|
|
500
|
+
.appium-flow-editor :deep(.el-input-number),
|
|
501
|
+
.appium-flow-editor :deep(.el-select) { width: 100%; }
|
|
502
|
+
.appium-flow-editor :deep(.appium-flow-editor__grid),
|
|
503
|
+
.appium-flow-editor :deep(.ai-recognition-settings__grid) { grid-template-columns: minmax(0, 1fr); gap: var(--node-editor-gap); }
|
|
504
|
+
.appium-flow-editor :deep(.el-input__wrapper),
|
|
505
|
+
.appium-flow-editor :deep(.el-select__wrapper),
|
|
506
|
+
.appium-flow-editor :deep(.el-textarea__inner) { background: var(--ui-bg-soft); box-shadow: inset 0 0 0 1px var(--ui-border); }
|
|
507
|
+
.appium-flow-editor :deep(.el-form-item:has(.el-textarea)) { display: block; }
|
|
508
|
+
.appium-flow-editor :deep(.el-radio-group) { width: 100%; }
|
|
509
|
+
.appium-flow-editor :deep(.el-radio-button__inner) { padding: 5px 8px; font-size: 12px; }
|
|
474
510
|
|
|
475
511
|
.appium-flow-editor__fallback-alert {
|
|
476
512
|
padding: 8px 12px;
|
|
@@ -483,10 +519,10 @@ function patchSelector(patch: Partial<AppiumSelector>) {
|
|
|
483
519
|
|
|
484
520
|
.appium-flow-editor__groups {
|
|
485
521
|
overflow: hidden;
|
|
486
|
-
margin
|
|
522
|
+
margin: 0;
|
|
487
523
|
border: 1px solid var(--el-border-color-lighter);
|
|
488
524
|
border-radius: 10px;
|
|
489
|
-
background:
|
|
525
|
+
background: var(--ui-surface);
|
|
490
526
|
}
|
|
491
527
|
|
|
492
528
|
.appium-flow-editor__groups :deep(.el-collapse-item__header) {
|
|
@@ -497,7 +533,6 @@ function patchSelector(patch: Partial<AppiumSelector>) {
|
|
|
497
533
|
}
|
|
498
534
|
|
|
499
535
|
.appium-flow-editor__groups :deep(.el-collapse-item__wrap) { border-bottom: 0; }
|
|
500
|
-
.appium-flow-editor__groups :deep(.el-collapse-item__content) { padding: 8px 10px 2px; }
|
|
501
536
|
.appium-flow-editor__group-title { display: flex; align-items: center; justify-content: space-between; min-width: 0; width: 100%; padding-right: 8px; gap: 8px; }
|
|
502
537
|
.appium-flow-editor__group-title strong { flex: none; color: var(--ui-text); font-size: 12px; }
|
|
503
538
|
.appium-flow-editor__group-title small { min-width: 0; overflow: hidden; color: var(--ui-text-muted); font-size: 11px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
|
|
@@ -23,7 +23,7 @@ function changeCoordinate(key: 'centerX' | 'centerY', value: number | undefined)
|
|
|
23
23
|
</script>
|
|
24
24
|
|
|
25
25
|
<template>
|
|
26
|
-
<div>
|
|
26
|
+
<div class="appium-flow-editor__section">
|
|
27
27
|
<el-form-item label="长按方式">
|
|
28
28
|
<el-radio-group :model-value="mode" :disabled="disabled" @update:model-value="changeMode($event as AppiumRecordedStep['longPressMode'])">
|
|
29
29
|
<el-radio-button value="element">长按元素</el-radio-button>
|
|
@@ -241,7 +241,13 @@ async function deleteSelectedNodes() {
|
|
|
241
241
|
finally { deleting.value = false; }
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
watch(() => props.steps, () => {
|
|
244
|
+
watch(() => props.steps, (steps, previous) => {
|
|
245
|
+
if (copyMode.value) cancelCopyMode();
|
|
246
|
+
if (expandedStepIndex.value === null) return;
|
|
247
|
+
const id = previous[expandedStepIndex.value]?.id;
|
|
248
|
+
const index = steps.findIndex(step => step.id === id);
|
|
249
|
+
expandedStepIndex.value = index < 0 ? null : index;
|
|
250
|
+
});
|
|
245
251
|
|
|
246
252
|
function resetMainFlowPosition() {
|
|
247
253
|
mainResetViewToken.value += 1;
|
|
@@ -31,3 +31,40 @@ export const flowLineStyleKey: InjectionKey<Readonly<Ref<FlowLineStyle>>> = Symb
|
|
|
31
31
|
export function normalizeFlowLineStyle(value: unknown): FlowLineStyle {
|
|
32
32
|
return value === 'straight' ? 'straight' : 'curved';
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
export type FlowLayoutDirection = 'vertical' | 'horizontal';
|
|
36
|
+
export const flowLayoutDirectionKey: InjectionKey<Readonly<Ref<FlowLayoutDirection>>> = Symbol('flowLayoutDirection');
|
|
37
|
+
|
|
38
|
+
export function normalizeFlowLayoutDirection(value: unknown): FlowLayoutDirection {
|
|
39
|
+
return value === 'horizontal' ? 'horizontal' : 'vertical';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const DEFAULT_FLOW_NODE_COLOR = '#ffffff';
|
|
43
|
+
export const DEFAULT_FLOW_NODE_BORDER_COLOR = '#dfe8f3';
|
|
44
|
+
export const flowNodeColorKey: InjectionKey<Readonly<Ref<string>>> = Symbol('flowNodeColor');
|
|
45
|
+
export const flowNodeBorderColorKey: InjectionKey<Readonly<Ref<string>>> = Symbol('flowNodeBorderColor');
|
|
46
|
+
|
|
47
|
+
export function normalizeFlowNodeColor(value: unknown) {
|
|
48
|
+
return normalizeFlowColor(value, DEFAULT_FLOW_NODE_COLOR);
|
|
49
|
+
}
|
|
50
|
+
export function normalizeFlowNodeBorderColor(value: unknown) {
|
|
51
|
+
return normalizeFlowColor(value, DEFAULT_FLOW_NODE_BORDER_COLOR);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const FLOW_APPEARANCE_THEMES = [
|
|
55
|
+
{ id: 'default', name: '默认浅灰', colors: { flowBackgroundColor: DEFAULT_FLOW_BACKGROUND, flowNodeColor: DEFAULT_FLOW_NODE_COLOR, flowNodeBorderColor: DEFAULT_FLOW_NODE_BORDER_COLOR, flowLineColor: DEFAULT_FLOW_LINE_COLOR } },
|
|
56
|
+
{ id: 'blue', name: '雾蓝', colors: { flowBackgroundColor: '#eaf2fb', flowNodeColor: '#f6faff', flowNodeBorderColor: '#a8c1df', flowLineColor: '#6385b0' } },
|
|
57
|
+
{ id: 'mint', name: '薄荷', colors: { flowBackgroundColor: '#e9f3ee', flowNodeColor: '#f5fcf8', flowNodeBorderColor: '#a2c5b2', flowLineColor: '#5d8d74' } },
|
|
58
|
+
{ id: 'apricot', name: '暖杏', colors: { flowBackgroundColor: '#f8f0e6', flowNodeColor: '#fffaf3', flowNodeBorderColor: '#dcc3a2', flowLineColor: '#ac8256' } },
|
|
59
|
+
{ id: 'violet', name: '浅紫', colors: { flowBackgroundColor: '#f0ecf8', flowNodeColor: '#faf8ff', flowNodeBorderColor: '#c4b4df', flowLineColor: '#9175b3' } },
|
|
60
|
+
{ id: 'graphite', name: '石墨', colors: { flowBackgroundColor: '#191c22', flowNodeColor: '#292e38', flowNodeBorderColor: '#535e70', flowLineColor: '#a9a0d8' } },
|
|
61
|
+
];
|
|
62
|
+
export type FlowAppearanceTheme = typeof FLOW_APPEARANCE_THEMES[number];
|
|
63
|
+
|
|
64
|
+
export function flowNodeTextColors(value: unknown) {
|
|
65
|
+
const color = normalizeFlowNodeColor(value);
|
|
66
|
+
const rgb = [1, 3, 5].map(index => parseInt(color.slice(index, index + 2), 16) / 255)
|
|
67
|
+
.map(channel => channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4);
|
|
68
|
+
const dark = rgb[0] * 0.2126 + rgb[1] * 0.7152 + rgb[2] * 0.0722 < 0.179;
|
|
69
|
+
return { dark, text: dark ? '#f1f5f9' : '#0f172a', muted: dark ? '#b7c1d1' : '#64748b' };
|
|
70
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Position, type Edge, type Node } from '@vue-flow/core';
|
|
2
2
|
import * as dagre from '@dagrejs/dagre';
|
|
3
3
|
import type { AppiumRecordedStep } from './types';
|
|
4
|
+
import type { FlowLayoutDirection } from './flow-appearance';
|
|
4
5
|
import { defaultFlowKind as defaultKind, flowBranchLabel, isBooleanCondition } from './flow-labels';
|
|
5
6
|
|
|
6
7
|
type DagreApi = typeof dagre;
|
|
@@ -140,6 +141,7 @@ type StepItem = {
|
|
|
140
141
|
};
|
|
141
142
|
|
|
142
143
|
type BuildFlowGraphOptions = {
|
|
144
|
+
layoutDirection?: FlowLayoutDirection;
|
|
143
145
|
aiRecognitionModelConfigured?: boolean;
|
|
144
146
|
expandedStepIndex: number | null;
|
|
145
147
|
selectedCopyIndexes: number[];
|
|
@@ -307,7 +309,15 @@ export function buildFlowGraph(
|
|
|
307
309
|
steps: AppiumRecordedStep[],
|
|
308
310
|
options: BuildFlowGraphOptions,
|
|
309
311
|
) {
|
|
312
|
+
const horizontal = options.layoutDirection === 'horizontal';
|
|
313
|
+
const branchMinWidth = horizontal ? FLOW_STEP_NODE_HEIGHT : FLOW_STEP_NODE_WIDTH;
|
|
314
|
+
const branchMinSpread = horizontal ? 100 : FLOW_BRANCH_MIN_SPREAD;
|
|
310
315
|
const items = steps.map((step, index) => ({ step, index }));
|
|
316
|
+
const stepNodeHeight = ({ step, index }: StepItem) => {
|
|
317
|
+
const estimated = estimateStepNodeHeight(options.labelStep(step), step.type === 'aiRecognition' ? 3 : undefined)
|
|
318
|
+
+ (options.expandedStepIndex === index ? FLOW_EXPANDED_NODE_HEIGHT : 0);
|
|
319
|
+
return Math.max(FLOW_STEP_NODE_HEIGHT, Math.ceil(options.measuredNodeHeights?.[nodeIdForStep(step)] || estimated));
|
|
320
|
+
};
|
|
311
321
|
const nodes: FlowGraphNode[] = [];
|
|
312
322
|
const links: Link[] = [];
|
|
313
323
|
const layoutLinks: Link[] = [];
|
|
@@ -321,26 +331,26 @@ export function buildFlowGraph(
|
|
|
321
331
|
if (cached) return cached;
|
|
322
332
|
if (measuringBranches.has(condition.id)) {
|
|
323
333
|
return {
|
|
324
|
-
yesWidth:
|
|
325
|
-
noWidth:
|
|
326
|
-
centerGap:
|
|
327
|
-
totalWidth:
|
|
334
|
+
yesWidth: branchMinWidth,
|
|
335
|
+
noWidth: branchMinWidth,
|
|
336
|
+
centerGap: branchMinSpread * 2,
|
|
337
|
+
totalWidth: branchMinSpread * 2 + branchMinWidth,
|
|
328
338
|
};
|
|
329
339
|
}
|
|
330
340
|
|
|
331
341
|
measuringBranches.add(condition.id);
|
|
332
342
|
const branchWidth = (branch: FlowBranch) => Math.max(
|
|
333
|
-
|
|
334
|
-
...directBranchItems(items, condition.id, branch).map((
|
|
335
|
-
defaultKind(step) === 'condition'
|
|
336
|
-
? conditionBranchLayout(step).totalWidth
|
|
337
|
-
:
|
|
343
|
+
branchMinWidth,
|
|
344
|
+
...directBranchItems(items, condition.id, branch).map((item) => (
|
|
345
|
+
defaultKind(item.step) === 'condition'
|
|
346
|
+
? Math.max(conditionBranchLayout(item.step).totalWidth, horizontal ? stepNodeHeight(item) : branchMinWidth)
|
|
347
|
+
: horizontal ? stepNodeHeight(item) : branchMinWidth
|
|
338
348
|
)),
|
|
339
349
|
);
|
|
340
350
|
const yesWidth = branchWidth('yes');
|
|
341
351
|
const noWidth = branchWidth('no');
|
|
342
352
|
const centerGap = Math.max(
|
|
343
|
-
|
|
353
|
+
branchMinSpread * 2,
|
|
344
354
|
yesWidth / 2 + noWidth / 2 + FLOW_BRANCH_SUBTREE_GAP,
|
|
345
355
|
);
|
|
346
356
|
const sideExtent = Math.max(
|
|
@@ -351,7 +361,7 @@ export function buildFlowGraph(
|
|
|
351
361
|
yesWidth,
|
|
352
362
|
noWidth,
|
|
353
363
|
centerGap,
|
|
354
|
-
totalWidth: Math.max(
|
|
364
|
+
totalWidth: Math.max(branchMinWidth, sideExtent * 2),
|
|
355
365
|
};
|
|
356
366
|
measuringBranches.delete(condition.id);
|
|
357
367
|
branchLayouts.set(condition.id, layout);
|
|
@@ -363,12 +373,14 @@ export function buildFlowGraph(
|
|
|
363
373
|
.forEach(({ step }) => conditionBranchLayout(step));
|
|
364
374
|
|
|
365
375
|
const addNode = (node: FlowGraphNode) => {
|
|
376
|
+
// 在逻辑纵向坐标中复用分支、汇合和避让算法,横向布局交换节点尺寸后计算。
|
|
377
|
+
const width = Number(node.width) || FLOW_STEP_NODE_WIDTH;
|
|
378
|
+
const height = Number(node.height) || FLOW_STEP_NODE_HEIGHT;
|
|
366
379
|
nodes.push({
|
|
367
380
|
...node,
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
},
|
|
381
|
+
width: horizontal ? height : width,
|
|
382
|
+
height: horizontal ? width : height,
|
|
383
|
+
dimensions: { width: horizontal ? height : width, height: horizontal ? width : height },
|
|
372
384
|
} as FlowGraphNode);
|
|
373
385
|
};
|
|
374
386
|
const addVisibleLink = (source: string, target: string, branch?: FlowBranch) => {
|
|
@@ -427,14 +439,7 @@ export function buildFlowGraph(
|
|
|
427
439
|
const label = options.labelStep(item.step);
|
|
428
440
|
// 字数估算仅用于首次布局,不强制卡片高度;实际换行由浏览器决定。
|
|
429
441
|
const cardMinHeight = FLOW_STEP_NODE_HEIGHT;
|
|
430
|
-
const
|
|
431
|
-
label,
|
|
432
|
-
item.step.type === 'aiRecognition' ? 3 : undefined,
|
|
433
|
-
);
|
|
434
|
-
const estimatedNodeHeight = options.expandedStepIndex === item.index
|
|
435
|
-
? estimatedCardHeight + FLOW_EXPANDED_NODE_HEIGHT
|
|
436
|
-
: estimatedCardHeight;
|
|
437
|
-
const nodeHeight = Math.max(cardMinHeight, Math.ceil(options.measuredNodeHeights?.[id] || estimatedNodeHeight));
|
|
442
|
+
const nodeHeight = stepNodeHeight(item);
|
|
438
443
|
addNode({
|
|
439
444
|
id,
|
|
440
445
|
type: 'flow-node',
|
|
@@ -790,7 +795,7 @@ export function buildFlowGraph(
|
|
|
790
795
|
if (joinOwner && target.id !== joinOwner) {
|
|
791
796
|
const incoming = links.filter((edge) => edge.target === target.id).map((edge) => nodeById.get(edge.source)!).filter(Boolean);
|
|
792
797
|
if (incoming.length) {
|
|
793
|
-
target.position.y = Math.round(Math.max(...incoming.map((node) => node.position.y + nodeHeight(node))) + FLOW_STANDARD_LINE_GAP *
|
|
798
|
+
target.position.y = Math.round(Math.max(...incoming.map((node) => node.position.y + nodeHeight(node))) + FLOW_STANDARD_LINE_GAP * 8);
|
|
794
799
|
const incomingCenters = incoming.map(centerX);
|
|
795
800
|
setCenterX(target, (Math.min(...incomingCenters) + Math.max(...incomingCenters)) / 2);
|
|
796
801
|
}
|
|
@@ -806,7 +811,7 @@ export function buildFlowGraph(
|
|
|
806
811
|
let x = centerX(source);
|
|
807
812
|
if (target.data.kind === 'branch') {
|
|
808
813
|
const conditionId = steps[target.data.conditionIndex].id;
|
|
809
|
-
const spread = (branchLayouts.get(conditionId)?.centerGap ||
|
|
814
|
+
const spread = (branchLayouts.get(conditionId)?.centerGap || branchMinSpread * 2) / 2;
|
|
810
815
|
x += target.data.branch === 'yes' ? -spread : spread;
|
|
811
816
|
}
|
|
812
817
|
setCenterX(target, x);
|
|
@@ -830,14 +835,25 @@ export function buildFlowGraph(
|
|
|
830
835
|
source: link.source,
|
|
831
836
|
target: link.target,
|
|
832
837
|
type: 'flow-rounded',
|
|
833
|
-
sourceHandle: '
|
|
834
|
-
targetHandle: '
|
|
838
|
+
sourceHandle: 'output',
|
|
839
|
+
targetHandle: 'input',
|
|
835
840
|
selectable: false,
|
|
836
841
|
focusable: false,
|
|
837
842
|
class: 'appium-vue-flow-edge',
|
|
838
843
|
data: { branch: link.branch, merge: joins.has(link.target) },
|
|
839
844
|
}));
|
|
840
845
|
|
|
846
|
+
if (horizontal) {
|
|
847
|
+
positionedNodes.forEach((node) => {
|
|
848
|
+
node.position = { x: node.position.y, y: node.position.x };
|
|
849
|
+
const width = node.width;
|
|
850
|
+
node.width = node.height;
|
|
851
|
+
node.height = width;
|
|
852
|
+
Object.assign(node, { dimensions: { width: Number(node.width), height: Number(node.height) } });
|
|
853
|
+
node.sourcePosition = Position.Right;
|
|
854
|
+
node.targetPosition = Position.Left;
|
|
855
|
+
});
|
|
856
|
+
}
|
|
841
857
|
return { nodes: positionedNodes, edges };
|
|
842
858
|
}
|
|
843
859
|
|