From 4045076a56f66994588fd155296d2e37680c5e4c Mon Sep 17 00:00:00 2001 From: gutrse3321 Date: Fri, 15 Jun 2018 20:27:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/views/Home/chatroom.vue | 70 ++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/src/renderer/views/Home/chatroom.vue b/src/renderer/views/Home/chatroom.vue index 3b62661..76f6e2d 100644 --- a/src/renderer/views/Home/chatroom.vue +++ b/src/renderer/views/Home/chatroom.vue @@ -51,7 +51,8 @@ const YOU = 'You' export default { data () { return { - talk_list: [] + talk_list: [], + cmd_flag: 0 } }, methods: { @@ -64,32 +65,63 @@ export default { content: _content } this.talk_list.push(_youTalk) + switch (this.cmd_flag) { + case 0: this._marisaThinking(_content) + break + case 1: this._teachMarisa(_content) + break + } this.$refs.you.value = '' - // this._marisaRelpy() } + }, + _marisaThinking (_content) { switch (_content) { - case 'teach': this._teachMode() + case 'teach': + this.talk_list.push({ + name: MARISA, + content: '好哒,你要教我什么呢?格式:You的消息`白絲魔理沙的回复' + }) + this.cmd_flag = 1 break - default: this._marisaRelpy() + default: this._marisaReply(_content) } }, - _teachMode () { - let _marisaTalk = { - name: MARISA, - content: '好哒,你要教我什么呀?' + _marisaReply (_content) { + let memorise = this.$db.get('memorise').value() + let answer = '' + for (let i = 0; i < memorise.length; i++) { + memorise[i].keyword.forEach(item => { + if (item === _content) { + answer = memorise[i].answer + } + }) + } + if (answer !== '') { + this.talk_list.push({ + name: MARISA, + content: answer + }) + } else { + this.talk_list.push({ + name: MARISA, + content: '唔嗯...不懂你在说什么呢...' + }) } - setTimeout(() => { - this.talk_list.push(_marisaTalk) - }, 300) }, - _marisaRelpy () { - let _marisaTalk = { - name: MARISA, - content: '人类的本质就是复读机。' + _teachMarisa (_content) { + let str = _content.split('`') + let memorey = { + keyword: [ + str[0] + ], + answer: str[1] } - setTimeout(() => { - this.talk_list.push(_marisaTalk) - }, 300) + this.$db.get('memorise').push(memorey).write() + this.talk_list.push({ + name: MARISA, + content: `ok,当你说"${str[0]}"的时候,嗯...好!老子就说"${str[1]}"DA☆ZE` + }) + this.cmd_flag = 0 }, _scrollBottom () { this.$nextTick(() => { @@ -104,7 +136,7 @@ export default { created () { let _startTalk = { name: MARISA, - content: '白絲魔理沙 Type 0.001,还在继续升级da★ze!' + content: '白絲魔理沙 Type 0.001,还在继续升级DA☆ZE!' } this.talk_list.push(_startTalk) }