首先,附上小程序二维码,欢迎大家浏览
一、项目效果展示
由于时间关系,页面做的稍微有些简陋。
二、项目介绍
该项目包含三个页面
首页,历史,我的
首页,用于数据的计算,计算出结果后可以进行保存
点击保存按钮,若是未登录,会自动跳转到登录页面,登录之后,方可开放存档功能。
历史页,登录后,可以查询保存的历史记录
我的,用于用户登录
三、核心代码
//请求数据库,用户信息
wx.cloud.callFunction({
name: 'getId',
}).then(res => {
app.openID = res.result.openid
db.collection('userList').where({
_openid: res.result.openid
}).get().then(res => {
app.data = res.data[0]
console.log(res.data);
if (res.data[0]) {
app.status = 1
} else {
app.status = 0
}
})
})
// 年级选择
gradeChange(e) {
this.setData({
index: e.detail.value
})
},
// 性别选择
genderChange(e) {
this.setData({
gender: e.detail.value
})
},
//存档
cundang() {
console.log(app.status, 'cundang');
if (app.status) {
db.collection('userList').where({
_openid: app.openID
}).update({
data: {
history: _.push(this.data.zong),
bmi: _.push(this.data.bmi)
}
})
} else {
wx.showToast({
title: '请先登录!',
icon: 'loading',
}).then(res => {
setTimeout(() => {
wx.switchTab({
url: '/pages/mine/index',
})
}, 1000)
// 点击登录,请求用户信息
getUser() {
wx.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
db.collection('userList').add({
data: {
name: res.userInfo.nickName,
phone: res.userInfo.avatarUrl,
history: [],
bmi:[]
}
})
this.setData({
userInfo: {
name: res.userInfo.nickName,
phone: res.userInfo.avatarUrl
}
})
console.log(this.data.userInfo);
app.status = 1
}
})
},
代码数量过大,内容展示有限,如对完整代码有兴趣,可以留下自己的邮箱