common.js
8.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
* 通用方法封装处理
* Copyright (c) 2018 huaheng
*/
$(function(){
// 复选框事件绑定
if ($.fn.select2 !== undefined) {
$("select.form-control:not(.noselect2)").each(function () {
$(this).select2().on("change", function () {
$(this).valid();
})
})
}
if ($(".i-checks").length > 0) {
$(".i-checks").iCheck({
checkboxClass: "icheckbox_square-green",
radioClass: "iradio_square-green",
})
}
if ($(".time").length > 0) {
layui.use('laydate', function() {
var laydate = layui.laydate;
var day1 = new Date();
day1.setTime(day1.getTime()-24*60*60*1000*7);
var endDay = new Date();
endDay.setTime(endDay.getTime()+24*60*60*1000);
laydate.render({ elem: '#startTime', theme: 'molv',value: new Date(day1), isInitValue: true});
laydate.render({ elem: '#endTime', theme: 'molv',value: new Date(endDay), isInitValue: true });
});
}
if ($(".time2").length > 0) {
layui.use('laydate', function() {
var laydate = layui.laydate;
var day1 = new Date();
day1.setTime(day1.getTime()-24*60*60*1000*7);
var endDay = new Date();
endDay.setTime(endDay.getTime()+24*60*60*1000);
laydate.render({ elem: '#startTime', theme: 'molv'});
laydate.render({ elem: '#endTime', theme: 'molv'});
});
}
if ($(".select-time").length > 0) {
layui.use('laydate', function() {
var laydate = layui.laydate;
var day1 = new Date();
day1.setTime(day1.getTime()-24*60*60*1000*7);
var endDay = new Date();
endDay.setTime(endDay.getTime()+24*60*60*1000);
laydate.render({ elem: '#startTime', theme: 'molv'});
laydate.render({ elem: '#endTime', theme: 'molv'});
});
}
if ($(".select-time2").length > 0) {
layui.use('laydate', function() {
var laydate = layui.laydate;
var day1 = new Date();
day1.setTime(day1.getTime()-24*60*60*1000*7);
var endDay = new Date();
endDay.setTime(endDay.getTime()+24*60*60*1000);
laydate.render({ elem: '#startTime', theme: 'molv'});
laydate.render({ elem: '#endTime', theme: 'molv'});
});
}
// tree表格树 展开/折叠
var expandFlag;
$("#expandAllBtn").click(function() {
var dataExpand = $.common.isEmpty(table.options.expandAll) ? true : table.options.expandAll;
expandFlag = $.common.isEmpty(expandFlag) ? dataExpand : expandFlag;
if (!expandFlag) {
$.bttTable.bootstrapTreeTable('expandAll');
} else {
$.bttTable.bootstrapTreeTable('collapseAll');
}
expandFlag = expandFlag ? false: true;
})
});
function throttles(func, wait, options) {
let _this, args, timeout;
let old = 0; //时间戳
//如果没有options就将其设置为空对象
if (!options) options = {};
let later = function () {
old = new Date().valueOf();
timeout = null;
func.apply(_this, args);
}
return function () {
_this = this;
args = arguments;
let now = new Date().valueOf();
if (options.leading === false && !old) {
old = now;
}
if (now - old > wait) {
// 第一次直接执行
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
func.apply(_this, args);
old = now;
} else if (!timeout && options.trailing !== false) {
//最后一次也被执行
timeout = setTimeout(later, wait)
}
}
}
// 返回当前激活的Tab页面关联的iframe的Windows对象
function activeWindow() {
var topWindow = $(window.parent.document);
var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-id');
if (!currentId) {
return window.parent;
}
return $('.huaheng_iframe[data-id="' + currentId + '"]', topWindow)[0].contentWindow;
}
/** 创建选项卡 */
function createMenuItem(dataUrl, menuName) {
dataIndex = $.common.random(1,100),
flag = true;
if (dataUrl == undefined || $.trim(dataUrl).length == 0) return false;
var topWindow = $(window.parent.document);
// 选项卡菜单已存在
$('.menuTab', topWindow).each(function() {
//todo 增加判断 如果是detail 则需去掉后面的/id 再判断
if ($(this).data('id') == dataUrl) {
if (!$(this).hasClass('active')) {
$(this).addClass('active').siblings('.menuTab').removeClass('active');
$('.page-tabs-content').animate({ marginLeft: ""}, "fast");
// 显示tab对应的内容区
$('.mainContent .huaheng_iframe', topWindow).each(function() {
if ($(this).data('id') == dataUrl) {
$(this).show().siblings('.huaheng_iframe').hide();
return false;
}
});
}
flag = false;
return false;
}
});
// 选项卡菜单不存在
if (flag) {
var str = '<a href="javascript:;" class="active menuTab" data-id="' + dataUrl + '">' + menuName + ' <i class="fa fa-times-circle"></i></a>';
$('.menuTab', topWindow).removeClass('active');
// 添加选项卡对应的iframe
var str1 = '<iframe class="huaheng_iframe" name="iframe' + dataIndex + '" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" seamless></iframe>';
$('.mainContent', topWindow).find('iframe.huaheng_iframe').hide().parents('.mainContent').append(str1);
// 添加选项卡
$('.menuTabs .page-tabs-content', topWindow).append(str);
}
return false;
}
/** 设置全局ajax超时处理 */
$.ajaxSetup({
complete: function(XMLHttpRequest, textStatus) {
if (textStatus == "parsererror") {
$.modal.confirm("登陆超时!请重新登陆!", function() {
window.location.href = ctx + "login";
})
}
}
});
// 本地缓存处理
var storage = {
set: function(key, value) {
window.localStorage.setItem(key, value);
},
get: function(key) {
return window.localStorage.getItem(key);
},
remove: function(key) {
window.localStorage.removeItem(key);
},
clear: function() {
window.localStorage.clear();
}
};
function getUrlParms(){
var args = new Object();
//获取查询串
var query = location.search.substring(1);
//在&处断开
var pairs = query.split("&");
for(var i=0; i<pairs.length; i++) {
//查找name=value
var pos = pairs[i].indexOf('=');
//如果没有找到就跳过
if(pos == -1) continue;
//提取name
var argname = pairs[i].substring(0,pos);
//提取value
var value = pairs[i].substring(pos+1);
//存为属性
args[argname] = decodeURI(value);
}
return args;
}
/** 拓展方法,替换字符串中字段的值 */
function formValueReplace (formData, replaceField, replaceValue) {
var beginIndex = formData.indexOf("&"+replaceField);
if (beginIndex > -1) {
var endIndex = formData.indexOf("&", beginIndex+1);
if (endIndex > -1) {
formData = formData.substring(0, beginIndex) + formData.substring(endIndex, formData.length);
}
else {
formData = formData.substring(0, beginIndex);
}
}
return formData + "&" + replaceField + "=" + replaceValue;
};
// function formValueReplace(formData, replaceField, replaceValue) {
// var beginIndex = formData.indexOf("&"+replaceField);
// if (beginIndex > -1) {
// var endIndex = formData.indexOf("&", beginIndex+1);
// if (endIndex > -1) {
// formData = formData.substring(0, beginIndex) + formData.substring(endIndex, tableValue.length);
// }
// else {
// formData = formData.substring(0, beginIndex);
// }
// formData = formData + "&" + replaceField + "=" + replaceValue;
// }
// }