-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
780 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Util from '../../utils/util'; | ||
|
||
const app = getApp(); | ||
let self; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
// miniprogram/pages/quwen/detail.js | ||
const app = getApp(); | ||
let self; | ||
|
||
Page({ | ||
|
||
/** | ||
* 页面的初始数据 | ||
*/ | ||
data: { | ||
isFollow: false, | ||
followText: '点击关注', | ||
jokeInfo: {}, | ||
likeId: '' | ||
}, | ||
|
||
/** | ||
* 生命周期函数--监听页面加载 | ||
*/ | ||
onLoad: function (options) { | ||
self = this; | ||
this.userId = app.getGlobalData().userId; | ||
let jokeId = options.jokeId || ''; | ||
this.jokeId = jokeId; | ||
|
||
wx.showLoading(); | ||
|
||
Promise.all([this.getListByIds([jokeId]), this.getListByUserId()]).then(function(res) { | ||
wx.hideLoading(); | ||
let _jokeInfo = res[0] && res[0].length > 0 ? res[0][0] : {}; | ||
let jokeLikes = res[1]; | ||
let filterArs = jokeLikes.filter((item) => { | ||
return item.jokeId == jokeId | ||
}); | ||
let _isFollow = false, _id = '', _followText = '点击关注'; | ||
|
||
if (filterArs.length > 0) { | ||
_isFollow = true; | ||
_id = filterArs[0]._id; | ||
_followText = '已关注'; | ||
} | ||
|
||
self.setData({ | ||
isFollow: _isFollow, | ||
jokeInfo: _jokeInfo, | ||
followText: _followText, | ||
likeId: _id | ||
}); | ||
}); | ||
}, | ||
|
||
onShareAppMessage: function () { | ||
|
||
}, | ||
|
||
onClipboard: function() { | ||
wx.setClipboardData({ | ||
data: self.data.jokeInfo.cont, | ||
success(res) { | ||
wx.getClipboardData({ | ||
success(res) { } | ||
}); | ||
} | ||
}); | ||
}, | ||
onShare: function() { | ||
wx.redirectTo({ | ||
url: '/pages/quwen/share?info=' + JSON.stringify(this.data.jokeInfo) | ||
}); | ||
}, | ||
onFollow: function() { | ||
if (this.data.isFollow) { | ||
this.unlike(this.data.likeId); | ||
} else { | ||
this.like(this.userId, this.jokeId); | ||
} | ||
}, | ||
// 获取用户关注的列表 | ||
getListByUserId: function() { | ||
return new Promise((resolve, reject) => { | ||
wx.cloud.callFunction({ | ||
name: 'jokelikes', | ||
data: { | ||
getLikes: true, | ||
userId: self.userId, | ||
jokeId: self.jokeId | ||
}, | ||
success: res => { | ||
if (res.errMsg == "cloud.callFunction:ok") { | ||
resolve(res.result.data); | ||
} | ||
}, | ||
fail: err => { | ||
resolve([]); | ||
} | ||
}); | ||
}); | ||
}, | ||
getListByIds: function (ids) { | ||
return new Promise((resolve, reject) => { | ||
wx.cloud.callFunction({ | ||
name: 'jokes', | ||
data: { | ||
getByIds: true, | ||
ids: ids, | ||
offset: 0 | ||
}, | ||
success: res => { | ||
if (res.errMsg == "cloud.callFunction:ok") { | ||
resolve(res.result.data); | ||
} | ||
}, | ||
fail: err => { | ||
resolve([]); | ||
} | ||
}); | ||
}); | ||
}, | ||
unlike: function(id) { | ||
wx.cloud.callFunction({ | ||
name: 'jokelikes', | ||
data: { | ||
remove: true, | ||
likeId: id | ||
}, | ||
success: res => { | ||
if (res.errMsg == "cloud.callFunction:ok" && res.result.stats.removed == 1) { | ||
wx.showToast({ | ||
title: '关注已取消', | ||
duration: 800, | ||
icon: 'none', | ||
success: function () { | ||
self.setData({ | ||
isFollow: false, | ||
followText: '点击关注' | ||
}); | ||
} | ||
}); | ||
} | ||
}, | ||
fail: err => { | ||
wx.showToast({ | ||
title: '取消关注失败', | ||
duration: 800, | ||
icon: 'none' | ||
}); | ||
} | ||
}); | ||
}, | ||
like: function (userId, jokeId) { | ||
wx.cloud.callFunction({ | ||
name: 'jokelikes', | ||
data: { | ||
setSelf: true, | ||
userId: userId, | ||
jokeId: jokeId | ||
}, | ||
success: res => { | ||
if (res.errMsg == "cloud.callFunction:ok") { | ||
self.setData({ | ||
isFollow: true, | ||
followText: '已关注', | ||
likeId: res.result._id | ||
}); | ||
} | ||
}, | ||
fail: err => { | ||
wx.showToast({ | ||
title: '请检查网络您的状态', | ||
duration: 800, | ||
icon: 'none' | ||
}); | ||
} | ||
}); | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"usingComponents": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!--miniprogram/pages/quwen/detail.wxml--> | ||
<view> | ||
<view class="quwen-box"> | ||
<text>{{jokeInfo.cont}}</text> | ||
<view class="zan-pennel"> | ||
<text>{{jokeInfo.likes}} 人浏览</text> | ||
</view> | ||
<view class="icon-label jakes" wx:if="{{ jokeInfo.type == 0 }}"> | ||
<text># 段子</text> | ||
</view> | ||
<view class="icon-label quotation" wx:elif="{{ jokeInfo.type == 1 }}"> | ||
<text># 语录</text> | ||
</view> | ||
<view class="icon-label phrase" wx:elif="{{ jokeInfo.type == 2 }}"> | ||
<text># 心灵短语</text> | ||
</view> | ||
<view class="icon-label jakes2" wx:else> | ||
<text># 冷笑话</text> | ||
</view> | ||
<view class="flex bottom-nav"> | ||
<view class="item-box" bindtap="onClipboard"> | ||
<image src="/icons/copy2.png" width="30" hidden="30"></image> | ||
<text>文本拷贝</text> | ||
</view> | ||
<view class="item-box" bindtap="onShare"> | ||
<image src="/icons/share2.png" width="30" hidden="30"></image> | ||
<text>生成海报</text> | ||
</view> | ||
<view class="item-box" bindtap="onFollow"> | ||
<image src="/icons/follow.png" width="30" hidden="30"></image> | ||
<text>{{followText}}</text> | ||
</view> | ||
</view> | ||
</view> | ||
</view> |
Oops, something went wrong.