You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
// pages/home/home.js
|
|
|
|
|
var app = getApp();
|
|
|
|
|
const db=wx.cloud.database()
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
userInfo:"",
|
|
|
|
|
hasUserInfo:false,
|
|
|
|
|
day:0,
|
|
|
|
|
openid:"",
|
|
|
|
|
count:0
|
|
|
|
|
},
|
|
|
|
|
handleContact (e) {
|
|
|
|
|
console.log(e.detail.path)
|
|
|
|
|
console.log(e.detail.query)
|
|
|
|
|
},
|
|
|
|
|
shouquanFs(){
|
|
|
|
|
this.getUserProfile()
|
|
|
|
|
},
|
|
|
|
|
handleCollection(){
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: '../myCollection/myCollection',
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
getUserProfile(e) {
|
|
|
|
|
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
|
|
|
|
|
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
|
|
|
|
|
wx.getUserProfile({
|
|
|
|
|
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
|
|
|
|
success: (res) => {
|
|
|
|
|
this.setData({
|
|
|
|
|
userInfo: res.userInfo,
|
|
|
|
|
hasUserInfo: true
|
|
|
|
|
})
|
|
|
|
|
app.globalData.islogin=true
|
|
|
|
|
|
|
|
|
|
db.collection("user").where({_openid:this.data.openid}).get()
|
|
|
|
|
.then(res=>{
|
|
|
|
|
//将此用户添加到user表中
|
|
|
|
|
if(res.data.length===0){
|
|
|
|
|
wx.cloud.database().collection('user').add({
|
|
|
|
|
data:{
|
|
|
|
|
date:new Date(),
|
|
|
|
|
}
|
|
|
|
|
})}
|
|
|
|
|
this.setData({
|
|
|
|
|
day:parseInt((new Date()-res.data[0].date)/86400000+1)
|
|
|
|
|
})
|
|
|
|
|
}).catch(res=>{
|
|
|
|
|
console.log("get失败",res);
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
//笔记数
|
|
|
|
|
db.collection("note").where({_openid:this.data.openid}).count().then(res=>{
|
|
|
|
|
const num=res.total
|
|
|
|
|
this.setData({
|
|
|
|
|
count:num
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
fail: (res)=>{
|
|
|
|
|
console.log("用户信息获取失败",res);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
wx.cloud.callFunction({
|
|
|
|
|
name:"getopid"
|
|
|
|
|
}).then(res=>{
|
|
|
|
|
this.setData({
|
|
|
|
|
openid:res.result.openid
|
|
|
|
|
})
|
|
|
|
|
}).catch(res=>{
|
|
|
|
|
console.log("获取用户opid失败",res);
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow: function () {
|
|
|
|
|
// const userinfo=wx.getStorageSync('userinfo');
|
|
|
|
|
// this.setData({userinfo})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|