From bab9c124ce397f04b8cab8aada87dde14a90ff2b Mon Sep 17 00:00:00 2001 From: luchenqun Date: Thu, 8 Aug 2019 14:28:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=BE=AE=E4=BF=A1=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E6=9B=BF=E6=8D=A2=E6=8E=89=E7=83=AD=E6=90=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- public/images/weixin.ico | Bin 0 -> 507 bytes public/index.html | 2 +- public/scripts/app-angular.js | 8 +- .../controllers/bookmark-info-controller.js | 23 +- .../controllers/weixin-article-controller.js | 305 ++++++++++++++++++ public/scripts/services/data-service.js | 4 +- public/views/bookmark-info.html | 16 +- public/views/tags.html | 10 +- public/views/weixin-article.html | 87 +++++ 10 files changed, 424 insertions(+), 35 deletions(-) create mode 100644 public/images/weixin.ico create mode 100644 public/scripts/controllers/weixin-article-controller.js create mode 100644 public/views/weixin-article.html diff --git a/README.md b/README.md index c378ac5..b88a16e 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ my-bookmark/ │ │ │ ├── bookmarks-controller.js # 书签页面控制器 │ │ │ ├── edit-controller.js # 编辑书签页面控制器 │ │ │ ├── home-controller.js # 未登录时首页页面控制器 -│ │ │ ├── hot-controller.js # 热门收藏页面控制器 +│ │ │ ├── weixin-article-controller.js # 热门收藏页面控制器 │ │ │ ├── login-controller.js # 登陆注册页面控制器 │ │ │ ├── menus-controller.js # 菜单栏控制器 │ │ │ ├── note-controller.js # 备忘录控制器 @@ -116,7 +116,7 @@ my-bookmark/ | | ├── dialog-del-tag.html # 分类删除确认页面 | | ├── edit.html # 书签添加修改页面 | | ├── home.html # 未登录时首页页面 -| | ├── hot.html # 热门收藏页面 +| | ├── weixin-article.html # 热门收藏页面 | | ├── login.html # 登陆注册页面 | | ├── menus.html # 菜单组件 | | ├── note.html # 备忘录页面 diff --git a/public/images/weixin.ico b/public/images/weixin.ico new file mode 100644 index 0000000000000000000000000000000000000000..a1b4cf60a47195b11831bba4450b931916ebd44f GIT binary patch literal 507 zcmV1PYB!qAnDFgew=~%7quA*$CYh|3sn7 z;t%i-Xcvw32JVD{t8TJa>SdSOj!+N`&3rT8>tbphn}CYG%ZGD)&w+oGodok6^Y`mf z?VdAt0q7jz-JtMkQe=-0`UekZ7HGX_UW)TmZ(PlFR0sl~N|XbOjF5%hJRV<3Z+?AG ziJ`gP>?fhIW6nDA!lnnqFyw_f>m;GE(_C-%j|(*BPCr5dfuvDZ_yORt;~9Nc_<^Jm z0;DnraEpW1bBioNV6ia{ektvx{Sd+yu51xP*h+h8e;oXh#RdY4ELnWgdS>0t_6N)^ zqOzOB$m6$bBsYNgXoEb%zf4Fjo6-Fdi}cYtPurQvlB%ud3>Bg(iwp(*G!~G_JH*~E zo{6bsIAT?7fb5Htcvo8amvSH#Z{2cl`I_1E*?uQ;#@XKa>u%Ln@p-mp^*=0P;N}eP z^R=N340Y!JX7`j!2==?W)9&%NqO6A;?Bnw=q3_MPZ+ xp?rJqPI`OhWDA3Z2i?u~u*xJMrZ4he^&Q+AzXMz;FXR9K002ovPDHLkV1jSI>W2UT literal 0 HcmV?d00001 diff --git a/public/index.html b/public/index.html index d8e82f5..2aeb871 100644 --- a/public/index.html +++ b/public/index.html @@ -85,7 +85,7 @@ - + diff --git a/public/scripts/app-angular.js b/public/scripts/app-angular.js index 2766bff..ea74290 100644 --- a/public/scripts/app-angular.js +++ b/public/scripts/app-angular.js @@ -12,10 +12,10 @@ app.config(function($stateProvider, $urlRouterProvider, $httpProvider) { }, controller: 'bookmarksCtr' }) - .state('hot', { - url: '/hot', - templateUrl: '/views/hot.html', - controller: 'hotCtr' + .state('weixin-article', { + url: '/weixin-article', + templateUrl: '/views/weixin-article.html', + controller: 'weixinArticleCtr' }) .state('praise', { url: '/praise', diff --git a/public/scripts/controllers/bookmark-info-controller.js b/public/scripts/controllers/bookmark-info-controller.js index 86f9462..59ee48d 100644 --- a/public/scripts/controllers/bookmark-info-controller.js +++ b/public/scripts/controllers/bookmark-info-controller.js @@ -13,17 +13,18 @@ app.controller('bookmarkInfoCtr', ['$scope', '$state', '$timeout', '$sce', '$win bookmark.snap_url = bookmark.snap_url || ('./images/snap/' + bookmark.id + '.png'); $scope.bookmark = bookmark; $scope.bookmark.description = $sce.trustAsHtml(bookmark.description); - $scope.content = ''; + $scope.content = $sce.trustAsHtml(bookmark.content) || ''; var params = { url: bookmark.url, requestId: 1 } - $scope.loading = true; - $timeout(function() { - $('.ui.modal.js-bookmark-info').modal("refresh"); - $("p").css("word-wrap", "break-word"); - }, 500); - bookmarkService.getArticle(params) + if (!$scope.content) { + $timeout(function() { + $('.ui.modal.js-bookmark-info').modal("refresh"); + $("p").css("word-wrap", "break-word"); + }, 500); + $scope.loading = true + bookmarkService.getArticle(params) .then((data) => { $scope.content = data.content ? $sce.trustAsHtml(data.content) : $sce.trustAsHtml('

