Button_wev8.js
2.52 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
define(['mUtil', "Component"],function(mUtil, Component) {
var Button = function(options) {
var _button = {};
Component.super(this, options);
this.type = "Button";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
var vm = this.viewModel = {
layout: "relative",
items: [],
fixed: false,
badge: null
};
this.beforeMount = function(){
if(vm.badge === true){
vm.badge = mUtil.getActionUrl(this.type, {action:"getBadge", "mec_id": this.id}, this.pageid);
}
};
this.mounted = function(){
var $comp = this.$el.children(".wev-comp-"+this.type);
var that = this;
// 按钮单击事件
$comp.on("click", ".wev-btn", function(event){
var index = $(this).index(),
btn = vm.items[index];
btn && mUtil.eval(btn.click, that.pageid);
});
_button.loadBadge();
_button.calculatePosition();
};
this.refreshBadge = function(){
_button.loadBadge();
};
_button.loadBadge = function() {
if(vm.badge == null){
return;
}
var $badges = $(".wev-badge", this.$el);
require(["remindHelper"], function(helper){
helper.renderBadge(vm.badge, $badges);
});
};
_button.calculatePosition = function(){
var $page = this.$container;
if (vm.fixed) {
this.$once("moveComponent", function(){
var $footer = $page.children(".page-footer");
var $content = $page.children(".page-content");
if (!$footer.length) {
$footer = $("<div class=\"page-footer\"></div>");
$content.after($footer);
}
if (!this.$el.parent().hasClass("page-footer")) {
$footer.append(this.$el).show();
}
if($footer.height()){
$footer.attr("footer-height", $footer.height());
$content.css("bottom", $footer.height() + "px");
}else{
if($footer.attr("footer-height")){
$content.css("bottom", $footer.attr("footer-height") + "px");
}else{
$content.css("bottom", "0px");
}
}
});
}
};
_button.loadBadge = _button.loadBadge.bind(this);
_button.calculatePosition = _button.calculatePosition.bind(this);
};
return Component.init(Button);
});