Skip to content

Commit

Permalink
fix(core): 优化搜索结果的显示BUG,已搜到答案的题目显示未匹配到正确答案的BUG,以及答题进度不一致的显示BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
ennnncy committed Mar 27, 2024
1 parent 3cf9968 commit 2fd9a72
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 40 deletions.
5 changes: 0 additions & 5 deletions packages/core/src/core/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export class OCSWorker<E extends RawElements = RawElements> extends CommonEventE
isClose = false;
isStop = false;
totalQuestionCount = 0;
requestFinished = 0;
resolverIndex = 0;

constructor(opts: WorkOptions<E>) {
super();
Expand All @@ -41,9 +39,6 @@ export class OCSWorker<E extends RawElements = RawElements> extends CommonEventE

/** 启动答题器 */
async doWork(options?: { enable_debug?: boolean }) {
this.requestFinished = 0;
this.resolverIndex = 0;

this.emit('start');
this.isRunning = true;

Expand Down
44 changes: 26 additions & 18 deletions packages/scripts/src/projects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,10 +729,10 @@ export const CommonProject = Project.create({
totalQuestionCount: {
defaultValue: 0
},
requestFinished: {
requestedCount: {
defaultValue: 0
},
resolverIndex: {
resolvedCount: {
defaultValue: 0
},
currentResultIndex: {
Expand All @@ -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;
},
/**
* 清空搜索结果
Expand Down Expand Up @@ -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'),
'表示已搜索已答题 '
]);

Expand All @@ -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 });
};
})
],
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/scripts/src/projects/cx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/src/projects/icourse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down
12 changes: 6 additions & 6 deletions packages/scripts/src/projects/icve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -614,8 +614,8 @@ function work({ answererWrappers, period, thread, answerSeparators, answerMatchM
}
CommonProject.scripts.workResults.methods.updateWorkState({
totalQuestionCount,
requestFinished,
resolverIndex
requestedCount,
resolvedCount
});
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/scripts/src/projects/zhs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
Expand All @@ -1026,8 +1026,8 @@ function xnkWork({ answererWrappers, period, thread, answerSeparators, answerMat
}
CommonProject.scripts.workResults.methods.updateWorkState({
totalQuestionCount,
requestFinished,
resolverIndex
requestedCount,
resolvedCount
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/src/projects/zjy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down

0 comments on commit 2fd9a72

Please sign in to comment.