TabBar_wev8.js
5.91 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
define(['mUtil', "Component"],function(mUtil, Component) {
var TabBar = function(options) {
var _tabBar = {};
Component.super(this, options);
this.type = "TabBar";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
var vm = this.viewModel = {
tabs : [],
badge : null,
isFixedTop: false
};
this.beforeMount = function(){
vm.pageid = this.$container.attr("id");
vm.remindApis = [];
vm.tabs.forEach(function(item){
var icon = item.icon;
var isNoImg = !icon || mUtil.isObject(icon) && !icon.normal && !icon.active;
var _getItemClass = function() {
if(isNoImg) return "wev-tabbar-noimg";
if(icon.normal && icon.active && icon.normal != icon.active) return;
return "wev-tabbar-singleimg";
}, _getIcon = function() {
var o = { normal: "", active: "" };
if(isNoImg) return o;
if(mUtil.isString(icon)) return { normal: icon, active: icon };
o.normal = icon.normal || icon.active;
o.active = icon.active || icon.normal;
return o;
};
if(item.remind && item.remindapi && item.remindapi.api){
item.uuid = item.remindapi.uuid = mUtil.UUID();
item.apiid = item.remindapi.api.id;
vm.remindApis.push(item.remindapi);
delete item.remindapi;
}
item.itemClass = _getItemClass();
item.icon = _getIcon();
});
if(vm.badge === true){
vm.badge = mUtil.getActionUrl(this.type, {action:"getBadge", "mec_id": this.id}, this.pageid);
}
var permItems = vm.tabs.filter(function(item){
return item.permission;
});
if(permItems.length){
var perms = permItems.map(function(item){
return item.permission;
});
return this.judgePermission(perms).done(function(res){
if(res.status == '1'){
var permRes = res.data;
permRes.forEach(function(hasPerm, index){
if(!hasPerm){
vm.tabs.splice(vm.tabs.indexOf(permItems[index]), 1);
}
});
} else {
vm.tabs = [];
}
}).fail(function(){
vm.tabs = [];
});
}
};
this.mounted = function(){
var that = this;
var $page = this.$container,
$abbr = this.$el,
position = vm.isFixedTop ? 'page-header' : 'page-footer',
$content = $page.children(".page-content"),
$comp = $abbr.children(".wev-comp-" + this.type);
this.$once("moveComponent", function(){
var $pageBound = $page.children('.' + position),
$scroller = $content.children(".page-scroller");
if(!$pageBound.length){
$pageBound = $("<div class=\""+position+"\"></div>");
vm.isFixedTop && $content.before($pageBound) || $content.after($pageBound);
}
if(!$abbr.parent().hasClass(position)){
vm.isFixedTop && $pageBound.prepend($abbr).show() || $pageBound.append($abbr).show();
}
$scroller.addClass("tabpanel in").attr("data-form", "show_hide").siblings(".tabpanel").each(function() {
this.firstintoBind = false;
});
var attrName = vm.isFixedTop ? "header-height" : "footer-height";
var posCss = vm.isFixedTop ? "top" : "bottom";
if($pageBound.height()){
$pageBound.attr(attrName, $pageBound.height());
$content.css(posCss, $pageBound.height() + "px");
}else{
if($pageBound.attr(attrName)){
$content.css(posCss, $pageBound.attr(attrName) + "px");
}else{
$content.css(posCss, "0px");
}
}
});
$comp.on("click", ".wev-tabbar-item", function(){
var $that = $(this),
index = $that.index(),
tabItem = vm.tabs[index],
$pageHeader = $page.children('.page-header'),
$pageFooter = $page.children('.page-footer'),
$abbr = $page.children(".page-header, .page-footer").children('abbr, .wev-topsearch-nav').not('[data-type="TabBar"]');
if(index === 0) {
//ios 首页头部有内容时 其他tab下拉能看到前一个页面bug
$abbr.show();
} else {
$abbr.hide();
}
$content.css("top", $pageHeader.height() + "px");
$content.css("bottom", $pageFooter.height() + "px");
if(!$that.hasClass("wev-tabbar-active")){
$that.addClass("wev-tabbar-active").siblings(".wev-tabbar-item.wev-tabbar-active").removeClass("wev-tabbar-active");
} else {
var pageId = $that.attr('href').replace('#page_', '').replace('_scroller', '');
Mobile_NS.refresh(pageId);
}
mUtil.eval(tabItem.click, that.pageid);
});
_tabBar.loadBadge();
};
this.refreshBadge = function(){
_tabBar.loadBadge();
};
this.judgePermission = function(perms) {
var actionUrl = mUtil.getActionUrl(this.type, {action: "judgePermission"}, this.pageid);
return $.ajax({
url: mUtil.completeUrl(actionUrl),
data: {
perms: JSON.stringify(perms)
},
type: 'POST',
dataType: 'json'
});
}
_tabBar.loadBadge = function(){
if(vm.badge == null){
return;
}
var $badges = $(".wev-badge", this.$el);
require(["remindHelper"], function(helper){
helper.renderBadge(vm.badge, $badges, vm.remindApis);
});
};
_tabBar.loadBadge = _tabBar.loadBadge.bind(this);
};
return Component.init(TabBar);
});