完成搜索功能

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, -- 描述(自己添加)
`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', -- 状态

View File

@ -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() });

View File

@ -95,6 +95,7 @@
<script src="scripts/externe/ngDialog.min.js"></script>
<script src="scripts/externe/clipboard.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/pnglib.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);
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();
}]);

View File

@ -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');
},
};
});

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>
<i class="dropdown icon"></i>
<div class="menu">
<div class="active item" data-value="1">自己书签</div>
<div class="item" data-value="2">全站书签</div>
<div class="item" data-value="3">热门收藏</div>
<div class="active item" data-value="self">自己书签</div>
<div class="item" data-value="other">全站书签</div>
<div class="item" data-value="hot">热门收藏</div>
</div>
</div>
</div>
@ -25,8 +25,8 @@
<div class="text">创建时间不限</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="active item" data-value="-1">创建时间不限</div>
<div class="item" data-value="0">今天</div>
<div class="active item" data-value="36500">创建时间不限</div>
<div class="item" data-value="1">今天</div>
<div class="item" data-value="7">一周内</div>
<div class="item" data-value="31">一月内</div>
<div class="item" data-value="365">一年内</div>
@ -59,8 +59,8 @@
<div class="text">点击时间不限</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="active item" data-value="-1">点击时间不限</div>
<div class="item" data-value="0">今天</div>
<div class="active item" data-value="36500">点击时间不限</div>
<div class="item" data-value="1">今天</div>
<div class="item" data-value="7">一周内</div>
<div class="item" data-value="31">一月内</div>
<div class="item" data-value="365">一年内</div>
@ -89,9 +89,6 @@
</div>
</div>
<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 multiple dropdown js-search-tags" style="padding:0;" ng-show="showTags" js-dropdown-tags-init>
<div class="default text">分类选择</div>
@ -104,7 +101,7 @@
</div>
<div class="two wide column" ng-show="showSearch">
<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 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>
</td>
<td>
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-if="!searchHotBookmarks">
{{ tag.name }}
<div class="ui label" tag-id="{{ tag.id }}" ng-if="!searchHotBookmarks">
{{ bookmark.tagName }}
</div>
<span ng-if="searchHotBookmarks">
{{ bookmark.createdBy }}