完成随机查看收趣收藏

This commit is contained in:
HelloWorld 2020-04-14 11:35:47 +08:00
parent b8a482f94c
commit 7425be2690
2 changed files with 31 additions and 8 deletions

View File

@ -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() { async articleAction() {
let url = this.get("url"); let url = this.get("url");

View File

@ -23,7 +23,7 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
$scope.loading = false; $scope.loading = false;
$scope.toastrId = 0; $scope.toastrId = 0;
$scope.random = 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) { $scope.jumpToUrl = async function (url) {
$window.open(url, '_blank'); $window.open(url, '_blank');
@ -77,8 +77,14 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
// 快捷键r随机推荐 // 快捷键r随机推荐
$document.bind("keydown", function (event) { $document.bind("keydown", function (event) {
$scope.$apply(function () { $scope.$apply(async () => {
var key = event.key.toUpperCase(); 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 ($scope.hoverBookmark && dataService.keyShortcuts()) {
if (key == 'I') { if (key == 'I') {
$scope.detailBookmark($scope.hoverBookmark) $scope.detailBookmark($scope.hoverBookmark)
@ -102,15 +108,22 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
} }
$scope.getWeixinArticles = async function (channelId, page) { $scope.getWeixinArticles = async function (channelId, page) {
$scope.bookmarks = [] $scope.bookmarks = [];
$scope.bookmark = {} $scope.bookmark = {};
$scope.loading = true; $scope.loading = true;
$scope.channelId = channelId; $scope.channelId = channelId;
$scope.currentPage = page; $scope.currentPage = page;
$scope.totalPages = 0; $scope.totalPages = 0;
$scope.count = 0; $scope.count = 0;
if (channelId == -1) {
if (channelId == 0) { 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 }); let reply = await get("hotBookmarks", { page, pageSize });
$timeout(() => { $timeout(() => {
$scope.bookmarks = reply.data; $scope.bookmarks = reply.data;
@ -138,7 +151,6 @@ app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$filter', '$win
var defaultFavicon = "./images/weixin.ico" var defaultFavicon = "./images/weixin.ico"
if (body.status == 0) { if (body.status == 0) {
var weixinArticles = body.result.list; var weixinArticles = body.result.list;
var id = body.result.channelid;
var total = body.result.total; var total = body.result.total;
$scope.count = total; $scope.count = total;
$scope.totalPages = parseInt(total / pageSize) + 1; $scope.totalPages = parseInt(total / pageSize) + 1;