完成部分搜索

This commit is contained in:
HelloWorld 2020-03-30 18:04:32 +08:00
parent e088df6cb4
commit 31fe4b063d
7 changed files with 70 additions and 54 deletions

View File

@ -235,11 +235,10 @@ module.exports = class extends Base {
}
// 根据书签id获取书签
async getBookmarksByTagAction() {
async bookmarksByTagAction() {
let tagId = this.get("tagId");
let showType = this.get("showType") || "createdAt";
// tagId = -1 个人定制 从自己里面取
// tagId = -2 全局定制 从非个人里面取
let where = {};
let order = showType + ' DESC';
@ -259,6 +258,28 @@ module.exports = class extends Base {
}
}
async bookmarksSearchAction() {
let condition = {};
let keyword = this.get("keyword");
let username = this.get("username");
if (username) {
} else {
condition.userId = this.ctx.state.user.id;
}
if (keyword) {
condition.url = ['like', `%${keyword}%`];
}
try {
let data = await this.model('bookmarks').where(condition).page(this.get('page') || 1, this.get('pageSize') || 50).countSelect();
this.json({ code: 0, data });
} catch (error) {
this.json({ code: 1, msg: error.toString() });
}
}
// 点击书签
async clickBookmarkAction() {
let id = this.post("id");
@ -412,9 +433,9 @@ module.exports = class extends Base {
async notesAction() {
let where = {};
try {
let searchWord = this.get('searchWord');
if (searchWord) {
where.content = ['like', `%${searchWord}%`]
let keyword = this.get('keyword');
if (keyword) {
where.content = ['like', `%${keyword}%`]
}
let data = await this.model('notes').where(where).order("createdAt DESC").page(this.get('page'), this.get('pageSize')).countSelect();
this.json({ code: 0, data });

View File

@ -72,7 +72,7 @@ app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
url: '/note',
templateUrl: 'views/note.html',
params: {
searchWord: null,
keyword: null,
key: null,
},
controller: 'noteCtr'
@ -81,7 +81,7 @@ app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
url: '/search',
templateUrl: 'views/search.html',
params: {
searchWord: null,
keyword: null,
},
controller: 'searchCtr'
})

View File

@ -3,7 +3,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.login = false; /**< 是否登陆 */
$scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */
$scope.selectNotLoginIndex = 0; /**< 默认未登陆之后的选择的菜单索引,下表从 0 开始 */
$scope.searchWord = ''; /**< 搜索关键字 */
$scope.keyword = ''; /**< 搜索关键字 */
$scope.showStyle = null;
$scope.searchHistory = [];
$scope.historyTypes = dataService.historyTypes;
@ -70,9 +70,9 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
* @func
* @desc 点击搜索按钮搜索书签
*/
$scope.search = function (searchWord, searchOption) {
console.log('search......', searchWord);
if (!searchWord) {
$scope.search = function (keyword, searchOption) {
console.log('search......', keyword);
if (!keyword) {
toastr.error('请输入搜索关键字', "错误");
return;
}
@ -81,42 +81,42 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
// var searchOption = $('.js-search-option').dropdown('get value') || 0;
if (searchOption == 0) {
$state.go('search', {
searchWord: searchWord,
keyword: keyword,
}, {
reload: true,
})
updateMenuActive($scope.selectLoginIndex = 0);
} else if (searchOption == 1) {
$window.open('https://www.google.com.hk/#newwindow=1&safe=strict&q=' + encodeURIComponent(searchWord), '_blank');
$window.open('https://www.google.com.hk/#newwindow=1&safe=strict&q=' + encodeURIComponent(keyword), '_blank');
} else if (searchOption == 2) {
$window.open('https://github.com/search?utf8=%E2%9C%93&q=' + encodeURIComponent(searchWord) + '&type=', '_blank');
$window.open('https://github.com/search?utf8=%E2%9C%93&q=' + encodeURIComponent(keyword) + '&type=', '_blank');
} else if (searchOption == 3) {
$window.open('https://stackoverflow.com/search?q=' + encodeURIComponent(searchWord), '_blank');
$window.open('https://stackoverflow.com/search?q=' + encodeURIComponent(keyword), '_blank');
} else if (searchOption == 4) {
$window.open('http://www.baidu.com/s?tn=mybookmark.cn&ch=3&ie=utf-8&wd=' + encodeURIComponent(searchWord), '_blank');
$window.open('http://www.baidu.com/s?tn=mybookmark.cn&ch=3&ie=utf-8&wd=' + encodeURIComponent(keyword), '_blank');
} else if (searchOption == 5) {
console.log('search note, word = ', searchWord);
console.log('search note, word = ', keyword);
$state.go('note', {
searchWord: searchWord,
keyword: keyword,
}, {
reload: true,
})
updateMenuActive($scope.selectLoginIndex = dataService.LoginIndexNote);
}
if (!searchWord) {
if (!keyword) {
return;
}
var newItem = {
t: searchOption,
d: searchWord,
d: keyword,
}
$scope.searchIcon(newItem)
var delIndex = -1;
$scope.searchHistory.unshift(newItem);
$scope.searchHistory.forEach((item, index) => {
if (index >= 1 && item.t == searchOption && item.d == searchWord) {
if (index >= 1 && item.t == searchOption && item.d == keyword) {
delIndex = index;
}
})
@ -125,7 +125,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
}
// 大于30的不保存到数据库
if (searchWord.length <= 30) {
if (keyword.length <= 30) {
saveHistory();
}
}
@ -133,8 +133,8 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.searchByHistory = function (type, data, $event) {
console.log("searchByHistory", type, data);
$event && $event.stopPropagation();
$scope.searchWord = data;
$('.search-item').val($scope.searchWord);
$scope.keyword = data;
$('.search-item').val($scope.keyword);
$('.js-search-option').dropdown('set value', type);
var types = $scope.historyTypes;

View File

@ -20,7 +20,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
$scope.totalPages = 0;
$scope.currentPage = 1;
$scope.inputPage = '';
$scope.searchWord = $stateParams.searchWord
$scope.keyword = $stateParams.keyword
$scope.key = $stateParams.key
$scope.totalItems = 0;
@ -119,7 +119,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
$scope.content = '';
$scope.currentTagId = null;
$scope.currentPage = 1;
$scope.searchWord = '';
$scope.keyword = '';
getNotes();
}
@ -316,7 +316,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
var params = {
page: $scope.currentPage,
pageSize: perPageItems,
searchWord: $scope.searchWord,
keyword: $scope.keyword,
tagId: tagId || $scope.currentTagId
};

View File

@ -11,7 +11,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
$scope.searchBookmarks = []; // 书签数据
$scope.showSearch = false; //
$scope.showTags = false; //
$scope.searchWord = ($stateParams && $stateParams.searchWord) || ''
$scope.keyword = ($stateParams && $stateParams.keyword) || ''
$scope.dateCreateBegin = '';
$scope.dateCreateEnd = '';
$scope.dateClickBegin = '';
@ -50,12 +50,12 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
});
var searchParams = {
searchWord: $scope.searchWord,
keyword: $scope.keyword,
page: 1,
perPageItems: perPageItems,
userRange: '1', // 默认搜索自己的书签
}
if ($scope.searchWord) {
if ($scope.keyword) {
searchBookmarks(searchParams);
} else {
toastr.warning("请输入搜索关键字再进行查询!", "提示");
@ -69,7 +69,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
$scope.searchBookmarks.forEach(function (bookmark) {
if (bookmark.id == id && bookmark.own) {
bookmark.click_count += 1;
bookmark.last_click = $filter("date")(new Date(), "yyyy-MM-dd HH:mm:ss");
bookmark.lastClick = $filter("date")(new Date(), "yyyy-MM-dd HH:mm:ss");
}
})
$timeout(function () {
@ -114,7 +114,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
$scope.favoriteBookmark = async function (bookmark) {
let id = await post("addBookmark", bookmark);
let bookmark = await get("bookmark", { id });
bookmark = await get("bookmark", { id });
pubSubService.publish('EditCtr.inserBookmarsSuccess', bookmark);
}
@ -133,8 +133,8 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
} else if ($scope.username) {
params.username = $scope.username
}
if ($scope.searchWord) {
params.searchWord = $scope.searchWord;
if ($scope.keyword) {
params.keyword = $scope.keyword;
}
var dateCreate = $('.js-create-date').dropdown('get value') || undefined;
@ -224,7 +224,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
})
});
function searchBookmarks(params) {
async function searchBookmarks(params) {
$scope.loading = true;
$('.js-table-search').transition('hide');
if ($scope.searchHotBookmarks) {
@ -237,8 +237,8 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
id: -1,
name: bookmark.created_by, // 给转存用
}]
bookmark.created_at = $filter('date')(new Date(bookmark.created_at), "yyyy-MM-dd HH:mm:ss");
bookmark.last_click = $filter('date')(new Date(bookmark.last_click), "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");
$scope.searchBookmarks.push(bookmark);
})
$scope.bookmarkCount = data.totalItems;
@ -251,18 +251,13 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
$scope.loading = false;
});
} else {
bookmarkService.searchBookmarks(params)
.then((data) => {
$scope.searchBookmarks = data.bookmarks;
$scope.bookmarkCount = data.totalItems;
$scope.totalPages = Math.ceil($scope.bookmarkCount / perPageItems);
$scope.loading = false;
transition();
})
.catch((err) => {
console.log('getBookmarks err', err);
$scope.loading = false;
});
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();
}
}

View File

@ -57,7 +57,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
showType: $scope.showType
};
let reply = await get('getBookmarksByTag', params);
let reply = await get('bookmarksByTag', params);
$scope.bookmarks = reply.data;
$scope.totalPages = reply.totalPages;
$scope.inputPage = '';

View File

@ -143,19 +143,19 @@
<td>
<span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.url)" style="cursor:default;">{{ bookmark.url }}</span>
</td>
<td>{{ bookmark.click_count || bookmark.fav_count }}</td>
<td>{{ bookmark.clickCount || bookmark.favCount }}</td>
<td>
<span title="{{bookmark.created_at}}" class="need_to_be_rendered" data-timeago="{{bookmark.created_at}}"></span>
<span title="{{bookmark.createdAt}}" class="need_to_be_rendered" data-timeago="{{bookmark.createdAt}}"></span>
</td>
<td>
<span id="time{{bookmark.id}}" title="{{bookmark.last_click}}" class="need_to_be_rendered" data-timeago="{{bookmark.last_click}}"></span>
<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>
<span ng-if="searchHotBookmarks">
{{ bookmark.created_by }}
{{ bookmark.createdBy }}
</span>
</td>
<td>