Browse Source

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@103 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d

administrator 11 years ago
parent
commit
71d8d776d0

+ 4 - 3
src/main/webapp/WEB-INF/views/normal/signin.html

@@ -34,7 +34,7 @@
 			<div id="en-info">
 				<h1>深圳华商龙科技有限公司</h1>
 			</div>
-			<div id="login-wrap" class="pull-right">
+			<div id="login-wrap" class="pull-right" ng-controller="AuthCtrl">
 				<h3>登录</h3>
 				<form ng-submit="login(user)" name="myform" novalidate>
 					<div class="form-group">
@@ -65,6 +65,7 @@
 						</div>
 					</div>
 				</form>
+				<div class="loading" ng-class="{'in': loading}"><i></i></div>
 			</div>
 			<div id="code-wrap">
 				<dt>
@@ -106,7 +107,7 @@
 			</div>
 		</div>
 	</div>
+	<script type="text/javascript" src="static/lib/require.js"
+		data-main="static/js/signin/main.js"></script>
 </body>
-<!-- <script type="text/javascript" src="static/lib/require.js"
-	data-main="static/js/user/main.js"></script> -->
 </html>

+ 28 - 20
src/main/webapp/resources/css/signin.css

@@ -66,6 +66,28 @@ h1,h2,h3 {
 	color: #fff;
 }
 
+.loading {
+	display: none;
+	position: absolute;
+	width: 100%;
+	height: 100%;
+	bottom: 0;
+	left: 0;
+}
+
+.loading.in {
+	display: block;
+}
+
+.loading.in>i {
+	position: absolute;
+	top: 50%;
+	left: 50%;
+	margin: -33px 0 0 -33px;
+	background: url("../img/all/loading.gif") no-repeat center center;
+	width: 66px;
+	height: 66px;
+}
 /*header*/
 #top {
 	border-top: 4px solid #44b549;
@@ -102,8 +124,8 @@ h1,h2,h3 {
 }
 /*main*/
 #banner {
-	background: url("../img/bg/bg_signin.jpg") no-repeat center center;
-	background-color: #090b1a;
+	background: url("../img/bg/bg_signin_2.jpg") no-repeat center center;
+	background-color: #000;
 }
 
 #banner>.container {
@@ -120,6 +142,7 @@ h1,h2,h3 {
 }
 
 #login-wrap {
+	position: relative;
 	width: 386px;
 	margin-top: 25px;
 	padding: 25px 35px 20px;
@@ -164,25 +187,10 @@ h1,h2,h3 {
 	border: 1px solid #e7e7eb;
 }
 
-#note
- 
-li
-:not
- 
-(
-:first-child
- 
-)
-{
-margin-left
-:
- 
-30
-px
-;
-
-
+#note li:not(:first-child){
+	margin-left:30px;
 }
+
 #note i {
 	display: inline-block;
 	font-weight: 400;

BIN
src/main/webapp/resources/img/all/loading.gif


BIN
src/main/webapp/resources/img/bg/bg_signin_2.jpg


+ 93 - 0
src/main/webapp/resources/js/common/services.js

@@ -0,0 +1,93 @@
+define([ 'angular' ], function(angular) {
+	'use strict';
+	angular.module('common.services', [ ]).factory('SessionService', function() {
+		return {
+			get : function(key) {
+				return sessionStorage.getItem(key);
+			},
+			set : function(key, val) {
+				return sessionStorage.setItem(key, val);
+			},
+			unset : function(key) {
+				return sessionStorage.removeItem(key);
+			}
+		};
+	}).factory('AuthenticationService', function($http, SessionService, SerializerUtil) {
+		var cacheSession = function() {
+			SessionService.set('authenticated', true);
+		};
+		var uncacheSession = function() {
+			SessionService.unset('authenticated');
+		};
+		var getRootPath = function() {
+			var fullPath = window.document.location.href;
+			var path = window.document.location.pathname;
+			var pos = fullPath.indexOf(path);
+			return fullPath.substring(0, pos) + path.substring(0, path.substr(1).indexOf('/') + 1);
+		};
+		var rootPath = getRootPath();
+		return {
+			login : function(user) {
+				var payload = SerializerUtil.param(user);
+				var config = {
+					headers : {
+						'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
+					}
+				};
+				var login = $http.post(rootPath + "/j_spring_security_check", payload, config);
+				login.success(cacheSession);
+				return login;
+			},
+			logout : function() {
+				var logout = $http.get(rootPath + "/j_spring_security_logout");
+				logout.success(uncacheSession);
+				return logout;
+			},
+			isAuthed : function() {
+				return SessionService.get('authenticated');
+			},
+			getAuthentication : function() {
+				var request = $http.get(rootPath + '/authentication');
+				request.success(function(data){
+					if(data)
+						cacheSession();
+					else
+						uncacheSession();
+				});
+				request.error(uncacheSession);
+				return request;
+			}
+		};
+	}).factory('SerializerUtil', function() {
+		return {
+			/**
+			 * @description 将元素值转换为序列化的字符串表示
+			 */
+			param : function(obj) {
+				var query = '', name, value, fullSubName, subName, subValue, innerObj, i, me = this;
+				for (name in obj) {
+					value = obj[name];
+					if (value instanceof Array) {
+						for (i = 0; i < value.length; ++i) {
+							subValue = value[i];
+							fullSubName = name + '[' + i + ']';
+							innerObj = {};
+							innerObj[fullSubName] = subValue;
+							query += me.param(innerObj) + '&';
+						}
+					} else if (value instanceof Object) {
+						for (subName in value) {
+							subValue = value[subName];
+							fullSubName = name + '[' + subName + ']';
+							innerObj = {};
+							innerObj[fullSubName] = subValue;
+							query += me.param(innerObj) + '&';
+						}
+					} else if (value !== undefined && value !== null)
+						query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
+				}
+				return query.length ? query.substr(0, query.length - 1) : query;
+			}
+		};
+	});
+});

+ 25 - 0
src/main/webapp/resources/js/signin/app.js

@@ -0,0 +1,25 @@
+define([ 'toaster', 'services' ], function() {
+	'use strict';
+	var app = angular.module('myApp', [ 'toaster', 'common.services' ]);
+	app.init = function() {
+		angular.bootstrap(document, [ 'myApp' ]);
+	};
+	app.controller('AuthCtrl', function($scope, $window, toaster, AuthenticationService) {
+		$scope.loading = false;
+		$scope.user = {
+			j_username : "",
+			j_password : ""
+		};
+		$scope.login = function(user) {
+			$scope.loading = true;
+			AuthenticationService.login(user).success(function(responseText, status) {
+				if (status == 200)
+					$window.location.href = responseText;
+			}).error(function() {
+				$scope.loading = false;
+				toaster.pop('error', '登录失败', '用户名或密码错误');
+			});
+		};
+	});
+	return app;
+});

+ 22 - 0
src/main/webapp/resources/js/signin/main.js

@@ -0,0 +1,22 @@
+require.config({
+	baseUrl : 'static',
+	paths : {
+		'app' : 'js/signin',
+		'lib' : 'lib',
+		'angular' : 'lib/angular/angular',
+		'ngAnimate': 'lib/angular/angular-animate.min',
+		'toaster' : 'lib/angular/angular-toaster.min',
+		'services' : 'js/common/services'
+	},
+	shim : {
+		'angular' : {
+			'exports' : 'angular'
+		},
+		'ngAnimate' : ['angular'],
+		'toaster' : ['angular', 'ngAnimate'],
+		'services': ['angular']
+	}
+});
+require([ 'app/app' ], function(app) {
+	app.init();
+});