feat: 多项填空
This commit is contained in:
18995
package-lock.json
generated
18995
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -333,7 +333,6 @@
|
|||||||
<!-- 多项填空 -->
|
<!-- 多项填空 -->
|
||||||
<q-input-blanks
|
<q-input-blanks
|
||||||
v-else-if="question.question_type === 27"
|
v-else-if="question.question_type === 27"
|
||||||
:list="question.list"
|
|
||||||
:config="question.config"
|
:config="question.config"
|
||||||
v-model:error="question.error"
|
v-model:error="question.error"
|
||||||
v-model:answer="question.answer"
|
v-model:answer="question.answer"
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div class="blanks">
|
||||||
<div v-html="config.text_content"></div>
|
<template
|
||||||
|
v-for="(item, index) in getMultiBlankLeftTexts(config.text_content)"
|
||||||
|
:key="index"
|
||||||
|
>
|
||||||
|
<!-- 文字 -->
|
||||||
|
<div v-if="typeof item === 'string'" class="text" v-html="item"></div>
|
||||||
|
<!-- 填空 -->
|
||||||
|
<input v-else class="input" :style="`width: ${item.length * 20}px`" />
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -9,11 +17,6 @@ import { defineComponent, ref, watch } from "vue";
|
|||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
// 列表
|
|
||||||
list: {
|
|
||||||
type: Array,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
// 配置
|
// 配置
|
||||||
config: {
|
config: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -45,9 +48,36 @@ export default defineComponent({
|
|||||||
function init() {}
|
function init() {}
|
||||||
init();
|
init();
|
||||||
|
|
||||||
return {};
|
// 获取多项填空左边的文本
|
||||||
|
function getMultiBlankLeftTexts(text) {
|
||||||
|
// text = text.replace(/(<([^>]+)>)/gi, ""); // 去除HTML标签
|
||||||
|
let index = -1;
|
||||||
|
const regex = /__+/g; // 匹配两个或以上的下划线
|
||||||
|
return text
|
||||||
|
.replace(regex, (match) => `_____{"length":${match.length}}___`)
|
||||||
|
.split("___")
|
||||||
|
.map((item) => {
|
||||||
|
if (item.substr(0, 2) === "__") {
|
||||||
|
index += 1;
|
||||||
|
return { index, ...JSON.parse(item.substr(2)) };
|
||||||
|
} else {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { getMultiBlankLeftTexts };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped>
|
||||||
|
.blanks {
|
||||||
|
.text {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user