android-midscene-automation 1.1.9 → 1.1.11

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +60 -53
  2. package/README.md +60 -53
  3. package/package.json +1 -1
  4. package/server/appium-recorder/appium-runner.ts +22 -0
  5. package/server/appium-recorder/random-value-replay.test.ts +101 -0
  6. package/server/appium-recorder/random-value.test.ts +114 -0
  7. package/server/appium-recorder/random-value.ts +34 -0
  8. package/server/appium-recorder/repository.ts +11 -1
  9. package/server/appium-recorder/script-export.ts +6 -1
  10. package/server/appium-recorder/stopwatch.test.ts +74 -0
  11. package/server/appium-recorder/stopwatch.ts +24 -0
  12. package/src/App.vue +18 -5
  13. package/src/appium-recorder/AppiumPage.vue +137 -6
  14. package/src/appium-recorder/action-descriptions.ts +2 -0
  15. package/src/appium-recorder/components/FlowStepEditor.vue +5 -1
  16. package/src/appium-recorder/components/NestedConditionBranches.vue +3 -0
  17. package/src/appium-recorder/components/PresetVariables.vue +6 -5
  18. package/src/appium-recorder/components/RandomValueSettings.vue +139 -0
  19. package/src/appium-recorder/components/RecordedSteps.vue +2 -0
  20. package/src/appium-recorder/components/StopwatchSettings.vue +40 -0
  21. package/src/appium-recorder/flow-copy.ts +3 -2
  22. package/src/appium-recorder/flow-graph.ts +2 -0
  23. package/src/appium-recorder/flow-labels.ts +7 -1
  24. package/src/appium-recorder/random-value.ts +60 -0
  25. package/src/appium-recorder/stopwatch.ts +27 -0
  26. package/src/appium-recorder/types.ts +6 -0
  27. package/src/appium-recorder/variable-presets.ts +24 -0
  28. package/src/components/AppSidebar.vue +37 -7
  29. package/src/components/config/AiDeduplicationSettings.vue +21 -10
  30. package/src/components/config/AppiumConfigPanel.vue +10 -5
  31. package/src/components/config/BaseConfigPanel.vue +54 -33
  32. package/src/components/config/MidsceneConfigPanel.vue +9 -0
  33. package/src/config/use-model-config.ts +1 -1
  34. package/src/pages/ConfigPage.vue +0 -19
  35. package/src/style.css +6 -1
  36. package/src/types.ts +1 -1
  37. package//346/265/201/347/250/213/350/212/202/347/202/271/346/223/215/344/275/234/350/257/264/346/230/216.md +10 -0
