diff --git a/package-lock.json b/package-lock.json index eb1c8c2..a25330e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,8 @@ "crypto-js": "^4.1.1", "node-uuid": "^1.4.8", "vue": "^3.2.13", - "vue-router": "^4.2.5" + "vue-router": "^4.2.5", + "vuex": "^4.1.0" }, "devDependencies": { "@babel/core": "^7.12.16", @@ -10974,6 +10975,17 @@ "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "dev": true }, + "node_modules/vuex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/vuex/-/vuex-4.1.0.tgz", + "integrity": "sha512-hmV6UerDrPcgbSy9ORAtNXDr9M4wlNP4pEFKye4ujJF8oqgFFuxDCdOLS3eNoRTtq5O3hoBDh9Doj1bQMYHRbQ==", + "dependencies": { + "@vue/devtools-api": "^6.0.0-beta.11" + }, + "peerDependencies": { + "vue": "^3.2.0" + } + }, "node_modules/warning": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/warning/-/warning-4.0.3.tgz", diff --git a/package.json b/package.json index 96a367e..af74c25 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "crypto-js": "^4.1.1", "node-uuid": "^1.4.8", "vue": "^3.2.13", - "vue-router": "^4.2.5" + "vue-router": "^4.2.5", + "vuex": "^4.1.0" }, "devDependencies": { "@babel/core": "^7.12.16", diff --git a/src/components/Recite.vue b/src/components/Recite.vue index 3ba224c..9447ab4 100644 --- a/src/components/Recite.vue +++ b/src/components/Recite.vue @@ -127,8 +127,26 @@ export default { key_listener(e) { if (this.mode === 1) { let ctrlKey = e.ctrlKey || e.metaKey; - if (ctrlKey && e.key === 'b') { - this.showAnswer(); + if (ctrlKey) { + switch (e.key) { + case 'b': + this.showAnswer(); + break; + case 'm': + this.skip(); + break; + case 'i': + this.add_to(); + break; + case 'ArrowLeft': + this.prev(); + break; + case 'ArrowRight': + this.next(); + break; + default: + return; + } } e.preventDefault(); return; @@ -179,7 +197,6 @@ export default { onlineSets: this.online.checkedSets, seed: seed })) - console.log(this.testWords); this.total = this.testWords.length; if (this.total === 0) { ElMessage({ @@ -265,19 +282,25 @@ export default { }); }, next() { - this.current++; - if (this.current === this.total) { - this.mode = 0; - ElNotification({ - message: "您已完成所有单词的背诵", - title: "Congratulations!", - type: "success" - }) - return; + if (this.current < this.answered) { + this.current++; + if (this.current === this.total) { + this.mode = 0; + ElNotification({ + message: "您已完成所有单词的背诵", + title: "Congratulations!", + type: "success" + }) + return; + } + nextTick(() => { + this.show(); + }); } - nextTick(() => { - this.show(); - }); + else ElMessage({ + type:"error", + message:"您还未答过该词,跳过请使用ctrl+M", + }) }, skip() { ElMessage({ @@ -290,8 +313,14 @@ export default { return; }, prev() { - this.current--; - this.show(); + if(this.current>0){ + this.current--; + this.show(); + } + else ElMessage({ + type:'error', + message:"已经是第一个单词" + }) }, showAnswer() { ElMessage(`答案:${this.word.word}`); @@ -332,7 +361,10 @@ export default { o += "_".repeat(this.word.word.length - n)); e.value = o; e.setSelectionRange(n, n); - e.style.height = `${e.scrollHeight}px`; + e.style.height = 0; + setTimeout(() => { + e.style.height = `${e.scrollHeight}px`; + }, 0); e.focus(); }, audio_play() { @@ -354,22 +386,28 @@ export default { this.$router.push("/"); }, add_to() { - let data = JSON.parse(localStorage.getItem(this.set_id)); - for (let i of data) { - if (i.word === this.word.word) { - ElMessage({ - message: '已经添加过该词', - type: 'error', - }) - return; + if (this.set_id) { + let data = JSON.parse(localStorage.getItem(this.set_id)); + for (let i of data) { + if (i.word === this.word.word) { + ElMessage({ + message: '已经添加过该词', + type: 'error', + }) + return; + } } + data.push(this.word); + localStorage.setItem(this.set_id, JSON.stringify(data)); + ElMessage({ + message: `已添加 ${this.word.word} (${this.word.type})`, + type: 'success', + }); } - data.push(this.word); - localStorage.setItem(this.set_id, JSON.stringify(data)); - ElMessage({ - message: `已添加 ${this.word.word} (${this.word.type})`, - type: 'success', - }); + else ElMessage({ + message: '请先选择单词本', + type: 'error', + }) return; }, }, @@ -390,7 +428,6 @@ export default { return; } this.online_sets = res.data; - console.log(this.online_sets); for (let i in this.online_sets) { for (let j in this.online_sets[i]) { for (let k in this.online_sets[i][j]) { diff --git a/src/components/manage/Editor.vue b/src/components/manage/Editor.vue index b5b8be9..fafb9ca 100644 --- a/src/components/manage/Editor.vue +++ b/src/components/manage/Editor.vue @@ -1,10 +1,9 @@