UserAvatar_wev8.js
1.95 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
define(['mUtil', "Component"],function(mUtil, Component) {
var UserAvatar = function(options) {
Component.super(this, options);
this.type = "UserAvatar";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
this.dataload = true;
var vm = this.viewModel = {
userid : "",
style : "wev-avatar-vertical",
avatar : "/messager/images/icon_m_wev8.jpg"
};
this.beforeMount = function () {
vm.style.indexOf("vertical") != -1 && (vm.style = "wev-avatar-vertical") || (vm.style = "wev-avatar-horizontal");
};
this.mounted = function(){
var that = this;
var type = this.type;
var $abbr = this.$el,
$comp = $abbr.children(".wev-comp-" + type);
var actionUrl = mUtil.getActionUrl(this.type, {action : "info", "userid" : vm.userid}, this.pageid);
mUtil.getJSON(actionUrl, function(result) {
var data = result.data;
var headPicMes = data.avatar;
var headFormat = headPicMes.headFormat;
//1:显示姓名首字 2:显示固定图片 3:显示姓名后两字
if("1" === headFormat || "3" === headFormat){
//以css形式显示
var bgColor = headPicMes.background;
var fontColor = headPicMes.fontColor;
var shortname = headPicMes.shortname;
var paddingleft = vm.style.indexOf("horizontal") != -1 ? "padding-left:0; " : "";
var htm = "<div class='resourceimage' style='background:"+ bgColor +"; color:"+ fontColor +";"+ paddingleft +" '>" + shortname + "</div>";
$("img", $comp).hide();
$(".wev-avatar-container", $comp).prepend(htm);
} else {
//以图片的形式显示
$("img", $comp).attr("src", headPicMes.messagerUrls || vm.avatar);
}
$(".wev-avatar-username", $comp).html(data.userName);
$(".wev-avatar-dept", $comp).html(data.deptName);
$(".wev-avatar-jobtitle", $comp).html(data.jobTitle);
mUtil.trigger('dataload', that.pageid, that.id);
});
};
};
return Component.init(UserAvatar);
});