msgListChat.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("listCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
  6. var self = this;
  7. var s4 = new SM4Util();
  8. self.userId = $.cookie("GlWorkPlatform-userid");
  9. self.userName = $.cookie("GlWorkPlatform-chineseName");
  10. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  11. self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
  12. self.get_type = sp.getUrlName("type");
  13. self.userList = [] // 左侧人员列表
  14. self.list = [] // 全部消息---已分成数组的数组
  15. self.listAll = [] // 全部消息---已分成数组的数组
  16. self.ItemList = [] // 右侧消息---提取数组的数组对应内容
  17. self.onlineList = [] // 在线名单
  18. self.onlineAll = [] // 名单接口所有人
  19. self.isOnlineList = [] // 两个表单中没有重合的人员名单
  20. self.selectTxt = null // 当前选择人
  21. self.contact = null // 当前选择人 --- 右上边文字
  22. self.messageText = '' // 发送的内容
  23. self.noRead = 0 // 未读消息数量
  24. var postCfg = {
  25. headers: {
  26. 'Content-Type': 'application/json',
  27. 'Authorization': "Bearer " + self.get_AccessToken
  28. }
  29. }
  30. self.type = self.get_type != "" ? self.get_type : "2";
  31. self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
  32. self.pageno = 1;
  33. self.total_count = 0;
  34. self.itemsPerPage = 10;
  35. self.pageOptions = [10, 20, 30, 40];
  36. // 获取人员
  37. self.getUser = function () {
  38. self.onlineList = []
  39. var data = {
  40. userid:self.userId
  41. }
  42. $http.post(apiurljs.login + "g2work/user/queryUserOnline", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  43. .success(function (obj) {
  44. var res = strToJson(s4.decryptData_CBC(obj.data));
  45. self.onlineAll = res.data
  46. for(var i = 0; i < res.data.length;i++) {
  47. if(res.data[i].LOGINSTATE === '1'){
  48. self.onlineList.push(res.data[i])
  49. }
  50. }
  51. // console.log('online', self.onlineList)
  52. })
  53. }
  54. self.isOnline = function(arr) {
  55. // console.log('isOnline', arr)
  56. if(Array.isArray(arr)){
  57. var names1 = arr.map(item => item.SENDER);
  58. var names2 = self.onlineList.map(item => item.USHOWNAME);
  59. var commonNames = names1.filter(name => names2.includes(name));
  60. // console.log('panduan:', names1, names2, names1.filter(name => names2.includes(name)))
  61. return commonNames.length > 0 ? true : false;
  62. }
  63. }
  64. /*self.onLineList = function (arr) {
  65. console.log('arr', arr)
  66. const names1 = arr.map(item => item.SENDER);
  67. const names2 = self.onlineAll.map(item => item.USHOWNAME);
  68. // const commonNames = names1.filter(name => names2.includes(name));
  69. // console.log('panduan:', names1, names2, names1.filter(name => names2.includes(name)))
  70. if(!names1.filter(name => names2.includes(name))) {
  71. self.isOnlineList.push(names2)
  72. }
  73. // return commonNames.length > 0 ? true : false;
  74. }*/
  75. self.getData = function (type) {
  76. // console.log('sp.savemenufile(id, title, src);', JSON.parse(localStorage.getItem('GlWorkPlatform-openfileArray')))
  77. self.list = []
  78. self.selectTxt = null
  79. // 右侧 未读
  80. var data = {
  81. userid: self.userId,
  82. msgkind: "全部",
  83. mark: self.type == 1 ? "全部" : "未读"
  84. }
  85. console.log('send data',data)
  86. $http.post(apiurljs.login + "g2work/routeinfo/queryDataMessage", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  87. .success(function (obj) {
  88. self.onlineAll = []
  89. self.onlineList = []
  90. var data1 = {
  91. userid:self.userId
  92. }
  93. $http.post(apiurljs.login + "g2work/user/queryUserOnline", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
  94. .success(function (obj1) {
  95. var res1 = strToJson(s4.decryptData_CBC(obj1.data));
  96. console.log('online1', res1.data)
  97. self.onlineAll = res1.data
  98. for(var i = 0; i < res1.data.length;i++) {
  99. if(res1.data[i].LOGINSTATE === '1'){
  100. self.onlineList.push(res1.data[i])
  101. }
  102. }
  103. var res = strToJson(s4.decryptData_CBC(obj.data));
  104. console.log('res', res)
  105. var groupedData = res.data.reverse().reduce((acc, obj) => {
  106. var key = obj.SENDER;
  107. if (!acc[key]) {
  108. acc[key] = [];
  109. }
  110. acc[key].push(obj);
  111. return acc;
  112. }, {});
  113. var result = Object.values(groupedData);
  114. console.log(result);
  115. self.ItemList = res.data.reverse()
  116. var array = []
  117. for(var i=0; i<result.length; i++){
  118. var tmp = Object.assign(result[i][0], {USHOWNAME: result[i][0].SENDER})
  119. // console.log('tmp:', tmp)
  120. array.push(tmp)
  121. }
  122. // console.log('array', array)
  123. array = array.concat(self.onlineAll)
  124. var counts = array.reduce((acc,obj) => {
  125. acc[obj.USHOWNAME] = (acc[obj.USHOWNAME] || 0) + 1;
  126. return acc;
  127. }, {});
  128. var duplicates = array.filter(obj => counts[obj.USHOWNAME] === 1);
  129. var tmpArray = []
  130. for(var i=0; i<duplicates.length; i++){
  131. if(!duplicates[i].SENDER){
  132. tmpArray.push({USHOWNAME:duplicates[i].USHOWNAME,USERID:duplicates[i].USERID})
  133. }
  134. }
  135. var tmpArray1 = []
  136. for(var i=0; i< tmpArray.length; i++){
  137. var tmp = [{SENDER:tmpArray[i].USHOWNAME,SENDERID:tmpArray[i].USERID}]
  138. tmpArray1.push(tmp)
  139. }
  140. console.log('duplicateValues', self.onlineAll, array); // [2 4]
  141. self.list = tmpArray1.concat(result)
  142. self.listAll = tmpArray1.concat(result)
  143. console.log('显示所以有数据:', self.listAll)
  144. setTimeout(function (){
  145. $("#chatContent").animate({ scrollTop: "10000px" }, 0);
  146. },100)
  147. })
  148. })
  149. // 右侧 已读
  150. }
  151. self.noRead = function () {
  152. var data = {
  153. userid: self.userId,
  154. msgkind: "全部",
  155. mark: "未读"
  156. }
  157. $http.post(apiurljs.login+"g2work/routeinfo/queryDataMessageCount",{ data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  158. .success(function (obj) {
  159. var res = strToJson(s4.decryptData_CBC(obj.data));
  160. self.noRead = res.data.MSGCOUNT
  161. })
  162. }
  163. // JavaScript 部分,处理加载和发送消息
  164. self.loadChatSystem = function(contact) {
  165. var chatSection = document.getElementById("chatSectionContent");
  166. chatSection.innerHTML = contact;
  167. self.contact = contact
  168. self.getData();
  169. }
  170. self.load = function () {
  171. if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") {
  172. self.getUser();
  173. self.loadChatSystem('系统消息')
  174. self.noRead()
  175. } else {
  176. $timeout(function () {
  177. self.getUser();
  178. self.loadChatSystem('系统消息')
  179. self.noRead()
  180. }, 1)
  181. }
  182. }
  183. self.changeType = function (str) {
  184. if (self.type == str) {
  185. return;
  186. } else {
  187. self.type = str;
  188. self.getData(1)
  189. }
  190. }
  191. self.load();
  192. self.refresh = function () {
  193. // self.getData(self.pageno);
  194. }
  195. self.goUrl = function (item) {
  196. if (item.MARK == "未读") {
  197. var data = {
  198. id: item.ID
  199. }
  200. $http.post(apiurljs.login + "g2work/routeinfo/updateDataMessage", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  201. .success(function (obj) {
  202. var res = strToJson(s4.decryptData_CBC(obj.data));
  203. self.getData(self.pageno)
  204. sp.openNewWindow("../../" + item.DURL, item.CONTENTS)
  205. })
  206. } else {
  207. sp.openNewWindow("../../" + item.DURL, item.CONTENTS)
  208. }
  209. }
  210. self.loadChat = function(contact, item) {
  211. // self.ItemList = []
  212. self.ItemList = []
  213. self.contact = null
  214. var chatSection = document.getElementById("chatSectionContent");
  215. chatSection.innerHTML = contact;
  216. self.contact = contact;
  217. self.SENDERID = item.SENDERID;
  218. self.RECEIVERID = item.RECEIVERID;
  219. //alert(self.RECEIVERID + "-" + self.SENDERID)
  220. document.getElementById("chatSection").innerHTML = ''
  221. var array = []
  222. for(var i = 0; i < self.listAll.length;i++) {
  223. if(contact == self.listAll[i][0].SENDER){
  224. array = self.listAll[i]
  225. // array.push(self.listAll[i])
  226. }
  227. }
  228. /* for (var i = 0; i < array[0].length; i++){
  229. self.ItemList.push(array[0][i])
  230. }*/
  231. self.ItemList = array
  232. console.log(item, self.listAll, self.ItemList)
  233. setTimeout(function (){
  234. $("#chatContent").animate({ scrollTop: "10000px" }, 0);
  235. },100)
  236. }
  237. self.selectContent = function (item) {
  238. self.selectTxt = item
  239. }
  240. self.sendMessage = function() {
  241. var messageInput = document.getElementById("messageInput");
  242. var messageText = messageInput.value;
  243. // var txt = self.selectTxt.FLOWNAME + self.selectTxt.CONTENTS
  244. if (messageText.trim() !== "") {
  245. var data = {
  246. receiverid: self.SENDERID,
  247. senderid: self.userId,
  248. msg: messageText,
  249. url:""
  250. }
  251. $http.post(apiurljs.login + "g2work/routeinfo/insertDataMessageChat", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  252. .success(function (obj) {
  253. var res = strToJson(s4.decryptData_CBC(obj.data));
  254. console.log('res', res)
  255. })
  256. var chatSection = document.getElementById("chatSection");
  257. var newMessage =
  258. '<div class="sender">'
  259. + '<div style="margin: 0 15px;">'
  260. + '<div style="padding: 0 10px; text-align: right;">' + self.convertTimestamp(new Date().getTime()) + '</div>'
  261. + '<div class="text">'
  262. // + '<span>消息:</span>' + txt + '<br />'
  263. // + '<span>回复内容:</span>'
  264. + messageText
  265. + '</div>'
  266. + '</div>'
  267. + '<img src="../../AFrontEnd/css/icons/photo/02.jpg" width="50" height="50">'
  268. + '</div>';
  269. chatSection.innerHTML += newMessage;
  270. messageInput.value = "";
  271. chatSection.scrollTop = chatSection.scrollHeight;
  272. setTimeout(function (){
  273. $("#chatContent").animate({ scrollTop: "10000px" }, 0);
  274. },100)
  275. }
  276. }
  277. self.creatRoom=function(){
  278. var data = {
  279. cman: self.userId,
  280. cname: self.userName + "和" + self.ItemList.SENDER + "—共享沟通",
  281. userids: self.ItemList.SENDERID
  282. }
  283. $http.post(apiurljs.login + "g2work/meetcoop/createMeetcoop", data, postCfg)
  284. .success(function (res) {
  285. sp.layerhide()
  286. if (res.success == true) {
  287. } else {
  288. sp.dialog(res.message)
  289. }
  290. })
  291. }
  292. // 时间戳转换
  293. self.convertTimestamp = function (timeStamp) {
  294. var year = new Date(timeStamp).getFullYear();
  295. var month =new Date(timeStamp).getMonth() + 1 < 10? "0" + (new Date(timeStamp).getMonth() + 1): new Date(timeStamp).getMonth() + 1;
  296. var date =new Date(timeStamp).getDate() < 10? "0" + new Date(timeStamp).getDate(): new Date(timeStamp).getDate();
  297. var hh =new Date(timeStamp).getHours() < 10? "0" + new Date(timeStamp).getHours(): new Date(timeStamp).getHours();
  298. var mm =new Date(timeStamp).getMinutes() < 10? "0" + new Date(timeStamp).getMinutes(): new Date(timeStamp).getMinutes();
  299. var ss =new Date(timeStamp).getSeconds() < 10? "0" + new Date(timeStamp).getSeconds(): new Date(timeStamp).getSeconds();
  300. var formattedDate = year + "-" + month + "-" + date + " " + hh + ":" + mm + ":" + ss;
  301. return formattedDate;
  302. }
  303. //头部下滚冻结
  304. $(function () {
  305. //页面高度撑满
  306. setTimeout(function () {
  307. if ($(".ibox-content").height() < $(window).height() - 31) {
  308. $(".ibox-content").css("height", $(window).height() - 31)
  309. }
  310. }, 1)
  311. })
  312. }])