main.js
6.17 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
//主调和监控模式
var operationMode = window.localStorage.getItem('operationMode');
if(operationMode == 0){
$('body>.north').addClass('monitor');
$(document).on('ajaxSend', interceptPOST);
}
else
$('body>.north').addClass('main');
//拦截POST请求
function interceptPOST(e, xhr, t){
if(t && (t.method == 'POST' || t.type == 'POST')){
console.log(e, xhr, t);
xhr.abort();
notify_err('监控模式!');
}
}
/* main js */
var gb_main_ep = new EventProxy(),
res_load_ep = EventProxy.create('load_data_basic', 'load_tab', 'load_home_layout', 'load_home_line_panel', function() {
var eq = gb_main_ep;
// basic data end
eq.once('data-basic', g_emit('tab'));
// tabs
eq.once('tab', function() {
gb_tabs.init(
g_emit('home-layout')
);
});
//home layout
eq.once('home-layout', function() {
gb_home_layout.layout(
g_emit('home-line-panel')
);
});
//home line panel
eq.once('home-line-panel', function() {
gb_home_line_panel.init(g_emit('gps-time-refresh'));
});
//start fixed time refresh gps
eq.once('gps-time-refresh', function() {
gb_data_gps.fixedTimeRefresh();
g_emit('line-schedule-layout')();
});
//line schedule layout
eq.once('line-schedule-layout', function() {
gb_line_layout.layout(g_emit('render-sch-table'));
});
//render schedule table
eq.once('render-sch-table', function() {
gb_schedule_table.show(function(){
//搜索框
gb_sch_search.init();
});
//嵌入地图页面
$('li.map-panel','#main-tab-content').load('/real_control_v2/mapmonitor/real.html');
showUpdateDescription();
});
function g_emit(id) {
console.log('g_emit [' + id + ']');
return function() {
console.log('eq.emitLater(' + id + ')');
return eq.emitLater(id);
};
}
});
//modal hide remove dom
$(document).on('hide.uk.modal', '.uk-modal', function() {
$(this).remove();
/* //如果modal内部存在context-menu,则注销
var ctx = $('.context-menu-item', this);
debugger
if(ctx.length > 0){
//ctx.contextMenu('destroy');
$.contextMenu('destroy', ctx);
}*/
});
$(document).on('click', '.ct-bottom-drawer-close', function () {
$(this).parent().removeClass('open');
});
function connectArr(arr, separator, transFun) {
var rs = '';
$.each(arr, function(i, item) {
if (transFun)
item = transFun(item);
rs += (separator + item);
});
return rs.substr(separator.length);
}
var gb_form_validation_opts = {
framework: 'uikit',
locale: 'zh_CN',
icon: {
valid: 'uk-icon-check',
invalid: 'uk-icon-times',
validating: 'uk-icon-refresh'
}
};
var notify_wait = function(t) {
UIkit.notify("<i class='uk-icon-spinner uk-icon-spin'></i> " + t, {
status: 'info'
});
}
var notify_succ = function(t) {
UIkit.notify("<i class='uk-icon-check'></i> " + t, {
status: 'success'
});
}
var notify_err = function(t) {
UIkit.notify("<i class='uk-icon-times'></i> " + t, {
status: 'danger'
});
}
var alt_confirm = function(content, succ, okBtn) {
var modalEl = UIkit.modal.confirm(content, function() {
succ && succ();
modalEl.hide();
}, {
labels: {
Ok: okBtn,
Cancel: '取消'
}
,center: true
});
}
var isArray = function(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}
var notify_err_form = function(t, form) {
$('.uk-alert-danger', form).remove();
$('.uk-modal-footer', form).before('<div class="uk-alert uk-alert-danger" data-uk-alert="">' +
'<a href="" class="uk-alert-close uk-close"></a>' +
'<p>' + t + '</p>' +
'</div>');
enable_submit_btn(form);
}
var enable_submit_btn = function(form) {
var subBtn = $('button[type=submit]', form);
if (subBtn) {
subBtn.removeClass('disabled').removeAttr('disabled');
}
}
var disabled_submit_btn = function(form) {
var subBtn = $('button[type=submit]', form);
if (subBtn) {
subBtn.addClass('disabled').attr('disabled','disabled');
}
}
var show_modal = function(id, dom) {
$(document.body).append(dom);
return UIkit.modal(id, {
bgclose: false
}).show();
}
var open_modal = function(pageUrl, data, opt) {
$.get(pageUrl, function(dom) {
if (!$(dom).hasClass('uk-modal')) {
alert('无效的dom片段!');
return;
}
var id = '#' + $(dom).attr('id');
$(document.body).append(dom);
UIkit.modal(id, opt).show();
if (data)
$(id).trigger('init', data);
});
};
function showUpdateDescription() {
//更新说明
var updateDescription={
date: '2016-12-11',
text: '<h5>1、电子路单单击“实发”时,tootip内的人员显示工号。</h5><h5>2、修复某些情况下,班次被操作后 点击“实发” 无法显示tootip的情况。</h5><h5>3、获取GPS数据失败时,页面会弹出提示,并等待7秒后尝试再次获取。</h5>'
};
var storage = window.localStorage
,key = 'update_' + updateDescription.date;
var text = storage.getItem(key);
if(!text){
var modal = '<div class="uk-modal" id="update-description-modal">'+
' <div class="uk-modal-dialog">'+
' <a class="uk-modal-close uk-close"></a>'+
' <div class="uk-modal-header">'+
' <h2>'+updateDescription.date+' 更新说明</h2></div>'+updateDescription.text+
' </div>';
show_modal('#update-description-modal', modal);
storage.setItem(key, updateDescription.text);
}
}