historymessages.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. (function() {
  2. 'use strict';
  3. angular
  4. .module('appMessage')
  5. .directive('ngHistoryMsg', HistoryMsg);
  6. HistoryMsg.inject = ['$location', '$anchorScroll', '$filter'];
  7. function HistoryMsg($location, $anchorScroll, $filter) {
  8. var directive = {
  9. link: link,
  10. restrict: 'A',
  11. scope: {
  12. msg: '=ngHistoryMsg',
  13. appContent: '=ngAppContent',
  14. count: '=ngCount'
  15. }
  16. };
  17. return directive;
  18. function link(scope, element, attrs) {
  19. var gotoBottom = function() {
  20. $location.hash("bottom");
  21. $anchorScroll();
  22. };
  23. var getFileName = function(item) {
  24. var arr = item.fileName.split("\\");
  25. return arr[arr.length - 1];
  26. };
  27. var getUserID = function() {
  28. var arr = scope.appContent.directory.user.split("\\");
  29. var userself = arr[arr.length - 2];
  30. return scope.msg.sender.indexOf(userself) !== -1;
  31. };
  32. var getFileSize = function(item) {
  33. var fileSize = item.length;
  34. if (fileSize > 1024 * 1024 * 1024)
  35. return (Math.round(fileSize * 100 / (1024 * 1024 * 1024)) / 100).toString() + 'GB';
  36. else if (fileSize > 1024 * 1024)
  37. return (Math.round(fileSize * 100 / (1024 * 1024)) / 100).toString() + 'MB';
  38. else
  39. return (Math.round(fileSize * 100 / 1024) / 100).toString() + 'KB';
  40. };
  41. var getTime = function(item) {
  42. return $filter("date")(item.ts, "yyyy-MM-dd HH:mm:ss");
  43. };
  44. var replaceSystemFace = function(content) {
  45. //匹配表情
  46. var g = (/\/\:([\w]+)/).exec(content);
  47. while (g !== null) {
  48. scope.appContent.faceConfig.sys.forEach(function(element) {
  49. content = content.replace(element.shortcut, '<img style="height:56px" src="local://' + scope.appContent.directory.base + element.image + '">');
  50. }, this);
  51. g = (/\/\:([\w]+)/).exec(content);
  52. }
  53. //匹配截图
  54. var g = (/\[image\-src=\"([\w\W]+?)\"\]/i).exec(content);
  55. while (g !== null) {
  56. content = content.replace(g[0],
  57. '<a href="#" class="thumbnail"' + '>' +
  58. // '<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="" >' +
  59. '<img class="lazy" style="max-width:270px;max-height:250px;" src="local://' + scope.appContent.directory.received + g[1] + '.JPG' + '" alt="" >' +
  60. '</a>'
  61. );
  62. g = (/\[image\-src=\"([\w\W]+?)\"\]/i).exec(content);
  63. }
  64. //匹配网址
  65. var i = 0;
  66. 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);
  67. console.log(m);
  68. if (m == null)
  69. return content;
  70. 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() {
  71. var html = '';
  72. var g = (/((((http|ftp|https|HTTP|FTP|HTTPS):\/\/)[\w\-_]+)(\.[\w\-_]+)+([\w\-\.,@?^=%:/~\+#]*[\w\-\@?^=%/~\+#\r\n]))/ig).exec(m[i]);
  73. if (getUserID()) {
  74. if (g == null)
  75. html = '<a style="color:white;text-decoration:underline;" target="_blank" href="http://' + m[i] + '">' +
  76. m[i] +
  77. '</a>';
  78. else
  79. html = '<a style="color:white;text-decoration:underline;" target="_blank" href="' + m[i] + '">' +
  80. m[i] +
  81. '</a>';
  82. i = i + 1;
  83. } else {
  84. if (g == null)
  85. html = '<a style="text-decoration:underline;" target="_blank" href="http://' + m[i] + '">' +
  86. m[i] +
  87. '</a>';
  88. else
  89. html = '<a style="text-decoration:underline;" target="_blank" href="' + m[i] + '">' +
  90. m[i] +
  91. '</a>';
  92. i = i + 1;
  93. }
  94. return html;
  95. });
  96. return content;
  97. };
  98. var message = document.getElementById("loadmore");
  99. if (scope.msg.senderDisplayName === undefined || scope.msg.senderDisplayName == '')
  100. scope.msg.senderDisplayName = scope.msg.sender;
  101. var html = '';
  102. // 消息类型([1,文本消息],[2,图片消息],[3,文件消息], [4,位置消息],[5,语音消息])
  103. if (scope.appContent === undefined || scope.appContent.faceConfig === undefined || scope.appContent.faceConfig.sys === undefined) {
  104. html = '<span class="text-message">' + scope.msg.content + '</span>';
  105. } else if (scope.msg.contentType == 1) {
  106. //var style = { style: "normal", weight: "normal" };
  107. if (getUserID()) {
  108. var style = scope.msg.style === "" || scope.msg.style === undefined ? {
  109. style: 'normal',
  110. weight: 'normal',
  111. size: 9,
  112. family: '微软雅黑',
  113. color: 16777215
  114. } : _.assign({
  115. style: 'normal',
  116. weight: 'normal',
  117. size: 9,
  118. family: '微软雅黑',
  119. color: 16777215
  120. }, JSON.parse(scope.msg.style));
  121. style.color = 16777215;
  122. } else {
  123. var style = scope.msg.style === "" || scope.msg.style === undefined ? {
  124. style: 'normal',
  125. weight: 'normal',
  126. size: 9,
  127. family: '微软雅黑',
  128. color: 0
  129. } : _.assign({
  130. style: 'normal',
  131. weight: 'normal',
  132. size: 9,
  133. family: '微软雅黑',
  134. color: 0
  135. }, JSON.parse(scope.msg.style));
  136. style.color = 0;
  137. }
  138. html = '<span class="text-message"' + ' style="font:' + style.style + ' ' + style.weight + ' ' + style.size + 'pt' + ' ' + style.family + ';color:#' + _.padStart(style.color.toString(16), 6, '0') + '">' +
  139. replaceSystemFace(scope.msg.content) + '</span>';
  140. } else if (scope.msg.contentType == 2) {
  141. html = '<span class="text-message">' +
  142. '<a href="#" class="thumbnail" >' +
  143. '<img src="' + scope.msg.content + '" alt="通用的占位符缩略图" >' +
  144. '</a>' +
  145. '</span>';
  146. } else if (scope.msg.contentType == 3) {
  147. var content = JSON.parse(scope.msg.content);
  148. console.log(content);
  149. html = '<div class="file-message" style="width:265px">' +
  150. '<img src="../img/unkown.png" onError= "this.src = \'../img/file/unkown.png\'">' +
  151. '<p><input type="text" readonly="readonly" value="' + getFileName(content) + '"></p>' +
  152. '<span>大小:' + getFileSize(content) + '</span>' +
  153. '<div class="p-t-sm text-right">' +
  154. '<span id="transinfo"><span style="color:green;" class="glyphicon glyphicon-ok"></span><span>传输完成</span></span>' +
  155. '<a class="text-primary" role="button"><span>打开</span></a>&nbsp&nbsp' +
  156. '<a class="text-primary" role="button"><span>打开文件夹</span></a>' +
  157. '</div>' +
  158. '</div>';
  159. } else if (scope.msg.contentType == 4) {
  160. html = '<span class="text-message">' +
  161. '<iframe class="map" border=0 src="' + scope.msg.content + '" frameBorder=no></iframe>' +
  162. '</span>';
  163. } else if (scope.msg.contentType == 5) {
  164. html = '<span class="text-message">' +
  165. '<audio src="' + scope.msg.content + '" controls="controls">' +
  166. '</audio>' +
  167. '</span>';
  168. }
  169. if (getUserID()) {
  170. var html_g = '<div class="feed-element">' +
  171. '<div class="media-body">' +
  172. '<p><strong>' +
  173. scope.msg.senderDisplayName +
  174. '</strong><small class="text-muted">-' +
  175. getTime(scope.msg) + '</small></p>' +
  176. '<div class="wellself m-l-xs m-t-xs fit-content" >' +
  177. '<div class="text-point"></div>' + html +
  178. '</div></div></div>';
  179. } else {
  180. var html_g = '<div class="feed-element">' +
  181. '<div class="media-body">' +
  182. '<p><strong>' +
  183. scope.msg.senderDisplayName +
  184. '</strong><small class="text-muted">-' +
  185. getTime(scope.msg) + '</small></p>' +
  186. '<div class="well m-l-xs m-t-xs fit-content" >' +
  187. '<div class="text-point"></div>' + html +
  188. '</div></div></div>';
  189. }
  190. angular.element("#loadmore").prepend(html_g);
  191. console.log(html_g);
  192. if (scope.count) {
  193. message.addEventListener('load', gotoBottom());
  194. }
  195. }
  196. }
  197. })();