增加一个搜索历史表

This commit is contained in:
luchenqun 2017-04-03 23:47:26 +08:00
parent 787b551696
commit 03d5807cc2
2 changed files with 9 additions and 3 deletions

View File

@ -68,6 +68,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
} else {
$window.open('http://www.baidu.com/s?tn=mybookmark.cn&ch=3&ie=utf-8&wd=' + encodeURIComponent(searchWord), '_blank');
}
// 如果第一个显示的搜索分类跟关键字跟列表一样,那么不要更新
var newItem = {
t: searchOption,
@ -85,6 +86,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
}
var datas = [];
$scope.searchHistory.slice(0, 15); // 最多保留15个历史记录
$scope.searchHistory.forEach((item, index) => {
datas.push({
t: item.t,
@ -93,8 +95,12 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
})
var parmes = {
searchHistory: JSON.stringify(datas),
searchHistory: JSON.stringify(data),
};
// 大于30的不保存到数据库
if (searchWord.length >= 30) {
return;
}
bookmarkService.updateSearchHistory(parmes)
.then((data) => {
if (data.retCode == 0) {
@ -161,7 +167,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
.popup({
on: 'focus'
});
}, 1000)
}, 500)
})
.catch((err) => {
toastr.error('获取信息失败。错误信息:' + JSON.stringify(err), "错误");

View File

@ -8,7 +8,7 @@ CREATE TABLE `users` (
`created_at` datetime DEFAULT now(), -- 创建时间
`last_login` datetime DEFAULT NULL, -- 最后一次登录时间
`show_style` char(16) NOT NULL DEFAULT 'navigate', -- 显示风格
`search_history` varchar(255) DEFAULT NULL, -- 历史搜索记录
`search_history` varchar(512) DEFAULT NULL, -- 历史搜索记录
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`)