main.js
8.32 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* 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 recorder;
var fired = false;
let timer = null;//定时器
const longPressDuration = 500; // 长按的阈值,单位毫秒
var zxFl = true; //定时器内只执行一次;
function openAi(){
if (zxFl){
console.log('长按回车键');
zxFl = false;
fired = true;
document.getElementById("recidress").style.display = "";
HZRecorder.get(function (rec) {
recorder = rec;
recorder.start();
});
}
}
document.addEventListener('keydown', function(event) {
if (event.key === 'Enter' && zxFl) {
// 开始计时
timer = setTimeout(() => {
openAi();
// 执行长按的逻辑
}, longPressDuration);
}
});
document.addEventListener('keyup', function(event) {
if (event.key === 'Enter') {
// 清除计时器,表示短按
clearTimeout(timer);
console.log('短按回车键');
// 执行短按的逻辑
}
});
document.onkeyup =function(e) { //对整个页面监听
var keyNum = window.event ? e.keyCode : e.which; //获取被按下的键值
//判断如果用户按下了回车键(keycody=13)
console.log('松开回车键');
clearTimeout(timer);
if (keyNum == 13) {
if(!fired)
return;
fired = false;zxFl= true;
let lineCode = gb_schedule_table.TablelineCode;
document.getElementById("recidress").style.display = 'none';
recorder.upload("zndd/do/"+lineCode, function (state, e) {
switch (state) {
case 'uploading':
//var `percentComplete` = Math.round(e.loaded * 100 / e.total) + '%';
break;
case 'ok':
// alert("识别成功");
break;
case 'error':
alert("识别失败");
break;
case 'cancel':
alert("识别被取消");
break;
}
});
}
};
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_signal_state.init();
});
//初始化gps异常判定
gb_gps_abnormal.initData();
setTimeout(function () {
//嵌入地图页面
$('li.map-panel', '#main-tab-content').load('/real_control_v2/mapmonitor/real.html');
}, 1000);
//弹出更新说明
showUpdateDescription();
});
function g_emit(id) {
console.log('g_emit [' + id + ']');
return function () {
console.log('eq.emitLater(' + id + ')');
return eq.emitLater(id);
};
}
});
$(document).on('click', '.ct-bottom-drawer-close', function () {
$(this).parents('.ct-bottom-drawer').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, noCenter) {
var modalEl = UIkit.modal.confirm(content, function () {
succ && succ();
modalEl.hide();
}, {
labels: {
Ok: okBtn,
Cancel: '取消'
}
, center: !noCenter
});
};
var show_wait_modal = function (text) {
var modalHtml =
'<div class="uk-modal" id="gb_wait_modal">' +
' <div class="uk-modal-dialog">' +
' <div class="uk-modal-spinner"></div>' +
' <div class="wait-modal-text">' + text + '</div>' +
' </div>' +
'</div>';
$(document.body).append(modalHtml);
return UIkit.modal('#gb_wait_modal', {
bgclose: false,
modal: false
}).show();
};
var hide_wait_modal = function () {
UIkit.modal('#gb_wait_modal').hide();
};
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');
}
};
function showUpdateDescription() {
//更新说明
var updateDescription = {
date: '...',
text: '<h5 style="line-height: 25px;letter-spacing: 1px;font-family: 微软雅黑;"> <span style="font-weight: 600;color: #ff0505;">修复了一个bug。</span><br><hr>该bug导致“调整人车”时,提交按钮可快速的重复点击(<small style="color: #6a6a6a;">提交按钮被误解锁</small>)。<br>有一定几率引起查询故障,导致线调页面看不到班次信息。</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);
}
}