优化一下搜索
This commit is contained in:
parent
a32a1893cb
commit
d07d4a8c91
|
|
@ -538,7 +538,6 @@ db.getBookmarksTable = function(params) {
|
||||||
sql += " ORDER BY bookmarks.click_count DESC, bookmarks.created_at DESC";
|
sql += " ORDER BY bookmarks.click_count DESC, bookmarks.created_at DESC";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(sql);
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
client.query(sql, (err, result) => {
|
client.query(sql, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -575,20 +574,11 @@ db.getBookmarksByTag = function(params) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
sql += " LIMIT " + (params.currentPage - 1) * params.perPageItems + ", " + params.perPageItems;
|
var bookmarksData = {
|
||||||
var totalItems = result.length;
|
totalItems: result.length,
|
||||||
console.log(totalItems, sql);
|
bookmarks: result.slice((params.currentPage - 1) * params.perPageItems, params.currentPage * params.perPageItems),
|
||||||
client.query(sql, (err, result) => {
|
}
|
||||||
if (err) {
|
resolve(bookmarksData);
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
var bookmarksData = {
|
|
||||||
totalItems: totalItems,
|
|
||||||
bookmarks: result,
|
|
||||||
}
|
|
||||||
resolve(bookmarksData);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
@ -641,20 +631,17 @@ db.getBookmarksSearch = function(params) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
|
// 如果是全站搜索,默认有限显示其他用户的
|
||||||
sql += " LIMIT " + (params.currentPage - 1) * params.perPageItems + ", " + params.perPageItems;
|
if (params.userRange == '2') {
|
||||||
var totalItems = result.length;
|
result.sort((a, b) => {
|
||||||
client.query(sql, (err, result) => {
|
return params.userId == a.user_id ? 1 : -1;
|
||||||
if (err) {
|
})
|
||||||
reject(err);
|
}
|
||||||
} else {
|
var searchData = {
|
||||||
var searchData = {
|
totalItems: result.length,
|
||||||
totalItems: totalItems,
|
bookmarks: result.splice((params.currentPage - 1) * params.perPageItems, params.currentPage * params.perPageItems),
|
||||||
bookmarks: result,
|
}
|
||||||
}
|
resolve(searchData);
|
||||||
resolve(searchData);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -126,14 +126,13 @@ app.controller('searchCtr', ['$scope', '$state', '$stateParams', '$filter', '$wi
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
pubSubService.publish('EditCtr.inserBookmarsSuccess', data);
|
pubSubService.publish('EditCtr.inserBookmarsSuccess', data);
|
||||||
if (data.title) {
|
if (data.title) {
|
||||||
toastr.success('[ ' + data.title + ' ] 收藏成功,将自动重新更新书签!', "提示");
|
toastr.success('[ ' + data.title + ' ] 收藏成功!', "提示");
|
||||||
} else {
|
} else {
|
||||||
toastr.error('[ ' + bookmark.title + ' ] 收藏失败', "提示");
|
toastr.error('[ ' + bookmark.title + ' ] 收藏失败!', "提示");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('favoriteBookmark err', err);
|
toastr.error('[ ' + bookmark.title + ' ] 收藏失败,' + JSON.stringify(err), "提示");
|
||||||
toastr.error('[ ' + bookmark.title + ' ] 收藏失败' + JSON.stringify(err), "提示");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="ui segment js-tags">
|
<div class="ui segment js-tags">
|
||||||
<div class="ui container" ng-show="!editMode">
|
<div class="ui container" ng-show="!editMode">
|
||||||
<div class="ui grid">
|
<div class="ui grid">
|
||||||
<div class="two wide column js-tag-label" ng-class="" ng-mouseover="" ng-mouseleave="" ng-repeat="tag in tags">
|
<div class="two wide column js-tag-label" ng-if="tag.cnt" ng-repeat="tag in tags">
|
||||||
<div class="ui small label" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)">
|
<div class="ui small label" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)">
|
||||||
{{ tag.name }}
|
{{ tag.name }}
|
||||||
({{ tag.cnt || 0 }})
|
({{ tag.cnt || 0 }})
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,6 @@ api.get('/bookmarks', function(req, res) {
|
||||||
db.getTags(userId)
|
db.getTags(userId)
|
||||||
.then((tags) => db.getBookmarksNavigate(tags))
|
.then((tags) => db.getBookmarksNavigate(tags))
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
console.log('ddddddddddddd')
|
|
||||||
var data = [];
|
var data = [];
|
||||||
var tag = {
|
var tag = {
|
||||||
id: result && result[0] && result[0].tag_id,
|
id: result && result[0] && result[0].tag_id,
|
||||||
|
|
@ -295,7 +294,6 @@ api.get('/bookmarks', function(req, res) {
|
||||||
click: item.click,
|
click: item.click,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log(JSON.stringify(temp));
|
|
||||||
res.json(data);
|
res.json(data);
|
||||||
})
|
})
|
||||||
.catch((err) => console.log('bookmarks navigate err', err));
|
.catch((err) => console.log('bookmarks navigate err', err));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue