You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
7.6 KiB

  1. /*页面加载完成事件绑定二级li的点击事件*/
  2. $(function(){
  3. var window_width = $(window).width();
  4. $(".main-show").css({
  5. "width": window_width-5,
  6. "left": 2,
  7. });
  8. //给只有二级菜单的li绑定事件负责背景颜色
  9. $("li.second-li").bind("click", function(){
  10. $(this).parents("ul.custom-style").find("li").removeClass("active");
  11. $(this).addClass("active");
  12. });
  13. $("ul").on("hide.bs.dropdown", function(){
  14. return false;
  15. });
  16. //失去open后的事件
  17. $("li.first-li").bind("click", function(){
  18. $(this).siblings("li.open").find("li").removeClass("active");
  19. if($(this).hasClass('open')){
  20. $(this).removeClass("open");
  21. }else{
  22. $(this).addClass("open");
  23. }
  24. });
  25. //负责有三级菜单的二级li的图标控制和ul的伸展和塑回
  26. $("li.dropdown-submenu").bind("click", function(){
  27. if($(this).hasClass('open')){
  28. $(this).removeClass("open");
  29. $(this).removeClass("active");
  30. $(this).find("ul.second-menu").removeAttr("display");
  31. }else{
  32. $(this).addClass("open");
  33. $(this).find("ul.second-menu").attr("display", "block");
  34. }
  35. });
  36. //数据展示
  37. $("a.header-show").bind("click", function(){
  38. var url = $(this).attr("href");
  39. $.ajax({
  40. url: url,
  41. type:"GET",
  42. data:{},// 你的formid
  43. dataType:"Html",
  44. success: function (data) {
  45. $(".main-show").html(data);
  46. },
  47. error: function(data) {
  48. var responseText = data.responseText;
  49. var json_str = JSON.parse(responseText);
  50. var status = json_str.status;
  51. var message = json_str.message;
  52. //判断是否是session超时
  53. if(403==status){
  54. layer.alert(message,function(){
  55. window.location.href="/login";
  56. });
  57. }
  58. layer.closeAll('loading');
  59. }
  60. })
  61. return false;
  62. });
  63. });
  64. /* 停止隐藏ul */
  65. function stop(){
  66. event.stopPropagation();
  67. }
  68. //展示修改密码模态框
  69. function editPasswordPage(){
  70. $("#first_password").val("");
  71. $("#confirm_password").val("");
  72. $("#user_password").modal();
  73. }
  74. //密码修改验证
  75. $("input.checkedPassword").bind("blur",function(){
  76. var first_password = $.trim($("#first_password").val());
  77. var confirm_password = $.trim($("#confirm_password").val());
  78. if(first_password==""){
  79. layer.msg("密码不能为空!");
  80. return false;
  81. }
  82. if(confirm_password==""){
  83. layer.msg("确认密码不能为空!");
  84. return false;
  85. }
  86. if(confirm_password!=first_password){
  87. layer.msg("确认密码和密码必须相同!");
  88. return false;
  89. }
  90. });
  91. //提交使用
  92. function checkedPassword(){
  93. var first_password = $.trim($("#first_password").val());
  94. var confirm_password = $.trim($("#confirm_password").val());
  95. if(first_password==""){
  96. layer.msg("密码不能为空!");
  97. return false;
  98. }
  99. if(confirm_password==""){
  100. layer.msg("确认密码不能为空!");
  101. return false;
  102. }
  103. if(confirm_password!=first_password){
  104. layer.msg("确认密码和密码必须相同!");
  105. return false;
  106. }
  107. }
  108. //修改密码
  109. function passwordSave(){
  110. checkedPassword();
  111. var first_password = $.trim($("#first_password").val());
  112. var confirm_password = $.trim($("#confirm_password").val());
  113. if (first_password==''){
  114. layer.msg("新密码不能为空");
  115. return false;
  116. }
  117. if (confirm_password==''){
  118. layer.msg("重复密码不能为空");
  119. return false;
  120. }
  121. $.ajax({
  122. url: "/user/passwordSave",
  123. type:"POST",
  124. data:{"id": $("#current_id").val(),
  125. "password": first_password,
  126. "confirm_password": confirm_password
  127. },// 你的formid
  128. dataType:"JSON",
  129. success: function (data) {
  130. if (data.success) {
  131. layer.msg(data.msg);
  132. $("#password_cancel").click();
  133. window.location.href="/login";
  134. }else{
  135. layer.msg(data.msg);
  136. }
  137. },
  138. error: function(data) {
  139. var responseText = data.responseText;
  140. var json_str = JSON.parse(responseText);
  141. var status = json_str.status;
  142. var message = json_str.message;
  143. //判断是否是session超时
  144. if(403==status){
  145. layer.alert(message,function(){
  146. window.location.href="/login";
  147. });
  148. }
  149. layer.closeAll('loading');
  150. }
  151. });
  152. }
  153. //清除输入内容
  154. function clear(){
  155. //初始化信息
  156. $("#username").val("");
  157. $("#display").val("");
  158. $("#password").val("");
  159. $("#user_des").val("");
  160. $("#id").val("0");
  161. $("#user_status").val("0");
  162. }
  163. //修改用户页面
  164. function editUserPage(){
  165. clear();
  166. var id = $("#current_id").val();
  167. var username = $("#current_username").val();
  168. var display = $("#current_display").val();
  169. $("#operate_username").val(username);
  170. $("#operate_display").val(display);
  171. $("#operate_id").val(id);
  172. //显示隐藏的数据
  173. $("#operate_user_modal").modal();
  174. }
  175. //用户的更新和新增
  176. function operateUserSave(){
  177. var username = $.trim($("#operate_username").val());
  178. var display = $.trim($("#operate_display").val());
  179. if (username=="") {
  180. layer.msg("请输入用户账号!");
  181. return false;
  182. }
  183. if (display=="") {
  184. layer.msg("请输入用户名称!");
  185. return false;
  186. }
  187. layer.load(2);
  188. /**
  189. * 保存数据
  190. */
  191. $.ajax({
  192. url: "/user/operateUserSave",
  193. type:"POST",
  194. data:$('#operate_user_form').serialize(),// 你的formid
  195. dataType:"JSON",
  196. success: function (data) {
  197. layer.closeAll('loading');
  198. if (data.success) {
  199. layer.msg(data.msg);
  200. clear();
  201. $("#operate_user_cancel").click();
  202. }else{
  203. layer.msg(data.msg);
  204. }
  205. },
  206. error: function(data) {
  207. var responseText = data.responseText;
  208. var json_str = JSON.parse(responseText);
  209. var status = json_str.status;
  210. var message = json_str.message;
  211. //判断是否是session超时
  212. if(403==status){
  213. layer.alert(message,function(){
  214. window.location.href="/login";
  215. });
  216. }
  217. layer.closeAll('loading');
  218. }
  219. })
  220. }
  221. //获取当天日期时间
  222. function getNowFormatDate() {
  223. var date = new Date();
  224. var seperator1 = "-";
  225. var seperator2 = ":";
  226. var month = date.getMonth() + 1;
  227. var strDate = date.getDate();
  228. if (month >= 1 && month <= 9) {
  229. month = "0" + month;
  230. }
  231. if (strDate >= 0 && strDate <= 9) {
  232. strDate = "0" + strDate;
  233. }
  234. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  235. + " " + date.getHours() + seperator2 + date.getMinutes()
  236. + seperator2 + date.getSeconds();
  237. return currentdate;
  238. }
  239. //获取当天日期时间
  240. function getNowFormatYMDHm() {
  241. var date = new Date();
  242. var seperator1 = "-";
  243. var seperator2 = ":";
  244. var month = date.getMonth() + 1;
  245. var strDate = date.getDate();
  246. var hour = date.getHours();
  247. var minutes = date.getMinutes();
  248. if (month >= 1 && month <= 9) {
  249. month = "0" + month;
  250. }
  251. if (strDate >= 0 && strDate <= 9) {
  252. strDate = "0" + strDate;
  253. }
  254. if (hour >= 0 && hour <= 9){
  255. hour = "0" + hour;
  256. }
  257. if (minutes >= 0 && minutes <= 9){
  258. minutes = "0" + minutes;
  259. }
  260. var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
  261. + " " + hour + seperator2 + minutes;
  262. return currentdate;
  263. }
  264. //获取当天日期时间
  265. function getNowDate() {
  266. var nowDate = new Date();
  267. var year = nowDate.getFullYear();
  268. var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1)
  269. : nowDate.getMonth() + 1;
  270. var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate
  271. .getDate();
  272. var dateStr = year + "-" + month + "-" + day;
  273. return dateStr;
  274. }