請加微信

右鍵保存圖片

close
'; parentStr += '
'; parentStr += '

'; if (sessions[i].lastMsg != undefined) { parentStr += '' + diffTime(sessions[i].lastMsg.time) + ''; } else { parentStr += ''; } parentStr += '

'; if (sessions[i].lastMsg != undefined) { if (sessions[i].lastMsg.type == "text") { parentStr += '

' + sessions[i].lastMsg.text + '

'; } else if (sessions[i].lastMsg.type == "audio") { parentStr += '

[語音]

'; } else if (sessions[i].lastMsg.type == "video") { parentStr += '

[視頻]

'; } else if (sessions[i].lastMsg.type == "image") { parentStr += '

[圖片]

'; } else if (sessions[i].lastMsg.type == "location") { parentStr += '

[位置]

'; } else if (sessions[i].lastMsg.type == "tip") { parentStr += '

' + sessions[i].lastMsg.tip + '

'; } else if (sessions[i].lastMsg.type == "custom") { parentStr += '

' + sessions[i].lastMsg.pushContent + '

'; } else { parentStr += '

' + sessions[i].lastMsg.text + '

'; } parentStr += '
'; } parentStr += ''; parentStr += ''; } if (num == 0) { $("#chatNum").hide(); } else { $("#chatNum").html(num); $("#chatNum").show(); } list.html(parentStr); } else if (type == 2) { if (sessions.lastMsg != undefined) { if (sessions.lastMsg.status == "success") { //聊天详情 getChatList(sessions.lastMsg, listNum); } } } else if (type == 3) { //聊天详情 getChatList(sessions, teamId); } } //批量加载会话消息 function batchUpdateSessionUI(arr) { $(".content .notice").empty(); if (arr.length > 0) { listNum = arr.length; for (var i = arr.length - 1; i >= 0; i--) { if (arr[i].status == "success") { //聊天详情 getChatList(arr[i], i) if (arr[i].geo != undefined) { LoadMap("map" + i, arr[i].geo.lng, arr[i].geo.lat); } } } } } //聊天详情 function getChatList(data, index) { let objInfo = listArray.find(o => o.account === staffNo); if (objInfo != undefined) { if (objInfo.alias != undefined && jobId.length < 7) { staffName = objInfo.alias; } else { staffName = objInfo.nick; } } else { staffName = data.fromNick; } userName = ""; let UserInfo = listArray.find(o => o.account === data.from); if (UserInfo != undefined) { if (UserInfo.alias != undefined) { userName = UserInfo.alias; } else { userName = UserInfo.nick; } } else { userName = data.fromNick; } if (data.type != "notification") { var content = $(".content .notice"); var result = ""; var direction = ""; var parentdiv = ''; if (data.custom != undefined) { if (data.from != account) { if (jobId.length > 7) { direction = "left"; result = "left"; } else { direction = "right"; result = "chat"; } } else { direction = "left"; result = "left"; } parentdiv += '
'; parentdiv += '
' + diffTime(data.time) + '
'; if (UserInfo != undefined) { if (UserInfo.avatar != undefined && UserInfo.avatar != "") { parentdiv += ''; } else { parentdiv += ''; } } else { parentdiv += ''; } } else if (data.type == "tip") { result = "center"; direction = "center"; parentdiv += '
'; parentdiv += '
' + diffTime(data.time) + '
'; } else { if (data.flow == "out") {//发送方 result = "chat"; direction = "right"; } else if (data.flow == "in") {//接收 result = "left"; direction = "left"; } parentdiv += '
'; parentdiv += '
' + diffTime(data.time) + '
'; if (jobId.length > 7) { if (data.flow == "in") { if (objInfo != undefined) { if (objInfo.avatar != undefined && objInfo.avatar != "") { parentdiv += ''; } else { parentdiv += ''; } } } else { if (UserInfo != undefined) { if (UserInfo.avatar != undefined && UserInfo.avatar != "") { parentdiv += ''; } else { parentdiv += ''; } } } } else { if (UserInfo != undefined) { if (UserInfo.avatar != undefined && UserInfo.avatar != "") { parentdiv += ''; } else { parentdiv += ''; } } } } parentdiv += '
'; if (data.type != "tip") { if (data.custom != undefined) { parentdiv += '

' + staffName + '

'; } else { if (jobId.length > 7) { if (data.flow == "in") { parentdiv += '

' + staffName + '

'; } else { parentdiv += '

' + userName + '

'; } } else { parentdiv += '

' + userName + '

