Skip to content

Commit

Permalink
feat(core): 优化答题uploadHandler API,新增 commonWork.options.onWorkerCreat…
Browse files Browse the repository at this point in the history
…ed 选项
  • Loading branch information
enncy committed Nov 29, 2023
1 parent f79fb08 commit c4154df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/core/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class OCSWorker<E extends RawElements = RawElements> extends CommonEventE
}

/** 答题结果处理器 */
async uploadHandler(options: {
uploadHandler(options: {
// doWork 的返回值结果
results: WorkResult<E>[];
// 提交类型
Expand All @@ -309,9 +309,9 @@ export class OCSWorker<E extends RawElements = RawElements> extends CommonEventE
const rate = results.length === 0 ? 0 : (finished / results.length) * 100;
if (type !== 'nomove') {
if (type === 'force') {
await callback(rate, true);
return callback(rate, true);
} else {
await callback(rate, type === 'save' ? false : rate >= parseFloat(type.toString()));
return callback(rate, type === 'save' ? false : rate >= parseFloat(type.toString()));
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/scripts/src/utils/work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function commonWork(
workerProvider: (opts: CommonWorkOptions) => OCSWorker<any> | undefined;
beforeRunning?: () => void | Promise<void>;
onRestart?: () => void | Promise<void>;
onWorkerCreated?: (worker: OCSWorker<any>) => void | Promise<void>;
}
) {
// 置顶当前脚本
Expand Down Expand Up @@ -101,6 +102,10 @@ export function commonWork(
await options.beforeRunning?.();
worker = options.workerProvider(workOptions);

if (worker) {
options.onWorkerCreated?.(worker);
}

const { container, controlBtn } = createControls();
// 更新状态
script.panel?.body?.replaceChildren(container, workResultPanel());
Expand Down

0 comments on commit c4154df

Please sign in to comment.