common.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // 用common.js必须加上Feng.addCtx("${ctxPath}");
  2. Feng.info = function (info) {
  3. top.layer.msg(info, {icon: 6});
  4. };
  5. Feng.success = function (info) {
  6. top.layer.msg(info, {icon: 1});
  7. };
  8. Feng.error = function (info) {
  9. top.layer.msg(info, {icon: 2});
  10. };
  11. Feng.confirm = function (tip, ensure) {
  12. top.layer.confirm(tip, {
  13. skin: 'layui-layer-admin'
  14. }, function () {
  15. ensure();
  16. });
  17. };
  18. Feng.currentDate = function () {
  19. // 获取当前日期
  20. var date = new Date();
  21. // 获取当前月份
  22. var nowMonth = date.getMonth() + 1;
  23. // 获取当前是几号
  24. var strDate = date.getDate();
  25. // 添加分隔符“-”
  26. var seperator = "-";
  27. // 对月份进行处理,1-9月在前面添加一个“0”
  28. if (nowMonth >= 1 && nowMonth <= 9) {
  29. nowMonth = "0" + nowMonth;
  30. }
  31. // 对月份进行处理,1-9号在前面添加一个“0”
  32. if (strDate >= 0 && strDate <= 9) {
  33. strDate = "0" + strDate;
  34. }
  35. // 最后拼接字符串,得到一个格式为(yyyy-MM-dd)的日期
  36. return date.getFullYear() + seperator + nowMonth + seperator + strDate;
  37. };
  38. Feng.getUrlParam = function (name) {
  39. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  40. var r = window.location.search.substr(1).match(reg);
  41. if (r != null) {
  42. return decodeURI(r[2]);
  43. } else {
  44. return null;
  45. }
  46. };
  47. Feng.infoDetail = function (title, info) {
  48. var display = "";
  49. if (typeof info === "string") {
  50. display = info;
  51. } else {
  52. if (info instanceof Array) {
  53. for (var x in info) {
  54. display = display + info[x] + "<br/>";
  55. }
  56. } else {
  57. display = info;
  58. }
  59. }
  60. top.layer.open({
  61. title: title,
  62. type: 1,
  63. skin: 'layui-layer-rim', //加上边框
  64. area: ['950px', '600px'], //宽高
  65. content: '<div style="padding: 20px;">' + display + '</div>'
  66. });
  67. };
  68. Feng.zTreeCheckedNodes = function (zTreeId) {
  69. var zTree = $.fn.zTree.getZTreeObj(zTreeId);
  70. var nodes = zTree.getCheckedNodes();
  71. var ids = "";
  72. for (var i = 0, l = nodes.length; i < l; i++) {
  73. ids += "," + nodes[i].id;
  74. }
  75. return ids.substring(1);
  76. };
  77. Feng.closeAllLoading = function () {
  78. layer.closeAll('loading');
  79. };
  80. // 以下代码是配置layui扩展模块的目录,每个页面都需要引入
  81. layui.config({
  82. base: Feng.ctxPath + '/static/common/module/'
  83. }).extend({
  84. formSelects: 'formSelects/formSelects-v4',
  85. treetable: 'treetable-lay/treetable',
  86. dropdown: 'dropdown/dropdown',
  87. notice: 'notice/notice',
  88. step: 'step-lay/step',
  89. dtree: 'dtree/dtree',
  90. citypicker: 'city-picker/city-picker',
  91. tableSelect: 'tableSelect/tableSelect',
  92. ax: 'ax/ax',
  93. excel: 'excel/excel',
  94. ztree: 'ztree/ztree-object'
  95. }).use(['admin'], function () {
  96. var $ = layui.$;
  97. var admin = layui.admin;
  98. // 单标签模式需要根据子页面的地址联动侧边栏的选中,用于适配浏览器前进后退按钮
  99. if (window != top && top.layui && top.layui.index && !top.layui.index.pageTabs) {
  100. top.layui.admin.activeNav(location.href.substring(Feng.ctxPath.length));
  101. }
  102. // 移除loading动画
  103. setTimeout(function () {
  104. admin.removeLoading();
  105. }, window == top ? 300 : 150);
  106. //注册session超时的操作
  107. $.ajaxSetup({
  108. contentType: "application/x-www-form-urlencoded;charset=utf-8",
  109. complete: function (XMLHttpRequest, textStatus) {
  110. //通过XMLHttpRequest取得响应头,sessionstatus,
  111. var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
  112. if (sessionstatus === "timeout") {
  113. //如果超时就处理 ,指定要跳转的页面
  114. window.location = Feng.ctxPath + "/global/sessionError";
  115. }
  116. }
  117. });
  118. });