add search page in search web app

This commit is contained in:
wlh
2014-12-12 16:20:05 +08:00
parent f05ae96998
commit 98c562ee8e
9 changed files with 127 additions and 42 deletions
+2 -1
View File
@@ -11,7 +11,8 @@ module.exports = function(grunt){
'./lib/main.js', './lib/main.js',
'./lib/directive/**/*.js', './lib/directive/**/*.js',
'./lib/service/**/*.js', './lib/service/**/*.js',
'./lib/list/**/*.js' './lib/list/**/*.js',
'./lib/search/**/*.js'
], ],
dest:'./build/main.js' dest:'./build/main.js'
} }
+47 -10
View File
@@ -125,6 +125,24 @@ app.config(['$stateProvider', '$urlRouterProvider',function($stateProvider, $url
controller: '' controller: ''
} }
} }
})
.state('search',{
url: '/search/:type',
views:{
header:{
templateUrl: '../html/views/search.html',
controller: 'Search'
},
container:{
templateUrl: '',
controller: ''
},
footer:{
templateUrl: '',
controller: ''
}
}
}); });
}]); }]);
; ;
@@ -263,32 +281,51 @@ app.controller('musicListController', ['$rootScope', 'musicList',function($rootS
} }
musicList.getData($rootScope.keywordsObj.music); musicList.getData($rootScope.keywordsObj.music);
}]); }]);
;/*搜索*/ ;/*负责搜索结果的导向*/
var SearchController = function($scope, $rootScope, $location, bookList, musicList, movieList){ var Search = function($scope, $rootScope, $location, bookList, musicList, movieList){
var path = $location.path(); var path = $location.path();
$rootScope.isNoLoaded = false;
//跳回列表页
$scope.search = function(){ $scope.search = function(){
var keywords = $scope.keywords; var keywords = $scope.keywords;
if(path.indexOf('/book') !== -1 || path === '/'){ if(path.indexOf('/book') !== -1){
if(keywords){ if(keywords){
$rootScope.keywordsObj.book = keywords; $rootScope.keywordsObj.book = keywords;
} }
bookList.getData($rootScope.keywordsObj.book); $location.path('/book');
}else if(path.indexOf('/music') !== -1 || path === '/music'){ }else if(path.indexOf('/music') !== -1){
if(keywords){ if(keywords){
$rootScope.keywordsObj.music = keywords; $rootScope.keywordsObj.music = keywords;
} }
musicList.getData($rootScope.keywordsObj.music); $location.path('/music');
}else if(path.indexOf('/movie') !== -1 || path === '/movie'){ }else if(path.indexOf('/movie') !== -1){
if(keywords){ if(keywords){
$rootScope.keywordsObj.movie = keywords; $rootScope.keywordsObj.movie = keywords;
} }
movieList.getData($rootScope.keywordsObj.movie); $location.path('/movie');
} }
}; };
}; };
Search.$inject = ['$scope', '$rootScope', '$location', 'bookList', 'musicList', 'movieList'];
app.controller('Search', Search);;/*仅负责搜索页面的打开*/
var SearchController = function($scope, $rootScope, $location){
var path = $location.path();
$scope.goToSearch = function(){
if(path.indexOf('/book') !== -1 || path === '/'){
$location.path('/search/book');
}else if(path.indexOf('/music') !== -1 || path === '/music'){
$location.path('/search/music');
}else if(path.indexOf('/movie') !== -1 || path === '/movie'){
$location.path('/search/movie');
}
};
};
SearchController.$inject = ['$scope', '$rootScope', '$location', 'bookList', 'musicList', 'movieList']; SearchController.$inject = ['$scope', '$rootScope', '$location'];
app.controller('SearchController', SearchController); app.controller('SearchController', SearchController);
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,9 +1,9 @@
<header ng-controller="SearchController"> <header ng-controller="SearchController">
<div> <div>
<input id="search_input" ng-model="keywords" type="text" placeholder="请输入关键字"/> <input id="search_input" ng-model="keywords" type="text" placeholder="请输入关键字" ng-click="goToSearch()"/>
</div> </div>
<div> <div>
<input type="button" id="search_btn" ng-click="search()" value="搜索"/> <input type="button" id="search_btn" value="搜索"/>
</div> </div>
</header> </header>
+8
View File
@@ -0,0 +1,8 @@
<header ng-controller="Search">
<div>
<input id="search_input" ng-model="keywords" type="text" placeholder="请输入关键字"/>
</div>
<div>
<input type="button" id="search_btn" ng-click="search()" value="搜索"/>
</div>
</header>
-28
View File
@@ -1,28 +0,0 @@
/*搜索*/
var SearchController = function($scope, $rootScope, $location, bookList, musicList, movieList){
var path = $location.path();
$scope.search = function(){
var keywords = $scope.keywords;
if(path.indexOf('/book') !== -1 || path === '/'){
if(keywords){
$rootScope.keywordsObj.book = keywords;
}
bookList.getData($rootScope.keywordsObj.book);
}else if(path.indexOf('/music') !== -1 || path === '/music'){
if(keywords){
$rootScope.keywordsObj.music = keywords;
}
musicList.getData($rootScope.keywordsObj.music);
}else if(path.indexOf('/movie') !== -1 || path === '/movie'){
if(keywords){
$rootScope.keywordsObj.movie = keywords;
}
movieList.getData($rootScope.keywordsObj.movie);
}
};
};
SearchController.$inject = ['$scope', '$rootScope', '$location', 'bookList', 'musicList', 'movieList'];
app.controller('SearchController', SearchController);
+18
View File
@@ -125,5 +125,23 @@ app.config(['$stateProvider', '$urlRouterProvider',function($stateProvider, $url
controller: '' controller: ''
} }
} }
})
.state('search',{
url: '/search/:type',
views:{
header:{
templateUrl: '../html/views/search.html',
controller: 'Search'
},
container:{
templateUrl: '',
controller: ''
},
footer:{
templateUrl: '',
controller: ''
}
}
}); });
}]); }]);
+29
View File
@@ -0,0 +1,29 @@
/*负责搜索结果的导向*/
var Search = function($scope, $rootScope, $location, bookList, musicList, movieList){
var path = $location.path();
$rootScope.isNoLoaded = false;
//跳回列表页
$scope.search = function(){
var keywords = $scope.keywords;
if(path.indexOf('/book') !== -1){
if(keywords){
$rootScope.keywordsObj.book = keywords;
}
$location.path('/book');
}else if(path.indexOf('/music') !== -1){
if(keywords){
$rootScope.keywordsObj.music = keywords;
}
$location.path('/music');
}else if(path.indexOf('/movie') !== -1){
if(keywords){
$rootScope.keywordsObj.movie = keywords;
}
$location.path('/movie');
}
};
};
Search.$inject = ['$scope', '$rootScope', '$location', 'bookList', 'musicList', 'movieList'];
app.controller('Search', Search);
+20
View File
@@ -0,0 +1,20 @@
/*仅负责搜索页面的打开*/
var SearchController = function($scope, $rootScope, $location){
var path = $location.path();
$scope.goToSearch = function(){
if(path.indexOf('/book') !== -1 || path === '/'){
$location.path('/search/book');
}else if(path.indexOf('/music') !== -1 || path === '/music'){
$location.path('/search/music');
}else if(path.indexOf('/movie') !== -1 || path === '/movie'){
$location.path('/search/movie');
}
};
};
SearchController.$inject = ['$scope', '$rootScope', '$location'];
app.controller('SearchController', SearchController);