-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.view.js
95 lines (86 loc) · 3.07 KB
/
app.view.js
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
define(['device', 'action'], function(device, action) {
/*页面历史管理类,控制历史记录,页面跳转*/
var ViewMgr = {
tmpParams: "", //临时记录参数值
recordLen: 10, //记录历史页面最大长度
pageParams: {}, //记录进入页面时所带的参数(如果有的话),便于回退时使用
firstPage: 'index',
init: function() { //取得历史页面
var that = this,
storEmail = Mix.base.storage.get('app_my_nick'),
storPwd = Mix.base.storage.get('app_my_pwd'),
ok = null,
fail = function() {
pageEngine.initPage(that.firstPage);
Mix.base.storage.remove("app_view_history", "session");
};
delete window['pageEngine'];
device.disetBackBtn();
window['pageEngine'] = new PageEngine();
ViewMgr.views = [that.firstPage];
if (storEmail && storPwd) {
action.sendLogin(storEmail, storPwd, null, ok, fail);
} else {
fail();
}
device.backFunc = [
function() {
ViewMgr.back();
}
];
},
gotoPage: function(page, params) {
var isBack = false,
that = ViewMgr;
page = page.replace("\.html", "");
var viewLen = that.views.length;
if (that.views[viewLen - 2] == page) { //back
that.views.pop(1);
isBack = true;
} else {
if (viewLen >= that.recordLen)
that.views.shift(1);
that.views.push(page);
}
Mix.base.storage.set("app_view_history", ViewMgr.views, "session");
try {
if (1 == that.views.length) { //设置返回按钮为历史回退
device.disetBackBtn();
} else {
device.setBackBtn();
}
} catch (e) {}
if ( !! params) {
ViewMgr.tmpParams = params;
this.pageParams[page] = params;
} else {
ViewMgr.tmpParams = '';
this.pageParams[page] = '';
}
that.setUrl(page, params, isBack);
},
/*切换页面*/
setUrl: function(url, params, back) {
if (back) {
pageEngine.initPage(url, 'right');
} else {
pageEngine.initPage(url);
}
},
back: function(late) { //返回上一个历史页面
var that = ViewMgr,
backPage = that.views[that.views.length - 2];
function doBack() {
if (backPage) {
that.gotoPage(backPage, that.pageParams[backPage]);
}
}
if (late) {
setTimeout(doBack, 500);
} else {
doBack();
}
}
};
return window['ViewMgr'] = ViewMgr;
});