From 2d765b5c63804fe101e8af29d1d43489745bc981 Mon Sep 17 00:00:00 2001 From: Caroline <2070136618@qq.com> Date: Tue, 2 Jul 2024 16:03:03 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E6=8A=BD=E5=8F=9610?= =?UTF-8?q?=E4=B8=AA=E7=94=9F=E8=AF=8D=EF=BC=8C=E5=B9=B6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/js/word_operation.js | 56 +++++++++++++++++++++++++++++++++ app/templates/userpage_get.html | 4 +++ 2 files changed, 60 insertions(+) diff --git a/app/static/js/word_operation.js b/app/static/js/word_operation.js index dcf38ff..7f2cdd2 100644 --- a/app/static/js/word_operation.js +++ b/app/static/js/word_operation.js @@ -102,9 +102,19 @@ function wordTemplate(word) { 不熟悉 删除 朗读 +
`; } + +/** + * 使用模板将传入的单词转换为相应的HTML字符串 +*/ +function wordTemplate(word) { + // 这个模板应当与 templates/userpage_get.html 中的...
保持一致 + return ``; +} + /** * 删除某一词频元素 * 此处word为词频元素对应的单词 @@ -171,4 +181,50 @@ function compareWord(first, second) { return first.word < second.word ? -1 : 1; } return 0; +} + +/** + * + * + */ +function random_select_word(word) { + // 获取所有带有 "word-container" 类的标签 + const container = document.querySelector('.word-container'); + + console.log("container",container) + + // 获取所有带有"new-word"类的
标签 + let wordContainers = container.querySelectorAll('.new-word'); + + // 检查是否存在带有"new-word"类的
标签 + if (wordContainers.length > 0) { + // 将NodeList转换为数组 + let wordContainersArray = [...wordContainers]; + + // 随机打乱数组 + for (let i = wordContainersArray.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [wordContainersArray[i], wordContainersArray[j]] = [wordContainersArray[j], wordContainersArray[i]]; + } + + // 选取前10个元素 + let selectedWordContainers = wordContainersArray.slice(0, 10); + + // 对选取的
标签进行处理 +// selectedWordContainers.forEach(container => { +// console.log(container.outerHTML); +// }); + // 置顶 +// selectedWordContainers.forEach(p => { +// container.insertBefore(p, container.firstChild); +// }); + + wordContainersArray.forEach((p, index) => { + if (index < 10) { + p.style.display = 'block'; + } else { + p.style.display = 'none'; + } + }) + } } \ No newline at end of file diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index e5c8d95..6df5c02 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -139,11 +139,15 @@ {% if d_len > 0 %}
标签进行处理 -// selectedWordContainers.forEach(container => { -// console.log(container.outerHTML); -// }); - // 置顶 -// selectedWordContainers.forEach(p => { -// container.insertBefore(p, container.firstChild); -// }); wordContainersArray.forEach((p, index) => { if (index < 10) { -- 2.17.1 From eb2051ca3f529d8c6164333fa53c4cb4eb15f4ac Mon Sep 17 00:00:00 2001 From: Caroline <2070136618@qq.com> Date: Wed, 3 Jul 2024 09:45:44 +0800 Subject: [PATCH 3/5] Fix bug 570 --- app/static/js/word_operation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/static/js/word_operation.js b/app/static/js/word_operation.js index 45032b9..b3c8bd4 100644 --- a/app/static/js/word_operation.js +++ b/app/static/js/word_operation.js @@ -201,7 +201,7 @@ function random_select_word(word) { // 将NodeList转换为数组 let wordContainersArray = [...wordContainers]; - // 随机打乱数组 + // 随机打乱数组,乱序 for (let i = wordContainersArray.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [wordContainersArray[i], wordContainersArray[j]] = [wordContainersArray[j], wordContainersArray[i]]; -- 2.17.1 From d8263d17e0bb4c2ef507f48232311b602514cf25 Mon Sep 17 00:00:00 2001 From: Caroline <2070136618@qq.com> Date: Thu, 4 Jul 2024 19:50:34 +0800 Subject: [PATCH 4/5] Fix bug 570 --- app/static/js/word_operation.js | 4 +++- app/templates/userpage_get.html | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/static/js/word_operation.js b/app/static/js/word_operation.js index b3c8bd4..5211f43 100644 --- a/app/static/js/word_operation.js +++ b/app/static/js/word_operation.js @@ -185,9 +185,11 @@ function compareWord(first, second) { /** * - * + * 随机选取 10 个单词学习 */ function random_select_word(word) { + + alert("点击熟悉与不熟悉之后,单词自动返回生词库") // 获取所有带有 "word-container" 类的
标签
const container = document.querySelector('.word-container');
diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html
index 6df5c02..581a038 100644
--- a/app/templates/userpage_get.html
+++ b/app/templates/userpage_get.html
@@ -146,8 +146,8 @@
允许动态调整顺序
- 随机选取10个
- 显示所有生词
+ 随机选取10个
+ 显示所有生词