完成搜索功能

This commit is contained in:
HelloWorld 2020-03-30 22:20:15 +08:00
parent 31fe4b063d
commit e72e08d033
7 changed files with 124 additions and 113 deletions

View File

@ -68,9 +68,9 @@ CREATE TABLE `hot_bookmarks` (
`description` varchar(4096) DEFAULT NULL, -- 描述(自己添加) `description` varchar(4096) DEFAULT NULL, -- 描述(自己添加)
`url` varchar(1024) DEFAULT NULL, -- 链接(url) `url` varchar(1024) DEFAULT NULL, -- 链接(url)
`favCount` smallint DEFAULT 1, -- 总共收藏人数(favCount) `favCount` smallint DEFAULT 1, -- 总共收藏人数(favCount)
`createdBy` varchar(64) DEFAULT NULL, -- 创建者(sourceName) `createdBy` varchar(64) DEFAULT NULL, -- 创建者(sourceName)
`createdAt` bigint DEFAULT 0, -- 创建时间(updatetime) `createdAt` datetime DEFAULT now(), -- 创建时间(updatetime)
`lastClick` bigint DEFAULT 0, -- 最后一次点击时间(createtime) `lastClick` datetime DEFAULT now(), -- 最后一次点击时间(createtime)
`snapUrl` varchar(1024) DEFAULT NULL, -- 截图链接(imageList[0]) `snapUrl` varchar(1024) DEFAULT NULL, -- 截图链接(imageList[0])
`faviconUrl` varchar(1024) DEFAULT NULL, -- icon链接(sourceLogo) `faviconUrl` varchar(1024) DEFAULT NULL, -- icon链接(sourceLogo)
`status` tinyint(4) DEFAULT '0', -- 状态 `status` tinyint(4) DEFAULT '0', -- 状态

View File

@ -261,19 +261,48 @@ module.exports = class extends Base {
async bookmarksSearchAction() { async bookmarksSearchAction() {
let condition = {}; let condition = {};
let keyword = this.get("keyword"); let keyword = this.get("keyword");
let username = this.get("username"); let tagIds = this.get("tagIds") || [];
if (username) { 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; 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) { 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 { 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 }); this.json({ code: 0, data });
} catch (error) { } catch (error) {
this.json({ code: 1, msg: error.toString() }); this.json({ code: 1, msg: error.toString() });

View File

@ -95,6 +95,7 @@
<script src="scripts/externe/ngDialog.min.js"></script> <script src="scripts/externe/ngDialog.min.js"></script>
<script src="scripts/externe/clipboard.min.js"></script> <script src="scripts/externe/clipboard.min.js"></script>
<script src="scripts/externe/timeago.min.js"></script> <script src="scripts/externe/timeago.min.js"></script>
<script src="scripts/externe/dayjs.min.js"></script>
<script src="scripts/externe/md5.js"></script> <script src="scripts/externe/md5.js"></script>
<script src="scripts/externe/pnglib.js"></script> <script src="scripts/externe/pnglib.js"></script>
<script src="scripts/externe/identicon.js"></script> <script src="scripts/externe/identicon.js"></script>

View File

@ -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); console.log("Hello searchCtr...", $stateParams);
if (dataService.smallDevice()) { if (dataService.smallDevice()) {
$window.location = "http://m.mybookmark.cn/#/tags"; $window.location = "http://m.mybookmark.cn/#/tags";
return; return;
} }
const perPageItems = 20; const pageSize = 20;
var dialog = null; var dialog = null;
$scope.hoverBookmark = null; $scope.hoverBookmark = null;
$scope.searchBookmarks = []; // 书签数据 $scope.searchBookmarks = []; // 书签数据
@ -16,13 +16,11 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
$scope.dateCreateEnd = ''; $scope.dateCreateEnd = '';
$scope.dateClickBegin = ''; $scope.dateClickBegin = '';
$scope.dateClickEnd = ''; $scope.dateClickEnd = '';
$scope.clickCount = ''; $scope.range = 'self';
$scope.username = '';
$scope.userRange = '';
$scope.bookmarkCount = 0; $scope.bookmarkCount = 0;
$scope.tags = [] $scope.tags = []
$scope.totalPages = 0; $scope.totalPages = 0;
$scope.page = 1; $scope.currentPage = 1;
$scope.inputPage = ''; $scope.inputPage = '';
$scope.loading = false; $scope.loading = false;
$scope.waitDelBookmark = {}; $scope.waitDelBookmark = {};
@ -31,9 +29,8 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
$scope.changeCurrentPage = async function (page) { $scope.changeCurrentPage = async function (page) {
page = parseInt(page) || 0; page = parseInt(page) || 0;
console.log(page);
if (page <= $scope.totalPages && page >= 1) { if (page <= $scope.totalPages && page >= 1) {
$scope.page = page; $scope.currentPage = page;
$scope.inputPage = ''; $scope.inputPage = '';
$scope.search(); $scope.search();
} }
@ -49,26 +46,14 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
index: dataService.LoginIndexBookmarks 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) { $scope.jumpToUrl = async function (url, id) {
if (!$scope.edit) { if (!$scope.edit) {
$window.open(url); $window.open(url);
await post("clickBookmark", { id }); await post("clickBookmark", { id });
$scope.searchBookmarks.forEach(function (bookmark) { $scope.searchBookmarks.forEach(function (bookmark) {
if (bookmark.id == id && bookmark.own) { if (bookmark.id == id) {
bookmark.click_count += 1; bookmark.clickCount += 1;
bookmark.lastClick = $filter("date")(new Date(), "yyyy-MM-dd HH:mm:ss"); 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); dataService.clipboard(url);
} }
$scope.search = async function (page) { $scope.search = async function () {
var params = {} let params = {};
params.userRange = $('.js-user-range').dropdown('get value');
if (params.userRange == '1') { params.range = $('.js-user-range').dropdown('get value');
var tags = $('.js-search-tags').dropdown('get value')
if (tags) { if (params.range == 'self') {
params.tags = tags; let tagIds = $('.js-search-tags').dropdown('get value');
if (tagIds) {
params.tagIds = tagIds;
} }
} else if ($scope.username) {
params.username = $scope.username
} }
if ($scope.keyword) { if ($scope.keyword) {
params.keyword = $scope.keyword; params.keyword = $scope.keyword;
} }
var dateCreate = $('.js-create-date').dropdown('get value') || undefined; let createdAt = parseInt($('.js-create-date').dropdown('get value') || 0);
console.log('dateCreate = ', dateCreate) console.log('dateCreate = ', createdAt)
if (dateCreate) { if (createdAt > 0) {
if (dateCreate != -1) { 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');
params.dateCreate = dateCreate; } 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');
} else {
params.dateCreateBegin = $scope.dateCreateBegin;
params.dateCreateEnd = $scope.dateCreateEnd;
} }
var dateClick = $('.js-click-date').dropdown('get value') || undefined; let lastClick = parseInt($('.js-click-date').dropdown('get value') || 0);
console.log('dateClick = ', dateClick) console.log('lastClick = ', lastClick)
if (dateClick) { if (lastClick > 0) {
if (dateClick != -1) { 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');
params.dateClick = dateClick } 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');
} else {
params.dateClickBegin = $scope.dateClickBegin;
params.dateClickEnd = $scope.dateClickEnd;
} }
params.page = page ? page : $scope.page;
params.perPageItems = perPageItems;
$scope.page = params.page; params.page = $scope.currentPage || 1;
searchBookmarks(params) params.pageSize = pageSize;
console.log('search..', page, 'params = ', params) 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 () { $scope.updateCreateDate = async function () {
console.log($scope.dateCreateBegin, $scope.dateCreateEnd); console.log($scope.dateCreateBegin, $scope.dateCreateEnd);
if ($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) { async function searchBookmarks(params) {
console.log(params);
$scope.loading = true; $scope.loading = true;
$('.js-table-search').transition('hide'); $('.js-table-search').transition('hide');
if ($scope.searchHotBookmarks) {
console.log(params); // bookmarkService.searchHotBookmarks(params)
bookmarkService.searchHotBookmarks(params) // .then((data) => {
.then((data) => { // $scope.searchBookmarks = [];
$scope.searchBookmarks = []; // data.bookmarks.forEach((bookmark) => {
data.bookmarks.forEach((bookmark) => { // bookmark.tags = [{
bookmark.tags = [{ // id: -1,
id: -1, // name: bookmark.created_by, // 给转存用
name: bookmark.created_by, // 给转存用 // }]
}] // bookmark.createdAt = $filter('date')(new Date(bookmark.createdAt), "yyyy-MM-dd HH:mm:ss");
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");
bookmark.lastClick = $filter('date')(new Date(bookmark.lastClick), "yyyy-MM-dd HH:mm:ss"); // $scope.searchBookmarks.push(bookmark);
$scope.searchBookmarks.push(bookmark); // })
}) // $scope.bookmarkCount = data.totalItems;
$scope.bookmarkCount = data.totalItems; // $scope.totalPages = Math.ceil($scope.bookmarkCount / pageSize);
$scope.totalPages = Math.ceil($scope.bookmarkCount / perPageItems); // $scope.loading = false;
$scope.loading = false; // transition();
transition(); // })
}) // .catch((err) => {
.catch((err) => { // console.log('searchHotBookmarks err', err);
console.log('searchHotBookmarks err', err); // $scope.loading = false;
$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();
}
} }
function transition() { function transition() {
@ -274,4 +255,6 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
}); });
} }
$scope.search();
}]); }]);

View File

@ -55,7 +55,7 @@ app.directive('jsDataCreateInit', function ($compile) {
startCalendar: $('.ui.calendar.js-date-create-begin') 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') 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({ $('.ui.dropdown.js-user-range').dropdown({
onChange: function (value, text, $choice) { onChange: function (value, text, $choice) {
$timeout(function () { $timeout(function () {
$scope.showTags = (value == '1'); $scope.showTags = (value == 'self');
$scope.searchHotBookmarks = (value == '3'); $scope.searchHotBookmarks = (value == 'hot');
$scope.bookmarks = []; $scope.bookmarks = [];
$scope.totalPages = 0 $scope.totalPages = 0
}) })
}, },
}); });
$('.js-user-range').dropdown('set value', '1'); $('.js-user-range').dropdown('set value', 'self');
}, },
}; };
}); });

1
www/scripts/externe/dayjs.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -14,9 +14,9 @@
<div class="text">搜索范围</div> <div class="text">搜索范围</div>
<i class="dropdown icon"></i> <i class="dropdown icon"></i>
<div class="menu"> <div class="menu">
<div class="active item" data-value="1">自己书签</div> <div class="active item" data-value="self">自己书签</div>
<div class="item" data-value="2">全站书签</div> <div class="item" data-value="other">全站书签</div>
<div class="item" data-value="3">热门收藏</div> <div class="item" data-value="hot">热门收藏</div>
</div> </div>
</div> </div>
</div> </div>
@ -25,8 +25,8 @@
<div class="text">创建时间不限</div> <div class="text">创建时间不限</div>
<i class="dropdown icon"></i> <i class="dropdown icon"></i>
<div class="menu"> <div class="menu">
<div class="active item" data-value="-1">创建时间不限</div> <div class="active item" data-value="36500">创建时间不限</div>
<div class="item" data-value="0">今天</div> <div class="item" data-value="1">今天</div>
<div class="item" data-value="7">一周内</div> <div class="item" data-value="7">一周内</div>
<div class="item" data-value="31">一月内</div> <div class="item" data-value="31">一月内</div>
<div class="item" data-value="365">一年内</div> <div class="item" data-value="365">一年内</div>
@ -59,8 +59,8 @@
<div class="text">点击时间不限</div> <div class="text">点击时间不限</div>
<i class="dropdown icon"></i> <i class="dropdown icon"></i>
<div class="menu"> <div class="menu">
<div class="active item" data-value="-1">点击时间不限</div> <div class="active item" data-value="36500">点击时间不限</div>
<div class="item" data-value="0">今天</div> <div class="item" data-value="1">今天</div>
<div class="item" data-value="7">一周内</div> <div class="item" data-value="7">一周内</div>
<div class="item" data-value="31">一月内</div> <div class="item" data-value="31">一月内</div>
<div class="item" data-value="365">一年内</div> <div class="item" data-value="365">一年内</div>
@ -89,9 +89,6 @@
</div> </div>
</div> </div>
<div class="two wide column" ng-show="showSearch"> <div class="two wide column" ng-show="showSearch">
<div class="ui transparent icon input" ng-show="(!showTags) && (!searchHotBookmarks)">
<input class="prompt" type="text" placeholder="用户账号" ng-model="username" ng-keypress="($event.which === 13)?search(1):0" />
</div>
<div class="ui grid container" style="padding-top: 8px;"> <div class="ui grid container" style="padding-top: 8px;">
<div class="ui multiple dropdown js-search-tags" style="padding:0;" ng-show="showTags" js-dropdown-tags-init> <div class="ui multiple dropdown js-search-tags" style="padding:0;" ng-show="showTags" js-dropdown-tags-init>
<div class="default text">分类选择</div> <div class="default text">分类选择</div>
@ -104,7 +101,7 @@
</div> </div>
<div class="two wide column" ng-show="showSearch"> <div class="two wide column" ng-show="showSearch">
<div class="ui transparent input"> <div class="ui transparent input">
<input type="text" placeholder="标题,链接..." ng-model="searchWord" ng-keypress="($event.which === 13)?search(1):0" /> <input type="text" placeholder="标题,链接..." ng-model="keyword" ng-keypress="($event.which === 13)?search():0" />
</div> </div>
</div> </div>
<div class=" left floated right aligned two wide column" ng-show=" showSearch"> <div class=" left floated right aligned two wide column" ng-show=" showSearch">
@ -151,8 +148,8 @@
<span id="time{{bookmark.id}}" title="{{bookmark.lastClick}}" class="need_to_be_rendered" data-timeago="{{bookmark.lastClick}}"></span> <span id="time{{bookmark.id}}" title="{{bookmark.lastClick}}" class="need_to_be_rendered" data-timeago="{{bookmark.lastClick}}"></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" tag-id="{{ tag.id }}" ng-if="!searchHotBookmarks">
{{ tag.name }} {{ bookmark.tagName }}
</div> </div>
<span ng-if="searchHotBookmarks"> <span ng-if="searchHotBookmarks">
{{ bookmark.createdBy }} {{ bookmark.createdBy }}