全局添加快捷键打开

This commit is contained in:
luchenqun 2017-05-17 10:32:17 +08:00
parent af917870af
commit 58c580abe1
7 changed files with 163 additions and 43 deletions

View File

@ -324,6 +324,20 @@ db.updateSearchHistory = function(userId, search_history) {
}); });
}; };
db.updateQuickUrl = function(userId, quick_url) {
var sql = "UPDATE `users` SET `quick_url`=" + client.escape(quick_url) + " WHERE (`id`='" + userId + "')";
console.log('updateQuickUrl', sql);
return new Promise(function(resolve, reject) {
client.query(sql, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result.affectedRows);
}
});
});
};
db.register = function(user) { db.register = function(user) {
console.log('register'); console.log('register');
var sql = "INSERT INTO `users` (`username`, `password`, `email`) VALUES ('" + user.username + "', '" + user.password + "', '" + user.email + "')"; var sql = "INSERT INTO `users` (`username`, `password`, `email`) VALUES ('" + user.username + "', '" + user.password + "', '" + user.email + "')";

View File

@ -7,6 +7,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.showStyle = null; $scope.showStyle = null;
$scope.searchHistory = []; $scope.searchHistory = [];
$scope.historyTypes = dataService.historyTypes; $scope.historyTypes = dataService.historyTypes;
$scope.quickUrl = { };
// 防止在登陆的情况下在浏览器里面直接输入url这时候要更新菜单选项 // 防止在登陆的情况下在浏览器里面直接输入url这时候要更新菜单选项
pubSubService.subscribe('Common.menuActive', $scope, function(event, params) { pubSubService.subscribe('Common.menuActive', $scope, function(event, params) {
@ -16,6 +17,10 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
updateMenuActive(index); updateMenuActive(index);
}); });
pubSubService.subscribe('Settings.quickUrl', $scope, function(event, params) {
$scope.quickUrl = params.quickUrl;
});
$scope.loginMenus = dataService.loginMenus; // 登陆之后显示的菜单数据。uiSerf内部跳转链接。 $scope.loginMenus = dataService.loginMenus; // 登陆之后显示的菜单数据。uiSerf内部跳转链接。
$scope.notLoginMenus = dataService.notLoginMenus; // 未登陆显示的菜单数据 $scope.notLoginMenus = dataService.notLoginMenus; // 未登陆显示的菜单数据
@ -168,6 +173,8 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
bookmarkService.userInfo({}) bookmarkService.userInfo({})
.then((user) => { .then((user) => {
$scope.searchHistory = JSON.parse(user.search_history || '[]'); $scope.searchHistory = JSON.parse(user.search_history || '[]');
$scope.quickUrl = JSON.parse(user.quick_url || '{}');
$timeout(function() { $timeout(function() {
var showStyle = (user && user.show_style) || 'navigate'; var showStyle = (user && user.show_style) || 'navigate';
if (showStyle) { if (showStyle) {
@ -188,17 +195,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.$apply(function() { $scope.$apply(function() {
if (dataService.keyShortcuts()) { if (dataService.keyShortcuts()) {
var key = event.key.toUpperCase(); var key = event.key.toUpperCase();
var urls = { var url = $scope.quickUrl[key];
'B':'https://www.baidu.com/',
'G':'https://www.google.com.hk/',
'L':'http://luchenqun.com/',
'H':'https://github.com/',
'S':'https://stackoverflow.com/',
'V':'https://www.v2ex.com/',
'Q':'http://www.iqiyi.com/',
};
var url = urls[key];
if (url) { if (url) {
$window.open(url, '_blank'); $window.open(url, '_blank');
} }

View File

@ -10,13 +10,15 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
$scope.loadShowStyle = false; $scope.loadShowStyle = false;
$scope.form[($stateParams && $stateParams.formIndex) || 0] = true; $scope.form[($stateParams && $stateParams.formIndex) || 0] = true;
$scope.key = ''; $scope.key = '';
$scope.url = '';
$scope.quickUrl = {};
$scope.changeForm = function(index) { $scope.changeForm = function(index) {
console.log("changeForm = ", index); console.log("changeForm = ", index);
$scope.form = $scope.form.map(() => false); $scope.form = $scope.form.map(() => false);
$scope.form[index] = true; $scope.form[index] = true;
if (index <= 1) { if (index == 0 || index == 1 || index == 4) {
$scope.loadShowStyle = true; $scope.loadShowStyle = true;
bookmarkService.userInfo({}) bookmarkService.userInfo({})
.then((data) => { .then((data) => {
@ -25,12 +27,17 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
updateShowStyle(($scope.user && $scope.user.show_style) || 'navigate'); updateShowStyle(($scope.user && $scope.user.show_style) || 'navigate');
$scope.loadShowStyle = false; $scope.loadShowStyle = false;
} }
if (index == 4) {
$scope.quickUrl = JSON.parse($scope.user.quick_url || '{}');
}
}) })
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
toastr.error('获取信息失败。错误信息:' + JSON.stringify(err), "错误"); toastr.error('获取信息失败。错误信息:' + JSON.stringify(err), "错误");
$scope.loadShowStyle = false; $scope.loadShowStyle = false;
}); });
}
if (index == 1) { if (index == 1) {
bookmarkService.getTags({}) bookmarkService.getTags({})
.then((data) => { .then((data) => {
@ -45,7 +52,6 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
}); });
} }
} }
}
$scope.changeForm($scope.form.indexOf(true)); // 马上调用一次 $scope.changeForm($scope.form.indexOf(true)); // 马上调用一次
@ -112,12 +118,52 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
console.log('key = ', key); console.log('key = ', key);
if (!((key >= 'A' && key <= 'Z') || (key >= '1' && key <= '9'))) { if (!((key >= 'A' && key <= 'Z') || (key >= '1' && key <= '9'))) {
key = ''; key = '';
toastr.warning('快捷键只能是数字1 ~ 9或者字母a ~ z字母不区分大小写。', "警告");
} }
$timeout(function() { $timeout(function() {
$scope.key = key; $scope.key = key;
}); });
} }
$scope.addQuickUrl = function(){
if (!/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/.test($scope.url)) {
toastr.warning($scope.url + '<br/>检撤到您的书签链接非法是否忘记加http或者https了建议直接从打开浏览器地址栏复制出来直接粘贴到输入框。', "警告");
$scope.url = '';
return;
}
if (!(($scope.key >= 'A' && $scope.key <= 'Z') || ($scope.key >= 'a' && $scope.key <= 'z') || ($scope.key >= '1' && $scope.key <= '9'))) {
toastr.warning('快捷键只能是数字1 ~ 9或者字母a ~ z字母不区分大小写。', "警告");
$scope.key = '';
return;
}
if (dataService.forbidQuickKey[$scope.key]) {
toastr.warning('快捷键' + $scope.key + ',已经设置为系统:' + dataService.forbidQuickKey[$scope.key] + '。无法使用该快捷键', "警告");
$scope.key = '';
return;
}
if ($scope.quickUrl[$scope.key]) {
toastr.warning('快捷键:' + $scope.key + ',已经设置为链接为:' + $scope.quickUrl[$scope.key] + '。您可以先删除再添加。', "警告");
$scope.key = '';
return;
}
$scope.key = $scope.key.toUpperCase();
$scope.quickUrl[$scope.key] = $scope.url;
console.log(JSON.stringify($scope.quickUrl));
saveQuickUrl();
$scope.url = '';
$scope.key = '';
}
$scope.delUrl = function(key) {
delete $scope.quickUrl[key];
saveQuickUrl();
}
function updateShowStyle(showStyle) { function updateShowStyle(showStyle) {
setTimeout(function() { setTimeout(function() {
if (showStyle) { if (showStyle) {
@ -155,8 +201,28 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
login: true, login: true,
index: dataService.LoginIndexSettings index: dataService.LoginIndexSettings
}); });
transition();
function saveQuickUrl() {
var parmes = {
quickUrl: JSON.stringify($scope.quickUrl),
};
bookmarkService.updateQuickUrl(parmes)
.then((data) => {
if (data.retCode == 0) {
toastr.success('全局快捷键更新成功', "提示");
pubSubService.publish('Settings.quickUrl', {
quickUrl: $scope.quickUrl
});
} else {
toastr.error('全局快捷键更新失败。错误信息:' + data.msg, "错误");
}
})
.catch((err) => {
toastr.error('全局快捷键更新失败。错误信息:' + JSON.stringify(err), "错误");
});
}
transition();
function transition() { function transition() {
var className = 'js-segment-settings'; var className = 'js-segment-settings';
$('.' + className).transition('hide'); $('.' + className).transition('hide');

View File

@ -326,6 +326,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
}); });
return def.promise; return def.promise;
}, },
updateQuickUrl: function(params) {
var def = $q.defer();
$http.post('/api/updateQuickUrl/', {
params: params
})
.success(function(data) {
def.resolve(data);
})
.error(function(data) {
def.reject('updateQuickUrl error');
});
return def.promise;
},
getAdvices: function(params) { getAdvices: function(params) {
var def = $q.defer(); var def = $q.defer();
$http.get('/api/advices/', { $http.get('/api/advices/', {

View File

@ -62,6 +62,12 @@ app.factory('dataService', [function() {
}, },
historyTypes: ['书签', '谷歌', 'Github', '栈溢出', '百度', '备忘录'], historyTypes: ['书签', '谷歌', 'Github', '栈溢出', '百度', '备忘录'],
showStyles: ['navigate', 'costomTag', 'card', 'table'], showStyles: ['navigate', 'costomTag', 'card', 'table'],
forbidQuickKey:{
'A':'在备忘录界面,已用做新增备忘录',
'R':'在热门收藏界面,已用作随机查看热门收藏',
'INSERT':'全局页面,已用做添加书签',
'ESC':'全局页面,已用做退出弹窗',
},
keyShortcuts: function() { // 判断快捷方式是否生效 keyShortcuts: function() { // 判断快捷方式是否生效
var ret = true; var ret = true;
var menusScope = $('div[ng-controller="menuCtr"]').scope(); var menusScope = $('div[ng-controller="menuCtr"]').scope();

View File

@ -157,29 +157,22 @@
<p>1、该代码我托管在Github上<a href="https://github.com/luchenqun/my-bookmark" target="_blank">my-bookmark</a>。该地址有文件夹详细说明以及部署步骤。git地址git@github.com:luchenqun/my-bookmark.git。如果你需要源码你尽可随意使用此项目无需通知我。</p> <p>1、该代码我托管在Github上<a href="https://github.com/luchenqun/my-bookmark" target="_blank">my-bookmark</a>。该地址有文件夹详细说明以及部署步骤。git地址git@github.com:luchenqun/my-bookmark.git。如果你需要源码你尽可随意使用此项目无需通知我。</p>
</div> </div>
<div class="ui container js-p-info" ng-show="form[4]"> <div class="ui container js-p-info" ng-show="form[4]">
<p>功能说明可在该页面设置全局快速打开的链接。快捷键只能是数字1 ~ 9或者字母a ~ z字母不区分大小写。</br>注意:在该设置界面,不触发全局的链接打开,否则没法设置了。</p> <p>功能说明可在该页面设置全局快速打开的链接。快捷键只能是数字1 ~ 9或者字母a ~ z字母不区分大小写。</p>
<div class="ui divider"></div> <div class="ui divider"></div>
<table class="ui selectable sortable celled table js-quick-url-table"> <table class="ui selectable sortable celled table js-quick-url-table">
<thead> <thead>
<tr> <tr>
<th style="width:80px;">快捷键</th> <th style="width:80px;">快捷键</th>
<th>链接</th> <th>网站地址</th>
<th style="width:45px;">操作</th> <th style="width:45px;">操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr ng-repeat="(key, value) in quickUrl">
<td>A</td> <td>{{key}}</td>
<td>http://mybookmark.cn/#/settings</td> <td>{{value}}</td>
<td> <td>
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/delete.png" ng-click="delBookmark(bookmark)" title="删除书签"> <img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/delete.png" ng-click="delUrl(key)" title="删除书签">
</td>
</tr>
<tr>
<td>B</td>
<td>https://www.google.com.hk/</td>
<td>
<img class="ui mini spaced image" style="width:16px;height:16px;margin:0 1px" ng-src="./images/delete.png" ng-click="delBookmark(bookmark)" title="删除书签">
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -187,16 +180,16 @@
<div class="ui divider"></div> <div class="ui divider"></div>
<div class="ui form"> <div class="ui form">
<div class="inline fields"> <div class="inline fields">
<div class="six wide field"> <div class="five wide field">
<label style="min-width:55px;">快捷键:</label> <label style="min-width:55px;">快捷键:</label>
<input type="text" placeholder="请用鼠标点击然后按相应的快捷键" ng-model="key" ng-keypress="quickKey($event.key)"> <input type="text" placeholder="请按相应的快捷键" ng-model="key" ng-keypress="quickKey($event.key)">
</div> </div>
<div class="eight wide field"> <div class="nine wide field">
<label style="min-width:66px;">网站地址:</label> <label style="min-width:66px;">网站地址:</label>
<input type="text" placeholder="请输入你需要快捷打开的网站地址"> <input type="text" placeholder="请输入你需要快捷打开的网站地址" ng-model="url">
</div> </div>
<div class="two wide field"> <div class="two wide field">
<div class="ui green button" ng-click="ok()">确定</div> <div class="ui green button" ng-click="addQuickUrl()">确定</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -227,6 +227,37 @@ api.post('/updateSearchHistory', function(req, res) {
}); });
}); });
api.post('/updateQuickUrl', function(req, res) {
console.log("updateQuickUrl username = ", req.session.username);
if (!req.session.user) {
res.send(401);
return;
}
var params = req.body.params;
db.getUser(req.session.user.username)
.then((user) => {
if (user) {
return db.updateQuickUrl(req.session.userId, params.quickUrl)
} else {
return Promise.resolve(0)
}
})
.then((affectedRows) => {
res.json({
retCode: (affectedRows == 1 ? 0 : 1),
msg: req.session.username + " 更新全局快捷键成功!",
})
})
.catch((err) => {
console.log('resetPassword error', err);
res.json({
retCode: 2,
msg: req.session.username + " 更新全局快捷键失败!: " + JSON.stringify(err),
})
});
});
api.get('/autoLogin', function(req, res) { api.get('/autoLogin', function(req, res) {
console.log("autoLogin username = ", req.session.username); console.log("autoLogin username = ", req.session.username);
var ret = { var ret = {