优化
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
"glb2": 3
|
||||
},
|
||||
"image_operation": {
|
||||
"compress": 8,
|
||||
"compress": 9,
|
||||
"resize": 1
|
||||
}
|
||||
}
|
||||
@ -15,13 +15,22 @@ const OPERATIONS = [
|
||||
|
||||
const run = async () => {
|
||||
try {
|
||||
while (true) {
|
||||
// 强制清理并重新初始化键盘
|
||||
stopKeypress();
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
const steps = getSteps();
|
||||
const ui = createStepUI({ title, getSteps: () => steps });
|
||||
const ui = createStepUI({
|
||||
title,
|
||||
getSteps: () => steps,
|
||||
validate: (results) => {
|
||||
// 验证是否有文件选择且至少有一个操作未跳过
|
||||
const files = results[0] || [];
|
||||
const hasOperation = OPERATIONS.some(op => results[op.stepIndex] !== "skip");
|
||||
return files.length > 0 && hasOperation;
|
||||
}
|
||||
});
|
||||
|
||||
const result = await ui.runInteractive();
|
||||
|
||||
if (!result) {
|
||||
@ -34,12 +43,6 @@ const run = async () => {
|
||||
|
||||
stopKeypress();
|
||||
|
||||
// 如果没有选择文件或所有操作都跳过,重新开始
|
||||
if (!selectedOp || !files.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 有效的选择,继续处理
|
||||
const params = buildProcessParams(selectedOp.id, result.results[selectedOp.stepIndex]);
|
||||
|
||||
ui.showSummary([
|
||||
@ -83,7 +86,6 @@ const run = async () => {
|
||||
await waitForKey(color.dim("按 Esc 返回"), key => key?.name === "escape" || (key?.ctrl && key?.name === "c"));
|
||||
stopKeypress();
|
||||
return "back";
|
||||
}
|
||||
} catch (err) {
|
||||
stopKeypress();
|
||||
console.error(color.red("发生错误:"), err);
|
||||
|
||||
@ -3,7 +3,7 @@ import { initKeypress, onKey, stopKeypress } from "../keyboard.js";
|
||||
import { clearScreen } from "./terminal.js";
|
||||
|
||||
export function createStepUI(options) {
|
||||
const { title, getSteps, onStepChange } = options;
|
||||
const { title, getSteps, onStepChange, validate } = options;
|
||||
|
||||
let steps = [];
|
||||
let results = [];
|
||||
@ -171,6 +171,11 @@ export function createStepUI(options) {
|
||||
}
|
||||
break;
|
||||
case "tab":
|
||||
// 如果提供了验证函数,先验证
|
||||
if (validate && !validate(results)) {
|
||||
// 验证失败,忽略此次提交
|
||||
break;
|
||||
}
|
||||
resolved = true;
|
||||
stopKeypress();
|
||||
setImmediate(() => resolve({ steps, results }));
|
||||
|
||||
Reference in New Issue
Block a user