diff --git a/schema.sql b/schema.sql index 8ffe47a..836d997 100644 --- a/schema.sql +++ b/schema.sql @@ -68,9 +68,9 @@ CREATE TABLE `hot_bookmarks` ( `description` varchar(4096) DEFAULT NULL, -- 描述(自己添加) `url` varchar(1024) DEFAULT NULL, -- 链接(url) `favCount` smallint DEFAULT 1, -- 总共收藏人数(favCount) - `createdBy` varchar(64) DEFAULT NULL, -- 创建者(sourceName) - `createdAt` bigint DEFAULT 0, -- 创建时间(updatetime) - `lastClick` bigint DEFAULT 0, -- 最后一次点击时间(createtime) + `createdBy` varchar(64) DEFAULT NULL, -- 创建者(sourceName) + `createdAt` datetime DEFAULT now(), -- 创建时间(updatetime) + `lastClick` datetime DEFAULT now(), -- 最后一次点击时间(createtime) `snapUrl` varchar(1024) DEFAULT NULL, -- 截图链接(imageList[0]) `faviconUrl` varchar(1024) DEFAULT NULL, -- icon链接(sourceLogo) `status` tinyint(4) DEFAULT '0', -- 状态 diff --git a/src/controller/api.js b/src/controller/api.js index 29b54e9..36796d6 100644 --- a/src/controller/api.js +++ b/src/controller/api.js @@ -261,19 +261,48 @@ module.exports = class extends Base { async bookmarksSearchAction() { let condition = {}; let keyword = this.get("keyword"); - let username = this.get("username"); - if (username) { + let tagIds = this.get("tagIds") || []; + let range = this.get("range") || "self"; // self hot other + let createdAt = this.get("createdAt"); + let lastClick = this.get("lastClick"); + let tableName = "bookmarks"; - } else { + if (range == "self") { condition.userId = this.ctx.state.user.id; + } else if (range == "hot") { + tableName = "hot_bookmarks"; + } else if (range == "other") { + condition.userId = ['!=', this.ctx.state.user.id]; } - if (keyword) { - condition.url = ['like', `%${keyword}%`]; + condition._complex = { + url: ['like', `%${keyword}%`], + title: ['like', `%${keyword}%`], + _logic: 'or' + } + } + if (tagIds.length > 0) { + condition.tagId = ['IN', tagIds]; + } + if (createdAt) { + condition.createdAt = ['between', createdAt]; + } + if (lastClick) { + condition.lastClick = ['between', lastClick]; } try { - let data = await this.model('bookmarks').where(condition).page(this.get('page') || 1, this.get('pageSize') || 50).countSelect(); + let data = await this.model(tableName).where(condition).page(this.get('page') || 1, this.get('pageSize') || 20).countSelect(); + if (tableName == "bookmarks") { + let ids = []; + for (let bookmark of data.data) { + ids.push(bookmark.tagId); + } + let tags = await this.model('tags').where({ id: ['IN', ids] }).select(); + for (let bookmark of data.data) { + bookmark.tagName = (tags.find((tag) => tag.id == bookmark.tagId) || { name: "未知分类" }).name; + } + } this.json({ code: 0, data }); } catch (error) { this.json({ code: 1, msg: error.toString() }); diff --git a/view/index_index.html b/view/index_index.html index a6bb730..2da8d19 100644 --- a/view/index_index.html +++ b/view/index_index.html @@ -95,6 +95,7 @@ + diff --git a/www/scripts/controllers/search-controller.js b/www/scripts/controllers/search-controller.js index 65a4137..e48c643 100644 --- a/www/scripts/controllers/search-controller.js +++ b/www/scripts/controllers/search-controller.js @@ -1,11 +1,11 @@ -app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$window', '$timeout', '$document', 'ngDialog', 'bookmarkService', 'pubSubService', 'dataService', function ($scope, $state, $stateParams, $filter, $window, $timeout, $document, ngDialog, bookmarkService, pubSubService, dataService) { +app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$window', '$timeout', '$document', 'ngDialog', 'pubSubService', 'dataService', function ($scope, $state, $stateParams, $filter, $window, $timeout, $document, ngDialog, pubSubService, dataService) { console.log("Hello searchCtr...", $stateParams); if (dataService.smallDevice()) { $window.location = "http://m.mybookmark.cn/#/tags"; return; } - const perPageItems = 20; + const pageSize = 20; var dialog = null; $scope.hoverBookmark = null; $scope.searchBookmarks = []; // 书签数据 @@ -16,13 +16,11 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi $scope.dateCreateEnd = ''; $scope.dateClickBegin = ''; $scope.dateClickEnd = ''; - $scope.clickCount = ''; - $scope.username = ''; - $scope.userRange = ''; + $scope.range = 'self'; $scope.bookmarkCount = 0; $scope.tags = [] $scope.totalPages = 0; - $scope.page = 1; + $scope.currentPage = 1; $scope.inputPage = ''; $scope.loading = false; $scope.waitDelBookmark = {}; @@ -31,9 +29,8 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi $scope.changeCurrentPage = async function (page) { page = parseInt(page) || 0; - console.log(page); if (page <= $scope.totalPages && page >= 1) { - $scope.page = page; + $scope.currentPage = page; $scope.inputPage = ''; $scope.search(); } @@ -49,26 +46,14 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi index: dataService.LoginIndexBookmarks }); - var searchParams = { - keyword: $scope.keyword, - page: 1, - perPageItems: perPageItems, - userRange: '1', // 默认搜索自己的书签 - } - if ($scope.keyword) { - searchBookmarks(searchParams); - } else { - toastr.warning("请输入搜索关键字再进行查询!", "提示"); - } - $scope.jumpToUrl = async function (url, id) { if (!$scope.edit) { $window.open(url); await post("clickBookmark", { id }); $scope.searchBookmarks.forEach(function (bookmark) { - if (bookmark.id == id && bookmark.own) { - bookmark.click_count += 1; + if (bookmark.id == id) { + bookmark.clickCount += 1; bookmark.lastClick = $filter("date")(new Date(), "yyyy-MM-dd HH:mm:ss"); } }) @@ -122,49 +107,53 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi dataService.clipboard(url); } - $scope.search = async function (page) { - var params = {} - params.userRange = $('.js-user-range').dropdown('get value'); - if (params.userRange == '1') { - var tags = $('.js-search-tags').dropdown('get value') - if (tags) { - params.tags = tags; + $scope.search = async function () { + let params = {}; + + params.range = $('.js-user-range').dropdown('get value'); + + if (params.range == 'self') { + let tagIds = $('.js-search-tags').dropdown('get value'); + if (tagIds) { + params.tagIds = tagIds; } - } else if ($scope.username) { - params.username = $scope.username } + if ($scope.keyword) { params.keyword = $scope.keyword; } - var dateCreate = $('.js-create-date').dropdown('get value') || undefined; - console.log('dateCreate = ', dateCreate) - if (dateCreate) { - if (dateCreate != -1) { - params.dateCreate = dateCreate; - } - } else { - params.dateCreateBegin = $scope.dateCreateBegin; - params.dateCreateEnd = $scope.dateCreateEnd; + let createdAt = parseInt($('.js-create-date').dropdown('get value') || 0); + console.log('dateCreate = ', createdAt) + if (createdAt > 0) { + params.createdAt = dayjs(Date.now() - createdAt * 24 * 60 * 60 * 1000).format('YYYY-MM-DD HH:mm:ss') + "," + dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss'); + } else if ($scope.dateCreateBegin && $scope.dateCreateEnd) { + params.createdAt = dayjs($scope.dateCreateBegin).format('YYYY-MM-DD HH:mm:ss') + "," + dayjs($scope.dateCreateEnd).format('YYYY-MM-DD HH:mm:ss'); } - var dateClick = $('.js-click-date').dropdown('get value') || undefined; - console.log('dateClick = ', dateClick) - if (dateClick) { - if (dateClick != -1) { - params.dateClick = dateClick - } - } else { - params.dateClickBegin = $scope.dateClickBegin; - params.dateClickEnd = $scope.dateClickEnd; + let lastClick = parseInt($('.js-click-date').dropdown('get value') || 0); + console.log('lastClick = ', lastClick) + if (lastClick > 0) { + params.lastClick = dayjs(Date.now() - lastClick * 24 * 60 * 60 * 1000).format('YYYY-MM-DD HH:mm:ss') + "," + dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss'); + } else if ($scope.dateClickBegin && $scope.dateClickEnd) { + params.lastClick = dayjs($scope.dateClickBegin).format('YYYY-MM-DD HH:mm:ss') + "," + dayjs($scope.dateClickEnd).format('YYYY-MM-DD HH:mm:ss'); } - params.page = page ? page : $scope.page; - params.perPageItems = perPageItems; - $scope.page = params.page; - searchBookmarks(params) - console.log('search..', page, 'params = ', params) + params.page = $scope.currentPage || 1; + params.pageSize = pageSize; + console.log('params = ', params) + + let reply = await get('bookmarksSearch', params); + + $timeout(() => { + $scope.searchBookmarks = reply.data; + $scope.totalPages = reply.totalPages; + $scope.bookmarkCount = reply.count; + $scope.loading = false; + }) + transition(); } + $scope.updateCreateDate = async function () { console.log($scope.dateCreateBegin, $scope.dateCreateEnd); if ($scope.dateCreateBegin && $scope.dateCreateEnd) { @@ -225,40 +214,32 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi }); async function searchBookmarks(params) { + console.log(params); + $scope.loading = true; $('.js-table-search').transition('hide'); - if ($scope.searchHotBookmarks) { - console.log(params); - bookmarkService.searchHotBookmarks(params) - .then((data) => { - $scope.searchBookmarks = []; - data.bookmarks.forEach((bookmark) => { - bookmark.tags = [{ - id: -1, - name: bookmark.created_by, // 给转存用 - }] - bookmark.createdAt = $filter('date')(new Date(bookmark.createdAt), "yyyy-MM-dd HH:mm:ss"); - bookmark.lastClick = $filter('date')(new Date(bookmark.lastClick), "yyyy-MM-dd HH:mm:ss"); - $scope.searchBookmarks.push(bookmark); - }) - $scope.bookmarkCount = data.totalItems; - $scope.totalPages = Math.ceil($scope.bookmarkCount / perPageItems); - $scope.loading = false; - transition(); - }) - .catch((err) => { - console.log('searchHotBookmarks err', err); - $scope.loading = false; - }); - } else { - console.log(params); - let reply = await get('bookmarksSearch', params); - $scope.searchBookmarks = reply.data; - $scope.totalPages = reply.totalPages; - $scope.bookmarkCount = reply.count; - $scope.loading = false; - transition(); - } + + // bookmarkService.searchHotBookmarks(params) + // .then((data) => { + // $scope.searchBookmarks = []; + // data.bookmarks.forEach((bookmark) => { + // bookmark.tags = [{ + // id: -1, + // name: bookmark.created_by, // 给转存用 + // }] + // bookmark.createdAt = $filter('date')(new Date(bookmark.createdAt), "yyyy-MM-dd HH:mm:ss"); + // bookmark.lastClick = $filter('date')(new Date(bookmark.lastClick), "yyyy-MM-dd HH:mm:ss"); + // $scope.searchBookmarks.push(bookmark); + // }) + // $scope.bookmarkCount = data.totalItems; + // $scope.totalPages = Math.ceil($scope.bookmarkCount / pageSize); + // $scope.loading = false; + // transition(); + // }) + // .catch((err) => { + // console.log('searchHotBookmarks err', err); + // $scope.loading = false; + // }); } function transition() { @@ -274,4 +255,6 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi }); } + $scope.search(); + }]); diff --git a/www/scripts/directives/js-init-directive.js b/www/scripts/directives/js-init-directive.js index 2b91bc6..4ab1978 100644 --- a/www/scripts/directives/js-init-directive.js +++ b/www/scripts/directives/js-init-directive.js @@ -55,7 +55,7 @@ app.directive('jsDataCreateInit', function ($compile) { startCalendar: $('.ui.calendar.js-date-create-begin') }); - $('.js-create-date').dropdown('set value', -1); + $('.js-create-date').dropdown('set value', '36500'); }, }; }); @@ -84,7 +84,7 @@ app.directive('jsDataClickInit', function ($compile) { }, startCalendar: $('.ui.calendar.js-date-click-begin') }); - $('.js-click-date').dropdown('set value', -1); + $('.js-click-date').dropdown('set value', '36500'); }, }; }); @@ -96,14 +96,14 @@ app.directive('jsDropdownUserRangeInit', function ($compile, $timeout) { $('.ui.dropdown.js-user-range').dropdown({ onChange: function (value, text, $choice) { $timeout(function () { - $scope.showTags = (value == '1'); - $scope.searchHotBookmarks = (value == '3'); + $scope.showTags = (value == 'self'); + $scope.searchHotBookmarks = (value == 'hot'); $scope.bookmarks = []; $scope.totalPages = 0 }) }, }); - $('.js-user-range').dropdown('set value', '1'); + $('.js-user-range').dropdown('set value', 'self'); }, }; }); diff --git a/www/scripts/externe/dayjs.min.js b/www/scripts/externe/dayjs.min.js new file mode 100644 index 0000000..ac8df8c --- /dev/null +++ b/www/scripts/externe/dayjs.min.js @@ -0,0 +1 @@ +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.dayjs=n()}(this,function(){"use strict";var t="millisecond",n="second",e="minute",r="hour",i="day",s="week",u="month",o="quarter",a="year",h=/^(\d{4})-?(\d{1,2})-?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d{1,3})?$/,f=/\[([^\]]+)]|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c=function(t,n,e){var r=String(t);return!r||r.length>=n?t:""+Array(n+1-r.length).join(e)+t},d={s:c,z:function(t){var n=-t.utcOffset(),e=Math.abs(n),r=Math.floor(e/60),i=e%60;return(n<=0?"+":"-")+c(r,2,"0")+":"+c(i,2,"0")},m:function(t,n){var e=12*(n.year()-t.year())+(n.month()-t.month()),r=t.clone().add(e,u),i=n-r<0,s=t.clone().add(e+(i?-1:1),u);return Number(-(e+(n-r)/(i?r-s:s-r))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(h){return{M:u,y:a,w:s,d:i,D:"date",h:r,m:e,s:n,ms:t,Q:o}[h]||String(h||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},$={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},l="en",m={};m[l]=$;var y=function(t){return t instanceof v},M=function(t,n,e){var r;if(!t)return l;if("string"==typeof t)m[t]&&(r=t),n&&(m[t]=n,r=t);else{var i=t.name;m[i]=t,r=i}return e||(l=r),r},g=function(t,n,e){if(y(t))return t.clone();var r=n?"string"==typeof n?{format:n,pl:e}:n:{};return r.date=t,new v(r)},D=d;D.l=M,D.i=y,D.w=function(t,n){return g(t,{locale:n.$L,utc:n.$u,$offset:n.$offset})};var v=function(){function c(t){this.$L=this.$L||M(t.locale,null,!0),this.parse(t)}var d=c.prototype;return d.parse=function(t){this.$d=function(t){var n=t.date,e=t.utc;if(null===n)return new Date(NaN);if(D.u(n))return new Date;if(n instanceof Date)return new Date(n);if("string"==typeof n&&!/Z$/i.test(n)){var r=n.match(h);if(r)return e?new Date(Date.UTC(r[1],r[2]-1,r[3]||1,r[4]||0,r[5]||0,r[6]||0,r[7]||0)):new Date(r[1],r[2]-1,r[3]||1,r[4]||0,r[5]||0,r[6]||0,r[7]||0)}return new Date(n)}(t),this.init()},d.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},d.$utils=function(){return D},d.isValid=function(){return!("Invalid Date"===this.$d.toString())},d.isSame=function(t,n){var e=g(t);return this.startOf(n)<=e&&e<=this.endOf(n)},d.isAfter=function(t,n){return g(t)搜索范围 @@ -25,8 +25,8 @@
创建时间不限
-
- -
- +
@@ -151,8 +148,8 @@ -
- {{ tag.name }} +
+ {{ bookmark.tagName }}
{{ bookmark.createdBy }}