@@ -0,0 +1,139 @@
1
+ <script setup lang="ts">
2
+ import { computed, inject, onMounted, shallowRef, useTemplateRef } from 'vue';
3
+ import { ElMessage } from 'element-plus';
4
+ import { Upload } from '@element-plus/icons-vue';
5
+ import type { AppiumRecordedStep } from '../types';
6
+ import { defaultRandomValue, MAX_RANDOM_FILE_BYTES, randomTextCandidates, type RandomValueConfig } from '../random-value';
7
+ import { sensitiveVariableName } from '../variables';
8
+ import { variablePresetKey, type VariablePresetContext } from '../variable-presets';
9
+
10
+ const props = defineProps<{ step: AppiumRecordedStep; disabled?: boolean; presets?: VariablePresetContext }>();
11
+ const emit = defineEmits<{ update: [Partial<AppiumRecordedStep>] }>();
12
+ const config = computed(() => ({ ...defaultRandomValue(), ...props.step.randomValue }));
13
+ const fileInput = useTemplateRef<HTMLInputElement>('fileInput');
14
+ const importing = shallowRef(false);
15
+ const inheritedPresets = inject(variablePresetKey, undefined);
16
+ const presets = computed(() => props.presets || inheritedPresets);
17
+ const variableOptions = computed(() => presets.value?.options.value || []);
18
+ const variablesLoading = computed(() => presets.value?.loading.value || false);
19
+ const variablesError = computed(() => presets.value?.error.value || '');
20
+ const selectedVariable = computed(() => variableOptions.value.find(variable => variable.name === config.value.name));
21
+ const fixedSensitive = computed(() => Boolean(selectedVariable.value?.sensitive || sensitiveVariableName(config.value.name)));
22
+ const sensitive = computed(() => Boolean(config.value.sensitive || fixedSensitive.value));
23
+ const missingVariable = computed(() => Boolean(config.value.name && !selectedVariable.value && !variablesLoading.value));
24
+ const reference = computed(() => `{{${config.value.name || '变量名'}}}`);
25
+ const candidateCount = computed(() => {
26
+ try {
27
+ const candidates = randomTextCandidates(config.value.text);
28
+ return config.value.withoutReplacement ? new Set(candidates).size : candidates.length;
29
+ } catch { return 0; }
30
+ });
31
+
32
+ function update(patch: Partial<RandomValueConfig>) {
33
+ emit('update', { randomValue: { ...config.value, ...patch } });
34
+ }
35
+
36
+ function refreshVariables(visible: boolean) {
37
+ if (visible) void presets.value?.refresh();
38
+ }
39
+
40
+ onMounted(() => { void presets.value?.refresh(); });
41
+
42
+ async function importText(event: Event) {
43
+ const input = event.target as HTMLInputElement;
44
+ const file = input.files?.[0];
45
+ input.value = '';
46
+ if (!file || props.disabled) return;
47
+ importing.value = true;
48
+ try {
49
+ if (file.size > MAX_RANDOM_FILE_BYTES) throw new Error('TXT 文件不能超过 1 MB');
50
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(await file.arrayBuffer());
51
+ randomTextCandidates(text);
52
+ update({ text, sourceName: file.name });
53
+ } catch (error) {
54
+ ElMessage.error(error instanceof TypeError ? '请导入 UTF-8 编码的 TXT 文件' : error instanceof Error ? error.message : 'TXT 导入失败');
55
+ } finally { importing.value = false; }
56
+ }
57
+
58
+ </script>
59
+
60
+ <template>
61
+ <div class="random-value-settings">
62
+ <el-form-item label="结果类型">
63
+ <el-select :model-value="config.mode" :disabled="disabled" aria-label="随机值类型" @update:model-value="update({ mode: $event })">
64
+ <el-option label="预设文本 / TXT" value="text" />
65
+ <el-option label="随机整数" value="integer" />
66
+ <el-option label="随机 ID(UUID)" value="uuid" />
67
+ </el-select>
68
+ </el-form-item>
69
+ <el-form-item label="保存到变量">
70
+ <div class="random-value-settings__field">
71
+ <el-select class="random-value-settings__variable-select" :model-value="config.name || undefined" :disabled="disabled" :loading="variablesLoading" filterable placeholder="选择预设变量 key" aria-label="随机值变量名" @visible-change="refreshVariables" @update:model-value="update({ name: String($event), sensitive: variableOptions.find(variable => variable.name === $event)?.sensitive || undefined })">
72
+ <el-option v-if="missingVariable" :label="`${config.name}(未预设)`" :value="config.name" disabled />
73
+ <el-option v-for="variable in variableOptions" :key="variable.name" :label="variable.name" :value="variable.name">
74
+ <span>{{ variable.name }}</span><small class="random-value-settings__scope">{{ variable.scope === 'private' ? '私有' : '全局' }}</small>
75
+ </el-option>
76
+ <template #empty><div class="random-value-settings__empty">暂无匹配的预设变量</div></template>
77
+ </el-select>
78
+ <div class="random-value-settings__variable-help">
79
+ <span class="random-value-settings__hint">{{ selectedVariable ? (selectedVariable.scope === 'private' ? '当前脚本私有变量' : '使用全局 key,结果保存在当前脚本') : '选择已有 key 保存结果' }}</span>
80
+ <el-button link type="primary" :disabled="disabled || !presets" @click="presets?.open()">去添加变量</el-button>
81
+ </div>
82
+ <span v-if="variablesError" class="random-value-settings__error" role="alert">变量加载失败 <el-button link type="primary" :disabled="variablesLoading" @click="presets?.refresh()">重试</el-button></span>
83
+ <span v-else-if="missingVariable" class="random-value-settings__error" role="alert">此 key 尚未预设,请先添加或重新选择。</span>
84
+ </div>
85
+ </el-form-item>
86
+ <template v-if="config.mode === 'text'">
87
+ <el-form-item label="候选内容">
88
+ <div class="random-value-settings__field">
89
+ <el-input type="textarea" :rows="4" :model-value="config.text || ''" :disabled="disabled" placeholder="每行一条候选内容" aria-label="随机候选内容" @update:model-value="update({ text: String($event), sourceName: undefined })" />
90
+ <div class="random-value-settings__import">
91
+ <input ref="fileInput" type="file" accept=".txt,text/plain" hidden aria-label="导入随机候选 TXT" :disabled="disabled || importing" @change="importText" />
92
+ <el-button :icon="Upload" :disabled="disabled" :loading="importing" @click="fileInput?.click()">导入 TXT</el-button>
93
+ <span class="random-value-settings__count">{{ candidateCount }} 条{{ config.withoutReplacement ? '不同' : '' }}候选</span>
94
+ </div>
95
+ <span v-if="config.sourceName" class="random-value-settings__hint random-value-settings__file" :title="config.sourceName">{{ config.sourceName }}</span>
96
+ <span class="random-value-settings__hint">UTF-8 · 每行一条,忽略空行和 # 注释。内容随脚本保存。</span>
97
+ </div>
98
+ </el-form-item>
99
+ <el-form-item label="抽取方式">
100
+ <div class="random-value-settings__field">
101
+ <el-select :model-value="config.withoutReplacement === true" :disabled="disabled" aria-label="随机抽取方式" @update:model-value="update({ withoutReplacement: $event === true })">
102
+ <el-option label="允许重复抽取" :value="false" />
103
+ <el-option label="本次运行不重复" :value="true" />
104
+ </el-select>
105
+ <span v-if="config.withoutReplacement" class="random-value-settings__hint">候选耗尽时停止,下次回放重新开始。</span>
106
+ </div>
107
+ </el-form-item>
108
+ </template>
109
+ <template v-if="config.mode === 'integer'">
110
+ <el-form-item label="最小值">
111
+ <el-input-number :model-value="config.min ?? 0" :disabled="disabled" :precision="0" controls-position="right" aria-label="随机整数最小值" @update:model-value="update({ min: $event ?? 0 })" />
112
+ </el-form-item>
113
+ <el-form-item label="最大值">
114
+ <el-input-number :model-value="config.max ?? 9999" :disabled="disabled" :precision="0" controls-position="right" aria-label="随机整数最大值" @update:model-value="update({ max: $event ?? 9999 })" />
115
+ </el-form-item>
116
+ <span class="random-value-settings__hint">包含最小值和最大值,结果以文本保存。</span>
117
+ </template>
118
+ <span v-if="config.mode === 'uuid'" class="random-value-settings__hint">每次执行生成一个 UUID,并以文本保存。</span>
119
+ <el-form-item label="敏感值">
120
+ <el-checkbox :model-value="sensitive" :disabled="disabled || fixedSensitive" @update:model-value="update({ sensitive: $event === true })">隐藏日志中的结果</el-checkbox>
121
+ </el-form-item>
122
+ <span v-if="sensitive && config.mode === 'text'" class="random-value-settings__hint">导出时清空敏感候选内容。</span>
123
+ <span class="random-value-settings__hint">后续通过 <code>{{ reference }}</code> 引用结果。</span>
124
+ </div>
125
+ </template>
126
+
127
+ <style scoped>
128
+ .random-value-settings { display: flex; flex-direction: column; gap: 12px; min-width: 0; text-align: left; }
129
+ .random-value-settings :deep(.el-form-item) { margin-bottom: 0; }
130
+ .random-value-settings__field { display: grid; gap: 8px; width: 100%; min-width: 0; }
131
+ .random-value-settings__import, .random-value-settings__variable-help { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
132
+ .random-value-settings__variable-help .el-button { padding: 0; font-size: 12px; }
133
+ .random-value-settings__count { font-size: 12px; color: var(--ui-text-secondary, #64748b); }
134
+ .random-value-settings__scope { float: right; margin-left: 16px; color: var(--el-text-color-secondary); }
135
+ .random-value-settings__empty { padding: 12px; color: var(--el-text-color-secondary); text-align: center; }
136
+ .random-value-settings__file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
137
+ .random-value-settings__error { color: var(--el-color-danger); font-size: 12px; line-height: 1.5; }
138
+ .random-value-settings__hint { color: var(--ui-text-secondary, #64748b); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
139
+ </style>
@@ -115,6 +115,7 @@ const insertActionGroups: FlowActionGroup[] = [
115
115
  {
116
116
  title: '流程控制',
117
117
  actions: [
118
+ { type: 'randomValue', label: '获取随机值' },
118
119
  { type: 'noop', label: '空节点' },
119
120
  { type: 'endFlow', label: '终止流程' },
120
121
  {
@@ -126,6 +127,7 @@ const insertActionGroups: FlowActionGroup[] = [
126
127
  ],
127
128
  },
128
129
  { type: 'log', label: '输出日志' },
130
+ { type: 'stopwatch', label: '计时打点' },
129
131
  { type: 'runScript', label: '连接脚本' },
130
132
  ],
131
133
  },
@@ -0,0 +1,40 @@
1
+ <script setup lang="ts">
2
+ import { computed, inject } from 'vue';
3
+ import { defaultStopwatch, stopwatchTargetsKey, STOPWATCH_ACTIONS, type StopwatchConfig, type StopwatchTarget } from '../stopwatch';
4
+ import type { AppiumRecordedStep } from '../types';
5
+ const props = defineProps<{ step: AppiumRecordedStep; disabled?: boolean; targets?: StopwatchTarget[] }>();
6
+ const emit = defineEmits<{ update: [patch: Partial<AppiumRecordedStep>] }>();
7
+ const providedTargets = inject(stopwatchTargetsKey, computed(() => []));
8
+ const targets = computed(() => props.targets ?? providedTargets.value);
9
+ const config = computed(() => props.step.stopwatch ?? defaultStopwatch());
10
+ const selected = computed(() => targets.value.find(target => target.timerId === config.value.timerId));
11
+ function patch(value: Partial<StopwatchConfig>) { emit('update', { stopwatch: { ...config.value, ...value } }); }
12
+ function changeAction(action: StopwatchConfig['action']) {
13
+ if (action === config.value.action) return;
14
+ const wasStart = config.value.action === 'start';
15
+ patch({ action, ...(action === 'start' ? { timerId: crypto.randomUUID() } : wasStart ? { timerId: '' } : {}) });
16
+ }
17
+ function selectTimer(timerId: string) {
18
+ const target = targets.value.find(item => item.timerId === timerId);
19
+ patch({ timerId, ...(target ? { name: target.name } : {}) });
20
+ }
21
+ </script>
22
+
23
+ <template>
24
+ <el-form-item label="计时操作">
25
+ <el-select :model-value="config.action" :disabled="disabled" aria-label="计时操作" @update:model-value="changeAction">
26
+ <el-option v-for="(label, value) in STOPWATCH_ACTIONS" :key="value" :label="label" :value="value" />
27
+ </el-select>
28
+ </el-form-item>
29
+ <el-form-item v-if="config.action !== 'start'" label="关联计时器" :error="config.timerId && !selected ? '关联的开始节点不存在,请重新选择' : ''">
30
+ <el-select :model-value="config.timerId" :disabled="disabled" filterable placeholder="请选择开始计时节点" aria-label="关联计时器" @update:model-value="selectTimer">
31
+ <el-option v-for="target in targets" :key="target.timerId" :label="target.label" :value="target.timerId" />
32
+ </el-select>
33
+ </el-form-item>
34
+ <el-form-item label="计时器名称">
35
+ <el-input :model-value="config.action === 'start' ? config.name : selected?.name || config.name" :readonly="config.action !== 'start'" :disabled="disabled" maxlength="80" aria-label="计时器名称" @update:model-value="patch({ name: String($event) })" />
36
+ </el-form-item>
37
+ <el-form-item label="计时器 ID">
38
+ <el-input :model-value="config.timerId" readonly aria-label="计时器 ID" placeholder="选择开始节点后显示" />
39
+ </el-form-item>
40
+ </template>
@@ -1,5 +1,6 @@
1
1
  import type { AppiumRecordedStep } from './types';
2
2
  import { insertBeforeSharedStep } from './flow-insert';
3
+ import { remapStopwatchIds } from './stopwatch';
3
4
 
4
5
  export type FlowBranch = 'yes' | 'no';
5
6
 
@@ -178,7 +179,7 @@ export function pasteFlowClipboard(
178
179
  const pairId = createId();
179
180
  visualChangePairKeys(step).forEach((key) => pairMap.set(key, pairId));
180
181
  });
181
- const copies = clipboard.steps.map((source) => {
182
+ const copies = remapStopwatchIds(clipboard.steps.map((source) => {
182
183
  const step = clone(source);
183
184
  // 合并记录引用原流程 ID,不能随节点复制到另一条流程。
184
185
  delete step.mergeUndo;
@@ -221,7 +222,7 @@ export function pasteFlowClipboard(
221
222
  };
222
223
  }
223
224
  return step;
224
- });
225
+ }));
225
226
 
226
227
  const copiedBySourceId = new Map(clipboard.steps.map((step, index) => [step.id, copies[index]]));
227
228
  const copiedRoots = clipboard.rootIds
@@ -50,6 +50,8 @@ export type InsertAction =
50
50
  | 'waitActivity'
51
51
  | 'runScript'
52
52
  | 'extractVariable'
53
+ | 'randomValue'
54
+ | 'stopwatch'
53
55
  | 'noop'
54
56
  | 'log'
55
57
  | 'visualChangeStart'
@@ -6,6 +6,8 @@ import { isNativeStateCondition } from './native-control-state';
6
6
  import { DEFAULT_LOG_PREFIX } from './stage-log';
7
7
  import { imageCheckSummary } from './image-check';
8
8
  import { isAiBranchEnabled } from './ai-recognition';
9
+ import { randomValueSummary } from './random-value';
10
+ import { STOPWATCH_ACTIONS } from './stopwatch';
9
11
 
10
12
  export function isBooleanCondition(step: Pick<AppiumRecordedStep, 'type' | 'aiBranchEnabled'>) {
11
13
  return isNativeStateCondition(step) || (step.type === 'aiRecognition' && isAiBranchEnabled(step)) || step.type === 'textClick' || step.type === 'imageCheck';
@@ -13,7 +15,7 @@ export function isBooleanCondition(step: Pick<AppiumRecordedStep, 'type' | 'aiBr
13
15
 
14
16
  export function defaultFlowKind(step: AppiumRecordedStep): FlowKind {
15
17
  if (step.type === 'aiRecognition') return isAiBranchEnabled(step) ? 'condition' : 'action';
16
- if (step.type === 'extractVariable') return 'action';
18
+ if (step.type === 'extractVariable' || step.type === 'randomValue' || step.type === 'stopwatch') return 'action';
17
19
  if (step.type === 'loop') return 'condition';
18
20
  if (step.type === 'breakLoop' || step.type === 'continueLoop') return 'action';
19
21
  if (step.type === 'log' || step.type === 'openGallery' || step.type === 'endFlow') return 'action';
@@ -73,12 +75,16 @@ export function flowTypeLabel(step: AppiumRecordedStep) {
73
75
  noop: '空节点',
74
76
  log: '输出日志',
75
77
  extractVariable: '提取变量',
78
+ randomValue: '获取随机值',
79
+ stopwatch: '计时打点',
76
80
  visualChange: '检测画面变化',
77
81
  };
78
82
  return labelMap[step.type] || step.type;
79
83
  }
80
84
 
81
85
  export function flowStepMeta(step: AppiumRecordedStep) {
86
+ if (step.type === 'stopwatch') return `${step.stopwatch?.name || '未命名'}${step.stopwatch?.timerId ? '' : '(未关联)'} · ${STOPWATCH_ACTIONS[step.stopwatch?.action || 'start']}`;
87
+ if (step.type === 'randomValue') return randomValueSummary(step.randomValue);
82
88
  if (step.type === 'imageCheck') return imageCheckSummary(step.imageCheck);
83
89
  if (step.type === 'extractVariable') return `${step.extractVariable?.attribute || 'text'} → ${step.extractVariable?.name || '未设置变量名'}`;
84
90
  if (step.type === 'loop') return `最多 ${step.loop?.maxIterations ?? '?'} 次 · ${step.loop?.exitWhen === 'exists' ? '元素出现时退出' : step.loop?.exitWhen === 'notExists' ? '元素消失时退出' : '固定次数'}${step.loop?.exitWhen !== 'never' ? ` ${step.selector?.value || ''}` : ''}`;
@@ -0,0 +1,60 @@
1
+ import { sensitiveVariableName, validateVariables } from './variables';
2
+
3
+ export type RandomValueConfig = {
4
+ name: string;
5
+ mode: 'text' | 'integer' | 'uuid';
6
+ text?: string;
7
+ sourceName?: string;
8
+ withoutReplacement?: boolean;
9
+ min?: number;
10
+ max?: number;
11
+ sensitive?: boolean;
12
+ };
13
+
14
+ export const MAX_RANDOM_TEXT_LENGTH = 200000;
15
+ export const MAX_RANDOM_FILE_BYTES = 1024 * 1024;
16
+ export const MAX_RANDOM_INTEGER_RANGE = 2 ** 48 - 1;
17
+ export const defaultRandomValue = (): RandomValueConfig => ({
18
+ name: 'RANDOM_VALUE', mode: 'text', text: '', min: 0, max: 9999, withoutReplacement: false,
19
+ });
20
+
21
+ export function randomTextCandidates(text: unknown): string[] {
22
+ if (typeof text !== 'string' || text.length > MAX_RANDOM_TEXT_LENGTH) throw new Error(`候选文本须为文本且不超过 ${MAX_RANDOM_TEXT_LENGTH} 字符`);
23
+ const candidates = text.replace(/^\uFEFF/, '').split(/\r?\n/u).map(line => line.trim())
24
+ .filter(line => line && !line.startsWith('#'));
25
+ if (!candidates.length) throw new Error('请填写候选文本或导入 TXT,每行一条');
26
+ if (candidates.length > 10000 || candidates.some(line => line.length > 20000)) throw new Error('候选最多 10000 条,每条不超过 20000 字符');
27
+ return candidates;
28
+ }
29
+
30
+ export function validateRandomValue(input: RandomValueConfig | undefined, options: { allowEmptySensitiveText?: boolean } = {}): RandomValueConfig {
31
+ if (!input || typeof input !== 'object') throw new Error('请配置获取随机值节点');
32
+ validateVariables([{ name: input.name, value: '', sensitive: input.sensitive }]);
33
+ if (input.withoutReplacement !== undefined && typeof input.withoutReplacement !== 'boolean') throw new Error('不重复抽取选项须为布尔值');
34
+ if (input.sensitive !== undefined && typeof input.sensitive !== 'boolean') throw new Error('敏感值选项须为布尔值');
35
+ // 敏感池导出时清空;允许导入为待填写模板,实际预览和执行仍须有候选内容。
36
+ if (input.mode === 'text') {
37
+ if (!(options.allowEmptySensitiveText && input.text === '' && (input.sensitive || sensitiveVariableName(input.name)))) randomTextCandidates(input.text);
38
+ }
39
+ else if (input.mode === 'integer') {
40
+ if (!Number.isSafeInteger(input.min) || !Number.isSafeInteger(input.max) || input.min! > input.max!) throw new Error('最小值和最大值须为安全整数,且最小值不能大于最大值');
41
+ const range = input.max! - input.min! + 1;
42
+ if (!Number.isSafeInteger(range) || range > MAX_RANDOM_INTEGER_RANGE) throw new Error(`整数范围跨度不能超过 ${MAX_RANDOM_INTEGER_RANGE}`);
43
+ } else if (input.mode !== 'uuid') throw new Error('随机值类型无效');
44
+ return input;
45
+ }
46
+
47
+ export function randomValueSummary(config: RandomValueConfig | undefined) {
48
+ if (!config) return '未配置随机值';
49
+ let source = '随机 ID(UUID)';
50
+ if (config.mode === 'integer') source = `随机整数 ${config.min ?? '?'}~${config.max ?? '?'}`;
51
+ if (config.mode === 'text') {
52
+ let count = 0;
53
+ try {
54
+ const candidates = randomTextCandidates(config.text);
55
+ count = config.withoutReplacement ? new Set(candidates).size : candidates.length;
56
+ } catch { /* 编辑中的空内容仍允许展示节点。 */ }
57
+ source = `${count} 条候选 · ${config.withoutReplacement ? '本次运行不重复' : '允许重复'}`;
58
+ }
59
+ return `${source} → ${config.name || '未设置变量名'}`;
60
+ }
@@ -0,0 +1,27 @@
1
+ import type { InjectionKey, Ref } from 'vue';
2
+
3
+ export type StopwatchConfig = { timerId: string; name: string; action: 'start' | 'mark' | 'end' };
4
+ export type StopwatchTarget = { timerId: string; name: string; label: string };
5
+ export const stopwatchTargetsKey: InjectionKey<Readonly<Ref<StopwatchTarget[]>>> = Symbol('stopwatch-targets');
6
+ export const STOPWATCH_ACTIONS = { start: '开始计时', mark: '记录时间点', end: '结束计时' };
7
+ export function defaultStopwatch(): StopwatchConfig {
8
+ return { timerId: crypto.randomUUID(), name: '计时器1', action: 'start' };
9
+ }
10
+ export function validateStopwatch(config?: StopwatchConfig) {
11
+ if (!config || typeof config.name !== 'string' || !config.name.trim() || config.name.length > 80
12
+ || !Object.prototype.hasOwnProperty.call(STOPWATCH_ACTIONS, config.action)) {
13
+ throw new Error('请填写计时器名称并选择有效操作');
14
+ }
15
+ if (typeof config.timerId !== 'string' || !config.timerId.trim() || config.timerId.length > 160) {
16
+ throw new Error('请通过关联计时器选择开始节点;计时器 ID 由系统生成');
17
+ }
18
+ return config;
19
+ }
20
+
21
+ // Copying a start creates a new timer; references copied with it follow the new ID.
22
+ export function remapStopwatchIds<T extends { stopwatch?: StopwatchConfig }>(steps: T[], ids?: Map<string, string>): T[] {
23
+ const replacements = ids ?? new Map(steps.filter(step => step.stopwatch?.action === 'start' && step.stopwatch.timerId)
24
+ .map(step => [step.stopwatch!.timerId, crypto.randomUUID()]));
25
+ return steps.map(step => step.stopwatch && replacements.has(step.stopwatch.timerId)
26
+ ? { ...step, stopwatch: { ...step.stopwatch, timerId: replacements.get(step.stopwatch.timerId)! } } : step);
27
+ }
@@ -1,6 +1,8 @@
1
1
  import type { AiInvalidResultBranch, AiObservationConfig } from './ai-recognition';
2
2
  import type { TestVariable, VariableExtraction, ScriptReturn } from './variables';
3
3
  import type { ImageCheckConfig } from './image-check';
4
+ import type { RandomValueConfig } from './random-value';
5
+ import type { StopwatchConfig } from './stopwatch';
4
6
 
5
7
  export type AppiumBounds = {
6
8
  left: number;
@@ -108,6 +110,8 @@ export type AppiumRecordedStep = {
108
110
  | 'runScript'
109
111
  | 'noop'
110
112
  | 'extractVariable'
113
+ | 'randomValue'
114
+ | 'stopwatch'
111
115
  | 'log'
112
116
  | 'visualChange';
113
117
  label: string;
@@ -119,6 +123,8 @@ export type AppiumRecordedStep = {
119
123
  value?: string;
120
124
  logPrefix?: string;
121
125
  extractVariable?: VariableExtraction;
126
+ randomValue?: RandomValueConfig;
127
+ stopwatch?: StopwatchConfig;
122
128
  parameters?: TestVariable[];
123
129
  returns?: ScriptReturn[];
124
130
  keyCode?: number;
@@ -0,0 +1,24 @@
1
+ import type { InjectionKey, Ref } from 'vue';
2
+ import { sensitiveVariableName, VARIABLE_NAME, type TestVariable } from './variables';
3
+
4
+ export type VariablePresetOption = { name: string; sensitive: boolean; scope: 'global' | 'private' };
5
+ export type VariablePresetContext = {
6
+ options: Readonly<Ref<VariablePresetOption[]>>;
7
+ loading: Readonly<Ref<boolean>>;
8
+ error: Readonly<Ref<string>>;
9
+ refresh: () => Promise<void>;
10
+ open: () => void;
11
+ };
12
+ export const variablePresetKey: InjectionKey<VariablePresetContext> = Symbol('variable-presets');
13
+
14
+ export function variablePresetOptions(globals: TestVariable[], privateVariables: TestVariable[]): VariablePresetOption[] {
15
+ const options = new Map<string, VariablePresetOption>();
16
+ for (const [scope, variables] of [['global', globals], ['private', privateVariables]] as const) {
17
+ for (const variable of variables) {
18
+ if (!VARIABLE_NAME.test(variable.name) || variable.name.length > 80) continue;
19
+ options.set(variable.name, { name: variable.name, scope,
20
+ sensitive: Boolean(variable.sensitive || options.get(variable.name)?.sensitive || sensitiveVariableName(variable.name)) });
21
+ }
22
+ }
23
+ return [...options.values()];
24
+ }
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { DataAnalysis, Grid, Monitor, Operation, InfoFilled, Setting } from '@element-plus/icons-vue';
2
+ import { DataAnalysis, Grid, Monitor, Operation, InfoFilled, Setting, VideoPlay } from '@element-plus/icons-vue';
3
3
  import type { MenuKey } from '../types';
4
4
 
5
5
  defineProps<{ activeMenu: MenuKey; collapsed: boolean }>();
@@ -12,14 +12,25 @@ defineEmits<{ select: [key: string] }>();
12
12
  <div class="layout-sidebar__logo" aria-hidden="true">A</div>
13
13
  <span v-if="!collapsed" class="layout-sidebar__brand" title="移动自动化控制台">移动自动化<span>控制台</span></span>
14
14
  </div>
15
- <el-menu :default-active="activeMenu" :default-openeds="['overview', 'midscene']" :collapse="collapsed"
15
+ <el-menu :default-active="activeMenu" :default-openeds="['overview', 'laboratory', 'midscene']" :collapse="collapsed"
16
16
  :collapse-transition="false" class="layout-menu" @select="$emit('select', $event)">
17
17
  <el-menu-item index="appium" aria-label="Appium"><el-icon><Monitor /></el-icon><template #title>Appium</template></el-menu-item>
18
- <el-menu-item index="artemis" aria-label="Artemis"><el-icon><Monitor /></el-icon><template #title>Artemis</template></el-menu-item>
19
- <el-sub-menu index="midscene" aria-label="Midscene">
20
- <template #title><el-icon><Operation /></el-icon><span>Midscene</span></template>
21
- <el-menu-item index="generator" aria-label="测试脚本生成"><el-icon><Operation /></el-icon><template #title>测试脚本生成</template></el-menu-item>
22
- <el-menu-item index="automation" aria-label="自动化测试"><el-icon><Monitor /></el-icon><template #title>自动化测试</template></el-menu-item>
18
+ <el-sub-menu index="laboratory" aria-label="实验室">
19
+ <template #title>
20
+ <el-icon>
21
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
22
+ <path d="M9 3h6M10 3v7L4.6 18.8A1.5 1.5 0 0 0 5.9 21h12.2a1.5 1.5 0 0 0 1.3-2.2L14 10V3M7 15h10" />
23
+ </svg>
24
+ </el-icon>
25
+ <span>实验室</span>
26
+ </template>
27
+ <el-menu-item index="artemis" aria-label="Artemis"><el-icon><Monitor /></el-icon><template #title>Artemis<span class="layout-menu__new">New</span></template></el-menu-item>
28
+ <el-sub-menu index="midscene" aria-label="Midscene">
29
+ <template #title><el-icon><Monitor /></el-icon><span>Midscene</span></template>
30
+ <el-menu-item index="generator" aria-label="测试脚本生成"><el-icon><Operation /></el-icon><template #title>测试脚本生成</template></el-menu-item>
31
+ <el-menu-item index="automation" aria-label="自动化测试"><el-icon><VideoPlay /></el-icon><template #title>自动化测试</template></el-menu-item>
32
+ <el-menu-item index="midscene-config" aria-label="Midscene参数配置"><el-icon><Setting /></el-icon><template #title><span class="layout-menu__label" title="参数配置">参数配置</span></template></el-menu-item>
33
+ </el-sub-menu>
23
34
  </el-sub-menu>
24
35
  <el-sub-menu index="overview" aria-label="概览">
25
36
  <template #title><el-icon><Grid /></el-icon><span>概览</span></template>
@@ -30,3 +41,22 @@ defineEmits<{ select: [key: string] }>();
30
41
  </el-menu>
31
42
  </aside>
32
43
  </template>
44
+
45
+ <style scoped>
46
+ .layout-menu__new {
47
+ margin-left: 6px;
48
+ color: var(--el-color-danger);
49
+ font-size: 11px;
50
+ font-weight: 600;
51
+ }
52
+
53
+ .layout-menu__label {
54
+ overflow: hidden;
55
+ text-overflow: ellipsis;
56
+ white-space: nowrap;
57
+ }
58
+
59
+ .layout-menu :deep(.el-sub-menu .el-sub-menu .el-menu-item) {
60
+ padding-left: 68px !important;
61
+ }
62
+ </style>
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { computed } from 'vue';
3
+ import { QuestionFilled } from '@element-plus/icons-vue';
3
4
  import { resolveAiDeduplication, type AiDeduplicationConfig } from '../../appium-recorder/ai-deduplication';
4
5
 
5
6
  const props = defineProps<{ modelValue?: AiDeduplicationConfig; disabled?: boolean }>();
@@ -14,6 +15,21 @@ function patch(value: Partial<AiDeduplicationConfig>) {
14
15
  <section class="ai-dedup-settings" aria-label="持续观察截图去重">
15
16
  <p class="ai-dedup-description">相似截图在本地过滤后再提交模型,减少重复图片和识别开销。</p>
16
17
  <el-form-item label="去重方式">
18
+ <template #label>
19
+ <span class="ai-dedup-label">去重方式
20
+ <el-tooltip placement="top" :show-after="200">
21
+ <template #content>
22
+ <div class="ai-dedup-explanation">
23
+ <p><strong>不去重:</strong>全部采样截图交给模型,保留信息最多,图片输入消耗也最高。</p>
24
+ <p><strong>pixelmatch:</strong>比较原图的像素颜色和变化面积,适合同设备的静态画面,对细节变化敏感。</p>
25
+ <p><strong>OpenCV(SSIM):</strong>缩小图片后比较彩色画面的局部亮度、对比度和结构,更侧重整体相似性;可能忽略小文字,不能识别语义,也不自动对齐位移。</p>
26
+ <p>仅对持续观察生效。首帧始终保留,后续与上一张保留的截图比较;两种去重均在本地完成,不调用模型。切换方式会保留各自参数,用于后续回放和识别测试。</p>
27
+ </div>
28
+ </template>
29
+ <el-button class="ai-dedup-help-button" text :icon="QuestionFilled" aria-label="去重方式说明" @click.prevent />
30
+ </el-tooltip>
31
+ </span>
32
+ </template>
17
33
  <el-radio-group :model-value="settings.method" :disabled="disabled" @update:model-value="patch({ method: $event as AiDeduplicationConfig['method'] })">
18
34
  <el-radio-button value="none">不去重</el-radio-button>
19
35
  <el-radio-button value="pixelmatch">pixelmatch(默认)</el-radio-button>
@@ -40,20 +56,15 @@ function patch(value: Partial<AiDeduplicationConfig>) {
40
56
  <p class="ai-dedup-help">默认 512。仅缩小本地比较图像;越大越能保留细节,也更耗本地计算资源,不改变提交模型的图片尺寸。</p>
41
57
  </el-form-item>
42
58
  </template>
43
- <div class="ai-dedup-explanation">
44
- <h4>去重方式说明</h4>
45
- <p><strong>不去重:</strong>全部采样截图交给模型,保留信息最多,图片输入消耗也最高。</p>
46
- <p><strong>pixelmatch:</strong>比较原图的像素颜色和变化面积,适合同设备的静态画面,对细节变化敏感。</p>
47
- <p><strong>OpenCV(SSIM):</strong>缩小图片后比较彩色画面的局部亮度、对比度和结构,更侧重整体相似性;可能忽略小文字,不能识别语义,也不自动对齐位移。</p>
48
- <p>仅对持续观察生效。首帧始终保留,后续与上一张保留的截图比较;两种去重均在本地完成,不调用模型。切换方式会保留各自参数,用于后续回放和识别测试。</p>
49
- </div>
50
59
  </section>
51
60
  </template>
52
61
 
53
62
  <style scoped>
54
63
  .ai-dedup-description { margin: 0 0 18px; color: var(--el-text-color-secondary); font-size: 12px; line-height: 1.6; }
55
64
  .ai-dedup-help { width: 100%; margin: 6px 0 0; color: var(--el-text-color-secondary); font-size: 12px; line-height: 1.6; }
56
- .ai-dedup-explanation { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--ui-border); color: var(--el-text-color-regular); font-size: 13px; line-height: 1.7; }
57
- .ai-dedup-explanation h4 { margin: 0 0 8px; color: var(--el-text-color-primary); font-size: 13px; }
58
- .ai-dedup-explanation p { margin: 6px 0; }
65
+ .ai-dedup-label { display: inline-flex; align-items: center; gap: 4px; }
66
+ .ai-dedup-help-button { width: 28px; height: 28px; padding: 0; font-size: 16px; }
67
+ .ai-dedup-explanation { max-width: min(360px, calc(100vw - 40px)); line-height: 1.6; overflow-wrap: anywhere; }
68
+ .ai-dedup-explanation p { margin: 0 0 8px; }
69
+ .ai-dedup-explanation p:last-child { margin-bottom: 0; }
59
70
  </style>
@@ -24,10 +24,12 @@ const activeSection = shallowRef<'basic' | 'models'>('basic');
24
24
  <template>
25
25
  <div class="appium-config-stack">
26
26
  <header class="appium-config-toolbar">
27
- <el-radio-group v-model="activeSection" aria-label="Appium配置分类">
28
- <el-radio-button value="basic">基础配置</el-radio-button>
29
- <el-radio-button value="models">模型配置</el-radio-button>
30
- </el-radio-group>
27
+ <div class="appium-config-categories">
28
+ <el-radio-group v-model="activeSection" aria-label="Appium配置分类">
29
+ <el-radio value="basic">基础配置</el-radio>
30
+ <el-radio value="models">模型配置</el-radio>
31
+ </el-radio-group>
32
+ </div>
31
33
  <div v-if="saveStatus || saveFailed" class="appium-config-save-state">
32
34
  <span v-if="saveStatus" class="config-save-status" role="status">{{ saveStatus }}</span>
33
35
  <el-button v-if="saveFailed" link type="primary" @click="$emit('retrySave')">重试保存</el-button>
@@ -96,7 +98,10 @@ const activeSection = shallowRef<'basic' | 'models'>('basic');
96
98
  <style scoped>
97
99
  .config-save-status { font-size: 12px; font-weight: 400; color: var(--el-text-color-secondary); }
98
100
  .appium-config-stack { display: grid; gap: 28px; }
99
- .appium-config-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
101
+ .appium-config-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding-top: 16px; border-top: 1px solid var(--ui-border); }
102
+ .appium-config-categories { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 24px; }
103
+ .appium-config-categories :deep(.el-radio-group) { gap: 24px; }
104
+ .appium-config-categories :deep(.el-radio) { height: 40px; margin-right: 0; }
100
105
  .appium-config-save-state { display: flex; align-items: center; gap: 8px; }
101
106
  .appium-config-section { display: grid; gap: 14px; min-width: 0; }
102
107
  .appium-section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 0 4px; }