commit
This commit is contained in:
12
pages.json
12
pages.json
@@ -14,17 +14,7 @@
|
|||||||
"enablePullDownRefresh": false
|
"enablePullDownRefresh": false
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
}
|
||||||
{
|
|
||||||
"path":"pages/answer-detail/answer-detail",
|
|
||||||
"style" :
|
|
||||||
{
|
|
||||||
"navigationBarTitleText": "请选择单词正确的中文含义",
|
|
||||||
"enablePullDownRefresh": false,
|
|
||||||
"backgroundColor":"#f6f8fa",
|
|
||||||
"navigationBarBackgroundColor":"#FFFFFF"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"globalStyle": {
|
"globalStyle": {
|
||||||
"navigationBarTextStyle": "black",
|
"navigationBarTextStyle": "black",
|
||||||
|
|||||||
@@ -1,366 +0,0 @@
|
|||||||
<template>
|
|
||||||
|
|
||||||
<view class="answer-root">
|
|
||||||
<!-- <view class="back-home">
|
|
||||||
<text>< 返回首页</text>
|
|
||||||
|
|
||||||
</view> -->
|
|
||||||
<view class="container" >
|
|
||||||
|
|
||||||
<view v-for="(item,index) in wordData" :key="wordData._id" >
|
|
||||||
|
|
||||||
<view v-if="index == currentIndex">
|
|
||||||
<!-- 题目选项卡模块开始 -->
|
|
||||||
<view class="answer-box" >
|
|
||||||
<view class="title" >
|
|
||||||
<text class="left-title">单选题(难度等级{{item.difficulty}})</text>
|
|
||||||
<text class="right-condition">
|
|
||||||
<text>{{index+1}}</text>
|
|
||||||
<text>/{{pageNum}}</text>
|
|
||||||
</text>
|
|
||||||
</view>
|
|
||||||
<view class="content">
|
|
||||||
<view>{{item.wordName}}</view>
|
|
||||||
</view>
|
|
||||||
<view class="select-item">
|
|
||||||
<text v-for="(itemOptions,indexOptions) in item.options" :key="indexOptions"
|
|
||||||
@click="getSelectedItem(itemOptions,index)"
|
|
||||||
:class="{'isSelected': mySelectArr[index] == itemOptions}"
|
|
||||||
> {{itemOptions}}</text>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
|
|
||||||
</view>
|
|
||||||
<!-- 题目选项卡模块结束 -->
|
|
||||||
|
|
||||||
<!-- 翻页按钮模块开始 -->
|
|
||||||
<view class="page-btn">
|
|
||||||
<view class="btn">
|
|
||||||
<button type="default" @tap="previous(index,item)" v-if="currentIndex >= 1">
|
|
||||||
上一题
|
|
||||||
</button>
|
|
||||||
<button type="default" @tap="next(index,item)" v-if="currentIndex < 9">
|
|
||||||
下一题
|
|
||||||
</button>
|
|
||||||
<button type="default" @tap="messageToggle('error')" v-if="currentIndex == 9 && mySelectArr.length==10">
|
|
||||||
提交!
|
|
||||||
</button>
|
|
||||||
<button type="default" v-if="currentIndex == 9 && mySelectArr.length<10">
|
|
||||||
还有题目未完成!
|
|
||||||
</button>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
</view>
|
|
||||||
<!-- 翻页按钮模块结束 -->
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<view>
|
|
||||||
|
|
||||||
<!-- 提示窗示例 -->
|
|
||||||
<uni-popup ref="alertDialog" type="dialog">
|
|
||||||
<uni-popup-dialog :type="msgType" cancelText="返回首页" :confirmText="confirmText" :title="testRes"
|
|
||||||
:content="resultDialog" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
|
|
||||||
</uni-popup>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
selectIndexArr: [],
|
|
||||||
pageSize: 1,
|
|
||||||
pageNum: 10,
|
|
||||||
currentIndex:0,
|
|
||||||
score:0,
|
|
||||||
level: '',
|
|
||||||
wordData:[],
|
|
||||||
selectItem:'',
|
|
||||||
type: 'center',
|
|
||||||
msgType: 'success',
|
|
||||||
messageText: '这是一条成功提示',
|
|
||||||
value: '',
|
|
||||||
// 我的答案
|
|
||||||
mySelectArr:[],
|
|
||||||
// 正确答案
|
|
||||||
rightSelectArr:[],
|
|
||||||
testRes:'',
|
|
||||||
resultDialog: '您的成绩合格!',
|
|
||||||
confirmText:'',
|
|
||||||
difficultLevel:0,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
watch:{
|
|
||||||
mySelectArr(){
|
|
||||||
console.log('触发')
|
|
||||||
// this.$set(this.mySelectArr,this.mySelectArr[index],item)
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
// 获取当前选中的选项并存到数组中
|
|
||||||
getSelectedItem(item, index) {
|
|
||||||
// this.mySelectArr[index] = item
|
|
||||||
this.mySelectArr.splice(index,1,item)
|
|
||||||
// this.$set(this.mySelectArr,this.mySelectArr[index],item)
|
|
||||||
|
|
||||||
|
|
||||||
console.log('当前的选项',this.mySelectArr)
|
|
||||||
},
|
|
||||||
|
|
||||||
// 获取上一题
|
|
||||||
previous(index,source) {
|
|
||||||
this.currentIndex--;
|
|
||||||
console.log('回到上一题',source)
|
|
||||||
},
|
|
||||||
|
|
||||||
// 获取下一题
|
|
||||||
next(index,source) {
|
|
||||||
this.currentIndex++;
|
|
||||||
console.log('跳转到下一题',source)
|
|
||||||
},
|
|
||||||
// 提交成功获取的信息
|
|
||||||
messageToggle(type) {
|
|
||||||
for(let i = 0;i<this.pageNum;i++){
|
|
||||||
if(this.mySelectArr[i].slice(3) == this.rightSelectArr[i]){
|
|
||||||
this.score++
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
this.score = this.score*10
|
|
||||||
this.resultDialog = `您最后的分数为:${this.score}`
|
|
||||||
if(this.score>=60 && this.difficultLevel < 6){
|
|
||||||
this.difficultLevel++
|
|
||||||
this.testRes = '恭喜及格!'
|
|
||||||
this.confirmText = '继续下一难度'
|
|
||||||
}else if(this.score>=60 && this.difficultLevel == 6){
|
|
||||||
this.difficultLevel++
|
|
||||||
this.testRes = '恭喜及格!'
|
|
||||||
this.confirmText = '去加强巩固'
|
|
||||||
|
|
||||||
}else{
|
|
||||||
this.testRes = '不及格哦!'
|
|
||||||
this.confirmText = '去背单词'
|
|
||||||
}
|
|
||||||
this.msgType = type
|
|
||||||
this.$refs.alertDialog.open()
|
|
||||||
},
|
|
||||||
//确认提交
|
|
||||||
dialogConfirm() {
|
|
||||||
if(this.score<60){
|
|
||||||
uni.switchTab({
|
|
||||||
url:"../recitation/index"
|
|
||||||
})
|
|
||||||
}else if(this.score >= 60){
|
|
||||||
console.log(this.difficultLevel,'当前难度等级')
|
|
||||||
if(this.difficultLevel <= 6){
|
|
||||||
uni.navigateTo({
|
|
||||||
url:"../answer-detail/answer-detail?wordId=" + this.difficultLevel,
|
|
||||||
})
|
|
||||||
}else if(this.difficultLevel){
|
|
||||||
uni.navigateTo({
|
|
||||||
url:"../answer-detail/answer-detail?wordId=1",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
// console.log('点击确认')
|
|
||||||
|
|
||||||
this.$refs.alertDialog.open()
|
|
||||||
},
|
|
||||||
// 关闭提交窗口
|
|
||||||
dialogClose() {
|
|
||||||
uni.switchTab({
|
|
||||||
url: "../../pages/home/index"
|
|
||||||
})
|
|
||||||
console.log('点击关闭')
|
|
||||||
},
|
|
||||||
|
|
||||||
// 调用云函数获取数据
|
|
||||||
async getApiQuestionData(){
|
|
||||||
try{
|
|
||||||
const {result} = await uniCloud.callFunction({
|
|
||||||
name:'provideQuestion',
|
|
||||||
data:{level:this.level,pageSize:this.pageSize}
|
|
||||||
})
|
|
||||||
this.wordData = result.resData
|
|
||||||
this.wordData.forEach(item=>{
|
|
||||||
this.rightSelectArr.push(item.means)
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log('题目数据获取',result)
|
|
||||||
console.log('正确答案',this.rightSelectArr)
|
|
||||||
|
|
||||||
}catch(e){
|
|
||||||
console.error(e)
|
|
||||||
//TODO handle the exception
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
onLoad(option) {
|
|
||||||
this.level = option.wordId;
|
|
||||||
this.difficultLevel = option.wordId;
|
|
||||||
this.getApiQuestionData()
|
|
||||||
console.log('当前难度等级:', this.level)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
page {
|
|
||||||
background-color: #f2f5f8;
|
|
||||||
// overflow: scroll;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.answer-root {
|
|
||||||
position: relative;
|
|
||||||
top: 60rpx;
|
|
||||||
|
|
||||||
.answer-box {
|
|
||||||
word-wrap: break-word;
|
|
||||||
word-break: break-all;
|
|
||||||
box-sizing: border-box;
|
|
||||||
padding: 30rpx;
|
|
||||||
border-radius: 20rpx;
|
|
||||||
width: 100%;
|
|
||||||
box-shadow: 5px 4px 20px rgba(0, 0, 0, 0.16);
|
|
||||||
background-color: #FFFFFF;
|
|
||||||
|
|
||||||
.title {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
box-sizing: border-box;
|
|
||||||
padding-bottom: 20rpx;
|
|
||||||
justify-content: space-between;
|
|
||||||
width: 100%;
|
|
||||||
border-bottom: 2rpx solid #eeeeee;
|
|
||||||
|
|
||||||
.left-title {
|
|
||||||
font-weight: bolder;
|
|
||||||
padding: 0 20rpx;
|
|
||||||
border-left: 8rpx solid #007AFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
.right-condition {
|
|
||||||
text {
|
|
||||||
&:nth-child(1) {
|
|
||||||
font-size: 40rpx;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 0 6rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:nth-child(2) {
|
|
||||||
color: gray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.content {
|
|
||||||
.read{
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
image{
|
|
||||||
// line-height: 36rpx;
|
|
||||||
vertical-align:middle;
|
|
||||||
width: 36rpx;
|
|
||||||
height: 36rpx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
view {
|
|
||||||
min-height: 100rpx;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
&:nth-child(1) {
|
|
||||||
font-size: 40rpx;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:nth-child(2) {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
font-size: 28rpx;
|
|
||||||
|
|
||||||
text {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.select-item {
|
|
||||||
|
|
||||||
text {
|
|
||||||
min-height: 100rpx;
|
|
||||||
margin: 20rpx 0;
|
|
||||||
|
|
||||||
&:nth-child(4) {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
border: 2rpx solid #dee1e6;
|
|
||||||
border-radius: 8rpx;
|
|
||||||
padding:15rpx;
|
|
||||||
background-color: #f2f5f8;
|
|
||||||
display: block;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
|
|
||||||
.isSelected {
|
|
||||||
border: 2rpx solid #007AFF;
|
|
||||||
background-color: rgba(52, 152, 219, 0.3)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.page-btn {
|
|
||||||
margin: 30px;
|
|
||||||
|
|
||||||
.btn {
|
|
||||||
display: flex;
|
|
||||||
|
|
||||||
button {
|
|
||||||
box-shadow: 0 2px 5px 0 rgba(50, 50, 105, 0.15), 0 1px 1px 0 rgba(0, 0, 0, 0.05);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
.noData{
|
|
||||||
font-size: 30rpx;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.back-home{
|
|
||||||
width: 100%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
line-height: 100rpx;
|
|
||||||
// padding: 20rpx;
|
|
||||||
margin-bottom: 50rpx;
|
|
||||||
height: 100rpx;
|
|
||||||
background-color: #FFFFFF;
|
|
||||||
font-size: 28rpx;
|
|
||||||
font-weight: bold;
|
|
||||||
border-bottom: 2rpx solid #EEEEEE;
|
|
||||||
text{
|
|
||||||
padding: 30rpx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,84 +1,395 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="home-root">
|
|
||||||
|
<view class="answer-root">
|
||||||
<view class="container">
|
<view class="container">
|
||||||
<view class="word-box" v-for="item in wordDivArray" :key="item.id" @tap="navgateToAnswer(item.id)" >
|
<view v-for="(item,index) in wordData" :key="wordData._id">
|
||||||
{{item.text}}
|
<view v-if="index == currentIndex">
|
||||||
|
<!-- 题目选项卡模块开始 -->
|
||||||
|
<view class="answer-box">
|
||||||
|
<view class="title">
|
||||||
|
<text class="left-title">单选题(难度等级{{item.difficulty}})</text>
|
||||||
|
<text class="right-condition">
|
||||||
|
<text>{{index+1}}</text>
|
||||||
|
<text>/{{pageNum}}</text>
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
<view class="content">
|
||||||
|
<view>{{item.wordName}}</view>
|
||||||
|
</view>
|
||||||
|
<view class="select-item">
|
||||||
|
<text v-for="(itemOptions,indexOptions) in item.options" :key="indexOptions"
|
||||||
|
@click="getSelectedItem(itemOptions,index)"
|
||||||
|
:class="{'isSelected': mySelectArr[index] == itemOptions}"> {{itemOptions}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
|
||||||
|
</view>
|
||||||
|
<!-- 题目选项卡模块结束 -->
|
||||||
|
|
||||||
|
<!-- 翻页按钮模块开始 -->
|
||||||
|
<view class="page-btn">
|
||||||
|
<view class="btn">
|
||||||
|
<button type="default" @tap="previous(index,item)" v-if="currentIndex >= 1">
|
||||||
|
上一题
|
||||||
|
</button>
|
||||||
|
<button type="default" @tap="next(index,item)" v-if="currentIndex < 9">
|
||||||
|
下一题
|
||||||
|
</button>
|
||||||
|
<button type="default" @tap="messageToggle('error')"
|
||||||
|
v-if="currentIndex == 9 && mySelectArr.length==10">
|
||||||
|
提交!
|
||||||
|
</button>
|
||||||
|
<button type="default" v-if="currentIndex == 9 && mySelectArr.length<10">
|
||||||
|
还有题目未完成!
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
</view>
|
||||||
|
<!-- 翻页按钮模块结束 -->
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<view>
|
||||||
|
|
||||||
|
<!-- 提示窗示例 -->
|
||||||
|
<uni-popup ref="alertDialog" type="dialog">
|
||||||
|
<uni-popup-dialog :type="msgType" cancelText="重新做题" :confirmText="confirmText" :title="testRes"
|
||||||
|
:content="resultDialog" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
|
||||||
|
</uni-popup>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="stance-box">
|
||||||
|
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
wordDivArray:[{
|
// 默认每页题目数量
|
||||||
id:'1',
|
pageSize: 1,
|
||||||
text:'一级词汇难度'
|
// 默认题目总数
|
||||||
},{
|
pageNum: 10,
|
||||||
id:'2',
|
// 默认选择
|
||||||
text:'二级词汇难度'
|
currentIndex: 0,
|
||||||
},{
|
// 默认分数
|
||||||
id:'3',
|
score: 0,
|
||||||
text:'三级词汇难度'
|
// 默认难度
|
||||||
},{
|
level: 1,
|
||||||
id:'4',
|
// 题库数据
|
||||||
text:'四级词汇难度'
|
wordData: [],
|
||||||
},{
|
// 是否居中弹窗
|
||||||
id:'5',
|
type: 'center',
|
||||||
text:'五级词汇难度'
|
// 成功信息样式
|
||||||
},{
|
msgType: 'success',
|
||||||
id:'6',
|
// 成功信息内容
|
||||||
text:'六级词汇难度'
|
messageText: '',
|
||||||
}]
|
// 我的答案
|
||||||
}
|
mySelectArr: [],
|
||||||
|
// 正确答案
|
||||||
|
rightSelectArr: [],
|
||||||
|
testRes: '',
|
||||||
|
// 成绩结果
|
||||||
|
resultDialog: '',
|
||||||
|
// 确定内容
|
||||||
|
confirmText: '',
|
||||||
|
};
|
||||||
},
|
},
|
||||||
onLoad() {
|
watch: {
|
||||||
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
navgateToAnswer(id){
|
// 获取当前选中的选项并存到数组中
|
||||||
uni.navigateTo({
|
getSelectedItem(item, index) {
|
||||||
url:"../answer-detail/answer-detail?wordId="+id,
|
this.mySelectArr.splice(index, 1, item)
|
||||||
|
console.log('当前的选项', this.mySelectArr)
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取上一题
|
||||||
|
previous(index, source) {
|
||||||
|
this.currentIndex--;
|
||||||
|
console.log('回到上一题', source)
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取下一题
|
||||||
|
next(index, source) {
|
||||||
|
this.currentIndex++;
|
||||||
|
console.log('跳转到下一题', source)
|
||||||
|
},
|
||||||
|
// 提交成功获取的信息
|
||||||
|
messageToggle(type) {
|
||||||
|
for (let i = 0; i < this.pageNum; i++) {
|
||||||
|
if (this.mySelectArr[i].slice(3) == this.rightSelectArr[i]) {
|
||||||
|
this.score++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.score = this.score * 10
|
||||||
|
this.resultDialog = `您最后的分数为:${this.score}`
|
||||||
|
if (this.score >= 60 && this.level < 6) {
|
||||||
|
this.level++
|
||||||
|
this.testRes = '恭喜及格!'
|
||||||
|
this.confirmText = '继续下一难度'
|
||||||
|
} else if (this.score >= 60 && this.level == 6) {
|
||||||
|
this.level = 1;
|
||||||
|
this.testRes = '恭喜及格!'
|
||||||
|
this.confirmText = '去加强巩固'
|
||||||
|
} else {
|
||||||
|
this.testRes = '不及格哦!'
|
||||||
|
this.confirmText = '去背单词'
|
||||||
|
}
|
||||||
|
this.msgType = type
|
||||||
|
this.$refs.alertDialog.open()
|
||||||
|
},
|
||||||
|
//右边选项
|
||||||
|
dialogConfirm() {
|
||||||
|
if (this.score < 60) {
|
||||||
|
this.resetParams(0);
|
||||||
|
uni.switchTab({
|
||||||
|
url:"../recitation/index"
|
||||||
})
|
})
|
||||||
// console.log('触发')
|
} else if (this.score >= 60) {
|
||||||
}
|
console.log('当前难度等级',this.level)
|
||||||
|
if (this.level <= 6) {
|
||||||
|
this.resetParams(1)
|
||||||
|
} else {
|
||||||
|
this.resetParams(2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setStorageData()
|
||||||
|
this.$refs.alertDialog.open()
|
||||||
|
},
|
||||||
|
// 左边选项(重新做题)
|
||||||
|
dialogClose() {
|
||||||
|
this.resetParams(0);
|
||||||
|
this.setStorageData()
|
||||||
|
// console.log('继续下一难度')
|
||||||
|
},
|
||||||
|
|
||||||
|
// 调用云函数获取数据
|
||||||
|
async getApiQuestionData() {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
result
|
||||||
|
} = await uniCloud.callFunction({
|
||||||
|
name: 'provideQuestion',
|
||||||
|
data: {
|
||||||
|
level: this.level,
|
||||||
|
pageSize: this.pageSize
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.wordData = result.resData
|
||||||
|
this.wordData.forEach(item => {
|
||||||
|
this.rightSelectArr.push(item.means)
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log('题目数据获取', result)
|
||||||
|
console.log('正确答案', this.rightSelectArr)
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
//TODO handle the exception
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
// 初始化参数
|
||||||
|
resetParams(condition){
|
||||||
|
this.wordData = [];
|
||||||
|
this.mySelectArr = [];
|
||||||
|
this.rightSelectArr = [];
|
||||||
|
this.currentIndex = 0;
|
||||||
|
this.score = 0;
|
||||||
|
//0=分数及格 1=不及格 2=难度到达6
|
||||||
|
if(condition == 2){
|
||||||
|
this.level = 1;
|
||||||
|
}
|
||||||
|
this.getApiQuestionData();
|
||||||
|
},
|
||||||
|
|
||||||
|
// 设置缓存
|
||||||
|
setStorageData(){
|
||||||
|
uni.setStorage({
|
||||||
|
key:"level_type",
|
||||||
|
data:this.level
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
onLoad(option) {
|
||||||
|
this.setStorageData()
|
||||||
|
this.getApiQuestionData()
|
||||||
|
console.log('当前难度等级:', this.level)
|
||||||
|
},
|
||||||
|
onShow() {
|
||||||
|
console.log('背单词页面显示')
|
||||||
|
|
||||||
|
// this.$forceUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
page {
|
||||||
.home-root{
|
background-color: #f2f5f8;
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-between;
|
|
||||||
.word-box{
|
|
||||||
box-sizing: border-box;
|
|
||||||
width: 100%;
|
|
||||||
height: 120rpx;
|
|
||||||
border-radius: 20rpx;
|
|
||||||
margin:40rpx 0;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
color: #FFFFFF;
|
|
||||||
border: 2rpx solid #4CD964;
|
|
||||||
&:nth-child(1){
|
|
||||||
margin-top: 30rpx;
|
|
||||||
}
|
|
||||||
// &:nth-child(n+1){
|
|
||||||
// opacity: 0.5;
|
|
||||||
// }
|
|
||||||
&:nth-child(odd){
|
|
||||||
background: linear-gradient(135deg,#43cbff,#9708cc);
|
|
||||||
}
|
|
||||||
&:nth-child(even){
|
|
||||||
background: linear-gradient(135deg,#f54ea2,#ff7676);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.answer-root {
|
||||||
|
position: relative;
|
||||||
|
top: 60rpx;
|
||||||
|
|
||||||
|
.answer-box {
|
||||||
|
word-wrap: break-word;
|
||||||
|
word-break: break-all;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 30rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
width: 100%;
|
||||||
|
box-shadow: 5px 4px 20px rgba(0, 0, 0, 0.16);
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding-bottom: 20rpx;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: 100%;
|
||||||
|
border-bottom: 2rpx solid #eeeeee;
|
||||||
|
|
||||||
|
.left-title {
|
||||||
|
font-weight: bolder;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
border-left: 8rpx solid #007AFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right-condition {
|
||||||
|
text {
|
||||||
|
&:nth-child(1) {
|
||||||
|
font-size: 40rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
margin: 0 6rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:nth-child(2) {
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
.read {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
image {
|
||||||
|
// line-height: 36rpx;
|
||||||
|
vertical-align: middle;
|
||||||
|
width: 36rpx;
|
||||||
|
height: 36rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
view {
|
||||||
|
min-height: 100rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
&:nth-child(1) {
|
||||||
|
font-size: 40rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:nth-child(2) {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 28rpx;
|
||||||
|
|
||||||
|
text {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-item {
|
||||||
|
|
||||||
|
text {
|
||||||
|
min-height: 100rpx;
|
||||||
|
margin: 20rpx 0;
|
||||||
|
|
||||||
|
&:nth-child(4) {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
border: 2rpx solid #dee1e6;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
padding:15rpx;
|
||||||
|
background-color: #f2f5f8;
|
||||||
|
display: block;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.isSelected {
|
||||||
|
border: 2rpx solid #007AFF;
|
||||||
|
background-color: rgba(52, 152, 219, 0.3)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-btn {
|
||||||
|
margin: 30px;
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
button {
|
||||||
|
box-shadow: 0 2px 5px 0 rgba(50, 50, 105, 0.15), 0 1px 1px 0 rgba(0, 0, 0, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.noData {
|
||||||
|
font-size: 30rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-home {
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
line-height: 100rpx;
|
||||||
|
// padding: 20rpx;
|
||||||
|
margin-bottom: 50rpx;
|
||||||
|
height: 100rpx;
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
border-bottom: 2rpx solid #EEEEEE;
|
||||||
|
|
||||||
|
|
||||||
|
text {
|
||||||
|
padding: 30rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.stance-box{
|
||||||
|
width: 100%;
|
||||||
|
height: 60rpx;
|
||||||
|
// background-color: red;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,61 +1,56 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="answer-root">
|
<view class="answer-root">
|
||||||
<view class="container" >
|
<view class="container">
|
||||||
<view v-for="(item,index) in wordData" :key="wordData._id" >
|
<view v-for="(item,index) in wordData" :key="wordData._id">
|
||||||
|
|
||||||
<view v-if="index == currentIndex">
|
<view v-if="index == currentIndex">
|
||||||
<!-- 题目选项卡模块开始 -->
|
<!-- 题目选项卡模块开始 -->
|
||||||
<view class="answer-box" >
|
<view class="answer-box">
|
||||||
<view class="title" >
|
<view class="title">
|
||||||
<text class="left-title">背单词 (词汇难度:{{item.difficulty}})</text>
|
<text class="left-title">背单词 (词汇难度:{{item.difficulty}})</text>
|
||||||
<text class="right-condition">
|
<text class="right-condition">
|
||||||
<text>{{index+1}}</text>
|
<!-- <text>{{index+1}}</text> -->
|
||||||
<text>/{{pageNum}}</text>
|
<!-- <text>/{{pageNum}}</text> -->
|
||||||
</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="content">
|
<view class="content">
|
||||||
<view>{{item.wordName}}</view>
|
<view>{{item.wordName}}</view>
|
||||||
<view class="read">
|
<view class="read">
|
||||||
<text>音标:{{item.phonetic}}</text>
|
<text>音标:{{item.phonetic}}</text>
|
||||||
<text @tap="getAudioResource">读音:{{item.pronunciation}}
|
<text @tap="getAudioResource">读音:{{item.pronunciation}}
|
||||||
<image src="../../static/icon/listen.png" mode="widthFix"></image>
|
<image src="../../static/icon/listen.png" mode="widthFix"></image>
|
||||||
<audio :src="current.src" controls></audio>
|
<audio :src="current.src" controls></audio>
|
||||||
</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="select-item">
|
<view class="select-item">
|
||||||
<text> {{item.means}}</text>
|
<text> {{item.means}}</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
<!-- 题目选项卡模块结束 -->
|
<!-- 题目选项卡模块结束 -->
|
||||||
<!-- 翻页按钮模块开始 -->
|
<!-- 翻页按钮模块开始 -->
|
||||||
<view class="page-btn">
|
<view class="page-btn">
|
||||||
<view class="btn">
|
<view class="btn">
|
||||||
<button type="default" @tap="previous(index,item.wordName)" v-if="currentIndex >= 1">
|
<button type="default" @tap="previous(index,item.wordName)" v-if="currentIndex >= 1">
|
||||||
上一个单词
|
上一个单词
|
||||||
</button>
|
</button>
|
||||||
<button type="default" @tap="next(index,item.wordName)" v-if="currentIndex < pageNum" >
|
<button type="default" @tap="next(index,item.wordName)" v-if="currentIndex < pageNum">
|
||||||
下一个单词
|
下一个单词
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
<!-- 翻页按钮模块结束 -->
|
<!-- 翻页按钮模块结束 -->
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view>
|
<view>
|
||||||
|
|
||||||
<!-- 提示窗示例 -->
|
|
||||||
<uni-popup ref="alertDialog" type="dialog">
|
|
||||||
<uni-popup-dialog :type="msgType" cancelText="返回首页" confirmText="继续下一难度" title="通知"
|
|
||||||
:content="resultDialog" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
|
|
||||||
</uni-popup>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
@@ -64,110 +59,103 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
selectIndex: -1,
|
|
||||||
pageSize: 21,
|
pageSize: 21,
|
||||||
pageNum: '',
|
pageNum: '',
|
||||||
currentIndex:0,
|
currentIndex: 0,
|
||||||
level: '',
|
level: '',
|
||||||
wordData:[],
|
wordData: [],
|
||||||
type: 'center',
|
type: 'center',
|
||||||
msgType: 'success',
|
msgType: 'success',
|
||||||
messageText: '这是一条成功提示',
|
messageText: '',
|
||||||
value: '',
|
value: '',
|
||||||
resultDialog: '您的成绩合格!',
|
resultDialog: '',
|
||||||
audio:'',
|
audio: '',
|
||||||
current: {
|
current: {
|
||||||
src: '',
|
src: '',
|
||||||
audioAction: {
|
audioAction: {
|
||||||
method: 'pause'
|
method: 'pause'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
// 获取上一题
|
// 获取上一题
|
||||||
previous(index,wordName) {
|
previous(index, wordName) {
|
||||||
this.getAudioResource()
|
this.getAudioResource()
|
||||||
this.currentIndex--;
|
this.currentIndex--;
|
||||||
this.audio = this.wordData[index-1].wordName;
|
this.audio = this.wordData[index - 1].wordName;
|
||||||
console.log('回到上一题',index,this.wordData[index-1].wordName)
|
console.log('回到上一题', index, this.wordData[index - 1].wordName)
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取下一题
|
// 获取下一题
|
||||||
next(index,wordName) {
|
next(index, wordName) {
|
||||||
this.currentIndex++;
|
this.currentIndex++;
|
||||||
if(this.currentIndex % 20 == 1){
|
if (this.currentIndex % 20 == 1) {
|
||||||
this.getApiQuestionData();
|
this.getApiQuestionData();
|
||||||
}
|
}
|
||||||
this.audio = this.wordData[index+1].wordName;
|
this.audio = this.wordData[index + 1].wordName;
|
||||||
this.getAudioResource()
|
this.getAudioResource()
|
||||||
console.log('跳转到下一题',index,this.wordData[index+1].wordName)
|
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)
|
// 调用云函数获取数据
|
||||||
|
async getApiQuestionData() {
|
||||||
}catch(e){
|
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)
|
console.error(e)
|
||||||
//TODO handle the exception
|
//TODO handle the exception
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取音频链接
|
// 获取音频链接
|
||||||
getAudioResource(){
|
getAudioResource() {
|
||||||
this.current.src = 'http://dict.youdao.com/dictvoice?type=0&audio=' + this.audio
|
this.current.src = 'http://dict.youdao.com/dictvoice?type=0&audio=' + this.audio
|
||||||
console.log(this.current.src)
|
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) {
|
onLoad() {
|
||||||
|
this.getApiQuestionData()
|
||||||
this.getApiQuestionData()
|
},
|
||||||
// setTimeout(()=>{
|
onShow(){
|
||||||
// this.audio = this.wordData[0].wordName;
|
|
||||||
// this.getAudioResource()
|
|
||||||
// },2000)
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -222,20 +210,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
.read{
|
.read {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
|
|
||||||
image{
|
image {
|
||||||
// line-height: 36rpx;
|
// line-height: 36rpx;
|
||||||
vertical-align:middle;
|
vertical-align: middle;
|
||||||
width: 36rpx;
|
width: 36rpx;
|
||||||
height: 36rpx;
|
height: 36rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
view {
|
view {
|
||||||
min-height: 100rpx;
|
min-height: 100rpx;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -261,12 +250,13 @@
|
|||||||
.select-item {
|
.select-item {
|
||||||
text {
|
text {
|
||||||
min-height: 100rpx;
|
min-height: 100rpx;
|
||||||
margin: 20rpx 0;
|
margin: 20rpx 0;
|
||||||
|
|
||||||
|
|
||||||
&:nth-child(4) {
|
&:nth-child(4) {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
border: 2rpx solid #dee1e6;
|
border: 2rpx solid #dee1e6;
|
||||||
border-radius: 8rpx;
|
border-radius: 8rpx;
|
||||||
padding: 20rpx;
|
padding: 20rpx;
|
||||||
@@ -300,35 +290,39 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
.noData{
|
|
||||||
|
.noData {
|
||||||
font-size: 30rpx;
|
font-size: 30rpx;
|
||||||
text-align: center;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -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
|
|
||||||
};
|
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
const db = uniCloud.database();
|
const db = uniCloud.database();
|
||||||
exports.main = async (event, context) => {
|
exports.main = async (event, context) => {
|
||||||
//event为客户端上传的参数
|
//event为客户端上传的参数
|
||||||
|
let difficultLevel = event.level.toString()
|
||||||
// 根据level字段随机返回数据库中不同的数据40组
|
// 根据level字段随机返回数据库中不同的数据40组
|
||||||
let res = await db.collection('allWordList').aggregate().match({
|
let res = await db.collection('allWordList').aggregate().match({
|
||||||
difficulty: event.level
|
difficulty: difficultLevel
|
||||||
}).sample({
|
}).sample({
|
||||||
size: 40
|
size: 40
|
||||||
}).limit(40).end()
|
}).limit(40).end()
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ exports.main = async (event, context) => {
|
|||||||
//event为客户端上传的参数
|
//event为客户端上传的参数
|
||||||
let count = await db.collection('allWordList').count()
|
let count = await db.collection('allWordList').count()
|
||||||
// 根据level字段随机返回不同的数据
|
// 根据level字段随机返回不同的数据
|
||||||
|
const level = event.level.toString();
|
||||||
let res = await db.collection('allWordList').aggregate().sample({
|
let res = await db.collection('allWordList').aggregate().match({
|
||||||
|
difficulty: level
|
||||||
|
}).sample({
|
||||||
size: event.pageSize
|
size: event.pageSize
|
||||||
}).limit(event.pageSize).end()
|
}).limit(event.pageSize).end()
|
||||||
res.total = count.total;
|
res.total = count.total;
|
||||||
|
|||||||
Reference in New Issue
Block a user