// pages/chat/chat.js Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.cloud.init() wx.cloud.callFunction({ name: 'getOpenId', complete: res => { console.log('callFunction test result: ', res) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { wx.cloud.init({env:'cloud1-2go8vh3uf39b51e1'}) const db = wx.cloud.database() const _=db.command const watcher = db.collection('message').where({ room:'bf4a0bf261c46ca1000a8f8d7fcf50e2', time:_.gt(new Date('2021-12-23 00:00:00')) }).watch({ onChange:snapshot=>{ console.log('新事件',snapshot) }, onError:err=>{ console.error('监听错误',err) } }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })