From 03d5807cc22fbc1d0eff90403a3f616aa3e94b83 Mon Sep 17 00:00:00 2001 From: luchenqun Date: Mon, 3 Apr 2017 23:47:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8E=86=E5=8F=B2=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/scripts/controllers/menus-controller.js | 10 ++++++++-- schema.sql | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/public/scripts/controllers/menus-controller.js b/public/scripts/controllers/menus-controller.js index 8f45dbb..e69e005 100644 --- a/public/scripts/controllers/menus-controller.js +++ b/public/scripts/controllers/menus-controller.js @@ -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), "错误"); diff --git a/schema.sql b/schema.sql index 76683e4..93a3db3 100644 --- a/schema.sql +++ b/schema.sql @@ -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`)