完成部分搜索
This commit is contained in:
parent
e088df6cb4
commit
31fe4b063d
|
|
@ -235,11 +235,10 @@ module.exports = class extends Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据书签id获取书签
|
// 根据书签id获取书签
|
||||||
async getBookmarksByTagAction() {
|
async bookmarksByTagAction() {
|
||||||
let tagId = this.get("tagId");
|
let tagId = this.get("tagId");
|
||||||
let showType = this.get("showType") || "createdAt";
|
let showType = this.get("showType") || "createdAt";
|
||||||
// tagId = -1 个人定制 从自己里面取
|
// tagId = -1 个人定制 从自己里面取
|
||||||
// tagId = -2 全局定制 从非个人里面取
|
|
||||||
let where = {};
|
let where = {};
|
||||||
let order = showType + ' DESC';
|
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() {
|
async clickBookmarkAction() {
|
||||||
let id = this.post("id");
|
let id = this.post("id");
|
||||||
|
|
@ -412,9 +433,9 @@ module.exports = class extends Base {
|
||||||
async notesAction() {
|
async notesAction() {
|
||||||
let where = {};
|
let where = {};
|
||||||
try {
|
try {
|
||||||
let searchWord = this.get('searchWord');
|
let keyword = this.get('keyword');
|
||||||
if (searchWord) {
|
if (keyword) {
|
||||||
where.content = ['like', `%${searchWord}%`]
|
where.content = ['like', `%${keyword}%`]
|
||||||
}
|
}
|
||||||
let data = await this.model('notes').where(where).order("createdAt DESC").page(this.get('page'), this.get('pageSize')).countSelect();
|
let data = await this.model('notes').where(where).order("createdAt DESC").page(this.get('page'), this.get('pageSize')).countSelect();
|
||||||
this.json({ code: 0, data });
|
this.json({ code: 0, data });
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
|
||||||
url: '/note',
|
url: '/note',
|
||||||
templateUrl: 'views/note.html',
|
templateUrl: 'views/note.html',
|
||||||
params: {
|
params: {
|
||||||
searchWord: null,
|
keyword: null,
|
||||||
key: null,
|
key: null,
|
||||||
},
|
},
|
||||||
controller: 'noteCtr'
|
controller: 'noteCtr'
|
||||||
|
|
@ -81,7 +81,7 @@ app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
|
||||||
url: '/search',
|
url: '/search',
|
||||||
templateUrl: 'views/search.html',
|
templateUrl: 'views/search.html',
|
||||||
params: {
|
params: {
|
||||||
searchWord: null,
|
keyword: null,
|
||||||
},
|
},
|
||||||
controller: 'searchCtr'
|
controller: 'searchCtr'
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
|
||||||
$scope.login = false; /**< 是否登陆 */
|
$scope.login = false; /**< 是否登陆 */
|
||||||
$scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */
|
$scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */
|
||||||
$scope.selectNotLoginIndex = 0; /**< 默认未登陆之后的选择的菜单索引,下表从 0 开始 */
|
$scope.selectNotLoginIndex = 0; /**< 默认未登陆之后的选择的菜单索引,下表从 0 开始 */
|
||||||
$scope.searchWord = ''; /**< 搜索关键字 */
|
$scope.keyword = ''; /**< 搜索关键字 */
|
||||||
$scope.showStyle = null;
|
$scope.showStyle = null;
|
||||||
$scope.searchHistory = [];
|
$scope.searchHistory = [];
|
||||||
$scope.historyTypes = dataService.historyTypes;
|
$scope.historyTypes = dataService.historyTypes;
|
||||||
|
|
@ -70,9 +70,9 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
|
||||||
* @func
|
* @func
|
||||||
* @desc 点击搜索按钮搜索书签
|
* @desc 点击搜索按钮搜索书签
|
||||||
*/
|
*/
|
||||||
$scope.search = function (searchWord, searchOption) {
|
$scope.search = function (keyword, searchOption) {
|
||||||
console.log('search......', searchWord);
|
console.log('search......', keyword);
|
||||||
if (!searchWord) {
|
if (!keyword) {
|
||||||
toastr.error('请输入搜索关键字', "错误");
|
toastr.error('请输入搜索关键字', "错误");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -81,42 +81,42 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
|
||||||
// var searchOption = $('.js-search-option').dropdown('get value') || 0;
|
// var searchOption = $('.js-search-option').dropdown('get value') || 0;
|
||||||
if (searchOption == 0) {
|
if (searchOption == 0) {
|
||||||
$state.go('search', {
|
$state.go('search', {
|
||||||
searchWord: searchWord,
|
keyword: keyword,
|
||||||
}, {
|
}, {
|
||||||
reload: true,
|
reload: true,
|
||||||
})
|
})
|
||||||
updateMenuActive($scope.selectLoginIndex = 0);
|
updateMenuActive($scope.selectLoginIndex = 0);
|
||||||
} else if (searchOption == 1) {
|
} 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) {
|
} 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) {
|
} 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) {
|
} 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) {
|
} else if (searchOption == 5) {
|
||||||
console.log('search note, word = ', searchWord);
|
console.log('search note, word = ', keyword);
|
||||||
$state.go('note', {
|
$state.go('note', {
|
||||||
searchWord: searchWord,
|
keyword: keyword,
|
||||||
}, {
|
}, {
|
||||||
reload: true,
|
reload: true,
|
||||||
})
|
})
|
||||||
updateMenuActive($scope.selectLoginIndex = dataService.LoginIndexNote);
|
updateMenuActive($scope.selectLoginIndex = dataService.LoginIndexNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!searchWord) {
|
if (!keyword) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newItem = {
|
var newItem = {
|
||||||
t: searchOption,
|
t: searchOption,
|
||||||
d: searchWord,
|
d: keyword,
|
||||||
}
|
}
|
||||||
$scope.searchIcon(newItem)
|
$scope.searchIcon(newItem)
|
||||||
var delIndex = -1;
|
var delIndex = -1;
|
||||||
$scope.searchHistory.unshift(newItem);
|
$scope.searchHistory.unshift(newItem);
|
||||||
$scope.searchHistory.forEach((item, index) => {
|
$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;
|
delIndex = index;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -125,7 +125,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
|
||||||
}
|
}
|
||||||
|
|
||||||
// 大于30的不保存到数据库
|
// 大于30的不保存到数据库
|
||||||
if (searchWord.length <= 30) {
|
if (keyword.length <= 30) {
|
||||||
saveHistory();
|
saveHistory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -133,8 +133,8 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
|
||||||
$scope.searchByHistory = function (type, data, $event) {
|
$scope.searchByHistory = function (type, data, $event) {
|
||||||
console.log("searchByHistory", type, data);
|
console.log("searchByHistory", type, data);
|
||||||
$event && $event.stopPropagation();
|
$event && $event.stopPropagation();
|
||||||
$scope.searchWord = data;
|
$scope.keyword = data;
|
||||||
$('.search-item').val($scope.searchWord);
|
$('.search-item').val($scope.keyword);
|
||||||
|
|
||||||
$('.js-search-option').dropdown('set value', type);
|
$('.js-search-option').dropdown('set value', type);
|
||||||
var types = $scope.historyTypes;
|
var types = $scope.historyTypes;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
|
||||||
$scope.totalPages = 0;
|
$scope.totalPages = 0;
|
||||||
$scope.currentPage = 1;
|
$scope.currentPage = 1;
|
||||||
$scope.inputPage = '';
|
$scope.inputPage = '';
|
||||||
$scope.searchWord = $stateParams.searchWord
|
$scope.keyword = $stateParams.keyword
|
||||||
$scope.key = $stateParams.key
|
$scope.key = $stateParams.key
|
||||||
$scope.totalItems = 0;
|
$scope.totalItems = 0;
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
|
||||||
$scope.content = '';
|
$scope.content = '';
|
||||||
$scope.currentTagId = null;
|
$scope.currentTagId = null;
|
||||||
$scope.currentPage = 1;
|
$scope.currentPage = 1;
|
||||||
$scope.searchWord = '';
|
$scope.keyword = '';
|
||||||
getNotes();
|
getNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,7 +316,7 @@ app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$wind
|
||||||
var params = {
|
var params = {
|
||||||
page: $scope.currentPage,
|
page: $scope.currentPage,
|
||||||
pageSize: perPageItems,
|
pageSize: perPageItems,
|
||||||
searchWord: $scope.searchWord,
|
keyword: $scope.keyword,
|
||||||
tagId: tagId || $scope.currentTagId
|
tagId: tagId || $scope.currentTagId
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
||||||
$scope.searchBookmarks = []; // 书签数据
|
$scope.searchBookmarks = []; // 书签数据
|
||||||
$scope.showSearch = false; //
|
$scope.showSearch = false; //
|
||||||
$scope.showTags = false; //
|
$scope.showTags = false; //
|
||||||
$scope.searchWord = ($stateParams && $stateParams.searchWord) || ''
|
$scope.keyword = ($stateParams && $stateParams.keyword) || ''
|
||||||
$scope.dateCreateBegin = '';
|
$scope.dateCreateBegin = '';
|
||||||
$scope.dateCreateEnd = '';
|
$scope.dateCreateEnd = '';
|
||||||
$scope.dateClickBegin = '';
|
$scope.dateClickBegin = '';
|
||||||
|
|
@ -50,12 +50,12 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
||||||
});
|
});
|
||||||
|
|
||||||
var searchParams = {
|
var searchParams = {
|
||||||
searchWord: $scope.searchWord,
|
keyword: $scope.keyword,
|
||||||
page: 1,
|
page: 1,
|
||||||
perPageItems: perPageItems,
|
perPageItems: perPageItems,
|
||||||
userRange: '1', // 默认搜索自己的书签
|
userRange: '1', // 默认搜索自己的书签
|
||||||
}
|
}
|
||||||
if ($scope.searchWord) {
|
if ($scope.keyword) {
|
||||||
searchBookmarks(searchParams);
|
searchBookmarks(searchParams);
|
||||||
} else {
|
} else {
|
||||||
toastr.warning("请输入搜索关键字再进行查询!", "提示");
|
toastr.warning("请输入搜索关键字再进行查询!", "提示");
|
||||||
|
|
@ -69,7 +69,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
||||||
$scope.searchBookmarks.forEach(function (bookmark) {
|
$scope.searchBookmarks.forEach(function (bookmark) {
|
||||||
if (bookmark.id == id && bookmark.own) {
|
if (bookmark.id == id && bookmark.own) {
|
||||||
bookmark.click_count += 1;
|
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 () {
|
$timeout(function () {
|
||||||
|
|
@ -114,7 +114,7 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
||||||
|
|
||||||
$scope.favoriteBookmark = async function (bookmark) {
|
$scope.favoriteBookmark = async function (bookmark) {
|
||||||
let id = await post("addBookmark", bookmark);
|
let id = await post("addBookmark", bookmark);
|
||||||
let bookmark = await get("bookmark", { id });
|
bookmark = await get("bookmark", { id });
|
||||||
pubSubService.publish('EditCtr.inserBookmarsSuccess', bookmark);
|
pubSubService.publish('EditCtr.inserBookmarsSuccess', bookmark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,8 +133,8 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
||||||
} else if ($scope.username) {
|
} else if ($scope.username) {
|
||||||
params.username = $scope.username
|
params.username = $scope.username
|
||||||
}
|
}
|
||||||
if ($scope.searchWord) {
|
if ($scope.keyword) {
|
||||||
params.searchWord = $scope.searchWord;
|
params.keyword = $scope.keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dateCreate = $('.js-create-date').dropdown('get value') || undefined;
|
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;
|
$scope.loading = true;
|
||||||
$('.js-table-search').transition('hide');
|
$('.js-table-search').transition('hide');
|
||||||
if ($scope.searchHotBookmarks) {
|
if ($scope.searchHotBookmarks) {
|
||||||
|
|
@ -237,8 +237,8 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
||||||
id: -1,
|
id: -1,
|
||||||
name: bookmark.created_by, // 给转存用
|
name: bookmark.created_by, // 给转存用
|
||||||
}]
|
}]
|
||||||
bookmark.created_at = $filter('date')(new Date(bookmark.created_at), "yyyy-MM-dd HH:mm:ss");
|
bookmark.createdAt = $filter('date')(new Date(bookmark.createdAt), "yyyy-MM-dd HH:mm:ss");
|
||||||
bookmark.last_click = $filter('date')(new Date(bookmark.last_click), "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;
|
||||||
|
|
@ -251,18 +251,13 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
bookmarkService.searchBookmarks(params)
|
console.log(params);
|
||||||
.then((data) => {
|
let reply = await get('bookmarksSearch', params);
|
||||||
$scope.searchBookmarks = data.bookmarks;
|
$scope.searchBookmarks = reply.data;
|
||||||
$scope.bookmarkCount = data.totalItems;
|
$scope.totalPages = reply.totalPages;
|
||||||
$scope.totalPages = Math.ceil($scope.bookmarkCount / perPageItems);
|
$scope.bookmarkCount = reply.count;
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
transition();
|
transition();
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log('getBookmarks err', err);
|
|
||||||
$scope.loading = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
||||||
showType: $scope.showType
|
showType: $scope.showType
|
||||||
};
|
};
|
||||||
|
|
||||||
let reply = await get('getBookmarksByTag', params);
|
let reply = await get('bookmarksByTag', params);
|
||||||
$scope.bookmarks = reply.data;
|
$scope.bookmarks = reply.data;
|
||||||
$scope.totalPages = reply.totalPages;
|
$scope.totalPages = reply.totalPages;
|
||||||
$scope.inputPage = '';
|
$scope.inputPage = '';
|
||||||
|
|
|
||||||
|
|
@ -143,19 +143,19 @@
|
||||||
<td>
|
<td>
|
||||||
<span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.url)" style="cursor:default;">{{ bookmark.url }}</span>
|
<span title="{{bookmark.url}} 点击复制链接" ng-click="copy(bookmark.url)" style="cursor:default;">{{ bookmark.url }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ bookmark.click_count || bookmark.fav_count }}</td>
|
<td>{{ bookmark.clickCount || bookmark.favCount }}</td>
|
||||||
<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>
|
||||||
<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>
|
||||||
<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">
|
||||||
{{ tag.name }}
|
{{ tag.name }}
|
||||||
</div>
|
</div>
|
||||||
<span ng-if="searchHotBookmarks">
|
<span ng-if="searchHotBookmarks">
|
||||||
{{ bookmark.created_by }}
|
{{ bookmark.createdBy }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue