Tab_wev8.js
5.53 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
define(['mUtil', "Component"],function(mUtil, Component) {
var Tab = function(options) {
var _tab = {};
Component.super(this, options);
this.type = "Tab";
this.tpl = this.type + "_html";
this.css = [this.type + "_css", "commonTab_css"];
var vm = this.viewModel = {
tabs : [],
badge: null,
lazyload: true,
standalone : true
};
this.beforeMount = function(){
vm.remindApis = [];
vm.tabs.map(function(tab){
if(tab.remind && tab.remindapi && tab.remindapi.api){
tab.uuid = tab.remindapi.uuid = mUtil.UUID();
tab.apiid = tab.remindapi.api.id;
vm.remindApis.push(tab.remindapi);
delete tab.remindapi;
}
});
if(vm.badge === true){
vm.badge = mUtil.getActionUrl(this.type, {action:"getBadge", "mec_id": this.id}, this.pageid);
}
};
this.mounted = function(){
var that = this, $comp = this.$el.children(".wev-comp-" + this.type), $tabNavs = $(".wev-tab-nav", $comp), deferreds = [];
if(vm.lazyload){
deferreds.push(_tab.loadTabPanel(0));
}else{
$tabNavs.each(function(){
var tabIndex = $(this).index();
deferreds.push(_tab.loadTabPanel(tabIndex, tabIndex > 0 ? true : false));
});
}
$tabNavs.on("click", function(){
var $nav = $(this);
var index = $nav.index();
if ($nav.hasClass("wev-tab-selected")) return;
$nav.addClass("wev-tab-selected").siblings("li.wev-tab-selected").removeClass("wev-tab-selected");
var $tabpanel = $(".wev-tab-panel", $comp).addClass("wev-tabpanel-hidden").eq(index).removeClass("wev-tabpanel-hidden");
_tab.toggleExternalCompnents(index);
_tab.loadTabPanel(index, function(compoids){
compoids.forEach(function(compoid) {
var ins = mUtil.getInstance(compoid, that.pageid);
ins.onResetView && ins.onResetView();
});
//触发图片延迟加载
require(['lazyImgHelper']);
});
});
_tab.loadBadge();
return $.when.apply($.when, deferreds);
};
this.refreshBadge = function () {
_tab.loadBadge();
};
this.onTabChange = function (compId, cb) {
var that = this, $comp = this.$el.children(".wev-comp-" + this.type), $tabNavs = $(".wev-tab-nav", $comp);
var index = that.$container.find("#" + compId).parent(".wev-tab-panel").index();
$tabNavs.on("click", function(){
var $nav = $(this),
currIndex = $nav.index();
mUtil.isFunction(cb) && cb(index == currIndex);
});
};
_tab.loadBadge = function () {
if(vm.badge == null){
return;
}
var $badges = $(".wev-badge", this.$el);
require(["remindHelper"], function (helper) {
helper.renderBadge(vm.badge, $badges, vm.remindApis);
});
};
_tab.toggleExternalCompnents = function (index) {
var $page = this.$container;
var $header = $page.children('.page-header');
var $content = $page.children('.page-content');
var $footer = $page.children('.page-footer');
var _toggle = function ($el, position) {
if (!$el.length) return;
$el.children('abbr[data-tabpanel]').hide();
$el.children('abbr[data-tabpanel="' + index + '"]').show();
$content.css(position, $el.height());
};
_toggle($header, "top");
_toggle($footer, "bottom");
};
_tab.loadTabPanel = function(index, forceLazyload, callback){
if(mUtil.isFunction(forceLazyload)){
callback = forceLazyload;
forceLazyload = false;
}
var $comp = this.$el.children(".wev-comp-" + this.type),
$tabpanel = $(".wev-tab-panel", $comp).eq(index),
$container = this.$container;
var pageid = this.pageid;
var components = [], compoids = [],
//强制延迟加载控件
forceLazyloadCompos = ["Calendar", "Chart", "BarChart", "FunnelChart", "GaugeChart", "LineChart",
"PieChart", "RadarChart", "Countdown", "GridTable", "UrlGridTable", "Slide",
"NavPanel", "Toolbar", "NoticeBar"];
$("abbr[data-type]", $tabpanel).each(function() {
var $abbr = $(this),
id = this.id,
type = $abbr.attr("data-type"),
loaded = $abbr.data("loaded");
if(loaded){
compoids.push(id);
}else{
if(forceLazyload && forceLazyloadCompos.indexOf(type) != -1){
return;
}
var mecparam = {
el: id,
type: type,
container: $container,
pageid: pageid
};
vm.tabs[index].tabContent.forEach(function (tabItem) {
if (tabItem.el == id) {
$.extend(mecparam, tabItem);
}
});
mecparam.priority = $abbr.attr("data-priority");
components.push(mecparam);
}
});
var deferred = $.Deferred();
if(!components.length){
deferred.resolve();
}else{
Component.load(components, function(){
deferred.resolve();
}, function (component) {
mUtil.trigger('load', pageid, component.id);
});
}
callback && callback(compoids);
return deferred;
};
_tab.loadTabPanel = _tab.loadTabPanel.bind(this);
_tab.toggleExternalCompnents = _tab.toggleExternalCompnents.bind(this);
_tab.loadBadge = _tab.loadBadge.bind(this);
};
return Component.init(Tab);
});