mobilemode.js
11.4 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
define(['mUtil', 'pageStack', 'pageEvent', 'zepto','i18n'], function () {
var mUtil = require("mUtil");
var pageEvent = require("pageEvent");
var i18n = require("i18n");
var _page = (function () {
var $el = null;
var mods = null;
var queues = {
first: $.Deferred(),
second: $.Deferred()
};
return {
setParams: function (pageid, formdata) {
var pageIntId = mUtil.getPageIntId(pageid);
var params = { "pageKey": mUtil.UUID() + "_" + pageIntId };
var pArr = (formdata || "").split("&");
pArr.forEach(function (pStr) {
var pIndex = pStr.indexOf("=");
if (pIndex != -1) {
var pName = pStr.substring(0, pIndex);
var pValue = pStr.substring(pIndex + 1);
params[pName] = pValue;
}
});
mUtil.setPageParam(pageid, params);
},
setPaths: function () {
if (mods) return;
mods = ['mApi/popup'];
$(document.body).find(".page").each(function (i, page) {
var pageIntid = mUtil.getPageIntId(page.id);
var path = mUtil.getPageScriptPath(pageIntid);
mods.push(path);
});
},
setElement: function ($page) {
$el = $page;
},
hideLoading: function () {
$el.children(".page-loading").remove();
},
prevcache: {
start: function () {
if (mods.length === 0) return;
var _start = function (i) {
var modName = mods.shift();
if (!modName) return;
mUtil.require(modName).then(function () {
queues[i].resolve().then(function () {
queues[i] = $.Deferred();
_start(i);
});
});
};
queues.first = $.Deferred();
queues.second = $.Deferred();
_start("first");
_start("second");
},
stop: function () {
queues.first.reject();
queues.second.reject();
}
},
blurPageEle: function(pageOut, back) {
var $page = $(pageOut).children(".page-content")[0];
if(!$page) return;
try{
if(back){
$("input,textarea,select", $page).not("input[type='hidden']").each(function(i, ele){
ele.blur();
});
//明细表
var $dtpage = $(pageOut).children(".wev-detailtable-page.in")[0];
if($dtpage){
$("input,textarea,select", $dtpage).not("input[type='hidden']").each(function(i, ele){
ele.blur();
});
}
}
require(['audioHelper'], function(audioHelper){//语音暂停播放
audioHelper.pauseAllAudios();
});
$(".wev-comp-Video", $page).each(function(i, ele){//视频控件暂停播放
var instance = mUtil.getInstance($(ele).parent().attr("id"), pageOut.id);
instance && instance.pauseVideo();
});
}catch(e){
console.log(e);
}
},
clearPage: function($page){
var that = this;
var $pageHeader = $page.children(".page-header"),
$pageContent = $page.children(".page-content"),
$pageFooter = $page.children(".page-footer");
$page.children().not(".page-header, .page-content, .page-footer, .page-tip").remove();
$pageHeader.children().not("abbr[data-type]").remove();
$pageContent.children(".page-scroller").children().not("abbr[data-type]").remove();
$pageFooter.children().not("abbr[data-type]").remove();
$pageContent.children(".tabpanel").each(function () {
var $tabpanel = $(this);
var clsName = "page-scroller";
if (!$tabpanel.hasClass("page-scroller")) {
clsName = "tabpanel show_hide out";
that.clearPage($tabpanel);
}
$tabpanel.attr("class", clsName).removeAttr("style");
});
$pageHeader.children("abbr[data-tabpanel]").remove();
$pageFooter.children("abbr[data-tabpanel]").remove();
$(
$pageHeader.children("abbr[data-type]").concat(
$pageContent.children(".page-scroller").children("abbr[data-type]"),
$pageFooter.children("abbr[data-type]")
)
).each(function () {
$(this).data("loaded", false).html("");
});
}
};
})();
(function handleIosKeyboard() {
if(mUtil.isIOS()){
$('body').on('blur', 'input, select, textarea', function () {
if(mUtil.isFunction(this.scrollIntoViewIfNeeded)){
this.scrollIntoViewIfNeeded();
}
});
}
}())
return {
pageInit: function (page, pageOut, options) {
//添加水印
var $watermarkWrap = $('#wea_watermark_wrap');
if(!$watermarkWrap.length){
require(['watermark'], function(WM){
WM.getSystemSetting();
});
}
var $page = $(page);
if ($page.hasClass("page-scroller")) return;
var pageid = page.id;
var pageIntId = mUtil.getPageIntId(pageid);
var Component = require("Component");
var _evalPageScript = function(type) {
mUtil.getPageScript(pageIntId).then(function(o) {
var code = o[type].toString();
code = mUtil.replaceVariables(code);
code = code.replace(/^function([\s\S]*)/i, '(function fun$1)();');
mUtil.eval(code, pageid);
});
}
if (!options.isrefresh) { // 页面刷新
mUtil.setCurrentPageId(pageid);
}
_page.setElement($page);
_page.setParams(pageid, options.formdata);
_page.setPaths();
var components = [];
$(
$page.children(".page-header").children("abbr[data-type]").concat(
$page.children(".page-content").children(".page-scroller").children("abbr[data-type]"),
$page.children(".page-footer").children("abbr[data-type]")
)
).each(function () {
var $abbr = $(this);
var priority = $abbr.data("priority");
$abbr.data("loaded", false).html("");
if ($abbr.data("lazyload") == true) return;
components.push({
el: this.id,
type: $abbr.data("type"),
container: $page,
priority: priority === undefined ? Math.pow(2, 53) - 1 : priority,
pageid: pageid
});
});
_page.prevcache.stop();
// 防止在A页面调用refresh函数刷新B页面后,再次打开B页面,B页面事件无法及时清空,造成多次绑定的问题
mUtil.unbind(pageid);
_evalPageScript("sourcecode");
if (components.length > 0) {
mUtil.getPageScript(pageIntId).then(function (o) {
var props = o.props;
components.forEach(function (component) {
component.option = props[component.el];
});
Component.load(components, function () {
mUtil.trigger('load', pageid);
_page.prevcache.start();
}, function (component, index) {
if (index === 0) {
_page.hideLoading();
}
mUtil.trigger('load', pageid, component.id);
});
});
Component.preload(components);
}else{
_page.hideLoading();
mUtil.trigger('load', pageid);
}
mUtil.onload(pageid, function () {
_evalPageScript("onload");
components.forEach(function (component) {
var Com = Component.getInstance(component.el, component.pageid);
Com.$emit("moveComponent");
});
$page.off("click.viewimg");
$page.on("click.viewimg", "img[data-groupid]", function (e) {
var currSrc = $(this).attr("src");
if($(this).closest("a[data-ignoreviewimg]").length) return;
if (currSrc) {
var imgs = [];
var groupid = $(this).attr("data-groupid");
$("img[data-groupid='" + groupid + "']", $page).each(function () {
if (!this.src) return true;
imgs.push(this);
});
var actIndex = imgs.indexOf(this);
require(["imgViewerHelper"], function (Viewer) {
Viewer(imgs, actIndex);
});
}
e.stopPropagation();
e.preventDefault();
});
$page.off("click.viewfile");
$page.on("click.viewfile", ".wev-file[data-id]", function(e) {
var $this = $(this);
mUtil.previewFile($this.data("id"), decodeURIComponent($this.data("name")), $this.data("authorize")||"");
e.stopPropagation();
e.preventDefault();
});
$page.off("click.textlink").on("click.textlink", ".text-haslink", function(e){
var $this = $(this);
require(["browserHelper"], function (browserHelper) {
browserHelper.openBrowserLink($this);
});
e.stopPropagation();
e.preventDefault();
});
options.onPageLoad && options.onPageLoad();
});
},
pageChange: function (pageInto, pageOut, options, back) {
//触发水印hashChange事件
require(['watermark'], function(WM){
WM.handleHashChange();
});
//页面切换时input、select焦点blur处理
pageOut && _page.blurPageEle(pageOut, back);
var tabpanelPageId;
var pageTitle = pageInto.getAttribute("data-title") || "";
if (back) {
//返回时包含tab页获取当前页
var tabpanel = $(pageInto).children(".page-content").children(".tabpanel.in")[0];
tabpanel && (tabpanelPageId = pageInto.id, pageInto = tabpanel);
}
var pageid = pageInto.id,
pageOutId = pageOut && pageOut.id;
var stack = require("pageStack");
if (pageInto.classList.contains("page-scroller")) {
pageid = pageid.replace("_scroller", "");
}
if (pageOut && pageOut.classList.contains("page-scroller")) {
pageOutId = pageOutId.replace("_scroller", "");
}
var isTabChange = $(pageInto).hasClass("tabpanel") && $(pageOut).hasClass("tabpanel");
if (!isTabChange) {//非标签栏tab之间切换
//切换页面时改变标题
mUtil.checkEmpJsApi("changeTitle") && mUtil.invokeEmApi("changeTitle", {title: pageTitle});
if (!options.replaceState) {
!back && stack.push(pageInto) || stack.pop(tabpanelPageId || pageid);
} else {
stack.pop();
stack.push(pageInto);
}
//返回或者replace页面时清空pageOut
if((back || options.replaceState) && pageOut){
var $pageOut = $(pageOut);
if(!~$pageOut.attr("id").indexOf("page_service_")){
_page.clearPage($pageOut);
}
}
}
//触发插件内定义的pageChange方法
var component = require('Component'),
intoComs = component.getPageComs(pageid),
outComs = component.getPageComs(pageOutId);
intoComs.forEach(function(com){
com.$emit('pageChange', true);
});
outComs.forEach(function(com){
com.$emit('pageChange', false);
});
pageOutId && mUtil.unload(pageOutId);
mUtil.setCurrentPageId(pageid);
pageEvent.trigger("change");
},
none: function (pageInto, pageOut) {
},
serviceChange: function (pageInto, pageOut, options, back) {
var stack = require("pageStack");
if (!options.replaceState) {
!back && stack.push(pageInto) || stack.pop();
//页面切换时input、select焦点blur处理
pageOut && _page.blurPageEle(pageOut, back);
} else {
stack.pop();
stack.push(pageInto);
}
var pageOutId = pageOut && pageOut.id;
pageOutId && mUtil.unload(pageOutId);
}
};
});