数据获取失败,可能是服务器不允许获取,或者是https网站!

'); setTimeout(function() { @@ -35,6 +36,14 @@ app.controller('bookmarkInfoCtr', ['$scope', '$state', '$timeout', '$sce', '$win $scope.content = $sce.trustAsHtml('

数据获取失败:' + JSON.stringify(err) + '

'); $scope.loading = false; }) + } else { + setTimeout(function() { + $('.ui.modal.js-bookmark-info').modal && $('.ui.modal.js-bookmark-info').modal("refresh"); + }, 10); + setTimeout(function() { + $('.modals').animate({ scrollTop: 0 }, 100); + }, 500); + } }); $scope.jumpToUrl = function(url, id) { diff --git a/public/scripts/controllers/weixin-article-controller.js b/public/scripts/controllers/weixin-article-controller.js new file mode 100644 index 0000000..4a714a6 --- /dev/null +++ b/public/scripts/controllers/weixin-article-controller.js @@ -0,0 +1,305 @@ +app.controller('weixinArticleCtr', ['$scope', '$state', '$sce', '$stateParams', '$filter', '$window', '$timeout', '$document', 'ngDialog', 'bookmarkService', 'pubSubService', 'dataService', function($scope, $state, $sce, $stateParams, $filter, $window, $timeout, $document, ngDialog, bookmarkService, pubSubService, dataService) { + console.log("Hello weixinArticleCtr..."); + if(dataService.smallDevice()){ + $window.location = "http://m.mybookmark.cn/#/tags"; + return; + } + var key = curentDate(undefined, "yyyyMMdd"); + + $scope.hoverBookmark = null; + $scope.bookmarks = []; // 书签数据 + $scope.bookmark = {}; + $scope.bookmarkNormalHover = false; + $scope.bookmarkEditHover = false; + + const perPageItems = 40; + $scope.totalPages = 0; + $scope.currentPage = 1; + $scope.channelId = 1; + + $scope.inputPage = ''; + $scope.loadBusy = false; + $scope.curDay = 0; + $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":"萌宠"}]`); + $scope.callCount = parseInt((localStorage && localStorage.getItem('weixin' + key)) || 1); + $scope.maxCallCount = 100; + $scope.user = {}; + var timeagoInstance = timeago(); + + bookmarkService.autoLogin() + .then((data) => { + var login = data.logined; + var index = login ? dataService.LoginIndexHot : dataService.NotLoginIndexHot; + $scope.user = data.user || {}; + pubSubService.publish('Common.menuActive', { + login: login, + index: index + }); + }) + .catch((err) => { + console.log('autoLogin err', err) + }); + + $scope.jumpToUrl = function(url) { + $window.open(url, '_blank'); + } + + $scope.favoriteBookmark = function(b) { + var menusScope = $('div[ng-controller="menuCtr"]').scope(); + var login = (menusScope && menusScope.login) || false; + if (!login) { + $scope.toastrId = toastr.info('请先登录再收藏书签!', "提示"); + return; + } + + var bookmark = {} + bookmark.description = ''; + bookmark.title = b.title; + bookmark.url = b.url; + bookmark.public = 1; + bookmark.click_count = 1; + + bookmarkService.favoriteBookmark(bookmark) + .then((data) => { + pubSubService.publish('EditCtr.inserBookmarsSuccess', data); + if (data.title) { + toastr.success('[ ' + data.title + ' ] 收藏成功!', "提示"); + } else { + toastr.error('[ ' + bookmark.title + ' ] 收藏失败!', "提示"); + } + }) + .catch((err) => { + toastr.error('[ ' + bookmark.title + ' ] 收藏失败,' + JSON.stringify(err), "提示"); + }); + } + + $scope.storeBookmark = function(bookmark) { + var menusScope = $('div[ng-controller="menuCtr"]').scope(); + var login = (menusScope && menusScope.login) || false; + if (!login) { + $scope.toastrId = toastr.info('请先登录再转存书签!', "提示"); + } else { + var b = $.extend(true, {}, bookmark); // 利用jQuery执行深度拷贝 + b.tags = [{ + name: b.created_by + }] + pubSubService.publish('TagCtr.storeBookmark', b); + } + } + + $scope.copy = function(url) { + dataService.clipboard(url); + } + + $scope.detailBookmark = function(b) { + if(!b.content) { + $scope.jumpToUrl(b.url); + return; + } + $scope.bookmark = b; + setTimeout(function() { + $('body,html').animate({scrollTop:0},100); + }, 100); + } + + // 快捷键r随机推荐 + $document.bind("keydown", function(event) { + $scope.$apply(function() { + // console.log(event.keyCode); + var menusScope = $('div[ng-controller="menuCtr"]').scope(); + var login = (menusScope && menusScope.login) || false; + var blur = (menusScope && menusScope.blur) || false; + // r按键,显示 + if (event.keyCode == 82 && login && (!blur)) { + $scope.randomHotBookmarks(); + } + + var key = event.key.toUpperCase(); + if ($scope.hoverBookmark && dataService.keyShortcuts()) { + if (key == 'I') { + $scope.detailBookmark($scope.hoverBookmark) + } else if (key == 'C') { + $scope.copy($scope.hoverBookmark.url) + } + } + }) + }); + + $scope.randomHotBookmarks = function() { + var menusScope = $('div[ng-controller="menuCtr"]').scope(); + var login = (menusScope && menusScope.login) || false; + if (login) { + $scope.random = true; + var beginDay = new Date(2016, 7, 15); // 注意日期是从0 ~ 11 + var now = new Date(); + var dayGap = parseInt(Math.abs(now - beginDay) / (1000 * 60 * 60 * 24)) + 1; + $scope.curDay = -(parseInt(Math.random() * 1000000) % dayGap); + $scope.bookmarks = []; + getHotBookmarksbyCache(); + } else { + $scope.toastrId = toastr.info('您只有先登录,才能使用查看随机热门标签', "提示"); + } + } + + $scope.setHoverBookmark = function(bookmark) { + $scope.hoverBookmark = bookmark; + } + + $scope.changeCurrentPage = function (currentPage) { + currentPage = parseInt(currentPage) || 0; + console.log(currentPage); + if (currentPage <= $scope.totalPages && currentPage >= 1) { + $scope.getWeixinArticles($scope.channelId, currentPage); + $scope.currentPage = currentPage; + } + } + + $scope.getWeixinArticles = function(channelId, page) { + var menusScope = $('div[ng-controller="menuCtr"]').scope(); + var login = (menusScope && menusScope.login) || false; + var index = login ? dataService.LoginIndexHot : dataService.NotLoginIndexHot; + pubSubService.publish('Common.menuActive', { + login: login, + index: index + }); + $scope.bookmarks = [] + $scope.bookmark = {} + $scope.loadBusy = true; + $scope.channelId = channelId; + $scope.currentPage = page; + $scope.totalPages = 0; + var start = (page - 1) * perPageItems; + var api = `https://api.jisuapi.com/weixinarticle/get?channelid=${channelId}&start=${start}&num=${perPageItems}&appkey=e95887468ab87d69`; + if(localStorage) { + var count = parseInt(localStorage.getItem('weixin' + key) || 1); + if (count <= $scope.maxCallCount || $scope.user.username === 'lcq') { + $.ajax({ + url: api, + type: 'get', + dataType : "jsonp", + jsonp : "callback", + success: function(body) { + dealBody(body); + }, + error: function(json) { + $scope.loadBusy = false; + toastr.error('获取热门失败!失败原因:' + json.msg, "提示"); + getHotBookmarksbyCache(); + } + }); + localStorage.setItem('weixin' + key, count+1) + $scope.callCount = count+1; + } else { + getHotBookmarksbyCache(); + toastr.warning('每天只允许实时调用 100 次剩下的只从缓存中获取', "提示"); + } + } else { + getHotBookmarksbyCache(); + } + } + + function getHotBookmarksbyCache() { + $scope.loadBusy = true; + var date = curentDate($scope.curDay, "yyyyMMdd"); + if (date < "20160715") { + toastr.info('您已将将所有的热门标签都加载完了!', "提示"); + $scope.loadBusy = false; + return; // 这是最早的了。 + } + var params = { + date: date, + } + bookmarkService.getHotBookmarks(params) + .then((data) => { + data.forEach((bookmark) => { + bookmark.created_at = $filter('date')(new Date(bookmark.updatetime), "yyyy-MM-dd HH:mm:ss"); + bookmark.edit = false; + $scope.bookmarks.push(bookmark); + }) + $scope.curDay--; + $scope.loadBusy = false; + if (data && data.length == 0) { + getHotBookmarksbyCache(); // 没有继续请求 + } + }) + .catch((err) => { + toastr.error("getHotBookmarksbyCache: " + JSON.stringify(err), "提示"); + $scope.curDay--; + $scope.loadBusy = false; + getHotBookmarksbyCache(); // 没有继续请求 + }); + } + + // TODO: 我要将编辑按钮固定在容器的右上角 + + function curentDate(i, format) { + if (i == undefined) { + i = 0; + } + if (format == undefined) { + format = 'yyyyMMddhhmmss' + } + var now = new Date(); + now.setTime(now.getTime() + i * 24 * 60 * 60 * 1000); + clock = $filter('date')(now, format); + return clock; + } + + function dealBody(body) { + console.log('success............', body); + $scope.loadBusy = false; + var defaultSnap = "./images/default.jpg" + var defaultFavicon = "./images/weixin.ico" + $timeout(function() { + if (body.status == 0) { + 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; + } + }) + + 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.favicon_url = defaultFavicon; + b.created_by = articl.weixinname; + b.account = articl.weixinaccount; + b.snap_url = articl.pic || defaultSnap; + b.fav_count = articl.likenum; + b.created_at = 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); + }) + } else { + toastr.error('获取热门失败!失败原因:' + body.msg, "提示"); + } + }, 100); + } + + $document.bind("keydown", function(event) { + $scope.$apply(function() { + // Esc按键,退出 + if (event.keyCode == 27) { + $scope.bookmark = {}; + } + }) + }); + + $scope.getWeixinArticles($scope.channelId, $scope.currentPage); +}]); diff --git a/public/scripts/services/data-service.js b/public/scripts/services/data-service.js index 9dc5810..c33be74 100644 --- a/public/scripts/services/data-service.js +++ b/public/scripts/services/data-service.js @@ -25,7 +25,7 @@ app.factory('dataService', [function() { uiSref: 'note', title: '备忘' }, { - uiSref: 'hot', + uiSref: 'weixin-article', title: '热门' }, { uiSref: 'settings', @@ -41,7 +41,7 @@ app.factory('dataService', [function() { uiSref: 'login', title: '登录' }, { - uiSref: 'hot', + uiSref: 'weixin-article', title: '热门' }], animationIndex: 0, diff --git a/public/views/bookmark-info.html b/public/views/bookmark-info.html index 4a18ff0..c4293db 100644 --- a/public/views/bookmark-info.html +++ b/public/views/bookmark-info.html @@ -49,20 +49,8 @@
-
-
-
- 描述信息 -
-
{{ bookmark.description }}
-
-
-
-
-
-
- 内容摘抄 -
+
+

diff --git a/public/views/tags.html b/public/views/tags.html index d7a051e..ef02595 100644 --- a/public/views/tags.html +++ b/public/views/tags.html @@ -1,22 +1,22 @@
-
+
-
+
{{ costomTag.name }} ({{ costomTag.cnt || 0 }})
-
+
{{ tag.name }} ({{ tag.cnt || 0 }})
-
+
{{ costomAllUsersTag.name }} ({{ costomAllUsersTag.cnt || 0 }})
-
+
diff --git a/public/views/weixin-article.html b/public/views/weixin-article.html new file mode 100644 index 0000000..7bccf00 --- /dev/null +++ b/public/views/weixin-article.html @@ -0,0 +1,87 @@ + +
+
+
{{ channel.name }} {{ channel.total ? ('('+channel.total+')') : '' }}
+
+
+ +
+ +
+ 正在加载中...
+ +
+
+
+
+
+ {{bookmark.title}} +
+
+
+ +
+
+ + {{ bookmark.created_by }} + ·{{ bookmark.fav_count }}人收藏 + +
+
+ + + + +
+
+
+
+
+ {{bookmark.title}} +
+
+ {{bookmark.created_by}} +    + {{bookmark.account}} +        + {{bookmark.created_at}} +
+
+
+
+

+
+
+
+
+ + {{bookmark.url}} + +
+
+
+
+
+
+ {{ bookmarks[bookmark.index-1].title }}
+
+
+
+ {{ bookmarks[bookmark.index+1].title }}
+
+
+
+
+
+ +
+
+ +
+
+
\ No newline at end of file