Skip to content

Commit

Permalink
fix(cx): 兼容cx选项获取不到,以及设置保存bug
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Mar 25, 2022
1 parent b25ef93 commit 5a2e672
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
13 changes: 10 additions & 3 deletions packages/scripts/src/browser/core/create.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ export function createSettingPanel(...settingItems: (SettingSelect | SettingInpu
: type === "number"
? input.valueAsNumber
: type === "object"
? JSON.parse(input.value)
? input.value
? JSON.parse(input.value)
: {}
: type === "array"
? input.value
? JSON.parse(input.value)
: []
: parseFloat(input.value) || input.value;
res.push([key.toString(), value]);
setItem(key.toString(), value);
Expand Down Expand Up @@ -175,7 +181,8 @@ export interface SettingInput extends SettingItem {
| "week"

/** 自定义类型 */
| "object";
| "object"
| "array";
}

/**
Expand Down Expand Up @@ -318,7 +325,7 @@ export function createWorkerSetting(
{
label: "题库配置",
ref: "setting.answererWrappers",
type: "object",
type: "array",
icons: [
{
type: "bi bi-question-circle",
Expand Down
2 changes: 2 additions & 0 deletions packages/scripts/src/browser/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import interact from "interactjs";
import { findBestMatch, Rating } from "string-similarity";
import { RawElements, SearchedElements } from "./worker/interface";
import { h } from "vue";
import { logger } from "../../logger";

export async function sleep(period: number): Promise<void> {
return new Promise((resolve) => {
Expand Down Expand Up @@ -155,6 +156,7 @@ export function domSearchAll<E extends RawElements>(
*
*/
export function answerSimilar(answers: string[], options: string[]): Rating[] {
logger("debug", "结果匹配", { answers, options });
return options.map((option) => findBestMatch(option, answers).bestMatch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function defaultQuestionResolve<E>(
/** 填空题处理器 */
completion: function (results, options, handler) {
for (const answers of results.map((res) => res.answers.map((ans) => ans.answer))) {
if (answers.length === options.length) {
if (answers.length !== 0 && answers.length === options.length) {
options.forEach((el, i) => {
handler("completion", answers[i], el, ctx);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/scripts/src/browser/cx/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ async function chapterTestTask(setting: ScriptSettings["cx"]["work"], frame: HTM
root: TiMu,
elements: {
title: ".Zy_TItle .clearfix",
options: ".Zy_ulTop li",
/** 兼容各种选项 */
options: "ul li",
type: 'input[id^="answertype"]',
},
/** 默认搜题方法构造器 */
Expand Down

0 comments on commit 5a2e672

Please sign in to comment.