'use strict'; exports.main = async (event, context) => { const db = uniCloud.database() if (event.api === 'getByID') { const res = await db.collection('dishes').where({ _id: event.id }).get() return res } if (event.api === 'getFloorList') { const res = await db.collection('dishes').skip(4).limit(15).get() return res } if (event.api === 'getByName') { const res = await db.collection('dishes').where({ dish_name: new RegExp(event.dish_name, 'g') }).get() return res } if (event.api === 'getByLabels') { let dishes = [] let len = [] for(let i = 0;i < event.labels.length;i++) { let label = event.labels[i] const res1 = await db.collection('dish-label').where({label:label}).get() for(let i = 0;i < res1.data.length;i++) { dishes.push(res1.data[i]) } } let dishRes = [] console.log(dishes.length) for(let i = 0;i < dishes.length;i++) { const res = await db.collection('dishes').where({_id:dishes[i].dish_id}).get() console.log(res) dishRes.push(res.data[0]) } return dishRes } //返回数据给客户端 return "请求错误" };