From 7425be2690d39fdc53cba7974ea3803f928bc2a4 Mon Sep 17 00:00:00 2001 From: HelloWorld Date: Tue, 14 Apr 2020 11:35:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=9A=8F=E6=9C=BA=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E6=94=B6=E8=B6=A3=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/api.js | 11 ++++++++ .../controllers/weixin-article-controller.js | 28 +++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/controller/api.js b/src/controller/api.js index d0dc764..a28f8b6 100644 --- a/src/controller/api.js +++ b/src/controller/api.js @@ -544,6 +544,17 @@ module.exports = class extends Base { } } + // 随机获取收趣的热门书签 + async hotBookmarksRandomAction() { + try { + let sql = `SELECT * FROM hot_bookmarks ORDER BY RAND() LIMIT 50;`; + let data = await this.model('hot_bookmarks').query(sql); + 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 4987d72..a23a855 100644 --- a/www/scripts/controllers/weixin-article-controller.js +++ b/www/scripts/controllers/weixin-article-controller.js @@ -23,7 +23,7 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win $scope.loading = false; $scope.toastrId = 0; $scope.random = 0; - $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.channels = JSON.parse(`[{"id":0,"name":"收趣"},{"id":-1,"name":"随机一批"},{"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'); @@ -77,8 +77,14 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win // 快捷键r随机推荐 $document.bind("keydown", function (event) { - $scope.$apply(function () { - var key = event.key.toUpperCase(); + $scope.$apply(async () => { + let key = event.key.toUpperCase(); + let menusScope = $('div[ng-controller="menuCtr"]').scope(); + let blur = (menusScope && menusScope.blur) || false; + if (key == 'R' && (!blur)) { + $scope.getWeixinArticles(-1, 1); + } + if ($scope.hoverBookmark && dataService.keyShortcuts()) { if (key == 'I') { $scope.detailBookmark($scope.hoverBookmark) @@ -102,15 +108,22 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win } $scope.getWeixinArticles = async function (channelId, page) { - $scope.bookmarks = [] - $scope.bookmark = {} + $scope.bookmarks = []; + $scope.bookmark = {}; $scope.loading = true; $scope.channelId = channelId; $scope.currentPage = page; $scope.totalPages = 0; $scope.count = 0; - - if (channelId == 0) { + if (channelId == -1) { + let data = await get("hotBookmarksRandom"); + $timeout(() => { + $scope.bookmarks = data; + $scope.totalPages = 1; + $scope.count = data.length; + $scope.loading = false; + }) + } else if (channelId == 0) { let reply = await get("hotBookmarks", { page, pageSize }); $timeout(() => { $scope.bookmarks = reply.data; @@ -138,7 +151,6 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win var defaultFavicon = "./images/weixin.ico" if (body.status == 0) { var weixinArticles = body.result.list; - var id = body.result.channelid; var total = body.result.total; $scope.count = total; $scope.totalPages = parseInt(total / pageSize) + 1;