旭捷内部项目管理系统
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.

140 lines
3.7 KiB

10 months ago
  1. //公共参数
  2. var authTrees;//权限树结构
  3. //页面加载完事件
  4. $(function(){
  5. localStorage.removeItem("authTrees")
  6. getMenu();
  7. //加载权限树
  8. // getAuthTree();
  9. //加载树结构标签
  10. initAuthMenu();
  11. //清除所有cookie函数
  12. // cleanCookie();
  13. });
  14. function getMenu(){
  15. localStorage.setItem("returnPage",null)
  16. localStorage.setItem("titleName",null)
  17. var languageDefault = $("#current_languageDefault").val();
  18. var menuType = "pda";
  19. var token = $.cookie("token");
  20. var jsonData = {
  21. l : languageDefault,
  22. menuType : menuType,
  23. token: token,
  24. }
  25. $.ajax({
  26. url: "/sys/menu/nav",
  27. contentType: 'application/json',
  28. type:"GET",
  29. data:jsonData,//你的formid
  30. dataType:"JSON",
  31. async: false,
  32. beforeSend: function(request) {
  33. request.setRequestHeader("token", $.cookie("token"));
  34. },
  35. success: function (data) {
  36. if (data.code == 0) {
  37. authTrees = data.menuList;
  38. localStorage.setItem("authTrees",JSON.stringify(authTrees))
  39. }else if(data.code == 401 || data.code == 500){
  40. window.location.href="/login";
  41. }else {
  42. layer.msg(data.msg);
  43. }
  44. },
  45. error: function(data) {
  46. var responseText = data.responseText;
  47. var json_str = JSON.parse(responseText);
  48. var status = json_str.status;
  49. var message = json_str.message;
  50. //判断是否是session超时
  51. if(403==status){
  52. layer.alert(message,function(){
  53. window.location.href="/login";
  54. });
  55. }
  56. layer.closeAll('loading');
  57. }
  58. });
  59. }
  60. function cleanCookie(){
  61. var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
  62. if(keys) {
  63. for(var i = keys.length; i--;){
  64. document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
  65. }
  66. }
  67. }
  68. // //获取权限树结构
  69. // function getAuthTree(){
  70. // $.ajax({
  71. // url: "/base/getMenusByUsername",
  72. // type: "POST",
  73. // async: false,
  74. // data: {"username": $("#current_username").val(),
  75. // "authKey": ''},// 你的formid
  76. // dataType: "JSON",
  77. // success: function (data) {
  78. // if (data.success) {
  79. // authTrees = data.rows;
  80. // }else{
  81. // layer.msg(data.msg);
  82. // }
  83. // },
  84. // error: function(data) {
  85. // var responseText = data.responseText;
  86. // var json_str = JSON.parse(responseText);
  87. // var status = json_str.status;
  88. // var message = json_str.message;
  89. // //判断是否是session超时
  90. // if(403==status){
  91. // layer.alert(message,function(){
  92. // window.location.href="/login";
  93. // });
  94. // }
  95. // layer.closeAll('loading');
  96. // }
  97. // });
  98. // }
  99. //初始化树结构
  100. function initAuthMenu(){
  101. //权限的标签
  102. var authTags = '';
  103. //循环处理标签
  104. if(authTrees != null){
  105. for(var i = 0; i < authTrees.length; i++){
  106. //处理标签逻辑
  107. authTag = processMenuTags(authTrees[i]);
  108. authTags += authTag;
  109. }
  110. //替换标签
  111. $("#main-menu").append(authTags);
  112. }
  113. }
  114. //处理权限的菜单
  115. function processMenuTags(authTree){
  116. //公共参数
  117. var id = authTree.menuId;
  118. var url = ""
  119. var titleName = ""
  120. if(authTree.type == 0){
  121. url = "/pda/publicMenu"
  122. titleName = "&titleName=" + authTree.name
  123. }else {
  124. url = authTree.url
  125. }
  126. url = url + "?menuId=" + authTree.menuId + "&token=" + $.cookie("token")+titleName;
  127. var name = authTree.name;
  128. var authTag = '<div data-v-45aee492="" class="ivu-row" style ="margin: 20px;margin-top: -3px;">';
  129. authTag += '<div data-v-45aee492="" class="ivu-col ivu-col-span-13 ivu-col-offset-5" style="width: 105%;margin-left: -7px;">';
  130. authTag += '<a data-v-45aee492="" type="button" id="'+id+'" href="'+url+'"';
  131. authTag += 'class="ivu-btn ivu-btn-primary ivu-btn-long" >'; //style = "border-color: #FF7F24;"
  132. authTag += '<span style="font-size: 20px">'+name+'</span>';
  133. authTag += '</a></div></div>';
  134. return authTag;
  135. }