63 lines
1.2 KiB
JavaScript
63 lines
1.2 KiB
JavaScript
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
userInfo: null,
|
|
hasUserInfo: false,
|
|
canIUseGetUserProfile: false,
|
|
items: [],
|
|
todayItems: []
|
|
},
|
|
|
|
onLoad: function() {
|
|
if (wx.getUserProfile) {
|
|
this.setData({
|
|
canIUseGetUserProfile: true
|
|
})
|
|
}
|
|
|
|
if (app.globalData.userInfo) {
|
|
this.setData({
|
|
userInfo: app.globalData.userInfo,
|
|
hasUserInfo: true
|
|
})
|
|
}
|
|
},
|
|
|
|
onShow: function() {
|
|
// 更新物品数据
|
|
const items = app.globalData.items || []
|
|
const today = new Date().toISOString().split('T')[0]
|
|
const todayItems = items.filter(item => item.createTime.startsWith(today))
|
|
|
|
this.setData({
|
|
items: items,
|
|
todayItems: todayItems
|
|
})
|
|
},
|
|
|
|
getUserProfile() {
|
|
wx.getUserProfile({
|
|
desc: '用于完善用户资料',
|
|
success: (res) => {
|
|
app.globalData.userInfo = res.userInfo
|
|
this.setData({
|
|
userInfo: res.userInfo,
|
|
hasUserInfo: true
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
navigateToItems: function() {
|
|
wx.navigateTo({
|
|
url: '/pages/items/items'
|
|
})
|
|
},
|
|
|
|
navigateToAdd: function() {
|
|
wx.navigateTo({
|
|
url: '/pages/add/add'
|
|
})
|
|
}
|
|
})
|