feat: 脚本录制功能完善
This commit is contained in:
@@ -68,6 +68,7 @@ export enum IPC_EVENTS {
|
||||
SCRIPT_RUN = 'script:run',
|
||||
SCRIPT_RECORD_START = 'script:record-start',
|
||||
SCRIPT_RECORD_STOP = 'script:record-stop',
|
||||
SCRIPT_CODEGEN = 'script:codegen',
|
||||
|
||||
// 更新
|
||||
UPDATE_CHECK = 'update:check',
|
||||
|
||||
@@ -15,4 +15,6 @@ export const scriptApi = {
|
||||
window.api.scriptApi.startRecording(url),
|
||||
stopRecording: (): Promise<{ success: boolean; code?: string; error?: string }> =>
|
||||
window.api.scriptApi.stopRecording(),
|
||||
codegen: (id: string, url?: string): Promise<{ success: boolean; code?: string; error?: string }> =>
|
||||
window.api.scriptApi.codegen(id, url),
|
||||
};
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
:loading="saving"
|
||||
class="!rounded-full !px-6 !h-[42px] !text-[13px] !font-semibold"
|
||||
>
|
||||
{{ saving ? t('common.saving', 'Saving...') : t('script.dialog.createTitle') }}
|
||||
{{ saving ? t('common.saving', 'Saving...') : t('script.dialog.createAndRecord', '创建并录制') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -124,7 +124,6 @@ const form = ref({
|
||||
name: '',
|
||||
description: '',
|
||||
channel: '',
|
||||
enabled: true,
|
||||
});
|
||||
|
||||
function resetForm() {
|
||||
@@ -132,7 +131,6 @@ function resetForm() {
|
||||
name: '',
|
||||
description: '',
|
||||
channel: '',
|
||||
enabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -149,7 +147,7 @@ function handleSubmit() {
|
||||
description: form.value.description.trim(),
|
||||
code: defaultScriptTemplate,
|
||||
channel: form.value.channel,
|
||||
enabled: form.value.enabled,
|
||||
enabled: true,
|
||||
};
|
||||
emit('save', payload);
|
||||
visible.value = false;
|
||||
|
||||
@@ -193,7 +193,7 @@ function openEditDialog(script: AutomationScript) {
|
||||
}
|
||||
|
||||
function handleCreateDialogClose() {
|
||||
editingScript.value = undefined;
|
||||
// editingScript lifecycle is handled by handleSave / handleEditDialogClose
|
||||
}
|
||||
|
||||
function handleEditDialogClose() {
|
||||
@@ -207,8 +207,17 @@ async function handleSave(input: ScriptSaveInput) {
|
||||
await store.saveScript(input);
|
||||
ElMessage.success(t('script.toast.updated'));
|
||||
} else {
|
||||
await store.saveScript(input);
|
||||
const result = await store.saveScript(input);
|
||||
ElMessage.success(t('script.toast.created'));
|
||||
ElMessage.info(t('script.toast.codegenStarting', '正在启动 Playwright codegen 录制,请在新窗口中操作,完成后关闭窗口即可自动保存代码'));
|
||||
const codegenResult = await store.codegen(result.id, input.channel || 'about:blank');
|
||||
if (codegenResult.success) {
|
||||
ElMessage.success(t('script.toast.codegenFinished', '录制完成,代码已保存'));
|
||||
editingScript.value = { ...result, code: codegenResult.code || '' };
|
||||
editDialogVisible.value = true;
|
||||
} else {
|
||||
ElMessage.error(codegenResult.error || t('script.toast.codegenFailed', '录制失败'));
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
|
||||
@@ -140,6 +140,20 @@ export const useScriptStore = defineStore('script', () => {
|
||||
recordingStatus.value = 'idle';
|
||||
};
|
||||
|
||||
const codegen = async (id: string, url?: string) => {
|
||||
try {
|
||||
const result = await scriptApi.codegen(id, url);
|
||||
if (!result.success) {
|
||||
error.value = result.error || 'Codegen failed';
|
||||
}
|
||||
return result;
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
error.value = msg;
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
scripts,
|
||||
loading,
|
||||
@@ -157,5 +171,6 @@ export const useScriptStore = defineStore('script', () => {
|
||||
startRecording,
|
||||
stopRecording,
|
||||
resetRecording,
|
||||
codegen,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user