diff --git a/src/controller/api.js b/src/controller/api.js index 14ecc48..d0dc764 100644 --- a/src/controller/api.js +++ b/src/controller/api.js @@ -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"); diff --git a/www/scripts/controllers/weixin-article-controller.js b/www/scripts/controllers/weixin-article-controller.js index b7a411e..4987d72 100644 --- a/www/scripts/controllers/weixin-article-controller.js +++ b/www/scripts/controllers/weixin-article-controller.js @@ -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,16 +34,14 @@ 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); } - - 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) { @@ -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; - $.ajax({ - url: `https://api.jisuapi.com/weixinarticle/get?channelid=${channelId}&start=${(page - 1) * perPageItems}&num=${perPageItems}&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(); - } - }); - } + $scope.count = 0; - 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" + 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) * pageSize}&num=${pageSize}&appkey=e95887468ab87d69`, + type: 'get', + dataType: "jsonp", + jsonp: "callback", + complete: function () { $scope.loading = false }, + success: function (body) { dealBody(body) }, + error: function (json) { toastr.error('获取热门失败!失败原因:' + json.msg, "提示") } + }); } - - $.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, "提示"); diff --git a/www/views/search.html b/www/views/search.html index b3132ad..a0e6040 100644 --- a/www/views/search.html +++ b/www/views/search.html @@ -1,7 +1,7 @@