全局添加快捷键打开

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

View File

@ -10,13 +10,15 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
$scope.loadShowStyle = false;
$scope.form[($stateParams && $stateParams.formIndex) || 0] = true;
$scope.key = '';
$scope.url = '';
$scope.quickUrl = {};
$scope.changeForm = function(index) {
console.log("changeForm = ", index);
$scope.form = $scope.form.map(() => false);
$scope.form[index] = true;
if (index <= 1) {
if (index == 0 || index == 1 || index == 4) {
$scope.loadShowStyle = true;
bookmarkService.userInfo({})
.then((data) => {
@ -25,25 +27,29 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
updateShowStyle(($scope.user && $scope.user.show_style) || 'navigate');
$scope.loadShowStyle = false;
}
if (index == 4) {
$scope.quickUrl = JSON.parse($scope.user.quick_url || '{}');
}
})
.catch((err) => {
console.log(err);
toastr.error('获取信息失败。错误信息:' + JSON.stringify(err), "错误");
$scope.loadShowStyle = false;
});
if (index == 1) {
bookmarkService.getTags({})
.then((data) => {
$scope.tagCnt = data.length;
$scope.bookmarkCnt = 0;
data.forEach((tag) => {
$scope.bookmarkCnt += tag.cnt;
})
}
if (index == 1) {
bookmarkService.getTags({})
.then((data) => {
$scope.tagCnt = data.length;
$scope.bookmarkCnt = 0;
data.forEach((tag) => {
$scope.bookmarkCnt += tag.cnt;
})
.catch((err) => {
console.log('getTags err', err);
});
}
})
.catch((err) => {
console.log('getTags err', err);
});
}
}
@ -112,12 +118,52 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
console.log('key = ', key);
if (!((key >= 'A' && key <= 'Z') || (key >= '1' && key <= '9'))) {
key = '';
toastr.warning('快捷键只能是数字1 ~ 9或者字母a ~ z字母不区分大小写。', "警告");
}
$timeout(function() {
$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) {
setTimeout(function() {
if (showStyle) {
@ -155,8 +201,28 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$
login: true,
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() {
var className = 'js-segment-settings';
$('.' + className).transition('hide');

View File

@ -326,6 +326,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
});
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) {
var def = $q.defer();
$http.get('/api/advices/', {

View File

@ -62,6 +62,12 @@ app.factory('dataService', [function() {
},
historyTypes: ['书签', '谷歌', 'Github', '栈溢出', '百度', '备忘录'],
showStyles: ['navigate', 'costomTag', 'card', 'table'],
forbidQuickKey:{
'A':'在备忘录界面,已用做新增备忘录',
'R':'在热门收藏界面,已用作随机查看热门收藏',
'INSERT':'全局页面,已用做添加书签',
'ESC':'全局页面,已用做退出弹窗',
},
keyShortcuts: function() { // 判断快捷方式是否生效
var ret = true;
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>
</div>
<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>
<table class="ui selectable sortable celled table js-quick-url-table">
<thead>
<tr>
<th style="width:80px;">快捷键</th>
<th>链接</th>
<th>网站地址</th>
<th style="width:45px;">操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>A</td>
<td>http://mybookmark.cn/#/settings</td>
<tr ng-repeat="(key, value) in quickUrl">
<td>{{key}}</td>
<td>{{value}}</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>
</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="删除书签">
<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>
</tbody>
@ -187,16 +180,16 @@
<div class="ui divider"></div>
<div class="ui form">
<div class="inline fields">
<div class="six wide field">
<div class="five wide field">
<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 class="eight wide field">
<div class="nine wide field">
<label style="min-width:66px;">网站地址:</label>
<input type="text" placeholder="请输入你需要快捷打开的网站地址">
<input type="text" placeholder="请输入你需要快捷打开的网站地址" ng-model="url">
</div>
<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>

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) {
console.log("autoLogin username = ", req.session.username);
var ret = {