• js封装openDialog方法


    1. // 对话框数组
    2. var dialogArray = [];
    3. function openDialog(args, cb) {
    4. console.log("args", args);
    5. var height = args.height || (args.full ? window.innerHeight : 500);
    6. var width = args.width || (args.full ? window.innerWidth : 660);
    7. //var rootFontSize = parseInt($("html").css('fontSize'));
    8. if (height.toString().indexOf('%') === -1) {
    9. // window.devicePixelRatio是浏览器缩放比例
    10. height = (height / window.devicePixelRatio);
    11. // debugger
    12. if (height > window.innerHeight) {
    13. height = window.innerHeight - 20;
    14. }
    15. height = height + "px";
    16. }
    17. if (width.toString().indexOf('%') === -1) {
    18. width = (width / window.devicePixelRatio);
    19. if (width > window.innerWidth) {
    20. width = window.innerWidth - 20;
    21. }
    22. width = width + "px";
    23. }
    24. var closeBtn = 1;
    25. if (args.closeBtn === 0) {
    26. closeBtn = 0;
    27. }
    28. //右上角关闭时候是否提示
    29. var isConfirm = 0;
    30. if (args.isConfirm === 1) {
    31. isConfirm = 1;
    32. }
    33. var maxmin = false;
    34. if (args.maxmin === true) {
    35. maxmin = true;
    36. }
    37. var moveEl = ".layui-layer-title";
    38. if (args.move == false) {
    39. moveEl = false;
    40. }
    41. var resize = true;
    42. if (args.resize == false) {
    43. resize = false;
    44. }
    45. // 格式化Url
    46. try {
    47. // 将..替换成全路径
    48. if (getRootUrl && typeof (getRootUrl) == "function") {
    49. args.url = args.url.replace("../", getRootUrl());
    50. }
    51. } catch (e) {
    52. }
    53. var type = typeof (args.url) === "string" ? 2 : 1;
    54. var index = clayer.open({
    55. type: type,
    56. title: args.title || "",
    57. maxmin: maxmin,
    58. moveType: 1, //拖拽风格,0是默认,1是传统拖动
    59. move: moveEl, //是否允许拖动
    60. resize: resize, //是否允许拉伸
    61. shift: 0, //0-6的动画形式,-1不开启
    62. shadeClose: false, //是否点击遮罩关闭
    63. area: [width, height],
    64. content: args.url || "",
    65. closeBtn: closeBtn,
    66. end:args.end,
    67. success: function (layero, index) {
    68. // 关闭loading...
    69. hideLoad();
    70. },
    71. cancel: function (index) {
    72. // 维护dialogArray中数据
    73. if (isConfirm == 1) {
    74. layer.confirm('确定关闭吗?', function (index2) {
    75. console.log("关闭");
    76. layer.close(index2);
    77. if (args.cancel) {
    78. args.cancel();
    79. }
    80. var start = -1;
    81. $.each(dialogArray, function (i, value) {
    82. if (value.index == index) {
    83. start = i;
    84. }
    85. });
    86. // 如果搜索出数据,则进行删除
    87. if (start != -1) {
    88. dialogArray.splice(start, 1);
    89. }
    90. layer.close(index);
    91. });
    92. return false;
    93. } else {
    94. if (args.cancel) {
    95. args.cancel();
    96. }
    97. var start = -1;
    98. $.each(dialogArray, function (i, value) {
    99. if (value.index == index) {
    100. start = i;
    101. }
    102. });
    103. // 如果搜索出数据,则进行删除
    104. if (start != -1) {
    105. dialogArray.splice(start, 1);
    106. }
    107. }
    108. }
    109. });
    110. dialogArray.push({
    111. index: index,
    112. callback: cb
    113. });
    114. //console.log("dialogArray", dialogArray);
    115. // 显示loading...
    116. //showLoad();
    117. //if (type != 1) {
    118. // clayer.load();
    119. //}
    120. }
    121. function _closeDialog(b) {
    122. //移除最后一个数组元素
    123. //console.log("dialogArray1", dialogArray);
    124. var dialog = dialogArray.pop();
    125. //console.log("dialogArray2", dialogArray);
    126. console.log("dialog", dialog);
    127. if (dialog === undefined)
    128. return;
    129. try {
    130. dialog.callback & dialog.callback(b);
    131. } catch (e) {
    132. }
    133. layer.close(dialog.index);
    134. }
    135. var clayer = window.layer || window.parent.layer || {};
    136. if (window.parent.openDialog) {
    137. //console.log("main.window.parent", window.parent.openDialog);
    138. window._closeDialog = window.parent._closeDialog;
    139. window.openDialog = window.parent.openDialog;
    140. window.clayer = window.parent.clayer;
    141. }
    142. function showLoad() {
    143. try {
    144. clayer && clayer.load(1, {
    145. shade: [0.5, '#000'] //0.5透明度的黑色背景
    146. });
    147. } catch (e) {
    148. }
    149. }
    150. function hideLoad() {
    151. try {
    152. // 关闭所有的加载层
    153. if (clayer) {
    154. clayer.closeAll('loading');
    155. // clayer.closeAll();
    156. } else {
    157. console.log("hideLoad,未取到clayer");
    158. }
    159. } catch (e) {
    160. }
    161. }
    162. function closeAllLayer() {
    163. try {
    164. // 关闭所有的加载层
    165. if (clayer) {
    166. clayer.closeAll();
    167. } else {
    168. console.log("closeAllLayer,未取到clayer");
    169. }
    170. } catch (e) {
    171. }
    172. }

  • 相关阅读:
    PHP8的类与对象的基本操作之成员变量-PHP8知识详解
    Textbooks Are All You Need
    好的期货公司开户让人省心省钱
    详细的科技特长生路径和成长规划
    鼠标参数以及选购DPI和报告率
    「iOS」UI——无限轮播图实现与UIPageControl运用
    kettle安装
    居然会有外贸人拒接来访客户的电话
    Android 13.0 锁屏页面禁止下拉状态栏
    研究生英语复习(一)
  • 原文地址:https://blog.csdn.net/m0_71349739/article/details/132756545