123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- 'use strict';
- var app = angular.module('app', [
- 'angularUtils.directives.dirPagination'
- ]);
- app.controller("listCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) {
- var self = this;
- var s4 = new SM4Util();
- self.userId = $.cookie("GlWorkPlatform-userid");
- self.userName = $.cookie("GlWorkPlatform-chineseName");
- self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
- self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
- self.get_type = sp.getUrlName("type");
- self.userList = [] // 左侧人员列表
- self.list = [] // 全部消息---已分成数组的数组
- self.listAll = [] // 全部消息---已分成数组的数组
- self.ItemList = [] // 右侧消息---提取数组的数组对应内容
- self.onlineList = [] // 在线名单
- self.onlineAll = [] // 名单接口所有人
- self.isOnlineList = [] // 两个表单中没有重合的人员名单
- self.selectTxt = null // 当前选择人
- self.contact = null // 当前选择人 --- 右上边文字
- self.messageText = '' // 发送的内容
- self.noRead = 0 // 未读消息数量
- var postCfg = {
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': "Bearer " + self.get_AccessToken
- }
- }
- self.type = self.get_type != "" ? self.get_type : "2";
- self.noDataTip = 1;//没有数据时赋变量为0,先默认为1
- self.pageno = 1;
- self.total_count = 0;
- self.itemsPerPage = 10;
- self.pageOptions = [10, 20, 30, 40];
- // 获取人员
- self.getUser = function () {
- self.onlineList = []
- var data = {
- userid:self.userId
- }
- $http.post(apiurljs.login + "g2work/user/queryUserOnline", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- self.onlineAll = res.data
- for(var i = 0; i < res.data.length;i++) {
- if(res.data[i].LOGINSTATE === '1'){
- self.onlineList.push(res.data[i])
- }
- }
- // console.log('online', self.onlineList)
- })
- }
- self.isOnline = function(arr) {
- // console.log('isOnline', arr)
- if(Array.isArray(arr)){
- var names1 = arr.map(item => item.SENDER);
- var names2 = self.onlineList.map(item => item.USHOWNAME);
- var commonNames = names1.filter(name => names2.includes(name));
- // console.log('panduan:', names1, names2, names1.filter(name => names2.includes(name)))
- return commonNames.length > 0 ? true : false;
- }
- }
- /*self.onLineList = function (arr) {
- console.log('arr', arr)
- const names1 = arr.map(item => item.SENDER);
- const names2 = self.onlineAll.map(item => item.USHOWNAME);
- // const commonNames = names1.filter(name => names2.includes(name));
- // console.log('panduan:', names1, names2, names1.filter(name => names2.includes(name)))
- if(!names1.filter(name => names2.includes(name))) {
- self.isOnlineList.push(names2)
- }
- // return commonNames.length > 0 ? true : false;
- }*/
- self.getData = function (type) {
- // console.log('sp.savemenufile(id, title, src);', JSON.parse(localStorage.getItem('GlWorkPlatform-openfileArray')))
- self.list = []
- self.selectTxt = null
- // 右侧 未读
- var data = {
- userid: self.userId,
- msgkind: "全部",
- mark: self.type == 1 ? "全部" : "未读"
- }
- console.log('send data',data)
- $http.post(apiurljs.login + "g2work/routeinfo/queryDataMessage", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- self.onlineAll = []
- self.onlineList = []
- var data1 = {
- userid:self.userId
- }
- $http.post(apiurljs.login + "g2work/user/queryUserOnline", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
- .success(function (obj1) {
- var res1 = strToJson(s4.decryptData_CBC(obj1.data));
- console.log('online1', res1.data)
- self.onlineAll = res1.data
- for(var i = 0; i < res1.data.length;i++) {
- if(res1.data[i].LOGINSTATE === '1'){
- self.onlineList.push(res1.data[i])
- }
- }
- var res = strToJson(s4.decryptData_CBC(obj.data));
- console.log('res', res)
- var groupedData = res.data.reverse().reduce((acc, obj) => {
- var key = obj.SENDER;
- if (!acc[key]) {
- acc[key] = [];
- }
- acc[key].push(obj);
- return acc;
- }, {});
- var result = Object.values(groupedData);
- console.log(result);
- self.ItemList = res.data.reverse()
- var array = []
- for(var i=0; i<result.length; i++){
- var tmp = Object.assign(result[i][0], {USHOWNAME: result[i][0].SENDER})
- // console.log('tmp:', tmp)
- array.push(tmp)
- }
- // console.log('array', array)
- array = array.concat(self.onlineAll)
- var counts = array.reduce((acc,obj) => {
- acc[obj.USHOWNAME] = (acc[obj.USHOWNAME] || 0) + 1;
- return acc;
- }, {});
- var duplicates = array.filter(obj => counts[obj.USHOWNAME] === 1);
- var tmpArray = []
- for(var i=0; i<duplicates.length; i++){
- if(!duplicates[i].SENDER){
- tmpArray.push({USHOWNAME:duplicates[i].USHOWNAME,USERID:duplicates[i].USERID})
- }
- }
- var tmpArray1 = []
- for(var i=0; i< tmpArray.length; i++){
- var tmp = [{SENDER:tmpArray[i].USHOWNAME,SENDERID:tmpArray[i].USERID}]
- tmpArray1.push(tmp)
- }
- console.log('duplicateValues', self.onlineAll, array); // [2 4]
- self.list = tmpArray1.concat(result)
- self.listAll = tmpArray1.concat(result)
- console.log('显示所以有数据:', self.listAll)
- setTimeout(function (){
- $("#chatContent").animate({ scrollTop: "10000px" }, 0);
- },100)
- })
- })
- // 右侧 已读
- }
- self.noRead = function () {
- var data = {
- userid: self.userId,
- msgkind: "全部",
- mark: "未读"
- }
- $http.post(apiurljs.login+"g2work/routeinfo/queryDataMessageCount",{ data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- self.noRead = res.data.MSGCOUNT
- })
- }
- // JavaScript 部分,处理加载和发送消息
- self.loadChatSystem = function(contact) {
- var chatSection = document.getElementById("chatSectionContent");
- chatSection.innerHTML = contact;
- self.contact = contact
- self.getData();
- }
- self.load = function () {
- if (self.get_lastReturnPageno == undefined || self.get_lastReturnPageno == null || self.get_lastReturnPageno == "") {
- self.getUser();
- self.loadChatSystem('系统消息')
- self.noRead()
- } else {
- $timeout(function () {
- self.getUser();
- self.loadChatSystem('系统消息')
- self.noRead()
- }, 1)
- }
- }
- self.changeType = function (str) {
- if (self.type == str) {
- return;
- } else {
- self.type = str;
- self.getData(1)
- }
- }
- self.load();
- self.refresh = function () {
- // self.getData(self.pageno);
- }
- self.goUrl = function (item) {
- if (item.MARK == "未读") {
- var data = {
- id: item.ID
- }
- $http.post(apiurljs.login + "g2work/routeinfo/updateDataMessage", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- self.getData(self.pageno)
- sp.openNewWindow("../../" + item.DURL, item.CONTENTS)
- })
- } else {
- sp.openNewWindow("../../" + item.DURL, item.CONTENTS)
- }
- }
- self.loadChat = function(contact, item) {
- // self.ItemList = []
- self.ItemList = []
- self.contact = null
- var chatSection = document.getElementById("chatSectionContent");
- chatSection.innerHTML = contact;
- self.contact = contact;
- self.SENDERID = item.SENDERID;
- self.RECEIVERID = item.RECEIVERID;
- //alert(self.RECEIVERID + "-" + self.SENDERID)
- document.getElementById("chatSection").innerHTML = ''
- var array = []
- for(var i = 0; i < self.listAll.length;i++) {
- if(contact == self.listAll[i][0].SENDER){
- array = self.listAll[i]
- // array.push(self.listAll[i])
- }
- }
- /* for (var i = 0; i < array[0].length; i++){
- self.ItemList.push(array[0][i])
- }*/
- self.ItemList = array
- console.log(item, self.listAll, self.ItemList)
- setTimeout(function (){
- $("#chatContent").animate({ scrollTop: "10000px" }, 0);
- },100)
- }
- self.selectContent = function (item) {
- self.selectTxt = item
- }
- self.sendMessage = function() {
- var messageInput = document.getElementById("messageInput");
- var messageText = messageInput.value;
- // var txt = self.selectTxt.FLOWNAME + self.selectTxt.CONTENTS
- if (messageText.trim() !== "") {
- var data = {
- receiverid: self.SENDERID,
- senderid: self.userId,
- msg: messageText,
- url:""
- }
- $http.post(apiurljs.login + "g2work/routeinfo/insertDataMessageChat", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- console.log('res', res)
- })
- var chatSection = document.getElementById("chatSection");
- var newMessage =
- '<div class="sender">'
- + '<div style="margin: 0 15px;">'
- + '<div style="padding: 0 10px; text-align: right;">' + self.convertTimestamp(new Date().getTime()) + '</div>'
- + '<div class="text">'
- // + '<span>消息:</span>' + txt + '<br />'
- // + '<span>回复内容:</span>'
- + messageText
- + '</div>'
- + '</div>'
- + '<img src="../../AFrontEnd/css/icons/photo/02.jpg" width="50" height="50">'
- + '</div>';
- chatSection.innerHTML += newMessage;
- messageInput.value = "";
- chatSection.scrollTop = chatSection.scrollHeight;
- setTimeout(function (){
- $("#chatContent").animate({ scrollTop: "10000px" }, 0);
- },100)
- }
- }
- self.creatRoom=function(){
- var data = {
- cman: self.userId,
- cname: self.userName + "和" + self.ItemList.SENDER + "—共享沟通",
- userids: self.ItemList.SENDERID
- }
- $http.post(apiurljs.login + "g2work/meetcoop/createMeetcoop", data, postCfg)
- .success(function (res) {
- sp.layerhide()
- if (res.success == true) {
- } else {
- sp.dialog(res.message)
- }
- })
- }
- // 时间戳转换
- self.convertTimestamp = function (timeStamp) {
- var year = new Date(timeStamp).getFullYear();
- var month =new Date(timeStamp).getMonth() + 1 < 10? "0" + (new Date(timeStamp).getMonth() + 1): new Date(timeStamp).getMonth() + 1;
- var date =new Date(timeStamp).getDate() < 10? "0" + new Date(timeStamp).getDate(): new Date(timeStamp).getDate();
- var hh =new Date(timeStamp).getHours() < 10? "0" + new Date(timeStamp).getHours(): new Date(timeStamp).getHours();
- var mm =new Date(timeStamp).getMinutes() < 10? "0" + new Date(timeStamp).getMinutes(): new Date(timeStamp).getMinutes();
- var ss =new Date(timeStamp).getSeconds() < 10? "0" + new Date(timeStamp).getSeconds(): new Date(timeStamp).getSeconds();
- var formattedDate = year + "-" + month + "-" + date + " " + hh + ":" + mm + ":" + ss;
- return formattedDate;
- }
- //头部下滚冻结
- $(function () {
- //页面高度撑满
- setTimeout(function () {
- if ($(".ibox-content").height() < $(window).height() - 31) {
- $(".ibox-content").css("height", $(window).height() - 31)
- }
- }, 1)
- })
- }])
|