ReLogin.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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('s_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. });
  144. this.items.push({
  145. columnWidth: 0.28,
  146. xtype: 'checkbox',
  147. id: 'rmbUser',
  148. boxLabel: '<font style="color:gray;font-size:12px;">记住密码?</font>',
  149. checked: true
  150. });
  151. },
  152. validCode: function(){
  153. var me = this;
  154. Ext.Ajax.request({
  155. url : basePath + "common/validCode.action",
  156. params: {
  157. code: me.down('textfield[name=validcode]').value
  158. },
  159. method : 'post',
  160. async: false,
  161. callback : function(options,success,response){
  162. var localJson = new Ext.decode(response.responseText);
  163. if(localJson.exceptionInfo){
  164. showError(localJson.exceptionInfo);return;
  165. }
  166. if(localJson.ex){
  167. showError(localJson.ex);return;
  168. }
  169. if(!localJson.success){
  170. alert("验证码错误");
  171. me.down('textfield[name=validcode]').setValue('');
  172. me.down('textfield[name=validcode]').focus(false, 200);
  173. me.down('displayfield[id=valid]').refreshLabel();return;
  174. } else {
  175. me.login();
  176. }
  177. }
  178. });
  179. },
  180. login: function(){
  181. var me = this;
  182. var username = me.down('textfield[name=username]').value;
  183. var password = me.down('textfield[name=password]').value;
  184. var sob = me.down('field[name=sob]').value;
  185. var language = me.down('radio[checked=true]') ? me.down('radio[checked=true]').inputValue :
  186. (getCookie("language") || 'zh_CN');
  187. if(!username){
  188. alert("请输入用户名");
  189. if(!me.isSessionOut){
  190. me.down('displayfield[id=valid]').refreshLabel();return;
  191. }
  192. }
  193. if(!password){
  194. alert("请输入密码");
  195. if(!me.isSessionOut){
  196. me.down('displayfield[id=valid]').refreshLabel();return;
  197. }
  198. }
  199. if(getCookie("s_username") != username){//切换了用户,刷新页面
  200. warnMsg("您切换了用户,重新登录会刷新当前页面,之前数据将会消失,确定继续登录?", function(btn){
  201. if(btn == 'yes'){
  202. me.sendLoginPost(username, password, language, sob, true);
  203. } else {
  204. me.close();
  205. }
  206. });
  207. } else {
  208. me.sendLoginPost(username, password, language, sob);
  209. }
  210. },
  211. sendLoginPost: function(username, password, language, sob, refresh){
  212. var me = this;
  213. Ext.Ajax.request({
  214. url : basePath + "common/login.action",
  215. params: {
  216. username: username,
  217. password: password,
  218. language: language,
  219. sob: sob
  220. },
  221. method : 'post',
  222. callback : function(options,success,response){
  223. var localJson = new Ext.decode(response.responseText);
  224. if(localJson.reason){
  225. alert(localJson.reason);
  226. } else if(localJson.exceptionInfo){
  227. showError(localJson.exceptionInfo);//显示错误信息
  228. } else if(localJson.success){
  229. if(me.down('checkbox[id=rmbUser]').checked == true){
  230. SetCookie("s_username", username);//记录用户账号密码到cookie
  231. }
  232. SetCookie("language", language);
  233. if(refresh){
  234. window.location.href = basePath;
  235. } else {
  236. em_name = localJson.em_name;
  237. me.close();
  238. parent.document.getElementById('activeUser').innerHTML = username + "(" + em_name + ")";
  239. }
  240. }
  241. }
  242. });
  243. },
  244. refresh: function(){
  245. if(!this.isSessionOut){
  246. this.down('displayfield[id=valid]').focus(false, 200);
  247. this.down('displayfield[id=valid]').refreshLabel();
  248. } else {
  249. this.testHost();
  250. }
  251. },
  252. testHost: function(){
  253. var me = this;
  254. Ext.Ajax.request({
  255. url: basePath + 'jsps/common/vcode.jsp?' + Math.random(),
  256. method: 'get',
  257. callback: function(options,success,response){
  258. if(!success){
  259. me.down('button[name=login]').setText('<img src="' + basePath + 'resource/images/loading.gif">' +
  260. '<font size=1 color=red">连接中</font>');
  261. me.down('button[name=login]').setDisabled(true);
  262. } else {
  263. me.down('button[name=login]').setText('登&nbsp;录&raquo;');
  264. me.down('button[name=login]').setDisabled(false);
  265. }
  266. }
  267. });
  268. },
  269. onkeydown: function(e){
  270. var me = this;
  271. if(e.keyCode == 13){//ENTER
  272. if(!me.isSessionOut){
  273. me.validCode();
  274. } else {
  275. if(!me.down('button[name=login]').disabled){
  276. me.login();
  277. }
  278. }
  279. } else if(e.keyCode == 27){//ESC
  280. me.close();
  281. }
  282. },
  283. addKeyDownEvent: function(){
  284. var me = this;
  285. if(Ext.isIE){
  286. me.getEl().dom.attachEvent('onkeydown', function(){
  287. if(window.event.keyCode == 13 || window.event.keyCode == 27){
  288. me.onkeydown(window.event);
  289. }
  290. });
  291. } else {
  292. me.getEl().dom.addEventListener("keydown", function(e){
  293. if(Ext.isFF5){
  294. e = e || window.event;
  295. }
  296. if(e.keyCode == 13 || e.keyCode == 27){
  297. me.onkeydown(e);
  298. }
  299. });
  300. }
  301. }
  302. });