diff --git a/packages/core/src/core/worker/worker.ts b/packages/core/src/core/worker/worker.ts index d4255111..cb5f7769 100644 --- a/packages/core/src/core/worker/worker.ts +++ b/packages/core/src/core/worker/worker.ts @@ -31,8 +31,6 @@ export class OCSWorker extends CommonEventE isClose = false; isStop = false; totalQuestionCount = 0; - requestFinished = 0; - resolverIndex = 0; constructor(opts: WorkOptions) { super(); @@ -41,9 +39,6 @@ export class OCSWorker extends CommonEventE /** 启动答题器 */ async doWork(options?: { enable_debug?: boolean }) { - this.requestFinished = 0; - this.resolverIndex = 0; - this.emit('start'); this.isRunning = true; diff --git a/packages/scripts/src/projects/common.ts b/packages/scripts/src/projects/common.ts index b7aa0fda..a3a2022f 100644 --- a/packages/scripts/src/projects/common.ts +++ b/packages/scripts/src/projects/common.ts @@ -729,10 +729,10 @@ export const CommonProject = Project.create({ totalQuestionCount: { defaultValue: 0 }, - requestFinished: { + requestedCount: { defaultValue: 0 }, - resolverIndex: { + resolvedCount: { defaultValue: 0 }, currentResultIndex: { @@ -744,21 +744,29 @@ export const CommonProject = Project.create({ }, methods() { return { + /** + * 从搜索结果中计算状态,并更新 + */ + updateWorkStateByResults: (results: { requested: boolean; resolved: boolean }[]) => { + this.cfg.totalQuestionCount = results.length; + this.cfg.requestedCount = results.filter((result) => result.requested).length; + this.cfg.resolvedCount = results.filter((result) => result.resolved).length; + }, /** * 更新状态 */ - updateWorkState: (state: { totalQuestionCount: number; requestFinished: number; resolverIndex: number }) => { + updateWorkState: (state: { totalQuestionCount: number; requestedCount: number; resolvedCount: number }) => { this.cfg.totalQuestionCount = state.totalQuestionCount; - this.cfg.requestFinished = state.requestFinished; - this.cfg.resolverIndex = state.resolverIndex; + this.cfg.requestedCount = state.requestedCount; + this.cfg.resolvedCount = state.resolvedCount; }, /** * 刷新状态 */ refreshState: () => { this.cfg.totalQuestionCount = 0; - this.cfg.requestFinished = 0; - this.cfg.resolverIndex = 0; + this.cfg.requestedCount = 0; + this.cfg.resolvedCount = 0; }, /** * 清空搜索结果 @@ -974,13 +982,13 @@ export const CommonProject = Project.create({ }); const tip = el('div', [ - el('div', { className: 'search-infos-num requesting' }, 'n'), - '表示搜索中 ', + el('div', { className: 'search-infos-num' }, '1'), + '表示等待处理中', el('br'), - el('div', { className: 'search-infos-num resolving' }, 'n'), - '表示已搜索但未开始答题 ', + el('div', { className: 'search-infos-num requested' }, '1'), + '表示已完成搜索 ', el('br'), - el('div', { className: 'search-infos-num' }, 'n'), + el('div', { className: 'search-infos-num finish' }, '1'), '表示已搜索已答题 ' ]); @@ -992,12 +1000,12 @@ export const CommonProject = Project.create({ [ $creator.space( [ - el('span', `当前搜题: ${this.cfg.requestFinished + 1}/${this.cfg.totalQuestionCount}`), - el('span', `当前答题: ${this.cfg.resolverIndex + 1}/${this.cfg.totalQuestionCount}`), + el('span', `已搜题: ${this.cfg.requestedCount}/${this.cfg.totalQuestionCount}`), + el('span', `已答题: ${this.cfg.resolvedCount}/${this.cfg.totalQuestionCount}`), el('a', '提示', (btn) => { btn.style.cursor = 'pointer'; btn.onclick = () => { - $modal('confirm', { content: tip }); + $modal('confirm', { content: tip, footer: undefined }); }; }) ], @@ -1045,7 +1053,7 @@ export const CommonProject = Project.create({ } else { error.innerText = '此题未完成, 可能是没有匹配的选项。'; return el('div', [ - ...(result.finish ? [] : [result.requested === false ? '正在等待答题中,请稍等。' : error]), + ...(result.finish ? [] : [result.resolved === false ? '正在等待答题中,请稍等。' : error]), el('search-infos-element', { infos: result.searchInfos, question: result.question @@ -1060,8 +1068,8 @@ export const CommonProject = Project.create({ render(); this.onConfigChange('type', render); - this.onConfigChange('requestFinished', render); - this.onConfigChange('resolverIndex', render); + this.onConfigChange('requestedCount', render); + this.onConfigChange('resolvedCount', render); $store.addChangeListener(TAB_WORK_RESULTS_KEY, render); return container; diff --git a/packages/scripts/src/projects/cx.ts b/packages/scripts/src/projects/cx.ts index 1f90df09..73cc3671 100644 --- a/packages/scripts/src/projects/cx.ts +++ b/packages/scripts/src/projects/cx.ts @@ -718,7 +718,7 @@ function workOrExam( /** 完成答题后 */ onResultsUpdate(current, _, res) { CommonProject.scripts.workResults.methods.setResults(simplifyWorkResult(res, workOrExamQuestionTitleTransform)); - CommonProject.scripts.workResults.methods.updateWorkState(worker); + CommonProject.scripts.workResults.methods.updateWorkStateByResults(res); if (current.result?.finish) { CommonProject.scripts.apps.methods.addQuestionCacheFromWorkResult( simplifyWorkResult([current], workOrExamQuestionTitleTransform) @@ -1598,7 +1598,7 @@ async function chapterTestTask( simplifyWorkResult([curr], chapterTestTaskQuestionTitleTransform) ); } - CommonProject.scripts.workResults.methods.updateWorkState(worker); + CommonProject.scripts.workResults.methods.updateWorkStateByResults(res); // 没有完成时随机作答 if (curr.result?.finish === false && curr.resolved === true) { diff --git a/packages/scripts/src/projects/icourse.ts b/packages/scripts/src/projects/icourse.ts index 851926aa..ac261aec 100644 --- a/packages/scripts/src/projects/icourse.ts +++ b/packages/scripts/src/projects/icourse.ts @@ -483,7 +483,7 @@ function workAndExam( if (curr.result?.finish) { CommonProject.scripts.apps.methods.addQuestionCacheFromWorkResult(simplifyWorkResult([curr], titleTransform)); } - CommonProject.scripts.workResults.methods.updateWorkState(worker); + CommonProject.scripts.workResults.methods.updateWorkStateByResults(res); } }); diff --git a/packages/scripts/src/projects/icve.ts b/packages/scripts/src/projects/icve.ts index 2c0a9db0..a86f3fd1 100644 --- a/packages/scripts/src/projects/icve.ts +++ b/packages/scripts/src/projects/icve.ts @@ -483,8 +483,8 @@ function work({ answererWrappers, period, thread, answerSeparators, answerMatchM const workResults: SimplifyWorkResult[] = []; let totalQuestionCount = 0; - let requestFinished = 0; - let resolverIndex = 0; + let requestedCount = 0; + let resolvedCount = 0; function getType(options: HTMLElement[]) { const radio_len = options @@ -604,8 +604,8 @@ function work({ answererWrappers, period, thread, answerSeparators, answerMatchM workResults.push(...simplifyWorkResult([currentResult], titleTransform)); CommonProject.scripts.workResults.methods.setResults(workResults); totalQuestionCount++; - requestFinished++; - resolverIndex++; + requestedCount++; + resolvedCount++; if (currentResult.result?.finish) { CommonProject.scripts.apps.methods.addQuestionCacheFromWorkResult( @@ -614,8 +614,8 @@ function work({ answererWrappers, period, thread, answerSeparators, answerMatchM } CommonProject.scripts.workResults.methods.updateWorkState({ totalQuestionCount, - requestFinished, - resolverIndex + requestedCount, + resolvedCount }); } } diff --git a/packages/scripts/src/projects/zhs.ts b/packages/scripts/src/projects/zhs.ts index 5e0eba59..ec88438d 100644 --- a/packages/scripts/src/projects/zhs.ts +++ b/packages/scripts/src/projects/zhs.ts @@ -892,7 +892,7 @@ function gxkWorkAndExam( if (curr.result?.finish) { CommonProject.scripts.apps.methods.addQuestionCacheFromWorkResult(simplifyWorkResult([curr], titleTransform)); } - CommonProject.scripts.workResults.methods.updateWorkState(worker); + CommonProject.scripts.workResults.methods.updateWorkStateByResults(res); } }); @@ -959,8 +959,8 @@ function xnkWork({ answererWrappers, period, thread, answerSeparators, answerMat const workResults: SimplifyWorkResult[] = []; let totalQuestionCount = 0; - let requestFinished = 0; - let resolverIndex = 0; + let requestedCount = 0; + let resolvedCount = 0; const worker = new OCSWorker({ root: '.questionBox', @@ -1015,8 +1015,8 @@ function xnkWork({ answererWrappers, period, thread, answerSeparators, answerMat workResults.push(...simplifyWorkResult([current], titleTransform)); CommonProject.scripts.workResults.methods.setResults(workResults); totalQuestionCount++; - requestFinished++; - resolverIndex++; + requestedCount++; + resolvedCount++; } if (current.result?.finish) { @@ -1026,8 +1026,8 @@ function xnkWork({ answererWrappers, period, thread, answerSeparators, answerMat } CommonProject.scripts.workResults.methods.updateWorkState({ totalQuestionCount, - requestFinished, - resolverIndex + requestedCount, + resolvedCount }); } }); diff --git a/packages/scripts/src/projects/zjy.ts b/packages/scripts/src/projects/zjy.ts index 09bc9fab..3e8d40c8 100644 --- a/packages/scripts/src/projects/zjy.ts +++ b/packages/scripts/src/projects/zjy.ts @@ -381,7 +381,7 @@ function workOrExam( if (curr.result?.finish) { CommonProject.scripts.apps.methods.addQuestionCacheFromWorkResult(simplifyWorkResult([curr], titleTransform)); } - CommonProject.scripts.workResults.methods.updateWorkState(worker); + CommonProject.scripts.workResults.methods.updateWorkStateByResults(res); } });