Skip to content

Commit

Permalink
新增详情 和 海报生成页面
Browse files Browse the repository at this point in the history
  • Loading branch information
blue68 committed Nov 22, 2019
1 parent 579b381 commit e5bd065
Show file tree
Hide file tree
Showing 27 changed files with 780 additions and 60 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- 每日一语
- 精选趣文
- 查询列表页面
- 详情页面
- 海报生成页面
- 搜索页面
- 我的页面
- 我的关注
Expand Down Expand Up @@ -37,6 +39,22 @@ module.exports = {

````

#### App_id 值变更

```js
1. 修改 project.config.json
// "appid": "小程序appid"
2. 修改 utils/util.js 文件中 APP_ID & 变量为自己申请的值
// const APP_ID = '自己申请的APP_ID';
// const APP_KEY = '自己申请的APP_KEY';
```


#### 签名相关逻辑

```js
Expand Down Expand Up @@ -128,6 +146,8 @@ function aiReq(param) {
![首页](./images/index.png)
![列表](./images/list.png)
![详情](./images/detail.png)
![海报生成](./images/shareimg.png)
![搜索](./images/search.png)
![我的关注](./images/like.png)
![沸点](./images/feidian.png)
Expand Down
25 changes: 21 additions & 4 deletions cloudfunctions/jokelikes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const MAX_LIMIT = 20;
// 云函数入口函数
exports.main = async (event, context) => {
if (event.getList == true) {
const resultCount = await likesTable.count();
const total = resultCount.total;

try {
return await likesTable.where({
userId: event.userId
Expand All @@ -33,6 +30,25 @@ exports.main = async (event, context) => {
} catch (e) {
console.error('likes-getList----0', e)
}
} else if (event.getLikes == true) {
try {
return await likesTable.where({
userId: event.userId,
jokeId: event.jokeId
}).field({
jokeId: true,
_id: true
}).get({
success: (res) => {
if (res && res.length > 0) {
return res;
}
return [];
}
});
} catch (e) {
console.error('likes-getLikes----0', e)
}
} else if (event.setSelf == true) {
try {
let _data = {
Expand All @@ -44,7 +60,8 @@ exports.main = async (event, context) => {
return await likesTable.add({
data: _data
}).then(e => {
return _data;
console.log('===========jokelikes add===', e._id);
return Object.assign(_data, e);;
}).catch(console.error)
} catch (e) {
console.error('likes-setSelf----0', e);
Expand Down
Binary file added images/detail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/shareimg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion miniprogram/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"pages/translation/index",
"pages/translation/texttrans/index",
"pages/translation/speechtranslate/index",
"pages/translation/imagetranslate/index"
"pages/translation/imagetranslate/index",
"pages/quwen/detail",
"pages/quwen/share"
],
"window": {
"backgroundColor": "#F6F6F6",
Expand Down
Binary file added miniprogram/icons/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprogram/icons/copy2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprogram/icons/follow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added miniprogram/icons/wxcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions miniprogram/pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,23 @@ Page({
title: '一起欣赏趣文之乐',
path: `pages/index/index`
}
},
onDetail: function (e) {
let dataset = e.currentTarget.dataset;
let id = this.data.recommend._id;

if (dataset && dataset.id) {
id = dataset.id;
}

app.checkAuth(function (flag) {
if (flag) {
wx.redirectTo({
url: '/pages/quwen/detail?jokeId=' + id
});
} else {
app.navigateToLogin(); // 跳转至登录页面
}
});
}
});
8 changes: 4 additions & 4 deletions miniprogram/pages/index/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
</navigator>
</view>
<view class="cont-box qwfd-listview">
<view class='item-container' >
<text>{{ recommend.cont }}</text>
<view class='item-container' bindtap="onDetail">
<text>{{ recommend.cont }}</text>
<view class="share-box" style="{{publish == 0 ? 'display:none': 'display:block;'}}">
<image src="/icons/share.png"></image>
<text>分享</text>
Expand All @@ -63,11 +63,11 @@
</view>
<view class="cont-box qwfd-listview">
<block wx:for="{{ hostList }}" wx:key="item">
<view class='item-container' data-index="{{ index }}" data-id="{{ item._id }}">
<view class='item-container' data-index="{{ index }}" data-id="{{ item._id }}" bindtap="onDetail">
<text>{{ item.cont }}</text>
<view class="zan-pennel">
<image src="/icons/love2.png"></image>
<text>被关注{{ item.likes }}次</text>
<text>被浏览{{ item.likes }}次</text>
</view>
<view class="icon-label jakes" wx:if="{{ item.type == 0 }}">
<text># 段子</text>
Expand Down
2 changes: 1 addition & 1 deletion miniprogram/pages/jokelike/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<view class="zan-pennel">
<view>
<image src="/icons/zan.png"></image>
<text>被关注{{ item.likes }}次</text>
<text>被浏览{{ item.likes }}次</text>
</view>
<view class="zan-sub" bindtap="unlike" data-jokelikeId="{{item.jokelikeId}}">
<image src="/icons/unlike.png"></image>
Expand Down
1 change: 1 addition & 0 deletions miniprogram/pages/me/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Util from '../../utils/util';

const app = getApp();
let self;

Expand Down
176 changes: 176 additions & 0 deletions miniprogram/pages/quwen/detail.js
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'
});
}
});
},
})
3 changes: 3 additions & 0 deletions miniprogram/pages/quwen/detail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usingComponents": {}
}
35 changes: 35 additions & 0 deletions miniprogram/pages/quwen/detail.wxml
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>
Loading

0 comments on commit e5bd065

Please sign in to comment.