layTool.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. function LayTool () {
  2. let version = 'v1.0';
  3. }
  4. LayTool.prototype.layerIndex = null;
  5. // iframe 弹层
  6. LayTool.prototype.open = function (url, title, width, height) {
  7. layui.use('layer', function () {
  8. let layer = layui.layer;
  9. if (!width) {
  10. width = '90%';
  11. }
  12. if (!height) {
  13. height = '90%';
  14. }
  15. layer.ready(function () {
  16. layer.open({
  17. type: 2,
  18. title: title,
  19. shade: 0.2,
  20. area: [width, height],
  21. content: url,
  22. });
  23. });
  24. });
  25. };
  26. // alert 弹层
  27. LayTool.prototype.alert = function (content, title, icon, closeBtn) {
  28. layui.use('layer', function () {
  29. let layer = layui.layer;
  30. if (!title) {
  31. title = '友情提示';
  32. }
  33. if (!icon) {
  34. icon = 1;
  35. }
  36. if (0 != closeBtn) {
  37. closeBtn = 1;
  38. }
  39. layer.alert(content, {
  40. title: title,
  41. icon: icon,
  42. closeBtn: closeBtn
  43. });
  44. });
  45. };
  46. // msg 弹层
  47. LayTool.prototype.msg = function (content, conf) {
  48. layui.use('layer', function () {
  49. let layer = layui.layer;
  50. layer.msg(content, conf);
  51. });
  52. };
  53. // 加载中
  54. LayTool.prototype.loading = function (type) {
  55. if (typeof type == 'undefined') {
  56. type = 0;
  57. }
  58. layui.use('layer', function () {
  59. let layer = layui.layer;
  60. layTool.layerIndex = layer.load(type, {shade: false});
  61. });
  62. };
  63. // 隐藏加载中
  64. LayTool.prototype.hideLoading = function () {
  65. setTimeout(function () {
  66. layui.use('layer', function () {
  67. let layer = layui.layer;
  68. layer.close(layTool.layerIndex);
  69. });
  70. }, 100);
  71. };
  72. // 日历
  73. LayTool.prototype.layDate = function (dom, type, range) {
  74. if (!type) {
  75. type = 'date';
  76. }
  77. if (!range) {
  78. range = false;
  79. }
  80. layui.use('laydate', function(){
  81. let laydate = layui.laydate;
  82. laydate.render({
  83. elem: dom,
  84. type: type,
  85. range: range
  86. });
  87. });
  88. };
  89. // 数据表格
  90. LayTool.prototype.table = function (dom, url, cols, limit) {
  91. layui.use('table', function(){
  92. let table = layui.table;
  93. if (!limit) {
  94. limit = 10;
  95. }
  96. table.render({
  97. elem: dom
  98. ,limit: limit
  99. ,height: 'full-200'
  100. ,url: url
  101. ,page: true
  102. ,cols: cols
  103. });
  104. });
  105. };
  106. window.layTool = new LayTool();