格式化一下显示流逝的时间

This commit is contained in:
luchenqun 2017-03-19 20:45:18 +08:00
parent 6043d064b1
commit a6caaeaef9
12 changed files with 36 additions and 35 deletions

View File

@ -641,7 +641,7 @@ db.getBookmarksByTag = function(params) {
} }
db.getBookmarksSearch = function(params) { db.getBookmarksSearch = function(params) {
var sql = "SELECT id, user_id, title, description, url, public, click_count, DATE_FORMAT(created_at, '%Y-%m-%d') as created_at, DATE_FORMAT(last_click, '%Y-%m-%d') as last_click FROM `bookmarks` WHERE 1=1"; var sql = "SELECT id, user_id, title, description, url, public, click_count, DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') as created_at, DATE_FORMAT(last_click, '%Y-%m-%d %H:%i:%s') as last_click FROM `bookmarks` WHERE 1=1";
if (params.dateCreate) { if (params.dateCreate) {
var d = new Date(); var d = new Date();
@ -701,22 +701,6 @@ db.getBookmarksSearch = function(params) {
}) })
} }
// CREATE TABLE `hot_bookmarks` (
// `id` int(11) NOT NULL AUTO_INCREMENT, -- id(articleId)
// `date` int(11) NOT NULL DEFAULT 0, -- 日期(自己添加)
// `title` varchar(255) DEFAULT NULL, -- 标题(title)
// `description` varchar(4096) DEFAULT NULL, -- 描述(自己添加)
// `url` varchar(1024) DEFAULT NULL, -- 链接(url)
// `fav_count` smallint DEFAULT 1, -- 总共收藏人数(favCount)
// `created_by` varchar(64) DEFAULT NULL, -- 创建者(sourceName)
// `created_at` bigint DEFAULT 0, -- 创建时间(updatetime)
// `last_click` bigint DEFAULT 0, -- 最后一次点击时间(createtime)
// `snap_url` varchar(1024) DEFAULT NULL, -- 截图链接(imageList[0])
// `favicon_url` varchar(1024) DEFAULT NULL, -- icon链接(sourceLogo)
// `status` tinyint(4) DEFAULT '0', -- 状态
// PRIMARY KEY (`id`)
// );
db.getHotBookmarksSearch = function(params) { db.getHotBookmarksSearch = function(params) {
var sql = "SELECT id, title, description, url, fav_count, created_by, created_at, last_click, snap_url, favicon_url FROM `hot_bookmarks` WHERE status=0"; var sql = "SELECT id, title, description, url, fav_count, created_by, created_at, last_click, snap_url, favicon_url FROM `hot_bookmarks` WHERE status=0";

View File

@ -67,5 +67,6 @@
<script src="/scripts/externe/clipboard.min.js"></script> <script src="/scripts/externe/clipboard.min.js"></script>
<script src="/scripts/externe/angular-medium-editor.min.js"></script> <script src="/scripts/externe/angular-medium-editor.min.js"></script>
<script src="/scripts/externe/medium-editor.min.js"></script> <script src="/scripts/externe/medium-editor.min.js"></script>
<script src="/scripts/externe/timeago.min.js"></script>
</body> </body>
</html> </html>

View File

@ -63,6 +63,14 @@ app.config(function($stateProvider, $urlRouterProvider, $httpProvider) {
}); });
}); });
//自定义过滤器
app.filter('formatDate', function() {
return function(date) {
console.log(date);
return 22222;
}
})
console.log([ console.log([
" _ooOoo_", " _ooOoo_",
" o8888888o", " o8888888o",

View File

@ -1,4 +1,4 @@
app.controller('bookmarkInfoCtr', ['$scope', '$state', '$timeout', '$sce', '$window', '$filter', '$document', 'bookmarkService', 'pubSubService', function($scope, $state, $timeout, $sce, $window, $filter, $document, bookmarkService, pubSubService) { app.controller('bookmarkInfoCtr', ['$scope', '$state', '$timeout', '$sce', '$window', '$filter', '$document', '$timeout', 'bookmarkService', 'pubSubService', function($scope, $state, $timeout, $sce, $window, $filter, $document, $timeout, bookmarkService, pubSubService) {
console.log("Hello bookmarkInfoCtr"); console.log("Hello bookmarkInfoCtr");
$scope.bookmark = {} $scope.bookmark = {}
$scope.content = ''; $scope.content = '';
@ -19,7 +19,7 @@ app.controller('bookmarkInfoCtr', ['$scope', '$state', '$timeout', '$sce', '$win
requestId: 1 requestId: 1
} }
$scope.loading = true; $scope.loading = true;
setTimeout(function() { $timeout(function() {
$('.ui.modal.js-bookmark-info').modal("refresh"); $('.ui.modal.js-bookmark-info').modal("refresh");
}, 500); }, 500);
bookmarkService.getArticle(params) bookmarkService.getArticle(params)

View File

@ -190,6 +190,11 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
} else { } else {
$scope.bookmarks = $scope.bookmarkData.bookmarksLatestClick; $scope.bookmarks = $scope.bookmarkData.bookmarksLatestClick;
} }
$timeout(function() {
var timeagoInstance = timeago();
timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN');
}, 100)
} }
$scope.updateCostomTagBookmarks = function(index) { $scope.updateCostomTagBookmarks = function(index) {

View File

@ -273,6 +273,10 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
} }
function transition() { function transition() {
$timeout(function() {
var timeagoInstance = timeago();
timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN');
}, 100)
var className = 'js-table-search'; var className = 'js-table-search';
$('.' + className).transition('hide'); $('.' + className).transition('hide');
$('.' + className).transition({ $('.' + className).transition({

View File

@ -41,6 +41,10 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
} else { } else {
$scope.bookmarks = $scope.bookmarkData.bookmarksLatestClick; $scope.bookmarks = $scope.bookmarkData.bookmarksLatestClick;
} }
$timeout(function() {
var timeagoInstance = timeago();
timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN');
}, 100)
} }
$scope.getBookmarks = function(tagId, currentPage) { $scope.getBookmarks = function(tagId, currentPage) {

1
public/scripts/externe/timeago.min.js vendored Normal file
View File

@ -0,0 +1 @@
!function(t,e){"object"==typeof module&&module.exports?module.exports=e(t):t.timeago=e(t)}("undefined"!=typeof window?window:this,function(){function t(t){return t instanceof Date?t:isNaN(t)?/^\d+$/.test(t)?new Date(e(t)):(t=(t||"").trim().replace(/\.\d+/,"").replace(/-/,"/").replace(/-/,"/").replace(/(\d)T(\d)/,"$1 $2").replace(/Z/," UTC").replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"),new Date(t)):new Date(e(t))}function e(t){return parseInt(t)}function n(t,n,r){n=d[n]?n:d[r]?r:"en";var i=0,a=t<0?1:0;for(t=Math.abs(t);t>=l[i]&&i<h;i++)t/=l[i];return t=e(t),i*=2,t>(0===i?9:1)&&(i+=1),d[n](t,i)[a].replace("%s",t)}function r(e,n){return n=n?t(n):new Date,(n-t(e))/1e3}function i(t){for(var e=1,n=0,r=Math.abs(t);t>=l[n]&&n<h;n++)t/=l[n],e*=l[n];return r%=e,r=r?e-r:e,Math.ceil(r)}function a(t){return t.dataset.timeago?t.dataset.timeago:t.getAttribute?t.getAttribute(p):t.attr?t.attr(p):void 0}function o(t,e){function o(a,c,f,s){var d=r(c,t);a.innerHTML=n(d,f,e),u["k"+s]=setTimeout(function(){o(a,c,f,s)},Math.min(1e3*i(d),2147483647))}var u={};return e||(e="en"),this.format=function(i,a){return n(r(i,t),a,e)},this.render=function(t,e){void 0===t.length&&(t=[t]);for(var n=0;n<t.length;n++)o(t[n],a(t[n]),e,++c)},this.cancel=function(){for(var t in u)clearTimeout(u[t]);u={}},this.setLocale=function(t){e=t},this}function u(t,e){return new o(t,e)}var c=0,f="second_minute_hour_day_week_month_year".split("_"),s="秒_分钟_小时_天_周_月_年".split("_"),d={en:function(t,e){if(0===e)return["just now","right now"];var n=f[parseInt(e/2)];return t>1&&(n+="s"),[t+" "+n+" ago","in "+t+" "+n]},zh_CN:function(t,e){if(0===e)return["刚刚","片刻后"];var n=s[parseInt(e/2)];return[t+n+"前",t+n+"后"]}},l=[60,60,24,7,365/7/12,12],h=6,p="datetime";return u.register=function(t,e){d[t]=e},u});

View File

@ -19,10 +19,10 @@
</div> </div>
<div class="two column row"> <div class="two column row">
<div class="column"> <div class="column">
<i class="add to calendar icon"></i>创建日期:{{bookmark.created_at}} <i class="add to calendar icon"></i>创建日期:<span>{{bookmark.created_at}}</span>
</div> </div>
<div class="column"> <div class="column">
<i class="calendar icon"></i>最后点击:{{bookmark.last_click}} <i class="calendar icon"></i>最后点击:<span>{{bookmark.last_click}}</span>
</div> </div>
</div> </div>
<div class="two column row"> <div class="two column row">

View File

@ -103,12 +103,10 @@
</td> </td>
<td>{{ bookmark.click_count }}</td> <td>{{ bookmark.click_count }}</td>
<td> <td>
<span title="{{bookmark.created_at}}">{{ bookmark.created_at.substr(0, 10) }} <span title="{{bookmark.created_at}}" class="need_to_be_rendered" data-timeago="{{bookmark.created_at}}"></span>
</span>
</td> </td>
<td> <td>
<span title="{{bookmark.last_click}}">{{ bookmark.last_click.substr(0, 10) }} <span title="{{bookmark.last_click}}" class="need_to_be_rendered" data-timeago="{{bookmark.last_click}}"></span>
</span>
</td> </td>
<td> <td>
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="jumpToTags(tag.id)"> <div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="jumpToTags(tag.id)">

View File

@ -154,12 +154,10 @@
</td> </td>
<td>{{ bookmark.click_count || bookmark.fav_count }}</td> <td>{{ bookmark.click_count || bookmark.fav_count }}</td>
<td> <td>
<span title="{{bookmark.created_at}}">{{ bookmark.created_at.substr(0, 10) }} <span title="{{bookmark.created_at}}" class="need_to_be_rendered" data-timeago="{{bookmark.created_at}}"></span>
</span>
</td> </td>
<td> <td>
<span title="{{bookmark.last_click}}">{{ bookmark.last_click.substr(0, 10) }} <span title="{{bookmark.last_click}}" class="need_to_be_rendered" data-timeago="{{bookmark.last_click}}"></span>
</span>
</td> </td>
<td> <td>
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-if="!searchHotBookmarks"> <div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-if="!searchHotBookmarks">

View File

@ -73,12 +73,10 @@
</td> </td>
<td>{{ bookmark.click_count }}</td> <td>{{ bookmark.click_count }}</td>
<td> <td>
<span title="{{bookmark.created_at}}">{{ bookmark.created_at.substr(0, 10) }} <span title="{{bookmark.created_at}}" class="need_to_be_rendered" data-timeago="{{bookmark.created_at}}"></span>
</span>
</td> </td>
<td> <td>
<span title="{{bookmark.last_click}}">{{ bookmark.last_click.substr(0, 10) }} <span title="{{bookmark.last_click}}" class="need_to_be_rendered" data-timeago="{{bookmark.last_click}}"></span>
</span>
</td> </td>
<td> <td>
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="getBookmarks(tag.id, 1)"> <div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="getBookmarks(tag.id, 1)">