懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
提交 | 用户 | 时间
71e81e 1 /**
2  * 高频方法集
3  *
4  * @author fengshuonan
5  * @Date 2019/7/29 21:20
6  */
7 layui.define(['jquery', 'layer', 'admin', 'table', 'ax', 'form'], function (exports) {
8     var $ = layui.$;
9     var layer = layui.layer;
10     var admin = layui.admin;
11     var table = layui.table;
12     var $ax = layui.ax;
13     var form = layui.form;
14
15     var func = {
16
17         /**
18          * 拼接下拉字典
19          */
20         initDictSelect: function (url, selectId, optValue, optName) {
21             $("#" + selectId).html('<option value="">请选择</option>');
22             var ajax = new $ax(Feng.ctxPath + url, function (data) {
23                 for (var i = 0; i < data.data.length; i++) {
24                     var optionValue = data.data[i][optValue];
25                     var optionName = data.data[i][optName];
26                     $("#" + selectId).append('<option value="' + optionValue + '">' + optionName + '</option>');
27                 }
28                 form.render();
29             }, function (data) {
30             });
31             ajax.start();
32         },
33
34         /**
35          * 获取内部高度,返回数值
36          */
37         getClientHeight: function () {
38             var clientHeight = 0;
39             if (document.body.clientHeight && document.documentElement.clientHeight) {
40                 clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
41             } else {
42                 clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
43             }
44             return clientHeight;
45         },
46
47         /**
48          * 获取内部高度,返回字符串
49          */
50         getClientHeightPx: function () {
51             return Feng.getClientHeight() + 'px';
52         },
53
54         /**
55          * 打开表单的弹框
56          */
57         open: function (param) {
58
59             //宽度计算
60             var width = '1000px';
61             if (param.width) {
62                 width = param.width;
63             }
64
65             //计算高度
66             var clientHeight = func.getClientHeight();
67             if (param.height) {
68                 if (clientHeight < param.height) {
69                     param.area = [width, clientHeight + "px"];
70                 } else {
71                     param.area = [width, param.height + "px"];
72                 }
73             } else {
74                 param.area = [width, clientHeight + "px"];
75             }
76
77             param.skin = 'layui-layer-admin';
78             param.offset = '35px';
79             param.type = 2;
80
81             admin.putTempData('formOk', false);
82             param.end = function () {
83                 layer.closeAll('tips');
84                 if (param.tableId) {
85                     admin.getTempData('formOk') && table.reload(param.tableId);
86                 }
87
88                 if (param.endCallback) {
89                     admin.getTempData('formOk') && param.endCallback();
90                 }
91             };
92
93             if (!param.fixed) {
94                 param.fixed = false;
95             }
96
97             if (!param.resize) {
98                 param.resize = false;
99             }
100
101             if (!param.shade) {
102                 param.shade = .1;
103             }
104
105             var thisIndex = top.layui.layer.open(param);
106
107             //按键监听esc关闭对话框
108             $(window).keydown(function (event) {
109                 if (event.keyCode === 27) {
110                     parent.layer.close(thisIndex)
111                 }
112             });
113
114             return thisIndex;
115         }
116     };
117
118     exports('func', func);
119 });