优化菜单栏代码

This commit is contained in:
luchenqun 2017-05-07 20:09:59 +08:00
parent fc9de8e146
commit 9e4971151c
4 changed files with 19 additions and 34 deletions

View File

@ -6,6 +6,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$scope.searchWord = ''; /**< 搜索关键字 */
$scope.showStyle = null;
$scope.searchHistory = [];
$scope.historyTypes = dataService.historyTypes;
// 防止在登陆的情况下在浏览器里面直接输入url这时候要更新菜单选项
pubSubService.subscribe('Common.menuActive', $scope, function(event, params) {
@ -15,11 +16,8 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
updateMenuActive(index);
});
// 登陆之后显示的菜单数据。uiSerf内部跳转链接。
$scope.loginMenus = dataService.loginMenus;
// 未登陆显示的菜单数据
$scope.notLoginMenus = dataService.notLoginMenus;
$scope.loginMenus = dataService.loginMenus; // 登陆之后显示的菜单数据。uiSerf内部跳转链接。
$scope.notLoginMenus = dataService.notLoginMenus; // 未登陆显示的菜单数据
/**
* @func
@ -49,7 +47,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
}, {
reload: true,
})
updateMenuActive($scope.selectLoginIndex = 6);
updateMenuActive($scope.selectLoginIndex = dataService.LoginIndexNote);
}
if (!searchWord) {
@ -82,12 +80,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
$('.search-item').val($scope.searchWord);
$('.js-search-option').dropdown('set value', type);
var types = {};
types[0] = '书签';
types[1] = '谷歌';
types[2] = 'Github';
types[3] = '栈溢出';
types[4] = '百度';
var types = $scope.historyTypes;
$('.js-search-option').dropdown('set text', types[type]);
$('.js-search-option').dropdown('save defaults', types[type]);
$('.js-search-option .menu .item').removeClass('active');
@ -170,8 +163,17 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
}
bookmarkService.userInfo({})
.then((data) => {
$scope.searchHistory = JSON.parse(data.search_history || '[]');
.then((user) => {
$scope.searchHistory = JSON.parse(user.search_history || '[]');
$timeout(function() {
var showStyle = (user && user.show_style) || 'navigate';
if (showStyle) {
$('.js-bookmark-dropdown' + ' .radio.checkbox').checkbox('set unchecked');
$('.js-radio-' + showStyle).checkbox('set checked');
$('.js-bookmark-dropdown' + ' .field.item').removeClass('active selected');
$('.js-field-' + showStyle).addClass('active selected');
}
}, 1000)
})
.catch((err) => {
console.log(err);

View File

@ -223,19 +223,6 @@ app.directive('faviconErr', function() {
}
});
app.filter('searchType', function() {
return function(type) {
var types = {};
types[0] = '书签';
types[1] = '谷歌';
types[2] = 'Github';
types[3] = '栈溢出';
types[4] = '百度';
types[5] = '备忘录';
return types[type];
}
});
app.filter('characters', function() {
return function(input, chars, breakOnWord) {
if (isNaN(chars)) return input;

View File

@ -60,6 +60,7 @@ app.factory('dataService', [function() {
var t = data[parseInt(Math.random() * 1000) % data.length];
return t;
},
historyTypes: ['书签', '谷歌', 'Github', '栈溢出', '百度', '备忘录'],
};
return service;

View File

@ -42,12 +42,7 @@
<div class="text " style="color:#C9C9C9;font-weight:normal;">书签</div>
<i class="angle down icon"></i>
<div class="menu">
<div class="item active" data-value="0">书签</div>
<div class="item" data-value="1">谷歌</div>
<div class="item" data-value="2">Github</div>
<div class="item" data-value="3">栈溢出</div>
<div class="item" data-value="4">百度</div>
<div class="item" data-value="5">备忘录</div>
<div class="item" data-value="$index" ng-class="{active:$index==0}" ng-repeat="historyType in historyTypes">{{historyType}}</div>
</div>
</div>
</label>
@ -56,7 +51,7 @@
<div class="ui selection list">
<div class="item" ng-repeat="item in searchHistory" ng-click="searchByHistory(item.t, item.d)" style="height:30px;">
<div class="right floated content">
<span style="margin-right:10px;">{{ item.t | searchType }}</span>
<span style="margin-right:10px;">{{ historyTypes[item.t] }}</span>
</div>
<div class="content">
<span style="margin-left:10px;">{{ item.d}}</span>