This commit is contained in:
Ruin
2022-04-14 13:57:59 +08:00
parent 634db893dc
commit 91d82a277d
3 changed files with 49 additions and 20 deletions

View File

@@ -3,7 +3,7 @@
{ {
"path": "pages/home/index", "path": "pages/home/index",
"style": { "style": {
"navigationBarTitleText": "单词学习宝典" "navigationBarTitleText": "管制员英语词汇"
} }
} }
,{ ,{

View File

@@ -102,11 +102,7 @@
// 获取下一题 // 获取下一题
next(index) { next(index) {
// if (this.pageSize < 10) {
// this.pageSize++
// }
this.currentIndex++; this.currentIndex++;
// this.getApiQuestionData()
console.log('跳转到下一题',index) console.log('跳转到下一题',index)
}, },
// 提交成功获取的信息 // 提交成功获取的信息
@@ -239,6 +235,7 @@ this.currentIndex++;
} }
.select-item { .select-item {
text { text {
min-height: 100rpx; min-height: 100rpx;
margin: 20rpx 0; margin: 20rpx 0;
@@ -249,7 +246,7 @@ this.currentIndex++;
border: 2rpx solid #dee1e6; border: 2rpx solid #dee1e6;
border-radius: 8rpx; border-radius: 8rpx;
padding: 0 20rpx; padding:15rpx;
background-color: #f2f5f8; background-color: #f2f5f8;
display: block; display: block;
display: flex; display: flex;

View File

@@ -2,26 +2,58 @@
const db = uniCloud.database(); const db = uniCloud.database();
exports.main = async (event, context) => { exports.main = async (event, context) => {
//event为客户端上传的参数 //event为客户端上传的参数
// const count = await db.collection('questionList').count()
// 根据level字段随机返回不同的数据
// 根据level字段随机返回数据库中不同的数据40组
let res = await db.collection('allWordList').aggregate().match({ let res = await db.collection('allWordList').aggregate().match({
difficulty: event.level difficulty: event.level
}).sample({ }).sample({
size: 10 size: 40
}).limit(10).addFields({ }).limit(40).end()
'options':["$means",'B. v.爬升,上升.n.爬升率,上升率;上升距离','C adv.不变地;经常地;坚持不懈地','D n.积云;组合,集结;累积;形成']
}).end()
// let resMeans = await db.collection('allWordList').where({})
let data = res.data let data = res.data
console.log('入参:页码+难度', event, res) let optionData = [];
// 设置计数器
let count = 0;
// 前10组数据用于题目 后30组数据用于选项
data.forEach((item, index) => {
if (index < 10) {
item.options = [item.means]
} else if (index >= 10 && index < 40) {
optionData.push(item.means)
}
// let res })
// 将后30组数据中的单词含义赋值到前10组数据中的数组中
data.forEach((item, index) => {
if (item.options) {
for (let i = 1; i < 4; i++) {
item.options.push(optionData[count])
count++
}
}
})
// 打乱题目选项
data.forEach((item, index) => {
if (item.options) {
item.options.sort(() => {
return (0.5 - Math.random());
});
// 添加题标
item.options[0] = `A. ${item.options[0]}`
item.options[1] = `B. ${item.options[1]}`
item.options[2] = `C. ${item.options[2]}`
item.options[3] = `D. ${item.options[3]}`
}
})
console.log('选项列表', optionData)
console.log('入参:页码+难度', event, res)
//返回数据给客户端 //返回数据给客户端
return { return {
code: 200, code: 200,
msg: 'success', msg: 'success',
data data,
} }
}; };