sysMsg.js
4.4 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
/**
* 系统消息
*/
'use strict'
YX.fn.sysMsg = function () {
//消息中心
this.$notice = $('#notice')
$("#showNotice").on('click',this.clickNotice.bind(this))
this.$notice.delegate('.j-close', 'click', this.hideNotice.bind(this))
this.$notice.delegate('.j-reject', 'click', this.rejectNotice.bind(this))
this.$notice.delegate('.j-apply', 'click', this.acceptNotice.bind(this))
this.$notice.delegate('.j-rmAllSysNotice', 'click', this.rmAllSysNotice.bind(this))
this.$notice.delegate('.tab li', 'click', this.changeNotice.bind(this))
}
/*********************************************
* 消息中心红点
*********************************************/
YX.fn.showSysMsgCount = function () {
var $node = $("#showNotice .count")
var count = this.cache.getSysMsgCount()
if(this.$notice.hasClass("hide")){
if(count>0){
$node.removeClass("hide").text(count)
}else{
$node.addClass("hide").text(count)
}
}else{
this.cache.setSysMsgCount(0)
}
}
YX.fn.clickNotice = function () {
var that = this
this.cache.setSysMsgCount(0)
this.showSysMsgCount()
if(this.firstLoadSysMsg){
this.mysdk.getLocalSysMsgs(function(error, obj){
if(!error){
if(obj.sysMsgs.length>0){
that.cache.setSysMsgs(obj.sysMsgs)
}
that.firstLoadSysMsg = false
that.showNotice()
}else{
alert("获取系统消息失败")
}
})
}else{
this.showNotice()
}
}
YX.fn.showNotice = function(){
this.buildSysNotice()
this.buildCustomSysNotice()
this.$notice.removeClass('hide')
this.$mask.removeClass("hide")
document.documentElement.style.overflow = 'hidden'
}
YX.fn.buildSysNotice = function () {
var data = this.cache.getSysMsgs(),
array = [],
that = this
//确保用户信息存在缓存中
for(var i=0; i<data.length; i++){
if(!this.cache.getUserById(data[i].from)){
array.push(data[i].from)
}
}
if(array.length>0){
this.mysdk.getUsers(array,function(err,data){
for (var i = data.length - 1; i >= 0; i--) {
that.cache.setPersonlist(data[i])
}
})
}
var html = appUI.buildSysMsgs(data,this.cache)
this.$notice.find('.j-sysMsg').html(html)
}
YX.fn.buildCustomSysNotice = function(){
var data = this.cache.getCustomSysMsgs()
var html = appUI.buildCustomSysMsgs(data,this.cache)
this.$notice.find('.j-customSysMsg').html(html)
},
YX.fn.hideNotice = function () {
this.$notice.addClass('hide')
this.$mask.addClass("hide")
document.documentElement.style.overflow=''
},
YX.fn.changeNotice = function (evt) {
var $node = this.$notice
var $crt = $(evt.target)
$node.find(".tab li").removeClass("crt")
$crt.addClass("crt")
if($crt.attr("data-value")==="sys"){
$node.find(".j-sysMsg").removeClass("hide")
$node.find(".j-customSysMsg").addClass("hide")
}else{
$node.find(".j-sysMsg").addClass("hide")
$node.find(".j-customSysMsg").removeClass("hide")
}
},
YX.fn.acceptNotice = function (evt) {
var $node = $(evt.target).parent(),
teamId = $node.attr("data-id"),
from = $node.attr("data-from"),
type = $node.attr("data-type"),
idServer = $node.attr("data-idServer")
if(type ==="teamInvite"){
this.mysdk.acceptTeamInvite(teamId,from,idServer)
}else{
this.mysdk.passTeamApply(teamId,from,idServer)
}
},
YX.fn.rejectNotice = function (evt) {
var $node = $(evt.target).parent(),
teamId = $node.attr("data-id"),
from = $node.attr("data-from"),
type = $node.attr("data-type"),
idServer = $node.attr("data-idServer")
if(type ==="teamInvite"){
this.mysdk.rejectTeamInvite(teamId,from,idServer)
}else{
this.mysdk.rejectTeamApply(teamId,from,idServer)
}
},
YX.fn.rmAllSysNotice = function (){
var that = this
var type = this.$notice.find(".tab .crt").attr("data-value")
if(type ==="sys"){
this.mysdk.deleteAllLocalSysMsgs(function(err,obj){
if(err){
alert("删除失败")
}else{
that.cache.setSysMsgs([])
that.buildSysNotice()
}
})
}else{
this.cache.deleteCustomSysMsgs()
this.buildCustomSysNotice()
}
}