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.
174 lines
3.6 KiB
174 lines
3.6 KiB
// pages/community/community.js
|
|
const _ = wx.cloud.database().command;
|
|
var app = getApp();
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
_openid:"",
|
|
list:[],
|
|
title:"",
|
|
itemid:""
|
|
},
|
|
note: function (e) {
|
|
if (e.currentTarget.dataset.type == 1) {
|
|
wx.navigateTo({
|
|
url: '../chakan/chakan?id=' + e.currentTarget.dataset.id
|
|
})
|
|
} else {
|
|
wx.navigateTo({
|
|
url: '../chakan/chakan?id=' + e.currentTarget.dataset.id
|
|
})
|
|
}
|
|
},
|
|
getCollections(_id){
|
|
wx.cloud.callFunction({
|
|
name:"getCollection",
|
|
data:{
|
|
_id:_id
|
|
}
|
|
}).then(res=>{
|
|
if(app.globalData.islogin){
|
|
if(res.result.data[0]!=null){
|
|
wx.showToast({
|
|
icon:"none",
|
|
title: '已经收藏过了',
|
|
})
|
|
}else{
|
|
wx.cloud.callFunction({
|
|
name:"updatenote",
|
|
data:{
|
|
itemid:this.data.itemid
|
|
}
|
|
}).then(res=>{
|
|
wx.showToast({
|
|
title: '收藏成功',
|
|
})
|
|
this.getnotes()
|
|
wx.cloud.database().collection('Collection').add({
|
|
data:{
|
|
noteid:this.data.itemid
|
|
}
|
|
}).catch(res=>{
|
|
console.log("noteid写入数据库失败",res)
|
|
})
|
|
}).catch(res=>{
|
|
console.log("收藏失败",res)
|
|
})
|
|
}
|
|
}else{
|
|
wx.showToast({
|
|
icon:"none",
|
|
title: '请先授权',
|
|
})
|
|
}
|
|
|
|
}).catch(res=>{
|
|
console.log("getCollection失败",res);
|
|
})
|
|
},
|
|
search(e){
|
|
this.setData({
|
|
title:e.detail.value
|
|
}
|
|
)
|
|
this.getnotes()
|
|
},
|
|
CollectionFs(e){
|
|
this.setData({
|
|
itemid:e.currentTarget.dataset.itemid
|
|
}),
|
|
this.getCollections(this.data.itemid),
|
|
this.getnotes()
|
|
},
|
|
getnotes(){
|
|
wx.cloud.callFunction({
|
|
name:"getNotes",
|
|
data:{
|
|
title:this.data.title,
|
|
type:1
|
|
}
|
|
}).then(res=>{
|
|
this.setData({
|
|
list:res.result.data
|
|
})
|
|
}).catch(res=>{
|
|
console.log("调用getNotes失败",res);
|
|
})
|
|
},
|
|
onToggle() {
|
|
this.setData({
|
|
value: "",
|
|
isSearch:false,
|
|
title:"",
|
|
})
|
|
this.getnotes()
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
wx.cloud.callFunction({
|
|
name:"getopid",
|
|
success: res=>{
|
|
this.setData({
|
|
_openid:res.result.openid
|
|
})
|
|
},
|
|
fail(res){
|
|
console.log("getopid获取失败",res);
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.getnotes()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |