提交 360fd97d 编写于 作者: ijianbo's avatar ijianbo

1、增加专题订阅功能。

2、把最新评论放到导航菜单。
3、调整打开原文,如果是个人小程序就是复制链接,如果是企业小程序会跳转网页
上级 8349982a
......@@ -10,7 +10,8 @@
"pages/readlog/readlog",
"pages/hot/hot",
"pages/pay/pay",
"pages/webpage/webpage"
"pages/webpage/webpage",
"pages/comments/comments"
],
"window": {
"backgroundTextStyle": "light",
......@@ -29,7 +30,13 @@
"iconPath": "images/tar-home.png",
"selectedIconPath": "images/tar-home-on.png",
"text": "首页"
},
},
{
"pagePath": "pages/comments/comments",
"iconPath": "images/tar-comments.png",
"selectedIconPath": "images/tar-comments-on.png",
"text": "评论"
},
{
"pagePath": "pages/readlog/readlog",
"iconPath": "images/tar-person.png",
......
/*
*
* WordPres版微信小程序
* author: jianbo
* organization: 守望轩 www.watch-life.net
* github: https://github.com/iamxjb/winxin-app-watch-life.net
* 技术支持微信号:iamxjb
* 开源协议:MIT
*
* *Copyright (c) 2017 https://www.watch-life.net All rights reserved.
*/
var Api = require('../../utils/api.js');
var util = require('../../utils/util.js');
var WxParse = require('../../wxParse/wxParse.js');
var wxApi = require('../../utils/wxApi.js')
var wxRequest = require('../../utils/wxRequest.js')
import config from '../../utils/config.js'
var pageCount = config.getPageCount;
Page({
data: {
title: '最新评论列表',
showerror: "none",
showallDisplay: "block",
readLogs: []
},
onShareAppMessage: function () {
var title = "分享“+config.getWebsiteName+”的最新评论";
var path = "pages/comments/comments";
return {
title: title,
path: path,
success: function (res) {
// 转发成功
},
fail: function (res) {
// 转发失败
}
}
},
reload: function (e) {
var self = this;
this.setData({
readLogs: []
});
self.setData({
showallDisplay: "none",
showerror: "none",
});
self.fetchCommentsData();
},
onLoad: function (options) {
var self = this;
self.fetchCommentsData();
},
//获取文章列表数据
fetchCommentsData: function () {
var self = this;
wx.showLoading({
title: '正在加载',
mask: true
});
var getNewComments = wxRequest.getRequest(Api.getNewComments());
getNewComments.then(response => {
if (response.statusCode == 200) {
this.setData({
readLogs: self.data.readLogs.concat(response.data.map(function (item) {
item[0] = item.post;
item[1] = util.removeHTML(item.content.rendered + '(' + item.author_name + ')');
item[2] = "0";
return item;
}))
});
self.setData({
showallDisplay: "block"
});
}
else {
console.log(response);
this.setData({
showerror: 'block'
});
}
}).catch(function () {
self.setData({
showerror: "block",
floatDisplay: "none"
});
})
.finally(function () {
wx.hideLoading();
})
},
// 跳转至查看文章详情
redictDetail: function (e) {
// console.log('查看文章');
var id = e.currentTarget.id,
url = '../detail/detail?id=' + id;
wx.navigateTo({
url: url
})
},
onPullDownRefresh: function () {
var self = this;
this.setData({
readLogs: []
});
self.setData({
showallDisplay: "none",
showerror: "none",
});
self.fetchCommentsData();
//消除下刷新出现空白矩形的问题。
wx.stopPullDownRefresh();
}
})
{
"enablePullDownRefresh": true
}
\ No newline at end of file
<!--
/*
*
* WordPres版微信小程序
* author: jianbo
* organization: 守望轩 www.watch-life.net
* github: https://github.com/iamxjb/winxin-app-watch-life.net
* 技术支持微信号:iamxjb
* 开源协议:MIT
* Copyright (c) 2017 https://www.watch-life.net All rights reserved.
*
*/-->
<import src="../../templates/common-list.wxml" />
<import src="../../templates/copyright.wxml" />
<view class="topic-common-list">
<view class="topic-list-item">
<image src="../../images/comments.jpg" class="cover"></image>
</view>
</view>
<view class="container">
<view class="showerror" style="display:{{showerror}}">
<image src="../../images/cry80.png" style="height:100rpx;width:100rpx"></image>
<view class="errortext">
暂时无法访问网络
<view class="">
<button class="more-button" bindtap="reload" size="mini" bindtap="reload">重新加载</button>
</view>
</view>
</view>
<view style="display:{{showallDisplay}}">
<view class="log-list">
<block wx:key="id" wx:for="{{readLogs}}">
<view class="log-items" index="{{index}}" id="{{item[0]}}" data-itemtype="{{item[2]}}" catchtap="redictDetail">
<text class="log-text">{{index + 1}}. {{item[1]}}</text>
</view>
</block>
</view>
</view>
<view class="copyright" style="display:{{floatDisplay}}">
<template is="tempCopyright" />
</view>
</view>
/*
*
* WordPres版微信小程序
* author: jianbo
* organization: 守望轩 www.watch-life.net
* github: https://github.com/iamxjb/winxin-app-watch-life.net
* 技术支持微信号:iamxjb
* 开源协议:MIT
* Copyright (c) 2017 https://www.watch-life.net All rights reserved.
*/
.list-header {
padding: 50rpx 0;
text-align: left;
font-weight: normal;
font-size: 40rpx;
line-height: 40rpx;
color: #21759b;
border-bottom: 2rpx solid #ededed;
margin-bottom: 48rpx;
}
/*topic list*/
.topic-list-item {
position: relative;
/* border-bottom: 1px solid #eee; */
overflow: hidden;
clear: both;
/* border: 1px solid #ccc; *//* border-radius: 6px;
margin-bottom: 30rpx;*/
background: #fff;
}
.topic-list-item image.cover {
width: 100%;
height: 200rpx;
/*filter: blur(4px);*/
}
.log-list {
display: flex;
flex-direction: column;
/*padding: 32rpx 0;
margin-top: 5rpx; */
}
.log-items {
margin-top: 20rpx;
}
.log-text {
margin: 32rpx 0;
font-size: 30rpx;
color: #757575;
text-align: left;
word-wrap:break-word;
word-break:break-all;
}
\ No newline at end of file
......@@ -102,16 +102,26 @@ Page({
},
gotowebpage: function () {
var self = this;
var url = '../webpage/webpage'
wx.navigateTo({
url: url + '?url=' + this.data.link
})
self.ShowHideMenu();
var minAppType = config.getMinAppType;
var url ='';
if (minAppType=="0")
{
url = '../webpage/webpage';
wx.navigateTo({
url: url + '?url=' + self.data.link
})
}
else
{
self.copyLink(self.data.link);
}
},
copyLink: function () {
this.ShowHideMenu();
copyLink: function (url) {
//this.ShowHideMenu();
wx.setClipboardData({
data: this.data.link,
data: url,
success: function (res) {
wx.getClipboardData({
success: function (res) {
......
......@@ -28,11 +28,13 @@ Page({
{ id: '2', name: '评论', selected: false},
{ id: '3', name: '点赞', selected: false },
{ id: '4', name: '赞赏', selected: false },
{ id: '5', name: '最新评论', selected: false}
{ id: '5', name: '订阅', selected: false }
],
tab: '1',
showerror: "none",
shownodata:"none"
shownodata:"none",
subscription:""
},
......@@ -53,6 +55,7 @@ Page({
self.fetchPostsData('1');
},
// 跳转至查看文章详情
redictDetail: function (e) {
......@@ -96,10 +99,6 @@ Page({
} else {
this.fetchPostsData("1");
}
},
onShow: function ()
{
},
onShareAppMessage: function () {
var title = "分享我在“" + config.getWebsiteName + "浏览、评论、点赞、赞赏的文章";
......@@ -152,7 +151,6 @@ Page({
var openid = app.globalData.openid;
var getMyCommentsPosts = wxRequest.getRequest(Api.getWeixinComment(openid));
getMyCommentsPosts.then(response => {
if (response.statusCode == 200) {
self.setData({
readLogs: self.data.readLogs.concat(response.data.data.map(function (item) {
......@@ -197,7 +195,6 @@ Page({
var openid = app.globalData.openid;
var getMylikePosts = wxRequest.getRequest(Api.getMyLikeUrl(openid));
getMylikePosts.then(response => {
if (response.statusCode == 200) {
this.setData({
readLogs: self.data.readLogs.concat(response.data.data.map(function (item) {
......@@ -277,44 +274,52 @@ Page({
}
else if (tab == '5') {
this.setData({
self.setData({
readLogs: []
});
var getNewComments = wxRequest.getRequest(Api.getNewComments());
getNewComments.then(response => {
if (response.statusCode == 200) {
this.setData({
readLogs: self.data.readLogs.concat(response.data.map(function (item) {
count++;
item[0] = item.post;
item[1] = util.removeHTML(item.content.rendered + '(' + item.author_name+')');
item[2] = "0";
return item;
}))
});
if (count == 0) {
var subscription = self.data.subscription;
if (subscription !='')
{
var url = Api.getPostsByCategories(subscription);
var getMysubPost = wxRequest.getRequest(url);
getMysubPost.then(response =>{
if (response.statusCode == 200) {
this.setData({
readLogs: self.data.readLogs.concat(response.data.map(function (item) {
count++;
item[0] = item.id;
item[1] = item.title.rendered;
item[2] = "0";
return item;
}))
});
self.setData({
shownodata: 'block'
userInfo: app.globalData.userInfo
});
}
}
else {
console.log(response);
this.setData({
showerror: 'block'
});
}
})
if (count == 0) {
self.setData({
shownodata: 'block'
});
}
}
else {
console.log(response);
this.setData({
showerror: 'block'
});
}
})
}
else{
this.setData({
showerror: 'block'
});
}
}
},
userAuthorization: function () {
var self = this;
......@@ -403,10 +408,62 @@ Page({
else {
console.log(response.data.message);
}
}).then (response=>{
self.getSubscription();
})
}).catch(function (error) {
console.log('error: ' + error.errMsg);
self.userAuthorization();
})
},
getSubscription: function () {
if (app.globalData.isGetOpenid) {
var openid = app.globalData.openid;
var url = Api.getSubscription() + '?openid=' + app.globalData.openid;
var getMysub = wxRequest.getRequest(url);
getMysub.then(response => {
if (response.statusCode == 200 && response.data.status == '200') {
var _subscription = response.data.substr;
self.setData({
subscription: _subscription
});
}
// if (response.statusCode == 200 && response.data.status == '200') {
// self.setData({
// readLogs: self.data.readLogs.concat(response.data.usermetaList.map(function (item) {
// count++;
// item[0] = item.catid;
// item[1] = item.catname;
// item[2] = "1";
// return item;
// }))
// });
// self.setData({
// userInfo: app.globalData.userInfo
// });
// if (count == 0) {
// self.setData({
// shownodata: 'block'
// });
// }
// }
// else {
// console.log(response);
// self.setData({
// showerror: 'block'
// });
// }
})
}
else {
self.userAuthorization();
}
}
})
\ No newline at end of file
......@@ -40,7 +40,7 @@
width: 128rpx;
height: 128rpx;
margin: 36rpx 0 24rpx;
border-radius: 50%;
/*border-radius: 50%;*/
}
.dec {
......
......@@ -9,10 +9,14 @@
*
* *Copyright (c) 2017 https://www.watch-life.net All rights reserved.
*/
import config from '../../utils/config.js'
var Api = require('../../utils/api.js');
var util = require('../../utils/util.js');
var auth = require('../../utils/auth.js');
var WxParse = require('../../wxParse/wxParse.js');
var wxApi = require('../../utils/wxApi.js')
var wxRequest = require('../../utils/wxRequest.js')
var wxRequest = require('../../utils/wxRequest.js');
var app = getApp();
......@@ -20,54 +24,144 @@ var wxRequest = require('../../utils/wxRequest.js')
Page({
data:{
text:"Page topic",
categoriesList:{},
floatDisplay:"none"
categoriesList:[],
floatDisplay: "none",
subImag:"subscription.png"
},
onLoad:function(options){
var self=this;
wx.setNavigationBarTitle({
title: '守望轩-专题',
success: function (res) {
// success
}
});
wx.showLoading({
title: '正在加载',
mask:true
})
this.fetchCategoriesData();
if (!app.globalData.isGetOpenid) {
self.getUsreInfo();
}
else{
self.fetchCategoriesData("1");
}
},
getUsreInfo: function () {
var self=this;
var wxLogin = wxApi.wxLogin();
var jscode = '';
wxLogin().then(response => {
jscode = response.code
var wxGetUserInfo = wxApi.wxGetUserInfo();
return wxGetUserInfo()
}).
//获取用户信息
then(response => {
console.log(response.userInfo);
console.log("成功获取用户信息(公开信息)");
app.globalData.userInfo = response.userInfo;
app.globalData.isGetUserInfo = true;
var url = Api.getOpenidUrl();
var data = {
js_code: jscode,
encryptedData: response.encryptedData,
iv: response.iv,
avatarUrl: response.userInfo.avatarUrl
}
var postOpenidRequest = wxRequest.postRequest(url, data);
//获取openid
postOpenidRequest.then(response => {
if (response.data.status == '200') {
//console.log(response.data.openid)
console.log("openid 获取成功");
app.globalData.openid = response.data.openid;
app.globalData.isGetOpenid = true;
self.fetchCategoriesData("1");
}
else {
console.log(response.data.message);
}
})
})
.catch(function (error) {
console.log('error: ' + error.errMsg);
self.fetchCategoriesData("0");
})
},
//获取分类列表
fetchCategoriesData: function () {
fetchCategoriesData: function (flag) {
var self = this;
wx.showLoading({
title: '正在加载',
mask: true
});
self.setData({
categoriesList: []
});
//console.log(Api.getCategories());
var getCategoriesRequest = wxRequest.getRequest(Api.getCategories());
getCategoriesRequest.then(response =>{
if (response.statusCode === 200)
{
self.setData({
floatDisplay: "block",
categoriesList: self.data.categoriesList.concat(response.data.map(function (item) {
if (typeof (item.category_thumbnail_image) == "undefined" || item.category_thumbnail_image == "") {
item.category_thumbnail_image = "../../images/website.png";
}
return item;
})),
});
return response
}
else
{
console.log(response);
}
}).catch(function (response) {
return null;
}
}).then(response =>{
var url = Api.getSubscription() + '?openid=' + app.globalData.openid;
var getSubscriptionRequest = wxRequest.getRequest(url);
getSubscriptionRequest.then(res =>{
var catList = res.data.subscription.wl_sub;
var categoriesList = response.data;
var newCategoriesList=[];
for (var i = 0; i < categoriesList.length;i++)
{
var subimg ="subscription.png";
var subflag="0";
for (var j = 0; j < catList.length; j++)
{
if (categoriesList[i].id == catList[j])
{
subimg = "subscription-on.png";
subflag="1";
}
var category_thumbnail_image = "";
if (typeof (categoriesList[i].category_thumbnail_image) == "undefined" || categoriesList[i].category_thumbnail_image == "") {
category_thumbnail_image = "../../images/website.png";
}
else {
category_thumbnail_image = categoriesList[i].category_thumbnail_image;
}
}
var cat = {
"category_thumbnail_image": category_thumbnail_image,
"description": categoriesList[i].description,
"name": categoriesList[i].name,
"id": categoriesList[i].id,
"subimg": subimg,
"subflag": subflag
}
newCategoriesList.push(cat);
}
if (newCategoriesList.length > 0) {
self.setData({
floatDisplay: "block",
categoriesList: newCategoriesList
});
}
})
}) .catch(function (response) {
console.log(response);
})
......@@ -82,7 +176,7 @@ Page({
onShareAppMessage: function () {
return {
title: '分享“' + config.getWebsiteName +'的专题栏目.',
title: '分享“守望轩”小程序的专题栏目.',
path: 'pages/topic/topic',
success: function (res) {
// 转发成功
......@@ -93,6 +187,131 @@ Page({
}
},
postsub:function(e){
var self=this;
if (!app.globalData.isGetOpenid) {
self.userAuthorization();
}
else
{
var categoryid = e.currentTarget.dataset.id;
var openid = app.globalData.openid ;
var url = Api.postSubscription();
var subflag = e.currentTarget.dataset.subflag;
var data = {
categoryid: categoryid,
openid: openid
};
var postSubscriptionRequest = wxRequest.postRequest(url, data);
postSubscriptionRequest.then(response => {
if (response.statusCode === 200)
{
if (response.data.status == '200')
{
setTimeout(function () {
wx.showToast({
title: '订阅成功',
icon: 'success',
duration: 900,
success: function () {
}
});
}, 900);
var subimg = "";
if (subflag == "0") {
subflag = "1";
subimg = "subscription-on.png"
}
else {
subflag = "0";
subimg = "subscription.png"
}
self.reloadData(categoryid, subflag, subimg);
}
else if (response.data.status == '201') {
setTimeout(function () {
wx.showToast({
title: '取消订阅成功',
icon: 'success',
duration: 900,
success: function () {
}
});
}, 900);
var subimg="";
if (subflag == "0") {
subflag = "1";
subimg = "subscription-on.png"
}
else {
subflag = "0";
subimg = "subscription.png"
}
self.reloadData(categoryid, subflag, subimg);
}
else if (response.data.status == '501' || response.data.status == '501' )
{
console.log(response);
}
}
else
{
setTimeout(function () {
wx.showToast({
title: '操作失败,请稍后重试',
icon: 'success',
duration: 900,
success: function () {
}
});
}, 900);
console.log(response);
}
}).catch(function (response) {
setTimeout(function () {
wx.showToast({
title: '操作失败,请稍后重试',
icon: 'success',
duration: 900,
success: function () {
}
});
}, 900);
console.log(response);
})
}
},
reloadData:function(id,subflag,subimg)
{
var self=this;
var newCategoriesList=[];
var categoriesList = self.data.categoriesList;
for (var i=0;i<categoriesList.length;i++)
{
if (categoriesList[i].id==id)
{
categoriesList[i].subflag=subflag;
categoriesList[i].subimg=subimg;
}
newCategoriesList.push(categoriesList[i]);
}
if (newCategoriesList.length > 0) {
self.setData({
categoriesList: newCategoriesList
});
}
},
//跳转至某分类下的文章列表
redictIndex: function (e) {
//console.log('查看某类别下的文章');
......@@ -102,6 +321,54 @@ Page({
wx.navigateTo({
url: url
});
}
},
userAuthorization: function () {
var self = this;
// 判断是否是第一次授权,非第一次授权且授权失败则进行提醒
wx.getSetting({
success: function success(res) {
console.log(res.authSetting);
var authSetting = res.authSetting;
if (util.isEmptyObject(authSetting)) {
console.log('第一次授权');
} else {
console.log('不是第一次授权', authSetting);
// 没有授权的提醒
if (authSetting['scope.userInfo'] === false) {
wx.showModal({
title: '用户未授权',
content: '如需正常使用评论、点赞、赞赏等功能需授权获取用户信息。是否在授权管理中选中“用户信息”?',
showCancel: true,
cancelColor: '#296fd0',
confirmColor: '#296fd0',
confirmText: '设置权限',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
wx.openSetting({
success: function success(res) {
console.log('打开设置', res.authSetting);
var scopeUserInfo = res.authSetting["scope.userInfo"];
if (scopeUserInfo) {
self.getUsreInfo();
}
}
});
}
}
})
}
}
}
});
},
confirm: function () {
this.setData({
'dialog.hidden': true,
'dialog.title': '',
'dialog.content': ''
})
}
})
\ No newline at end of file
<import src="../../templates/copyright.wxml" />
<import src="../../templates/copyright.wxml" />
<scroll-view style="height:100%;" scroll-y="true" lower-threshold="100rpx">
<view class="topic-common-list">
<scroll-view style="height:100%;" scroll-y="true" lower-threshold="100rpx">
<view class="topic-common-list">
<block wx:key="id" wx:for="{{categoriesList}}">
<view class="list-item" data-item="{{item.name}}" data-id="{{item.id}}" bindtap="redictIndex">
<view>
<image src="{{item.category_thumbnail_image}}" class="cover"></image>
</view>
<view class="content-title">
<text>{{item.name}}</text>
</view>
<view class="content-brief">
<text>{{item.description}}</text>
<view class="list-item">
<view>
<image src="{{item.category_thumbnail_image}}" class="cover" data-item="{{item.name}}" data-id="{{item.id}}" bindtap="redictIndex"></image>
</view>
<view class="content-title" data-item="{{item.name}}" data-id="{{item.id}}" bindtap="redictIndex">
<view class="topic-name">
<text>{{item.name}}</text>
</view>
<view class="topic-img">
<image src="../../images/{{item.subimg}}" data-subflag="{{item.subflag}}" data-id="{{item.id}}" catchtap="postsub" class="img-menu"></image>
</view>
</view>
<view class="content-brief" data-item="{{item.name}}" data-id="{{item.id}}" bindtap="redictIndex">
<text>{{item.description}}</text>
</view>
</view>
</view>
</block>
</view>
</scroll-view>
</view>
</scroll-view>
<view class="copyright" style="display:{{floatDisplay}}">
<template is="tempCopyright" />
</view>
\ No newline at end of file
<view class="copyright" style="display:{{floatDisplay}}">
<template is="tempCopyright" />
</view>
\ No newline at end of file
......@@ -63,3 +63,20 @@
white-space: nowrap;
color: #959595;
}
.topic-name {
float: left;
width: 70%;
}
.topic-img {
float: right;
text-align: right;
width: 30%;
}
.img-menu {
width: 40rpx;
height: 40rpx;
display: inline-block;
text-align: center;
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
"newFeature": true
},
"compileType": "miniprogram",
"libVersion": "1.6.6",
"libVersion": "1.7.2",
"appid": "wx39075d0bde24f9f7",
"projectname": "%22%E5%AE%88%E6%9C%9B%E8%BD%A9%22%E7%BD%91%E7%AB%99%E5%B0%8F%E7%A8%8B%E5%BA%8F",
"miniprogramRoot": "./",
......
......@@ -33,6 +33,11 @@ module.exports = {
},
// 获取多个分类文章列表数据
getPostsByCategories: function (categories) {
var url = HOST_URI + 'posts?per_page=20&orderby=date&order=desc&page=1&categories='+ categories;
return url;
},
// 获取置顶的文章
getStickyPosts: function () {
var url = HOST_URI + 'posts?sticky=true&per_page=5&page=1';
......@@ -245,9 +250,28 @@ module.exports = {
var url = HOST_URI_WATCH_LIFE_JSON;
url += "weixin/sendmessage";
return url;
}
} ,
//获取订阅的分类
getSubscription() {
var url = HOST_URI_WATCH_LIFE_JSON;
url += "category/getsubscription";
return url;
},
//订阅的分类
postSubscription() {
var url = HOST_URI_WATCH_LIFE_JSON;
url += "category/postsubscription";
return url;
},
//删除订阅的分类
delSubscription() {
var url = HOST_URI_WATCH_LIFE_JSON;
url += "category/delSubscription";
return url;
}
};
\ No newline at end of file
......@@ -14,6 +14,7 @@
//配置域名,域名只修改此处。
//如果wordpress没有安装在网站根目录请加上目录路径,例如:"www.watch-life.net/blog"
var DOMAIN = "www.watch-life.net";
var MINAPPTYPE="1";//小程序的类型,如果是企业小程序请填:0 ,如果是个人小程序请填:1
var WEBSITENAME="守望轩"; //网站名称
var ABOUTID = 1136; //wordpress网站"页面"的id,注意这个"页面"是wordpress的"页面",不是"文章"
var PAGECOUNT='10'; //每页文章数目
......@@ -38,5 +39,6 @@ export default {
getPageCount: PAGECOUNT,
getCategoriesID :CATEGORIESID,
getIndexNav: INDEXNAV,
getReplayTemplateId: REPLAYTEMPPLATEID
getReplayTemplateId: REPLAYTEMPPLATEID,
getMinAppType:MINAPPTYPE
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册