'; } } parentdiv += '
'; } else { parentdiv += '
'; } parentdiv += '
'; if (data.type == "text") { parentdiv += '
' + data.text + '
'; } else if (data.type == "image") { parentdiv += '
'; parentdiv += ''; parentdiv += '
'; } else if (data.type == "audio") { parentdiv += '
'; parentdiv += '
'; parentdiv += ''; parentdiv += ''; parentdiv += '' + Math.trunc((data.file.dur) / 1000) + ''; parentdiv += '"'; parentdiv += ''; parentdiv += ''; parentdiv += '
'; parentdiv += '
'; } else if (data.type == "video") { parentdiv += '
'; parentdiv += '
'; } else if (data.type == "tip") { parentdiv += '
' + data.tip + '
'; } else if (data.geo != undefined) { parentdiv += '' } else if (data.type = "custom") { if (data.content != undefined) { var item = JSON.parse(data.content); parentdiv += '
'; if (item.Type == 1 || item.Type == 5) { //新盘、查图则 parentdiv += ''; parentdiv += '
'; parentdiv += ''; parentdiv += '
'; parentdiv += '

' + item.BuildingTitle + '

'; if (item.Type == 1) { parentdiv += ''; } else if (item.Type == 5) { parentdiv += ''; } parentdiv += '
'; } else if (item.Type == 2 || item.Type == 3 || item.Type == 4) { //房源、视频搵楼、工商铺 if (item.Type == 2) { parentdiv += ''; } else if (item.Type == 3) { parentdiv += ''; } else if (item.Type == 4) { parentdiv += ''; } parentdiv += '

' + item.BuildingTitle + '

'; if (item.Type != 3) { if (item.SellType == "放租") { parentdiv += '

HK $' + toPrice(item.Rent) + '元(租MOP $' + toPrice(item.MoRent) + '元)

'; } else if (item.SellType == "租售") { parentdiv += '

HK $' + toPrice(item.Price) + '萬(售MOP $' + toPrice(item.MoPrice) + '萬)

'; parentdiv += '

HK $' + toPrice(item.Rent) + '元(租MOP $' + toPrice(item.MoRent) + '元)

'; } else { parentdiv += '

HK $' + toPrice(item.Price) + '萬(售MOP $' + toPrice(item.MoPrice) + '萬)

'; } } parentdiv += '
'; parentdiv += '
'; if (item.PropertyNo != "") { parentdiv += '

商鋪編號#' + item.PropertyNo + '

'; } parentdiv += '

'; if (item.GrossArea != "" && item.GrossArea != 0) { parentdiv += '約' + toThousands(Math.round(item.GrossArea)) + '呎'; } if (item.CountF != null && item.CountF != 0 && item.CountT != null && item.CountT != 0) { parentdiv += ' / '; if (item.CountF != null && item.CountF != 0) { parentdiv += item.CountF + '房'; } if (item.CountT != null && item.CountT != 0) { parentdiv += item.CountT + '廳'; } } parentdiv += '

'; if (item.PropertyUsage != "") { parentdiv += ''; } parentdiv += '
'; parentdiv += ''; parentdiv += '
'; parentdiv += '
'; } parentdiv += '
'; parentdiv += '
'; } } parentdiv += '
' parentdiv += '
' content.append(parentdiv); var temMsgList = document.getElementById('msgEnd'); temMsgList.scrollIntoView(); } } function LoadMap(Mapid, PosX, PosY) { var PosX = PosX; var PosY = PosY; var map = new BMap.Map(Mapid); // 创建Map实例 map.centerAndZoom(new BMap.Point(PosX, PosY), 17); // 初始化地图,设置中心点坐标和地图级别 var icon = new BMap.Icon('../../images/base/location.png', new BMap.Size(32, 32)); mPotion = new BMap.Point(PosX, PosY); var mkr = new BMap.Marker(mPotion, { icon: icon }); MyMarker = mkr; map.addOverlay(mkr); } function onRoamingMsgs(obj) { console.log('漫游消息', obj.msgs); pushMsg(obj.msgs); } function onOfflineMsgs(obj) { console.log('离线消息', obj.msgs); pushMsg(obj.msgs); } function onMsg(msg) { //console.log('收到消息', msg, msg.type, msg.text); data.sessions = nim.mergeSessions(data.sessions, data.sessions); var num = 0; data.sessions.forEach((item, index, arr) => { num += item.unread; var html = $("#" + item.id).find(".head_contianer"); if (item.unread != 0) { if (html.attr("data-id") == 0) { html.append("" + item.unread + ""); } else { html.find("span").html(item.unread); } html.attr("data-id", item.unread); } var strHtml = $("#" + item.id).find(".right_contianer"); var aHtml = ""; if (item.lastMsg != undefined) { strHtml.find(".chat_dialog").remove(); if (item.lastMsg.type == "text") { aHtml = '

' + item.lastMsg.text + '

'; } else if (item.lastMsg.type == "audio") { aHtml = '

[語音]

'; } else if (item.lastMsg.type == "video") { aHtml = '

[視頻]

'; } else if (item.lastMsg.type == "image") { aHtml = '

[圖片]

'; } else if (item.lastMsg.type == "location") { aHtml = '

[位置]

'; } else if (item.lastMsg.type == "tip") { aHtml = '

' + item.lastMsg.tip + '

'; } else if (item.lastMsg.type == "custom") { aHtml = '

' + item.lastMsg.pushContent + '

'; } else { aHtml = '

' + item.lastMsg.text + '

'; } } strHtml.append(aHtml); }); updateSessionsUI(data.sessions[0], 2); $("#chatNum").html(num); if (num == 0) { $("#chatNum").hide(); } else { $("#chatNum").show(); } pushMsg(msg); } //用户名片渲染 function onUsers(users, type, teamId, index) { if (index != 1) { data.users = nim.mergeUsers(data.users, users); staffInfo = users; var prefix = "team-"; if (type == "edit") { // editUsers(users, teamId); var $person = $("#" + prefix + teamId); if (users.alias != undefined) { $person.find(".name label").html(users.alias); $person.attr("onclick", "OpenChat('" + teamId + "',0,'" + users.alias + "')"); } else { $person.find(".name label").html(users.nick); $person.attr("onclick", "OpenChat('" + teamId + "',0,'" + users.nick + "')"); } if (users.avatar != '') { $person.find(".head_contianer").find("img").attr("src", users.avatar); } else { $person.find(".head_contianer").find("img").attr("src", "/images/User/head.png"); } $person.find(".name span").html(diffTime(users.updateTime)); } } } //push信息上云信 function pushMsg(msgs) { console.log("推入云信:"); if (!Array.isArray(msgs)) { msgs = [msgs]; } var sessionId = msgs[0].sessionId; data.msgs = data.msgs || {}; data.msgs[sessionId] = nim.mergeMsgs(data.msgs[sessionId], msgs); } function UnixToDate(unixTime, isFull, timeZone) { if (typeof (timeZone) == 'number') { unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60; } var time = new Date(unixTime); var ymdhis = ""; ymdhis += time.getFullYear() + "-"; if (time.getDate() < 10) { ymdhis += "0" + (time.getMonth() + 1) + "-"; } else { ymdhis += (time.getMonth() + 1) + "-"; } if (time.getDate() < 10) { ymdhis += "0" + time.getDate(); } else { ymdhis += time.getDate(); } if (isFull === true) { ymdhis += " " + time.getHours() + ":"; if (time.getMinutes() < 10) { ymdhis += "0" + time.getMinutes(); } else { ymdhis += time.getMinutes(); } } return ymdhis; } //打开聊天框 function OpenChat(Id, type, name) { teamId = Id; listArray = []; nim.getTeamMembers({ teamId: teamId, done: getTeamMembersDoneMsg }); headImg = staffInfo.avatar; if (type == 1 || type == 2 || type == 3) { sendText(type, teamId); } nim.resetSessionUnread('team-' + teamId); // localMsgs("team-" + teamId, teamId) $("#team-" + teamId).find(".head_contianer").attr("data-id", "0"); $("#team-" + teamId).find(".head_contianer span").remove(); $("#chatNum").hide(); $(".onchat > .name").html(name); $(".Contact").css("display", "block"); $(".chat").css("width", "700px"); $(".person").css("width", "280px") } //关闭聊天框 function CloseChat() { $(".Contact").css("display", "none"); $(".chat").css("width", "280px"); $(".person").css("width","280px") } function OpenPerson() { $(".chat").css("display", "flex"); } //关闭联系人列表 function ClosePerson() { $(".chat").css("display", "none"); } $("#obs").click(function () { nim.resetSessionUnread('team-' + teamId); $("#team-" + teamId).find(".head_contianer").attr("data-id", "0"); $("#team-" + teamId).find(".head_contianer span").remove(); }); //播放语音 $('.content').on('click', '.audioBox span', function () { var currentNode = $(this); var audioEle = $(this).siblings('.audio'); playAudio(currentNode, audioEle); }); function playAudio(currentNode, audioEle) { /*jquery对象转换成js对象*/ var player = audioEle[0]; if (player.paused) { /*如果已经暂停*/ $(".audioBox span").removeClass('audioPlay'); $(".audioBox span").siblings('.audio')[0].pause(); player.play(); /*播放*/ currentNode.addClass('audioPlay'); } else { player.pause();/*暂停*/ currentNode.removeClass('audioPlay'); } // 录音播放结束停止动画 player.addEventListener('ended', function () { currentNode.removeClass('audioPlay'); }, false); } function getBase64(img) {//传入图片路径,返回base64 function getBase64Image(img, width, height) {//width、height调用时传入具体像素值,控制大小 ,不传则默认图像大小 var canvas = document.createElement("canvas"); canvas.width = width ? width : img.width; canvas.height = height ? height : img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0, canvas.width, canvas.height); var dataURL = canvas.toDataURL(); return dataURL; } var image = new Image(); image.crossOrigin = ''; image.src = img; var deferred = $.Deferred(); if (img) { image.onload = function () { deferred.resolve(getBase64Image(image));//将base64传给done上传处理 } return deferred.promise();//问题要让onload完成后再return sessionStorage['imgTest'] } } }