usermain.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /**
  2. * 用户管理
  3. *
  4. */
  5. $.namespace("user.main");
  6. user.main.init = function() {
  7. //把form传入,构造翻页控件
  8. pageinfo($("#userform"));
  9. }
  10. user.main.search = function() {
  11. //console.log($("#userform").serialize());
  12. //console.log($("#currentpage").val());
  13. $("#currentpage").val(1);
  14. $("#userform").submit();
  15. }
  16. user.main.isNotBlank=function(value){
  17. if(typeof(value)!='undefined'){
  18. value=value+"";
  19. for(var i=0; i<value.length; i++) {
  20. var c = value.charAt(i);
  21. if ((c!=' ')&&(c!='\n')&&(c!='\t')) return true;
  22. }
  23. }
  24. return false;
  25. }
  26. user.main.deluser = function(data,logindata) {
  27. if(data==logindata){
  28. $.alert({
  29. title : '提示',
  30. content : '不能删除当前登录用户',
  31. confirm : function() {
  32. }
  33. });
  34. }else{
  35. $.confirm({
  36. title : '确认框',
  37. content : '删除会导致其分配的角色也会删除,确认删除吗',
  38. confirm : function() {
  39. $.post($.app + "/user/deluser.html", {
  40. id : data
  41. }, function(data) {
  42. var message="";
  43. var success=false;
  44. if(data&&data.jsonInfo){
  45. console.log(data.jsonInfo);
  46. if(data.jsonInfo.isfail||data.jsonInfo.userIdisNull){
  47. message="提交参数错误";
  48. }else if(!data.jsonInfo.userexist){
  49. message="用户不存在";
  50. }else{
  51. for(var n in data){
  52. if(n=='jsonInfo'){
  53. continue;
  54. }
  55. var d=data[n];
  56. if(typeof(d.success)=="boolean"&&!d.success&&user.main.isNotBlank(d.sysname)){
  57. message=message+d.sysname+"、";
  58. }
  59. }
  60. if(!user.main.isNotBlank(message)){
  61. success=true;
  62. message="同步成功";
  63. }else{
  64. message=message.substring(0, message.length-1)+"同步失败"
  65. }
  66. }
  67. }
  68. $.alert({
  69. title : '提示',
  70. content : message,
  71. confirm : function() {
  72. /*
  73. if (data.success) {
  74. location.href = $.app + "/user/querylist.html";
  75. }
  76. */
  77. if(success){
  78. location.href = $.app + "/user/querylist.html";
  79. }
  80. }
  81. });
  82. /*
  83. if (data.success) {
  84. $.alert({
  85. title : '提示',
  86. content : '删除成功',
  87. confirm : function() {
  88. location.href = $.app + "/user/querylist.html";
  89. }
  90. });
  91. } else {
  92. $.alert({
  93. title : '提示',
  94. content : data.message,
  95. confirm : function() {
  96. }
  97. });
  98. }*/
  99. }, "json");
  100. },
  101. cancel : function() {
  102. }
  103. });
  104. }
  105. }
  106. user.main.edit = function(data) {
  107. $("#adduserName").attr("disabled",true);
  108. $.post(basePath + "/user/edit.html", {
  109. id : data
  110. }, function(data) {
  111. $("#htitle").html('用户修改');
  112. if (data) {
  113. for ( var a in data) {
  114. if ($("#add" + a)) {
  115. $("#add" + a).val(data[a]);
  116. }
  117. }
  118. }
  119. }, "json");
  120. }
  121. //增加用户
  122. user.main.adduser = function() {
  123. var id=$("#addid").val();
  124. var adduname=$("#adduname").val();
  125. if(adduname==''){
  126. $.alert({
  127. title : '提示',
  128. content : '姓名不能为空'
  129. });
  130. return;
  131. }
  132. var adduserName=$("#adduserName").val();
  133. if(adduserName==''){
  134. $.alert({
  135. title : '提示',
  136. content : '登录名不能为空'
  137. });
  138. return;
  139. }
  140. if(id!=null&&id!=""){
  141. //alert($("#addform").serialize())
  142. $.ajax({
  143. url : $.app + "/user/saveuser.html",
  144. data : $("#addform").serialize(),
  145. dataType : "json",
  146. type : "post",
  147. dataType : "json",
  148. success : function(data) {//ajax返回的数据
  149. if (data.success) {
  150. $.confirm({
  151. title : '提示',
  152. content : '修改成功,是否分配角色',
  153. confirm : function() {
  154. location.href = $.app + "/user/userrole.html?id="+data.attrs.id;
  155. },
  156. cancel : function() {
  157. location.href = $.app + "/user/querylist.html";
  158. }
  159. });
  160. } else {
  161. $.alert({
  162. title : '提示',
  163. content : data.message,
  164. confirm : function() {
  165. }
  166. });
  167. }
  168. }
  169. });
  170. }else{
  171. $.ajax({
  172. url : $.app + "/user/saveuser.html",
  173. data : $("#addform").serialize(),
  174. dataType : "json",
  175. type : "post",
  176. dataType : "json",
  177. success : function(data) {//ajax返回的数据
  178. if (data.success) {
  179. $.alert({
  180. title : '提示',
  181. content : '保存成功,请分配角色!',
  182. confirm : function() {
  183. location.href = $.app + "/user/userrole.html?id="+data.attrs.id;
  184. }
  185. });
  186. } else {
  187. $.alert({
  188. title : '提示',
  189. content : data.message,
  190. confirm : function() {
  191. }
  192. });
  193. }
  194. }
  195. });
  196. }
  197. };
  198. user.main.repsw = function(data) {
  199. $.confirm({
  200. title : '确认框',
  201. content : '确认重置密码吗',
  202. confirm : function() {
  203. $.post(basePath + "/user/repsw.html", {
  204. id : data
  205. }, function(data) {
  206. var message="";
  207. var success=false;
  208. if(data&&data.jsonInfo){
  209. console.log(data.jsonInfo);
  210. if(data.jsonInfo.isfail||data.jsonInfo.userIdisNull){
  211. message="提交参数错误";
  212. }else if(data.jsonInfo.passWordisNull){
  213. message="密码不能为空";
  214. }else if(!data.jsonInfo.userexist){
  215. message="用户不存在";
  216. }else{
  217. for(var n in data){
  218. if(n=='jsonInfo'){
  219. continue;
  220. }
  221. var d=data[n];
  222. if(typeof(d.success)=="boolean"&&!d.success&&user.main.isNotBlank(d.sysname)){
  223. message=message+d.sysname+"、";
  224. }
  225. }
  226. if(!user.main.isNotBlank(message)){
  227. success=true;
  228. message="同步成功";
  229. }else{
  230. message=message.substring(0, message.length-1)+"同步失败"
  231. }
  232. }
  233. }
  234. $.alert({
  235. title : '提示',
  236. content : message,
  237. confirm : function() {
  238. }
  239. });
  240. /*
  241. if (data.success) {
  242. $.alert({
  243. title : '提示',
  244. content : '重置成功',
  245. });
  246. } else {
  247. $.alert({
  248. title : '提示',
  249. content : data.message,
  250. confirm : function() {
  251. }
  252. });
  253. }*/
  254. }, "json");
  255. }
  256. });
  257. };
  258. user.main.clear = function() {
  259. $("#adduserName").attr("disabled",false);
  260. $("#htitle").html('用户新增');
  261. $("#adduname").val("");
  262. $("#adduserName").val("");
  263. }
  264. user.main.fprole = function(data) {
  265. location.href = $.app + "/user/userrole.html?id=" + data;
  266. }