From 76cad44e7691be003bbba6a94e7d439e68728e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9B=E8=BF=9B=E5=95=8A?= <1830275783@qq.com> Date: Sat, 16 Apr 2022 01:15:03 +0800 Subject: [PATCH] commit --- pages.json | 12 +- pages/answer-detail/answer-detail.vue | 366 --------------- pages/home/index.vue | 437 +++++++++++++++--- pages/recitation/index.vue | 348 +++++++------- .../createQuestionItem/index.js | 40 -- .../cloudfunctions/provideQuestion/index.js | 4 +- .../cloudfunctions/reciteWords/index.js | 6 +- 7 files changed, 552 insertions(+), 661 deletions(-) delete mode 100644 pages/answer-detail/answer-detail.vue delete mode 100644 uniCloud-aliyun/cloudfunctions/createQuestionItem/index.js diff --git a/pages.json b/pages.json index 4662a8b..1d8d0ff 100644 --- a/pages.json +++ b/pages.json @@ -14,17 +14,7 @@ "enablePullDownRefresh": false } - }, - { - "path":"pages/answer-detail/answer-detail", - "style" : - { - "navigationBarTitleText": "请选择单词正确的中文含义", - "enablePullDownRefresh": false, - "backgroundColor":"#f6f8fa", - "navigationBarBackgroundColor":"#FFFFFF" - } - } + } ], "globalStyle": { "navigationBarTextStyle": "black", diff --git a/pages/answer-detail/answer-detail.vue b/pages/answer-detail/answer-detail.vue deleted file mode 100644 index e950e74..0000000 --- a/pages/answer-detail/answer-detail.vue +++ /dev/null @@ -1,366 +0,0 @@ - - - - - diff --git a/pages/home/index.vue b/pages/home/index.vue index e7d32ea..143dbbc 100644 --- a/pages/home/index.vue +++ b/pages/home/index.vue @@ -1,84 +1,395 @@ diff --git a/pages/recitation/index.vue b/pages/recitation/index.vue index 799774c..1684cb9 100644 --- a/pages/recitation/index.vue +++ b/pages/recitation/index.vue @@ -1,61 +1,56 @@ @@ -64,110 +59,103 @@ export default { data() { return { - selectIndex: -1, pageSize: 21, - pageNum: '', - currentIndex:0, + pageNum: '', + currentIndex: 0, level: '', - wordData:[], + wordData: [], type: 'center', msgType: 'success', - messageText: '这是一条成功提示', + messageText: '', value: '', - resultDialog: '您的成绩合格!', - audio:'', - current: { - src: '', - audioAction: { - method: 'pause' - }, - } + resultDialog: '', + audio: '', + current: { + src: '', + audioAction: { + method: 'pause' + }, + } }; }, methods: { // 获取上一题 - previous(index,wordName) { - this.getAudioResource() - this.currentIndex--; - this.audio = this.wordData[index-1].wordName; - console.log('回到上一题',index,this.wordData[index-1].wordName) + previous(index, wordName) { + this.getAudioResource() + this.currentIndex--; + this.audio = this.wordData[index - 1].wordName; + console.log('回到上一题', index, this.wordData[index - 1].wordName) }, // 获取下一题 - next(index,wordName) { - this.currentIndex++; - if(this.currentIndex % 20 == 1){ - this.getApiQuestionData(); - } - this.audio = this.wordData[index+1].wordName; - this.getAudioResource() - console.log('跳转到下一题',index,this.wordData[index+1].wordName) + next(index, wordName) { + this.currentIndex++; + if (this.currentIndex % 20 == 1) { + this.getApiQuestionData(); + } + this.audio = this.wordData[index + 1].wordName; + this.getAudioResource() + console.log('跳转到下一题', index, this.wordData[index + 1].wordName) }, - - // 提交成功获取的信息 - messageToggle(type) { - this.msgType = type - this.$refs.alertDialog.open() - }, - - //确认提交 - dialogConfirm() { - console.log('点击确认') - this.$refs.alertDialog.open() - }, - - // 关闭提交窗口 - dialogClose() { - uni.switchTab({ - url: "../../pages/home/index" - }) - console.log('点击关闭') - }, - - // 调用云函数获取数据 - async getApiQuestionData(){ - try{ - const {result} = await uniCloud.callFunction({ - name:'reciteWords', - data:{pageSize:this.pageSize} - }) - result.res.data.forEach(e=>{ - this.wordData.push(e); - }) - this.pageNum = result.res.total - if(this.wordData.length<22){ - this.audio = this.wordData[0].wordName; - this.getAudioResource() - } - - - console.log('题目数据获取',this.wordData) - - }catch(e){ + // 调用云函数获取数据 + async getApiQuestionData() { + this.getLevelFromStorage(); + try { + const { + result + } = await uniCloud.callFunction({ + name: 'reciteWords', + data: { + pageSize: this.pageSize, + level:this.level + } + }) + result.res.data.forEach(e => { + this.wordData.push(e); + }) + this.pageNum = result.res.total + if (this.wordData.length < 22) { + this.audio = this.wordData[0].wordName; + this.getAudioResource() + } + + + + console.log('题目数据获取', this.wordData) + + } catch (e) { console.error(e) //TODO handle the exception } - - + + }, - - // 获取音频链接 - getAudioResource(){ - this.current.src = 'http://dict.youdao.com/dictvoice?type=0&audio=' + this.audio - console.log(this.current.src) + + // 获取音频链接 + getAudioResource() { + this.current.src = 'http://dict.youdao.com/dictvoice?type=0&audio=' + this.audio + console.log(this.current.src) + }, + + // 从缓存中获取到难度等级 + getLevelFromStorage(){ + try{ + const value = uni.getStorageSync('level_type') + this.level = value; + if(this.level){ + console.log('目前的缓存中的题目难度',this.level) + } + }catch(e){ + console.log(e) + } } }, - onLoad(option) { - - this.getApiQuestionData() - // setTimeout(()=>{ - // this.audio = this.wordData[0].wordName; - // this.getAudioResource() - // },2000) - - + onLoad() { + this.getApiQuestionData() + }, + onShow(){ } } @@ -222,20 +210,21 @@ } } - .content { - .read{ + .content { + .read { display: flex; - align-items: center; - position: relative; - - - image{ + align-items: center; + position: relative; + + + image { // line-height: 36rpx; - vertical-align:middle; - width: 36rpx; - height: 36rpx; - } + vertical-align: middle; + width: 36rpx; + height: 36rpx; + } } + view { min-height: 100rpx; display: flex; @@ -261,12 +250,13 @@ .select-item { text { min-height: 100rpx; - margin: 20rpx 0; - + margin: 20rpx 0; + &:nth-child(4) { margin-bottom: 0; } + border: 2rpx solid #dee1e6; border-radius: 8rpx; padding: 20rpx; @@ -300,35 +290,39 @@ } } - .noData{ + + .noData { font-size: 30rpx; text-align: center; - } - /deep/ .uni-audio-default{ - min-width:0rpx !important; - position: absolute; - padding: 0 !important; - margin: 0 !important; - height: 40rpx; - width: 40rpx; - - top: 30rpx; - right: 190rpx; - opacity: 0; - } - /deep/ .uni-audio-right{ - display: none !important; - - } - /deep/ .uni-audio-button{ - margin: 0 !important; - height: 40rpx; - width: 40rpx; - } - /deep/ .uni-audio-left{ - // height: 40rpx; - // display: none !important; - - } + } + /deep/ .uni-audio-default { + min-width: 0rpx !important; + position: absolute; + padding: 0 !important; + margin: 0 !important; + height: 40rpx; + width: 40rpx; + + top: 30rpx; + right: 190rpx; + opacity: 0; + } + + /deep/ .uni-audio-right { + display: none !important; + + } + + /deep/ .uni-audio-button { + margin: 0 !important; + height: 40rpx; + width: 40rpx; + } + + /deep/ .uni-audio-left { + // height: 40rpx; + // display: none !important; + + } diff --git a/uniCloud-aliyun/cloudfunctions/createQuestionItem/index.js b/uniCloud-aliyun/cloudfunctions/createQuestionItem/index.js deleted file mode 100644 index 2eaeee1..0000000 --- a/uniCloud-aliyun/cloudfunctions/createQuestionItem/index.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; -const db = uniCloud.database(); -exports.main = async (event, context) => { - // 创建数据库 - const collection = db.collection('questionList'); - // 添加示例数据 - const res = await collection.add({ - "wordData": { - "level": 1, - "wordName": "apple", - "phonetic": "abdc", - "pronunciation": "url:xx", - "options": [ - { - "itemId": "A", - "itemContent": "苹果", - "right": true - }, - { - "itemId": "B", - "itemContent": "香蕉" - }, - { - "itemId": "C", - "itemContent": "橙子" - }, - { - "itemId": "D", - "itemContent": "柠檬" - } - ] - } -}) - //event为客户端上传的参数 - event = '测试数据' - console.log('后端接口测试数据 : ', event) - - //返回数据给客户端 - return event -}; diff --git a/uniCloud-aliyun/cloudfunctions/provideQuestion/index.js b/uniCloud-aliyun/cloudfunctions/provideQuestion/index.js index e9f086a..50f4f6e 100644 --- a/uniCloud-aliyun/cloudfunctions/provideQuestion/index.js +++ b/uniCloud-aliyun/cloudfunctions/provideQuestion/index.js @@ -2,10 +2,10 @@ const db = uniCloud.database(); exports.main = async (event, context) => { //event为客户端上传的参数 - + let difficultLevel = event.level.toString() // 根据level字段随机返回数据库中不同的数据40组 let res = await db.collection('allWordList').aggregate().match({ - difficulty: event.level + difficulty: difficultLevel }).sample({ size: 40 }).limit(40).end() diff --git a/uniCloud-aliyun/cloudfunctions/reciteWords/index.js b/uniCloud-aliyun/cloudfunctions/reciteWords/index.js index 7a337c1..db93562 100644 --- a/uniCloud-aliyun/cloudfunctions/reciteWords/index.js +++ b/uniCloud-aliyun/cloudfunctions/reciteWords/index.js @@ -4,8 +4,10 @@ exports.main = async (event, context) => { //event为客户端上传的参数 let count = await db.collection('allWordList').count() // 根据level字段随机返回不同的数据 - - let res = await db.collection('allWordList').aggregate().sample({ + const level = event.level.toString(); + let res = await db.collection('allWordList').aggregate().match({ + difficulty: level + }).sample({ size: event.pageSize }).limit(event.pageSize).end() res.total = count.total;