123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- (function() {
- 'use strict';
- angular
- .module('appMessage')
- .directive('ngHistoryMsg', HistoryMsg);
- HistoryMsg.inject = ['$location', '$anchorScroll', '$filter'];
- function HistoryMsg($location, $anchorScroll, $filter) {
- var directive = {
- link: link,
- restrict: 'A',
- scope: {
- msg: '=ngHistoryMsg',
- appContent: '=ngAppContent',
- count: '=ngCount'
- }
- };
- return directive;
- function link(scope, element, attrs) {
- var gotoBottom = function() {
- $location.hash("bottom");
- $anchorScroll();
- };
- var getFileName = function(item) {
- var arr = item.fileName.split("\\");
- return arr[arr.length - 1];
- };
- var getUserID = function() {
- var arr = scope.appContent.directory.user.split("\\");
- var userself = arr[arr.length - 2];
- return scope.msg.sender.indexOf(userself) !== -1;
- };
- var getFileSize = function(item) {
- var fileSize = item.length;
- if (fileSize > 1024 * 1024 * 1024)
- return (Math.round(fileSize * 100 / (1024 * 1024 * 1024)) / 100).toString() + 'GB';
- else if (fileSize > 1024 * 1024)
- return (Math.round(fileSize * 100 / (1024 * 1024)) / 100).toString() + 'MB';
- else
- return (Math.round(fileSize * 100 / 1024) / 100).toString() + 'KB';
- };
- var getTime = function(item) {
- return $filter("date")(item.ts, "yyyy-MM-dd HH:mm:ss");
- };
- var replaceSystemFace = function(content) {
- //匹配表情
- var g = (/\/\:([\w]+)/).exec(content);
- while (g !== null) {
- scope.appContent.faceConfig.sys.forEach(function(element) {
- content = content.replace(element.shortcut, '<img style="height:56px" src="local://' + scope.appContent.directory.base + element.image + '">');
- }, this);
- g = (/\/\:([\w]+)/).exec(content);
- }
- //匹配截图
- var g = (/\[image\-src=\"([\w\W]+?)\"\]/i).exec(content);
- while (g !== null) {
- content = content.replace(g[0],
- '<a href="#" class="thumbnail"' + '>' +
- // '<img class="lazy" style="max-width:270px;max-height:250px;" src="../img/loading.jpg" data-original="local://' + scope.appContent.directory.received + g[1] + '.JPG' + '" alt="" >' +
- '<img class="lazy" style="max-width:270px;max-height:250px;" src="local://' + scope.appContent.directory.received + g[1] + '.JPG' + '" alt="" >' +
- '</a>'
- );
- g = (/\[image\-src=\"([\w\W]+?)\"\]/i).exec(content);
- }
- //匹配网址
- var i = 0;
- var m = content.match(/(((((http|ftp|https|HTTP|FTP|HTTPS):\/\/)[\w\-_]+)|www|WWW|[0-9]+)(\.(?!gif|jpg|png|mp3)[\w\-_]+)+([\w\-\.,@?^=%:/~\+#]*[\w\-\@?^=%/~\+#\r\n]))/ig);
- console.log(m);
- if (m == null)
- return content;
- content = content.replace(/(((((http|ftp|https|HTTP|FTP|HTTPS):\/\/)[\w\-_]+)|www|WWW|[0-9]+)(\.(?!gif|jpg|png|mp3)[\w\-_]+)+([\w\-\.,@?^=%:/~\+#]*[\w\-\@?^=%/~\+#\r\n]))/ig, function() {
- var html = '';
- var g = (/((((http|ftp|https|HTTP|FTP|HTTPS):\/\/)[\w\-_]+)(\.[\w\-_]+)+([\w\-\.,@?^=%:/~\+#]*[\w\-\@?^=%/~\+#\r\n]))/ig).exec(m[i]);
- if (getUserID()) {
- if (g == null)
- html = '<a style="color:white;text-decoration:underline;" target="_blank" href="http://' + m[i] + '">' +
- m[i] +
- '</a>';
- else
- html = '<a style="color:white;text-decoration:underline;" target="_blank" href="' + m[i] + '">' +
- m[i] +
- '</a>';
- i = i + 1;
- } else {
- if (g == null)
- html = '<a style="text-decoration:underline;" target="_blank" href="http://' + m[i] + '">' +
- m[i] +
- '</a>';
- else
- html = '<a style="text-decoration:underline;" target="_blank" href="' + m[i] + '">' +
- m[i] +
- '</a>';
- i = i + 1;
- }
- return html;
- });
- return content;
- };
- var message = document.getElementById("loadmore");
- if (scope.msg.senderDisplayName === undefined || scope.msg.senderDisplayName == '')
- scope.msg.senderDisplayName = scope.msg.sender;
- var html = '';
- // 消息类型([1,文本消息],[2,图片消息],[3,文件消息], [4,位置消息],[5,语音消息])
- if (scope.appContent === undefined || scope.appContent.faceConfig === undefined || scope.appContent.faceConfig.sys === undefined) {
- html = '<span class="text-message">' + scope.msg.content + '</span>';
- } else if (scope.msg.contentType == 1) {
- //var style = { style: "normal", weight: "normal" };
- if (getUserID()) {
- var style = scope.msg.style === "" || scope.msg.style === undefined ? {
- style: 'normal',
- weight: 'normal',
- size: 9,
- family: '微软雅黑',
- color: 16777215
- } : _.assign({
- style: 'normal',
- weight: 'normal',
- size: 9,
- family: '微软雅黑',
- color: 16777215
- }, JSON.parse(scope.msg.style));
- style.color = 16777215;
- } else {
- var style = scope.msg.style === "" || scope.msg.style === undefined ? {
- style: 'normal',
- weight: 'normal',
- size: 9,
- family: '微软雅黑',
- color: 0
- } : _.assign({
- style: 'normal',
- weight: 'normal',
- size: 9,
- family: '微软雅黑',
- color: 0
- }, JSON.parse(scope.msg.style));
- style.color = 0;
- }
- html = '<span class="text-message"' + ' style="font:' + style.style + ' ' + style.weight + ' ' + style.size + 'pt' + ' ' + style.family + ';color:#' + _.padStart(style.color.toString(16), 6, '0') + '">' +
- replaceSystemFace(scope.msg.content) + '</span>';
- } else if (scope.msg.contentType == 2) {
- html = '<span class="text-message">' +
- '<a href="#" class="thumbnail" >' +
- '<img src="' + scope.msg.content + '" alt="通用的占位符缩略图" >' +
- '</a>' +
- '</span>';
- } else if (scope.msg.contentType == 3) {
- var content = JSON.parse(scope.msg.content);
- console.log(content);
- html = '<div class="file-message" style="width:265px">' +
- '<img src="../img/unkown.png" onError= "this.src = \'../img/file/unkown.png\'">' +
- '<p><input type="text" readonly="readonly" value="' + getFileName(content) + '"></p>' +
- '<span>大小:' + getFileSize(content) + '</span>' +
- '<div class="p-t-sm text-right">' +
- '<span id="transinfo"><span style="color:green;" class="glyphicon glyphicon-ok"></span><span>传输完成</span></span>' +
- '<a class="text-primary" role="button"><span>打开</span></a>  ' +
- '<a class="text-primary" role="button"><span>打开文件夹</span></a>' +
- '</div>' +
- '</div>';
- } else if (scope.msg.contentType == 4) {
- html = '<span class="text-message">' +
- '<iframe class="map" border=0 src="' + scope.msg.content + '" frameBorder=no></iframe>' +
- '</span>';
- } else if (scope.msg.contentType == 5) {
- html = '<span class="text-message">' +
- '<audio src="' + scope.msg.content + '" controls="controls">' +
- '</audio>' +
- '</span>';
- }
- if (getUserID()) {
- var html_g = '<div class="feed-element">' +
- '<div class="media-body">' +
- '<p><strong>' +
- scope.msg.senderDisplayName +
- '</strong><small class="text-muted">-' +
- getTime(scope.msg) + '</small></p>' +
- '<div class="wellself m-l-xs m-t-xs fit-content" >' +
- '<div class="text-point"></div>' + html +
- '</div></div></div>';
- } else {
- var html_g = '<div class="feed-element">' +
- '<div class="media-body">' +
- '<p><strong>' +
- scope.msg.senderDisplayName +
- '</strong><small class="text-muted">-' +
- getTime(scope.msg) + '</small></p>' +
- '<div class="well m-l-xs m-t-xs fit-content" >' +
- '<div class="text-point"></div>' + html +
- '</div></div></div>';
- }
- angular.element("#loadmore").prepend(html_g);
- console.log(html_g);
- if (scope.count) {
- message.addEventListener('load', gotoBottom());
- }
- }
- }
- })();
|