完成热门抓取

This commit is contained in:
HelloWorld 2020-04-14 11:00:39 +08:00
parent c6d8a76102
commit b8a482f94c
4 changed files with 91 additions and 152 deletions

View File

@ -530,6 +530,20 @@ module.exports = class extends Base {
}
}
// 获取收趣的热门书签
async hotBookmarksAction() {
let page = this.get('page');
let pageSize = parseInt(this.get('pageSize') || 50);
try {
// 如果是第0页而且是个人定制的把 最近点击 与 最近新增 的返回去。
let data = {};
data = await this.model('hot_bookmarks').order('id DESC').page(page || 1, pageSize).countSelect();
this.json({ code: 0, data });
} catch (error) {
this.json({ code: 1, msg: error.toString() });
}
}
// 获取文章
async articleAction() {
let url = this.get("url");

View File

@ -5,6 +5,8 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
return;
}
pubSubService.publish('Menus.active');
const pageSize = 40;
var timeagoInstance = timeago();
$scope.hoverBookmark = null;
$scope.bookmarks = []; // 书签数据
@ -12,18 +14,16 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
$scope.bookmarkNormalHover = false;
$scope.bookmarkEditHover = false;
const perPageItems = 40;
$scope.count = 0;
$scope.totalPages = 0;
$scope.currentPage = 1;
$scope.channelId = 1;
$scope.channelId = 0; // 0 默认是后台抓取的收趣
$scope.inputPage = '';
$scope.loadBusy = false;
$scope.curDay = 0;
$scope.loading = false;
$scope.toastrId = 0;
$scope.random = 0;
$scope.channels = JSON.parse(`[{"id":1,"name":"热门", "clicked": true},{"id":2,"name":"搞笑"},{"id":3,"name":"养生堂"},{"id":4,"name":"私房话"},{"id":5,"name":"八卦精"},{"id":6,"name":"科技咖"},{"id":7,"name":"财经迷"},{"id":8,"name":"汽车控"},{"id":9,"name":"生活家"},{"id":10,"name":"时尚圈"},{"id":11,"name":"育儿"},{"id":12,"name":"旅游"},{"id":13,"name":"职场"},{"id":14,"name":"美食"},{"id":15,"name":"历史"},{"id":16,"name":"教育"},{"id":17,"name":"星座"},{"id":18,"name":"体育"},{"id":19,"name":"军事"},{"id":20,"name":"游戏"},{"id":21,"name":"萌宠"}]`);
var timeagoInstance = timeago();
$scope.channels = JSON.parse(`[{"id":0,"name":"收趣", "clicked": true},{"id":1,"name":"热门"},{"id":2,"name":"搞笑"},{"id":3,"name":"养生堂"},{"id":4,"name":"私房话"},{"id":5,"name":"八卦精"},{"id":6,"name":"科技咖"},{"id":7,"name":"财经迷"},{"id":8,"name":"汽车控"},{"id":9,"name":"生活家"},{"id":10,"name":"时尚圈"},{"id":11,"name":"育儿"},{"id":12,"name":"旅游"},{"id":13,"name":"职场"},{"id":14,"name":"美食"},{"id":15,"name":"历史"},{"id":16,"name":"教育"},{"id":17,"name":"星座"},{"id":18,"name":"体育"},{"id":19,"name":"军事"},{"id":20,"name":"游戏"},{"id":21,"name":"萌宠"}]`);
$scope.jumpToUrl = async function (url) {
$window.open(url, '_blank');
@ -34,17 +34,15 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
var login = (menusScope && menusScope.login) || false;
if (!login) {
$scope.toastrId = toastr.info('请先登录再收藏书签!', "提示");
return;
}
} else {
let bookmark = {}
bookmark.title = b.title;
bookmark.url = b.url;
let id = await post("bookmarkAdd", bookmark);
bookmark = await get("bookmark", { id })
pubSubService.publish('EditCtr.inserBookmarsSuccess', bookmark);
}
}
$scope.storeBookmark = async function (bookmark) {
var menusScope = $('div[ng-controller="menuCtr"]').scope();
@ -52,11 +50,7 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
if (!login) {
$scope.toastrId = toastr.info('请先登录再转存书签!', "提示");
} else {
var b = $.extend(true, {}, bookmark); // 利用jQuery执行深度拷贝
b.tags = [{
name: b.createdBy
}]
pubSubService.publish('TagCtr.storeBookmark', b);
pubSubService.publish('TagCtr.storeBookmark', $.extend(true, {}, bookmark));
}
}
@ -64,12 +58,12 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
dataService.clipboard(url);
}
$scope.detailBookmark = async function (b) {
if (!b.content) {
$scope.jumpToUrl(b.url);
$scope.detailBookmark = async function (bookmark) {
if (!bookmark.content) {
$scope.jumpToUrl(bookmark.url);
return;
}
$scope.bookmark = b;
$scope.bookmark = bookmark;
$('.js-weixin-content').modal({ blurring: true }).modal('setting', 'transition', dataService.animation()).modal('show')
$timeout(function () {
$('.js-main-content').animate({ scrollTop: 0 }, 100);
@ -101,7 +95,6 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
$scope.changeCurrentPage = async function (currentPage) {
currentPage = parseInt(currentPage) || 0;
console.log(currentPage);
if (currentPage <= $scope.totalPages && currentPage >= 1) {
$scope.getWeixinArticles($scope.channelId, currentPage);
$scope.currentPage = currentPage;
@ -109,95 +102,37 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
}
$scope.getWeixinArticles = async function (channelId, page) {
var menusScope = $('div[ng-controller="menuCtr"]').scope();
$scope.bookmarks = []
$scope.bookmark = {}
$scope.loadBusy = true;
$scope.loading = true;
$scope.channelId = channelId;
$scope.currentPage = page;
$scope.totalPages = 0;
$scope.count = 0;
if (channelId == 0) {
let reply = await get("hotBookmarks", { page, pageSize });
$timeout(() => {
$scope.bookmarks = reply.data;
$scope.totalPages = reply.totalPages;
$scope.count = reply.count;
$scope.loading = false;
})
} else {
$.ajax({
url: `https://api.jisuapi.com/weixinarticle/get?channelid=${channelId}&start=${(page - 1) * perPageItems}&num=${perPageItems}&appkey=e95887468ab87d69`,
url: `https://api.jisuapi.com/weixinarticle/get?channelid=${channelId}&start=${(page - 1) * pageSize}&num=${pageSize}&appkey=e95887468ab87d69`,
type: 'get',
dataType: "jsonp",
jsonp: "callback",
success: function (body) {
dealBody(body);
getHotBookmarksbyAPI(page - 1);
},
error: function (json) {
$scope.loadBusy = false;
toastr.error('获取热门失败!失败原因:' + json.msg, "提示");
getHotBookmarksbyAPI();
}
complete: function () { $scope.loading = false },
success: function (body) { dealBody(body) },
error: function (json) { toastr.error('获取热门失败!失败原因:' + json.msg, "提示") }
});
}
async function getHotBookmarksbyAPI(page) {
let requireData = {
userId: null,
lastupdataTime: new Date().getTime(),
pageNo: 1,
pageSize: 1000,
sort: 'desc',
renderType: 0,
date: dayjs(new Date().getTime() - page * 24 * 3600 * 1000).format("YYYY年M月D日"),
idfa: "d4995f8a0c9b2ad9182369016e376278",
os: "ios",
osv: "9.3.5"
}
$.ajax({
url: "https://api.shouqu.me/api_service/api/v1/daily/dailyMark",
type: 'post',
data: requireData,
success: function (json) {
$timeout(function () {
$scope.loadBusy = false;
var alterRex = "/mmbiz.qpic.cn|images.jianshu.io|zhimg.com/g";
var defaultSnap = "./images/default.jpg"
var defaultFavicon = "./images/default.ico"
if (json.code == 200) {
var bookmarkList = json.data.list;
bookmarkList.forEach((bookmark) => {
var b = {};
b.title = bookmark.title;
b.url = bookmark.url;
b.faviconUrl = bookmark.sourceLogo || defaultFavicon;
b.createdBy = bookmark.sourceName;
b.snapUrl = defaultSnap;
if (bookmark.imageList.length >= 1) {
if (bookmark.imageList[0].url) {
b.snapUrl = (json.data.pageNo == 1 ? (bookmark.imageList[0].url.match(alterRex) != null ? defaultSnap : bookmark.imageList[0].url) : defaultSnap);
} else {
for (var i = 0; i < bookmark.images.length; i++) {
if (bookmark.images[i]) {
b.snapUrl = bookmark.images[i];
break;
}
}
}
}
b.favCount = bookmark.favCount;
b.createdAt = $filter('date')(new Date(bookmark.createtime < bookmark.updatetime ? bookmark.createtime : bookmark.updatetime), "yyyy-MM-dd HH:mm:ss");
b.lastClick = $filter('date')(new Date(bookmark.createtime > bookmark.updatetime ? bookmark.createtime : bookmark.updatetime), "yyyy-MM-dd HH:mm:ss");
b.id = bookmark.articleId;
b.index = $scope.bookmarks.length - 1;
$scope.bookmarks.unshift(b);
})
}
}, 10)
},
error: function (json) {
$scope.loadBusy = false;
toastr.error('获取热门书签失败!失败原因:' + json.message + "。将尝试从缓存中获取!", "提示");
}
});
}
function dealBody(body) {
console.log('success............', body);
$scope.loadBusy = false;
$timeout(function () {
var defaultSnap = "./images/default.jpg"
var defaultFavicon = "./images/weixin.ico"
@ -205,34 +140,22 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
var weixinArticles = body.result.list;
var id = body.result.channelid;
var total = body.result.total;
$scope.totalPages = parseInt(total / perPageItems) + 1;
$scope.channels.forEach((channel) => {
if (channel.id === id) {
channel.total = total;
}
})
$scope.count = total;
$scope.totalPages = parseInt(total / pageSize) + 1;
weixinArticles.forEach((articl, index) => {
let cdate = new Date(articl.time).getTime() + (parseInt(Math.random() * 10000000000) % 36000)
var b = {};
b.index = index;
b.title = articl.title;
b.url = articl.url;
b.faviconUrl = defaultFavicon;
b.createdBy = articl.weixinname;
b.account = articl.weixinaccount;
b.snapUrl = articl.pic || defaultSnap;
b.favCount = articl.likenum;
b.createdAt = timeagoInstance.format(cdate, 'zh_CN');
b.content = articl.content
b.content = b.content.replace(/https:\/\/mmbiz.qpic.cn/gi, "http://img01.store.sogou.com/net/a/04/link?appid=100520029&url=https://mmbiz.qpic.cn")
b.content = b.content.replace(/http:\/\/mmbiz.qpic.cn/gi, "http://img01.store.sogou.com/net/a/04/link?appid=100520029&url=https://mmbiz.qpic.cn")
b.content = $sce.trustAsHtml(b.content);
b.tags = [{
id: -1,
name: body.result.channel
}];
$scope.bookmarks.push(b);
let bookmark = {};
bookmark.index = index;
bookmark.title = articl.title;
bookmark.url = articl.url;
bookmark.icon = defaultFavicon;
bookmark.tagName = articl.weixinname;
bookmark.account = articl.weixinaccount;
bookmark.snap = articl.pic || defaultSnap;
bookmark.clickCount = articl.likenum;
bookmark.createdAt = timeagoInstance.format(articl.addtime * 1000, 'zh_CN');
bookmark.content = articl.content.replace(/https:\/\/mmbiz.qpic.cn/gi, "http://img01.store.sogou.com/net/a/04/link?appid=100520029&url=https://mmbiz.qpic.cn").replace(/http:\/\/mmbiz.qpic.cn/gi, "http://img01.store.sogou.com/net/a/04/link?appid=100520029&url=https://mmbiz.qpic.cn");
bookmark.content = $sce.trustAsHtml(bookmark.content);
$scope.bookmarks.push(bookmark);
})
} else {
toastr.error('获取热门失败!失败原因:' + body.msg, "提示");

View File

@ -1,7 +1,7 @@
<div class="ui huge text centered inline loader" ng-class="{active:loading, disabled: !loading}">
加载中,请稍候...
</div>
<div class="ui grid" style="height:45px" ng-show="!loading">
<div class="ui grid" style="height:45px;padding-top:5px;" ng-show="!loading">
<div class="fourteen wide column" ng-show="!showSearch">
共为您找到相关书签约{{bookmarkCount}}个
</div>

View File

@ -1,28 +1,28 @@
<!-- 高度至少要设置1000元素少时才能触发滚动条事件 -->
<div class="ui segment js-hot-card js-weixin-articles">
<div class="ui container" style="cursor: default;">
<div class="ui label" style="margin:3px 20px 8px 0px;cursor:default;" ng-class="{green:channel.id===channelId}" ng-repeat="channel in channels" ng-click="getWeixinArticles(channel.id, 1)">{{ channel.name }} {{ channel.total ? ('('+channel.total+')') : '' }}</div>
<div class="ui label" style="margin: 3px 15px 8px 0px; cursor: default;" ng-class="{green:channel.id===channelId}" ng-repeat="channel in channels" ng-click="getWeixinArticles(channel.id, 1)">{{ channel.name }}</div>
</div>
<div class="ui massive text centered inline loader js-hot-loader" style="margin: 50px 0px 120px 0px;" ng-class="{active:loadBusy, disabled:!loadBusy}">
<div class="ui massive text centered inline loader js-hot-loader" style="margin: 50px 0px 120px 0px;" ng-class="{active:loading, disabled:!loading}">
正在加载中...
</div>
<div class="ui divider" style="margin: 3px 0px 8px 0px;"></div>
<div class="ui five stackable cards" ng-if="!loadBusy">
<div class="ui five stackable cards" ng-if="!loading">
<div class="card" ng-repeat="bookmark in bookmarks" ng-mouseover="setHoverBookmark(bookmark)" ng-mouseleave="setHoverBookmark(null)">
<div class="content" style="max-height:70px;cursor:pointer" ng-click="detailBookmark(bookmark)">
<div class="content" style="max-height: 70px; cursor: pointer;" ng-click="detailBookmark(bookmark)">
<div class="description bookmarkTitle" title="{{bookmark.title}}">
{{bookmark.title}}
</div>
</div>
<div class="image hot-image" href="{{ bookmark.url }}" style="cursor:pointer" ng-click="detailBookmark(bookmark)">
<img ng-src="{{bookmark.snapUrl}}" />
<div class="image hot-image" href="{{ bookmark.url }}" style="cursor: pointer;" ng-click="detailBookmark(bookmark)">
<img ng-src="{{bookmark.snap}}" />
</div>
<div class="extra content" ng-show="!bookmark.edit">
<img class="ui avatar image" style="width:16px;height:16px;" ng-src="{{bookmark.faviconUrl}}" />
<span class="sourceName" title="{{ bookmark.createdBy }}">{{ bookmark.createdBy }}</span>
<span class="favCount" ng-if="bookmark.favCount">·{{ bookmark.favCount }}人收藏</span>
<img class="ui avatar image" style="width: 16px; height: 16px;" ng-src="{{bookmark.icon}}" />
<span class="sourceName" title="{{ bookmark.tagName }}">{{ bookmark.tagName }}</span>
<span class="clickCount" ng-if="bookmark.clickCount">·{{ bookmark.clickCount }}人收藏</span>
<i class="ellipsis horizontal icon right floated" style="margin-top: 6px;" ng-mouseover="bookmark.edit=true;"></i>
</div>
<div class="extra content" ng-show="bookmark.edit" ng-mouseleave="bookmark.edit=false;">
@ -37,8 +37,8 @@
<i class="close icon" ng-click="close()"></i>
<div class="header">{{ bookmark.title }}</div>
<div class="scrolling content js-main-content">
<div class="ui center aligned container" style="margin: 10px 0px">
<span style="color: #4383BF" title="公众号名称">{{bookmark.createdBy}}</span>
<div class="ui center aligned container" style="margin: 10px 0px;">
<span style="color: #4383bf;" title="公众号名称">{{bookmark.tagName}}</span>
&nbsp;&nbsp;
<span title="公众号账号">{{bookmark.account}}</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
@ -48,16 +48,16 @@
<p ng-bind-html="bookmark.content"></p>
<div class="ui divider"></div>
<div class="ui container">
<img class="ui middle aligned mini image" ng-src="{{bookmark.faviconUrl}}" style="width:16px;height:16px;padding:0;cursor:pointer;" ng-click="jumpToUrl(bookmark.url, bookmark.id)" title="点击跳转到原页面(如果过期,需要在微信中才能打开)" />
<img class="ui middle aligned mini image" ng-src="{{bookmark.icon}}" style="width: 16px; height: 16px; padding: 0; cursor: pointer;" ng-click="jumpToUrl(bookmark.url, bookmark.id)" title="点击跳转到原页面(如果过期,需要在微信中才能打开)" />
<span title="点击复制链接" ng-click="copy(bookmark.url)" class="urlSpan">{{bookmark.url}} </span>
</div>
<div class="ui divider"></div>
<div class="ui grid" ng-if="bookmark.content">
<div class="eight wide column">
<div style="float: left;cursor: pointer" ng-click="detailBookmark(bookmarks[bookmark.index-1])" ng-if="bookmarks[bookmark.index-1]"><i class="chevron left icon"></i> {{ bookmarks[bookmark.index-1].title }}</div>
<div style="float: left; cursor: pointer;" ng-click="detailBookmark(bookmarks[bookmark.index-1])" ng-if="bookmarks[bookmark.index-1]"><i class="chevron left icon"></i> {{ bookmarks[bookmark.index-1].title }}</div>
</div>
<div class="eight wide column">
<div style="float: right;cursor: pointer" ng-click="detailBookmark(bookmarks[bookmark.index+1])" ng-if="bookmarks[bookmark.index+1]">{{ bookmarks[bookmark.index+1].title }} <i class="chevron right icon"></i></div>
<div style="float: right; cursor: pointer;" ng-click="detailBookmark(bookmarks[bookmark.index+1])" ng-if="bookmarks[bookmark.index+1]">{{ bookmarks[bookmark.index+1].title }} <i class="chevron right icon"></i></div>
</div>
</div>
</div>
@ -66,7 +66,9 @@
</div>
</div>
<div class="ui grid">
<div class="four wide column"></div>
<div class="four wide column">
<div ng-if="count" style="margin-top: 14px;">共计 {{count}} 个</div>
</div>
<div class="twelve wide column">
<pagination></pagination>
</div>