msgListChat.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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, postCfg)
  43. .success(function (obj) {
  44. //var res = strToJson(s4.decryptData_CBC(obj.data));
  45. var res = obj;
  46. self.onlineAll = res.data
  47. for(var i = 0; i < res.data.length;i++) {
  48. if(res.data[i].LOGINSTATE === '1'){
  49. self.onlineList.push(res.data[i])
  50. }
  51. }
  52. // console.log('online', self.onlineList)
  53. })
  54. }
  55. self.isOnline = function(arr) {
  56. // console.log('isOnline', arr)
  57. if(Array.isArray(arr)){
  58. var names1 = arr.map(item => item.SENDER);
  59. var names2 = self.onlineList.map(item => item.USHOWNAME);
  60. var commonNames = names1.filter(name => names2.includes(name));
  61. // console.log('panduan:', names1, names2, names1.filter(name => names2.includes(name)))
  62. return commonNames.length > 0 ? true : false;
  63. }
  64. }
  65. /*self.onLineList = function (arr) {
  66. console.log('arr', arr)
  67. const names1 = arr.map(item => item.SENDER);
  68. const names2 = self.onlineAll.map(item => item.USHOWNAME);
  69. // const commonNames = names1.filter(name => names2.includes(name));
  70. // console.log('panduan:', names1, names2, names1.filter(name => names2.includes(name)))
  71. if(!names1.filter(name => names2.includes(name))) {
  72. self.isOnlineList.push(names2)
  73. }
  74. // return commonNames.length > 0 ? true : false;
  75. }*/
  76. self.getData = function (type) {
  77. // console.log('sp.savemenufile(id, title, src);', JSON.parse(localStorage.getItem('GlWorkPlatform-openfileArray')))
  78. self.list = []
  79. self.selectTxt = null
  80. // 右侧 未读
  81. var data = {
  82. userid: self.userId,
  83. msgkind: "全部",
  84. mark: self.type == 1 ? "全部" : "未读"
  85. }
  86. $http.post(apiurljs.login + "g2work/routeinfo/queryDataMessage", 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", data1, postCfg)
  94. .success(function (obj1) {
  95. //var res1 = strToJson(s4.decryptData_CBC(obj1.data));
  96. var res1 = obj1;
  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. var res = obj.data;
  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. self.ItemList = res.data.reverse()
  115. var array = []
  116. for(var i=0; i<result.length; i++){
  117. var tmp = Object.assign(result[i][0], {USHOWNAME: result[i][0].SENDER})
  118. // console.log('tmp:', tmp)
  119. array.push(tmp)
  120. }
  121. // console.log('array', array)
  122. array = array.concat(self.onlineAll)
  123. var counts = array.reduce((acc,obj) => {
  124. acc[obj.USHOWNAME] = (acc[obj.USHOWNAME] || 0) + 1;
  125. return acc;
  126. }, {});
  127. var duplicates = array.filter(obj => counts[obj.USHOWNAME] === 1);
  128. var tmpArray = []
  129. for(var i=0; i<duplicates.length; i++){
  130. if(!duplicates[i].SENDER){
  131. tmpArray.push({USHOWNAME:duplicates[i].USHOWNAME,USERID:duplicates[i].USERID})
  132. }
  133. }
  134. var tmpArray1 = []
  135. for(var i=0; i< tmpArray.length; i++){
  136. var tmp = [{SENDER:tmpArray[i].USHOWNAME,SENDERID:tmpArray[i].USERID}]
  137. tmpArray1.push(tmp)
  138. }
  139. self.list = tmpArray1.concat(result)
  140. self.listAll = tmpArray1.concat(result)
  141. setTimeout(function (){
  142. $("#chatContent").animate({ scrollTop: "10000px" }, 0);
  143. },100)
  144. })
  145. })
  146. // 右侧 已读
  147. }
  148. self.noRead = function () {
  149. var data = {
  150. userid: self.userId,
  151. msgkind: "全部",
  152. mark: "未读"
  153. }
  154. $http.post(apiurljs.login+"g2work/routeinfo/queryDataMessageCount", data, postCfg)
  155. .success(function (obj) {
  156. // var res = strToJson(s4.decryptData_CBC(obj.data));
  157. var res = obj;
  158. self.noRead = res.data.MSGCOUNT
  159. })
  160. }
  161. // JavaScript 部分,处理加载和发送消息
  162. self.loadChatSystem = function(contact) {
  163. var chatSection = document.getElementById("chatSectionContent");
  164. chatSection.innerHTML = contact;
  165. self.contact = contact
  166. self.getData();
  167. }
  168. self.load = function () {
  169. if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") {
  170. self.getUser();
  171. self.loadChatSystem('系统消息')
  172. self.noRead()
  173. } else {
  174. $timeout(function () {
  175. self.getUser();
  176. self.loadChatSystem('系统消息')
  177. self.noRead()
  178. }, 1)
  179. }
  180. }
  181. self.changeType = function (str) {
  182. if (self.type == str) {
  183. return;
  184. } else {
  185. self.type = str;
  186. self.getData(1)
  187. }
  188. }
  189. self.load();
  190. self.refresh = function () {
  191. // self.getData(self.pageno);
  192. }
  193. self.goUrl = function (item) {
  194. if (item.MARK == "未读") {
  195. var data = {
  196. id: item.ID
  197. }
  198. $http.post(apiurljs.login + "g2work/routeinfo/updateDataMessage", data, postCfg)
  199. .success(function (obj) {
  200. // var res = strToJson(s4.decryptData_CBC(obj.data));
  201. var res = obj;
  202. self.getData(self.pageno)
  203. sp.openNewWindow("../../" + item.DURL, item.CONTENTS)
  204. })
  205. } else {
  206. sp.openNewWindow("../../" + item.DURL, item.CONTENTS)
  207. }
  208. }
  209. self.loadChat = function(contact, item) {
  210. // self.ItemList = []
  211. self.ItemList = []
  212. self.contact = null
  213. var chatSection = document.getElementById("chatSectionContent");
  214. chatSection.innerHTML = contact;
  215. self.contact = contact;
  216. self.SENDERID = item.SENDERID;
  217. self.RECEIVERID = item.RECEIVERID;
  218. //alert(self.RECEIVERID + "-" + self.SENDERID)
  219. document.getElementById("chatSection").innerHTML = ''
  220. var array = []
  221. for(var i = 0; i < self.listAll.length;i++) {
  222. if(contact == self.listAll[i][0].SENDER){
  223. array = self.listAll[i]
  224. // array.push(self.listAll[i])
  225. }
  226. }
  227. /* for (var i = 0; i < array[0].length; i++){
  228. self.ItemList.push(array[0][i])
  229. }*/
  230. self.ItemList = array
  231. setTimeout(function (){
  232. $("#chatContent").animate({ scrollTop: "10000px" }, 0);
  233. },100)
  234. }
  235. self.selectContent = function (item) {
  236. self.selectTxt = item
  237. }
  238. self.sendMessage = function() {
  239. var messageInput = document.getElementById("messageInput");
  240. var messageText = messageInput.value;
  241. // var txt = self.selectTxt.FLOWNAME + self.selectTxt.CONTENTS
  242. if (messageText.trim() !== "") {
  243. var data = {
  244. receiverid: self.SENDERID,
  245. senderid: self.userId,
  246. msg: messageText,
  247. url:""
  248. }
  249. $http.post(apiurljs.login + "g2work/routeinfo/insertDataMessageChat", data, postCfg)
  250. .success(function (obj) {
  251. //var res = strToJson(s4.decryptData_CBC(obj.data));
  252. var res=obj;
  253. })
  254. var chatSection = document.getElementById("chatSection");
  255. var newMessage =
  256. '<div class="sender">'
  257. + '<div style="margin: 0 15px;">'
  258. + '<div style="padding: 0 10px; text-align: right;">' + self.convertTimestamp(new Date().getTime()) + '</div>'
  259. + '<div class="text">'
  260. // + '<span>消息:</span>' + txt + '<br />'
  261. // + '<span>回复内容:</span>'
  262. + messageText
  263. + '</div>'
  264. + '</div>'
  265. + '<img src="../../AFrontEnd/css/icons/photo/02.jpg" width="50" height="50">'
  266. + '</div>';
  267. chatSection.innerHTML += newMessage;
  268. messageInput.value = "";
  269. chatSection.scrollTop = chatSection.scrollHeight;
  270. setTimeout(function (){
  271. $("#chatContent").animate({ scrollTop: "10000px" }, 0);
  272. },100)
  273. }
  274. }
  275. self.creatRoom=function(){
  276. var data = {
  277. cman: self.userId,
  278. cname: self.userName + "和" + self.ItemList.SENDER + "—共享沟通",
  279. userids: self.ItemList.SENDERID
  280. }
  281. $http.post(apiurljs.login + "g2work/meetcoop/createMeetcoop", data, postCfg)
  282. .success(function (res) {
  283. sp.layerhide()
  284. if (res.success == true) {
  285. } else {
  286. sp.dialog(res.message)
  287. }
  288. })
  289. }
  290. // 时间戳转换
  291. self.convertTimestamp = function (timeStamp) {
  292. var year = new Date(timeStamp).getFullYear();
  293. var month =new Date(timeStamp).getMonth() + 1 < 10? "0" + (new Date(timeStamp).getMonth() + 1): new Date(timeStamp).getMonth() + 1;
  294. var date =new Date(timeStamp).getDate() < 10? "0" + new Date(timeStamp).getDate(): new Date(timeStamp).getDate();
  295. var hh =new Date(timeStamp).getHours() < 10? "0" + new Date(timeStamp).getHours(): new Date(timeStamp).getHours();
  296. var mm =new Date(timeStamp).getMinutes() < 10? "0" + new Date(timeStamp).getMinutes(): new Date(timeStamp).getMinutes();
  297. var ss =new Date(timeStamp).getSeconds() < 10? "0" + new Date(timeStamp).getSeconds(): new Date(timeStamp).getSeconds();
  298. var formattedDate = year + "-" + month + "-" + date + " " + hh + ":" + mm + ":" + ss;
  299. return formattedDate;
  300. }
  301. //头部下滚冻结
  302. $(function () {
  303. //页面高度撑满
  304. setTimeout(function () {
  305. if ($(".ibox-content").height() < $(window).height() - 31) {
  306. $(".ibox-content").css("height", $(window).height() - 31)
  307. }
  308. }, 1)
  309. })
  310. }])