ReLogin.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. Ext.define('erp.view.core.window.ReLogin', {
  2. extend: 'Ext.window.Window',
  3. alias: 'widget.relogin',
  4. width: 440,
  5. height: 300,
  6. frame: true,
  7. modal: true,
  8. closable: false,
  9. closeAction: 'destroy',
  10. isSessionOut: false,
  11. bodyStyle: 'background: #E0EEEE;padding-top: 30px;padding-left:10px;',
  12. layout: 'column',
  13. initComponent: function() {
  14. this.items = new Array();
  15. this.addDefaultItems();
  16. if(!this.isSessionOut){
  17. this.addValid();
  18. this.addLanguage();
  19. }
  20. var me = this;
  21. this.items.push({
  22. xtype: 'form',
  23. columnWidth: 1,
  24. buttonAlign: 'center',
  25. bodyStyle: 'padding-top: 30px;border: none;background: #E0EEEE;',
  26. buttons: [{
  27. text: '登 录»',
  28. name: 'login',
  29. height: 25,
  30. cls: 'x-btn-blue',
  31. tooltip: '按ENTER登录',
  32. handler: function(){
  33. if(!me.isSessionOut){
  34. me.validCode();
  35. } else {
  36. me.login();
  37. }
  38. }
  39. },{
  40. text: '取 消»',
  41. cls: 'x-btn-blue',
  42. tooltip: '按ESC取消',
  43. height: 25,
  44. handler: function(){
  45. me.close();
  46. }
  47. }]
  48. });
  49. this.title = '<div style="height:25;padding-top:5px;color:blue;font-size:14px;background: #E0EEEE url(' +
  50. basePath + 'resource/ext/resources/themes/images/default/grid/grid-blue-hd.gif) repeat center center">&nbsp;&nbsp;' + this.title + '</div>';
  51. this.callParent(arguments);
  52. this.show();
  53. this.addKeyDownEvent();
  54. if(!me.isSessionOut){
  55. var language = getCookie("language") || 'zh_CN';
  56. me.down('radio[inputValue=' + language + ']').setValue(true);
  57. me.down('textfield[name=validcode]').focus(false, 200);
  58. } else {
  59. me.down('textfield[name=username]').focus(false, 200);
  60. me.testHost();
  61. }
  62. },
  63. addValid: function(){
  64. this.items.push({
  65. columnWidth: 0.65,
  66. xtype: 'textfield',
  67. labelWidth: 70,
  68. labelStyle: 'font-family:隶书;font-size:18px;color:#473C8B;',
  69. fieldCls: 'x-form-field-cir',
  70. fieldLabel: '验证码',
  71. name: 'validcode'
  72. });
  73. this.items.push({
  74. columnWidth: 0.3,
  75. xtype: 'displayfield',
  76. labelSeparator: '',
  77. id: 'valid',
  78. refreshLabel: function(){
  79. try{
  80. document.getElementById("validimg").src = basePath + 'jsps/common/vcode.jsp?' + Math.random();
  81. } catch (e){
  82. document.getElementById("validimg").src = basePath + 'resource/images/loading.gif';
  83. }
  84. },
  85. fieldLabel: "<img id='validimg' src='" + basePath + "jsps/common/vcode.jsp' onclick=\"document.getElementById('validimg').src='" + basePath + "jsps/common/vcode.jsp?'+Math.random();\" style='cursor: pointer;' onerror=\"document.getElementById('validimg').src='" + basePath + "resource/images/loading.gif'\"></img>"
  86. });
  87. },
  88. addLanguage: function(){
  89. this.items.push({
  90. columnWidth: 0.65,
  91. xtype: 'fieldcontainer',
  92. fieldLabel: '语&nbsp;&nbsp;言',
  93. labelStyle: 'font-family:隶书;font-size:18px;color:#473C8B;',
  94. labelWidth: 70,
  95. layout: 'hbox',
  96. items: [{
  97. xtype: 'radio',
  98. margin: '1 1 1 1',
  99. boxLabel: '<font style="color:gray;font-size:13px;">简体</font>',
  100. name: 'language',
  101. inputValue: 'zh_CN'
  102. },{
  103. xtype: 'radio',
  104. margin: '1 1 1 1',
  105. boxLabel: '<font style="color:gray;font-size:13px;">繁體</font>',
  106. name: 'language',
  107. inputValue: 'zh_TW'
  108. },{
  109. xtype: 'radio',
  110. margin: '1 1 1 1',
  111. boxLabel: '<font style="color:gray;font-size:13px;">English</font>',
  112. name: 'language',
  113. inputValue: 'en_US'
  114. }]
  115. });
  116. },
  117. addDefaultItems: function(){
  118. this.items.push({
  119. columnWidth: 0.65,
  120. xtype: 'textfield',
  121. labelWidth: 70,
  122. name: 'username',
  123. labelStyle: 'font-family:隶书;font-size:18px;color:#473C8B;',
  124. fieldLabel: '账&nbsp;&nbsp;号',
  125. fieldCls: 'x-form-field-cir',
  126. value: getCookie('username') || ""
  127. });
  128. this.items.push({
  129. columnWidth: 0.2,
  130. xtype: 'displayfield',
  131. name: 'sob',
  132. value: sob
  133. });
  134. this.items.push({
  135. columnWidth: 0.65,
  136. xtype: 'textfield',
  137. name: 'password',
  138. fieldCls: 'x-form-field-cir',
  139. labelWidth: 70,
  140. labelStyle: 'font-family:隶书;font-size:18px;color:#473C8B;',
  141. fieldLabel: '密&nbsp;&nbsp;码',
  142. inputType: 'password',
  143. value: getCookie('password') || ""
  144. });
  145. this.items.push({
  146. columnWidth: 0.28,
  147. xtype: 'checkbox',
  148. id: 'rmbUser',
  149. boxLabel: '<font style="color:gray;font-size:12px;">记住密码?</font>',
  150. checked: true
  151. });
  152. },
  153. validCode: function(){
  154. var me = this;
  155. Ext.Ajax.request({
  156. url : basePath + "common/validCode.action",
  157. params: {
  158. code: me.down('textfield[name=validcode]').value
  159. },
  160. method : 'post',
  161. async: false,
  162. callback : function(options,success,response){
  163. var localJson = new Ext.decode(response.responseText);
  164. if(localJson.exceptionInfo){
  165. showError(localJson.exceptionInfo);return;
  166. }
  167. if(localJson.ex){
  168. showError(localJson.ex);return;
  169. }
  170. if(!localJson.success){
  171. alert("验证码错误");
  172. me.down('textfield[name=validcode]').setValue('');
  173. me.down('textfield[name=validcode]').focus(false, 200);
  174. me.down('displayfield[id=valid]').refreshLabel();return;
  175. } else {
  176. me.login();
  177. }
  178. }
  179. });
  180. },
  181. login: function(){
  182. var me = this;
  183. var username = me.down('textfield[name=username]').value;
  184. var password = me.down('textfield[name=password]').value;
  185. var sob = me.down('field[name=sob]').value;
  186. var language = me.down('radio[checked=true]') ? me.down('radio[checked=true]').inputValue :
  187. (getCookie("language") || 'zh_CN');
  188. if(!username){
  189. alert("请输入用户名");
  190. if(!me.isSessionOut){
  191. me.down('displayfield[id=valid]').refreshLabel();return;
  192. }
  193. }
  194. if(!password){
  195. alert("请输入密码");
  196. if(!me.isSessionOut){
  197. me.down('displayfield[id=valid]').refreshLabel();return;
  198. }
  199. }
  200. if(getCookie("username") != username){//切换了用户,刷新页面
  201. warnMsg("您切换了用户,重新登录会刷新当前页面,之前数据将会消失,确定继续登录?", function(btn){
  202. if(btn == 'yes'){
  203. me.sendLoginPost(username, password, language, sob, true);
  204. } else {
  205. me.close();
  206. }
  207. });
  208. } else {
  209. me.sendLoginPost(username, password, language, sob);
  210. }
  211. },
  212. sendLoginPost: function(username, password, language, sob, refresh){
  213. var me = this;
  214. Ext.Ajax.request({
  215. url : basePath + "common/login.action",
  216. params: {
  217. username: username,
  218. password: password,
  219. language: language,
  220. sob: sob
  221. },
  222. method : 'post',
  223. callback : function(options,success,response){
  224. var localJson = new Ext.decode(response.responseText);
  225. if(localJson.reason){
  226. alert(localJson.reason);
  227. } else if(localJson.exceptionInfo){
  228. showError(localJson.exceptionInfo);//显示错误信息
  229. } else if(localJson.success){
  230. if(me.down('checkbox[id=rmbUser]').checked == true){
  231. SetCookie("username", username);//记录用户账号密码到cookie
  232. SetCookie("password", password);
  233. }
  234. SetCookie("language", language);
  235. if(refresh){
  236. window.location.href = basePath;
  237. } else {
  238. em_name = localJson.em_name;
  239. me.close();
  240. parent.document.getElementById('activeUser').innerHTML = username + "(" + em_name + ")";
  241. }
  242. }
  243. }
  244. });
  245. },
  246. refresh: function(){
  247. if(!this.isSessionOut){
  248. this.down('displayfield[id=valid]').focus(false, 200);
  249. this.down('displayfield[id=valid]').refreshLabel();
  250. } else {
  251. this.testHost();
  252. }
  253. },
  254. testHost: function(){
  255. var me = this;
  256. Ext.Ajax.request({
  257. url: basePath + 'jsps/common/vcode.jsp?' + Math.random(),
  258. method: 'get',
  259. callback: function(options,success,response){
  260. if(!success){
  261. me.down('button[name=login]').setText('<img src="' + basePath + 'resource/images/loading.gif">' +
  262. '<font size=1 color=red">连接中</font>');
  263. me.down('button[name=login]').setDisabled(true);
  264. } else {
  265. me.down('button[name=login]').setText('登&nbsp;录&raquo;');
  266. me.down('button[name=login]').setDisabled(false);
  267. }
  268. }
  269. });
  270. },
  271. onkeydown: function(e){
  272. var me = this;
  273. if(e.keyCode == 13){//ENTER
  274. if(!me.isSessionOut){
  275. me.validCode();
  276. } else {
  277. if(!me.down('button[name=login]').disabled){
  278. me.login();
  279. }
  280. }
  281. } else if(e.keyCode == 27){//ESC
  282. me.close();
  283. }
  284. },
  285. addKeyDownEvent: function(){
  286. var me = this;
  287. if(Ext.isIE){
  288. me.getEl().dom.attachEvent('onkeydown', function(){
  289. if(window.event.keyCode == 13 || window.event.keyCode == 27){
  290. me.onkeydown(window.event);
  291. }
  292. });
  293. } else {
  294. me.getEl().dom.addEventListener("keydown", function(e){
  295. if(Ext.isFF5){
  296. e = e || window.event;
  297. }
  298. if(e.keyCode == 13 || e.keyCode == 27){
  299. me.onkeydown(e);
  300. }
  301. });
  302. }
  303. }
  304. });