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.

581 lines
16 KiB

  1. //公共参数
  2. var authTrees;//权限树结构
  3. var currentPageStatus = 'Y';//原页面是否打开
  4. //获取权限树结构
  5. function getAuthTree(){
  6. $.ajax({
  7. url: "/base/getMenuTreesByUsername",
  8. type: "POST",
  9. async: false,
  10. data: {"username": $("#current_username").val()},// 你的formid
  11. dataType: "JSON",
  12. success: function (data) {
  13. if (data.success) {
  14. authTrees = data.rows;
  15. }else{
  16. authTrees = new Array();
  17. layer.msg('查无菜单!');
  18. }
  19. },
  20. error: function(data) {
  21. var responseText = data.responseText;
  22. var json_str = JSON.parse(responseText);
  23. var status = json_str.status;
  24. var message = json_str.message;
  25. //判断是否是session超时
  26. if(403==status){
  27. layer.alert(message,function(){
  28. window.location.href="/login";
  29. });
  30. }
  31. layer.closeAll('loading');
  32. }
  33. });
  34. }
  35. //初始化树结构
  36. function initAuthTree(){
  37. //权限的标签
  38. var authTags = '';
  39. //循环处理标签
  40. for(var i = 0; i < authTrees.length; i++){
  41. //处理标签逻辑
  42. authTag = processAuthTags(authTrees[i]);
  43. authTags += authTag;
  44. }
  45. //替换标签
  46. $("#main-nav").html(authTags);
  47. }
  48. //处理权限的菜单
  49. function processAuthTags(authTree){
  50. //公共参数
  51. var id = authTree.id;
  52. var fontLabel = authTree.fontLabel;
  53. var url = authTree.url;
  54. var name = authTree.name;
  55. var menuSet = authTree.menuSet;
  56. var authTag = '';
  57. var haveChild = authTree.haveChild;
  58. var newTab = authTree.newTab;
  59. var showMark = authTree.showMark;//是否显示菜单
  60. var showClass = "show-menu";
  61. if('Y' == showMark){
  62. showClass = "show-menu";
  63. }else{
  64. showClass = "hide-menu";
  65. }
  66. //不同等级的class不同
  67. if('Y' == haveChild){
  68. authTag = '<li class="first-li '+ showClass + '">';
  69. }else{
  70. authTag = '<li class="second-li '+ showClass + '">';
  71. }
  72. //判断是否存在子级
  73. if('Y' == haveChild){
  74. authTag += '<a href="#' + menuSet + '" class="nav-header collapsed" data-toggle="collapse">';
  75. //添加字体图标
  76. authTag += '<i class="' + fontLabel + '"></i>' + name;
  77. //添加向下的按钮
  78. authTag += '<span class="pull-right glyphicon glyphicon-chevron-toggle"></span>';
  79. }else{
  80. //判断是否是需要另外弹出页面的菜单
  81. if("Y" == newTab){
  82. authTag += '<a href="' + url + '" class="tab-show '+ showClass +'" newTab="Y" target="_blank" id="' + id + '">';
  83. }else{
  84. authTag += '<a href="' + url + '" class="tab-show '+ showClass + '" id="' + id + '">';
  85. }
  86. //添加字体图标
  87. authTag += '<i class="' + fontLabel + '"></i>' + name;
  88. }
  89. //a标签结束
  90. authTag += '</a>';
  91. //当存在子级的时候添加子级的内容(拼接子级内容)
  92. if('Y' == haveChild){
  93. var subNodes = authTree.subNodes;
  94. for(var i = 0; i < subNodes.length; i++){
  95. var subNode = subNodes[i];
  96. //第一个添加标记
  97. if(i == 0){
  98. authTag += '<ul id="' + menuSet + '" class="nav nav-list custom-style collapse">';
  99. }
  100. //中间拼写标签
  101. var subNodeTag = processAuthTags(subNode);
  102. authTag += subNodeTag;
  103. //最后添加标记
  104. if(i == subNodes.length - 1){
  105. authTag += '</ul>';
  106. }
  107. }
  108. }
  109. //最后填充li结束
  110. authTag += '</li>';
  111. return authTag;
  112. }
  113. //初始化homePage
  114. function initHomePage(){
  115. //加载新的页签
  116. //1.加载心的页签
  117. $('#main-tabs').append('<li id="tab_home" class="active"><a data-toggle="tab" '
  118. + 'href="#tab_content_home">首页</a></li>');
  119. //2.加载新的iframe
  120. $('.tab-content').append('<div id="tab_content_home" class="active" style="">'
  121. + '<iframe id="iframeTabHome" name="iframepage" frameborder="0" scrolling="no"'
  122. + 'src="/home"></iframe></div>');
  123. //重置iframe的高度和宽度
  124. resetIframeWidthAndHeight();
  125. return false;
  126. }
  127. //给只有一级菜单级菜单的li绑定事件负责背景颜色
  128. function bindFirstClick(){
  129. $("li.first-li > a").bind("click", function(){
  130. if($(this).hasClass('active')){
  131. $(this).removeClass("active");
  132. }else{
  133. $(this).addClass("active");
  134. }
  135. });
  136. }
  137. //给只有二级菜单的li绑定事件负责背景颜色
  138. function bindSecondClick(){
  139. $("li.second-li > a").bind("click", function(){
  140. $("li.second-li").find("a").removeClass("active");
  141. if(!$(this).hasClass('active')){
  142. $(this).addClass("active");
  143. }
  144. });
  145. }
  146. //数据展示绑定事件
  147. function bindMenuClick(){
  148. //数据展示
  149. $("a.tab-show").bind("click", function(){
  150. //当前的url
  151. var content_url = $(this).attr("href");
  152. var tab_id = "tab-"+$(this).attr("id");
  153. var tab_text = $.trim($(this).text());
  154. var tab_content_id = "tab-content-"+$(this).attr("id");
  155. var newTab = $(this).attr("newTab");
  156. //填充页签
  157. if('Y' == newTab){
  158. getPageStatus($(this).attr("id"));
  159. if("Y" == currentPageStatus){
  160. layer.msg('请先关闭车间工作平台页签!');
  161. }else{
  162. //重置标记
  163. currentPageStatus = 'Y';
  164. //打开或者刷新页面
  165. window.open(content_url, '车间工作平台');
  166. }
  167. }else{
  168. openTabLabel(tab_id, tab_content_id, tab_text, content_url, false);
  169. }
  170. return false;
  171. });
  172. }
  173. /*页面加载完成事件绑定二级li的点击事件*/
  174. $(function(){
  175. //初始化权限数据
  176. getAuthTree();
  177. //初始化树结构
  178. initAuthTree();
  179. var window_width = $(window).width();
  180. $(".main-show").css({
  181. "width": window_width-5,
  182. "left": 2,
  183. });
  184. //初始化page页面
  185. initHomePage();
  186. //加载一级权限点击事件
  187. bindFirstClick();
  188. //加载二级权限的事件
  189. bindSecondClick();
  190. //加载菜单的点击事件
  191. bindMenuClick();
  192. });
  193. //打开页签加载内容
  194. function openTabLabel(tab_id, tab_content_id, tab_text, content_url, innerTab){
  195. //判断是否已经打开过了
  196. if($('#main-tabs #' + tab_id).length > 0){
  197. //如果存在当前的页签则直接显示
  198. $('#main-tabs #' + tab_id + ' a').tab('show');
  199. }else{
  200. //不隐藏下划线
  201. $('#main-tabs').removeClass('none-topline');
  202. //加载新的页签
  203. //1.隐藏当前的所有的页签
  204. $('#main-tabs > li').removeClass('active');
  205. //2.加载心的页签
  206. $('#main-tabs').append('<li id=' +tab_id +' class="active"><a data-toggle="tab" '
  207. + 'href="#' + tab_content_id +'">'+ tab_text
  208. + '<i class="fa fa-times" aria-hidden="true"></i></a></li>');
  209. //3.隐藏显示的iframe
  210. $('.tab-content > div').removeClass('active');
  211. //4.加载新的iframe
  212. $('.tab-content').append('<div id="' + tab_content_id + '" class="active" style="">'
  213. + '<iframe id="iframe' + tab_content_id + '" name="iframepage"'
  214. +'style="" frameborder="0" scrolling="no" src="' + content_url
  215. + '"></iframe></div>');
  216. }
  217. //重置iframe的高度和宽度
  218. resetIframeWidthAndHeight();
  219. //绑定移除事件
  220. addRemoveFuntion(tab_id)
  221. return false;
  222. };
  223. //绑定移除事件
  224. function addRemoveFuntion(tabId){
  225. $('#'+tabId).find('i.fa.fa-times').bind('click', function(){
  226. var tabId = $(this).parents('li').attr('id');
  227. var resourceCode = tabId.substring(4);
  228. removeTabLabel(resourceCode);
  229. });
  230. return false;
  231. }
  232. //初始化计算合高度
  233. function resetIframeWidthAndHeight(){
  234. //可视区域的宽度和高度
  235. var width = $(window).width();
  236. var height = $(window).height();
  237. //左侧侧边栏的宽度
  238. var leftNavWidth = $("#main-nav").width();
  239. //右侧的nav高度
  240. var rightNavHeight = $("#right-nav").height();
  241. //页签的高度
  242. var tabHeight = $("#main-tabs").height();
  243. //计算iframe的宽度和高度
  244. var iframeWidth = width - leftNavWidth - 5;
  245. var iframeHeight = height - rightNavHeight - tabHeight - 34;
  246. //重置高度和宽度
  247. $("iframe").css("width", iframeWidth + "px");
  248. $("iframe").css("height", iframeHeight +"px");
  249. return false;
  250. }
  251. //根据resourceCode移除
  252. function removeTabLabel(resourceCode){
  253. //获取当前resourceCode标签
  254. var tabId = "tab-" + resourceCode;
  255. var tabContentId = "tab-content-" + resourceCode;
  256. //1.移除页签
  257. $('#' + tabId).remove();
  258. //2.移除页签iframe
  259. $('#' + tabContentId).remove();
  260. //判断是否存在最后一个标签
  261. var tabSize = $('#main-tabs').find('li').length;
  262. if(1 == tabSize){
  263. //不用管了 不存在子级的元素了
  264. $('#main-tabs #tab_home a').tab('show');
  265. }else{
  266. var lastTabId = $('#main-tabs').find('li:last').attr('id');
  267. var resourceCode = lastTabId.substring(4);
  268. var lastTabContentId = 'tab-content-' + resourceCode;
  269. //当前的最后一个显示
  270. $('#main-tabs #' + lastTabId + ' a').tab('show');
  271. //$('#' + lastTabId).addClass('active');
  272. //$('#' + lastTabContentId).addClass('active');
  273. }
  274. }
  275. //展示修改密码模态框
  276. function editPasswordPage(){
  277. $("#first_password").val("");
  278. $("#confirm_password").val("");
  279. $("#user_password").modal();
  280. }
  281. /*//密码修改验证
  282. $("input.checkedPassword").bind("blur",function(){
  283. var first_password = $.trim($("#first_password").val());
  284. var confirm_password = $.trim($("#confirm_password").val());
  285. if(first_password==""){
  286. layer.msg("密码不能为空!");
  287. return false;
  288. }
  289. if(confirm_password==""){
  290. layer.msg("确认密码不能为空!");
  291. return false;
  292. }
  293. if(confirm_password!=first_password){
  294. layer.msg("确认密码和密码必须相同!");
  295. return false;
  296. }
  297. });*/
  298. function editPasswordPage(){
  299. $("#first_password").val("");
  300. $("#confirm_password").val("");
  301. $("#user_password").modal();
  302. }
  303. //修改密码
  304. function savePassword(){
  305. var first_password = $.trim($("#first_password").val());
  306. var confirm_password = $.trim($("#confirm_password").val());
  307. if(first_password==""){
  308. layer.msg("密码不能为空!");
  309. return false;
  310. }
  311. if(confirm_password==""){
  312. layer.msg("确认密码不能为空!");
  313. return false;
  314. }
  315. if(confirm_password!=first_password){
  316. layer.msg("确认密码和密码必须相同!");
  317. return false;
  318. }
  319. $.ajax({
  320. url: "/user/uodatasetpassword",
  321. type:"POST",
  322. data:{"id": $("#current_id").val(),
  323. "password": first_password,
  324. "confirmpassword": confirm_password
  325. },// 你的formid
  326. dataType:"JSON",
  327. success: function (data) {
  328. if (data.success) {
  329. layer.msg(data.msg);
  330. $("#password_cancel").click();
  331. if (data.success==true){
  332. window.location.href="/login";
  333. }
  334. }else{
  335. layer.msg(data.msg);
  336. }
  337. },
  338. error: function(data) {
  339. var responseText = data.responseText;
  340. var json_str = JSON.parse(responseText);
  341. var status = json_str.status;
  342. var message = json_str.message;
  343. //判断是否是session超时
  344. if(403==status){
  345. layer.alert(message,function(){
  346. window.location.href="/login";
  347. });
  348. }
  349. layer.closeAll('loading');
  350. }
  351. });
  352. }
  353. //清除输入内容
  354. function clear(){
  355. //初始化信息
  356. $("#username").val("");
  357. $("#display").val("");
  358. $("#password").val("");
  359. $("#user_des").val("");
  360. $("#id").val("0");
  361. $("#user_status").val("0");
  362. }
  363. //修改用户页面
  364. function editUserPage(){
  365. clear();
  366. var id = $("#current_id").val();
  367. var username = $("#current_username").val();
  368. var display = $("#current_display").val();
  369. $("#operate_username").val(username);
  370. $("#operate_display").val(display);
  371. $("#operate_id").val(id);
  372. //显示隐藏的数据
  373. $("#operate_user_modal").modal();
  374. }
  375. //用户的更新和新增
  376. function operateUserSave(){
  377. var username = $.trim($("#operate_username").val());
  378. var display = $.trim($("#operate_display").val());
  379. if (username=="") {
  380. layer.msg("请输入用户账号!");
  381. return false;
  382. }
  383. if (display=="") {
  384. layer.msg("请输入用户名称!");
  385. return false;
  386. }
  387. layer.load(2);
  388. /**
  389. * 保存数据
  390. */
  391. $.ajax({
  392. url: "/user/operateUserSave",
  393. type:"POST",
  394. data:$('#operate_user_form').serialize(),// 你的formid
  395. dataType:"JSON",
  396. success: function (data) {
  397. layer.closeAll('loading');
  398. if (data.success) {
  399. layer.msg(data.msg);
  400. clear();
  401. $("#operate_user_cancel").click();
  402. }else{
  403. layer.msg(data.msg);
  404. }
  405. },
  406. error: function(data) {
  407. var responseText = data.responseText;
  408. var json_str = JSON.parse(responseText);
  409. var status = json_str.status;
  410. var message = json_str.message;
  411. //判断是否是session超时
  412. if(403==status){
  413. layer.alert(message,function(){
  414. window.location.href="/login";
  415. });
  416. }
  417. layer.closeAll('loading');
  418. }
  419. })
  420. }
  421. //公共方法
  422. //子级页面的菜单调用
  423. function subCallBackParentMenu(id){
  424. $('#'+id).trigger('click');
  425. }
  426. //子级调用父级删除某一个子菜单
  427. function subCallBackRemoveMenu(id){
  428. removeTabLabel(id);
  429. }
  430. //子级页面的菜单调用
  431. function subCallBackReload(){
  432. window.location.reload();
  433. }
  434. //公共方法
  435. //获取当前时间,格式YYYY-MM-DD
  436. function getNowFormatDate() {
  437. var date = new Date();
  438. var seperator1 = "-";
  439. var year = date.getFullYear();
  440. var month = date.getMonth() + 1;
  441. var strDate = date.getDate();
  442. if (month >= 1 && month <= 9) {
  443. month = "0" + month;
  444. }
  445. if (strDate >= 0 && strDate <= 9) {
  446. strDate = "0" + strDate;
  447. }
  448. var currentdate = year + seperator1 + month + seperator1 + strDate;
  449. return currentdate;
  450. }
  451. //获取菜单是否关闭了
  452. function getPageStatus(pageId){
  453. var pageKey = 'page-' + pageId;
  454. var pageStatus = $.cookie(pageKey);
  455. if(undefined == pageStatus){
  456. //初始化参数
  457. currentPageStatus = 'N';
  458. $.cookie(pageKey, currentPageStatus, {
  459. expires: 1,
  460. path: '/'
  461. });
  462. }else{
  463. currentPageStatus = pageStatus;
  464. }
  465. /*$.ajax({
  466. url: "/produce/getPageStatus",
  467. type: "POST",
  468. async: false,
  469. data: {"pageId": pageId},// 你的formid
  470. dataType:"JSON",
  471. success: function (data) {
  472. if(data.success){
  473. currentPageStatus = data.obj;
  474. }
  475. },
  476. error: function(data) {
  477. var responseText = data.responseText;
  478. var json_str = JSON.parse(responseText);
  479. var status = json_str.status;
  480. var message = json_str.message;
  481. //判断是否是session超时
  482. if(403==status){
  483. layer.alert(message,function(){
  484. window.parent.subCallBackReload();
  485. });
  486. }
  487. layer.closeAll('loading');
  488. }
  489. });*/
  490. }
  491. //打开打印机设置的页面
  492. function editPrinterModal(){
  493. //置空下拉框
  494. $("#operator_printer").html('');
  495. //添加下拉框
  496. CLODOP.Create_Printer_List(document.getElementById('operator_printer'));
  497. //CLODOP.Create_Printer_List($('#operator_printer'));
  498. $("#operator_printer").prepend("<option value='-1'>先预览后打印</option>");
  499. //判断是否打开设计模式
  500. if("admin" == $("#current_username").val()){
  501. $("#operator_printer").prepend("<option value='-2'>设计模式</option>");
  502. }
  503. $("#operator_printer").val($('#current_printer_index').val());
  504. //显示modal
  505. $('#printer_modal').modal();
  506. }
  507. //保存或修改用户的打印机
  508. function savePrinter(){
  509. let site = $('#current_site').val();
  510. let username = $("#current_username").val();
  511. let printerId = $("#printer_id").val();
  512. let printerIndex = $.trim($("#operator_printer").val());
  513. let printerName = $("#operator_printer").find('option:selected').text();
  514. let printerMethod = "print";
  515. //判断打印方式
  516. if(-2 == printerIndex){
  517. printerMethod = "design";
  518. }else if(-1 == printerIndex){
  519. printerMethod = "preview";
  520. }
  521. let currentRow = {"id": printerId, "site": site, "username": username, "labelNo": '', "printerIndex": printerIndex,
  522. "printerName": printerName, "printerMethod": printerMethod, "status": 'Y'}
  523. /**
  524. * 保存数据
  525. */
  526. $.ajax({
  527. url: "/user/savePrinter",
  528. type: "POST",
  529. contentType: 'application/json;charset=utf-8',
  530. data: JSON.stringify(currentRow),// 你的formid
  531. dataType:"JSON",
  532. success: function (data) {
  533. layer.closeAll('loading');
  534. if (data.success) {
  535. $("#printer_cancel").click();
  536. layer.msg(data.msg);
  537. window.location.reload();
  538. }else{
  539. layer.msg(data.msg);
  540. }
  541. },
  542. error: function(data) {
  543. var responseText = data.responseText;
  544. var json_str = JSON.parse(responseText);
  545. var status = json_str.status;
  546. var message = json_str.message;
  547. //判断是否是session超时
  548. if(403==status){
  549. layer.alert(message,function(){
  550. window.location.href="/login";
  551. });
  552. }
  553. layer.closeAll('loading');
  554. }
  555. })
  556. }