historymessages.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. (function() {
  2. 'use strict';
  3. angular
  4. .module('appMessage')
  5. .directive('ngHistoryMsg', HistoryMsg);
  6. HistoryMsg.inject = [];
  7. function HistoryMsg() {
  8. var directive = {
  9. link: link,
  10. restrict: 'A',
  11. scope: {
  12. msg: '=ngHistoryMsg',
  13. appContent: '=ngAppContent'
  14. }
  15. };
  16. return directive;
  17. function link(scope, element, attrs) {
  18. var replaceSystemFace = function(content) {
  19. //匹配表情
  20. var g = (/\/\:([\w]+)/).exec(content);
  21. while (g !== null) {
  22. scope.appContent.faceConfig.sys.forEach(function(element) {
  23. content = content.replace(element.shortcut, '<img style="height:56px" src="local://' + scope.appContent.directory.base + element.image + '">');
  24. }, this);
  25. g = (/\/\:([\w]+)/).exec(content);
  26. }
  27. //匹配截图
  28. var g = (/\[image\-src=\"([\w\W]+?)\"\]/i).exec(content);
  29. while (g !== null) {
  30. content = content.replace(g[0],
  31. '<a href="#" class="thumbnail"' + '>' +
  32. '<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="" >' +
  33. '</a>'
  34. );
  35. g = (/\[image\-src=\"([\w\W]+?)\"\]/i).exec(content);
  36. }
  37. //匹配网址
  38. var i = 0;
  39. 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);
  40. console.log(m);
  41. if (m == null)
  42. return content;
  43. 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() {
  44. var html = '';
  45. var g = (/((((http|ftp|https|HTTP|FTP|HTTPS):\/\/)[\w\-_]+)(\.[\w\-_]+)+([\w\-\.,@?^=%:/~\+#]*[\w\-\@?^=%/~\+#\r\n]))/ig).exec(m[i]);
  46. if (g == null)
  47. html = '<a target="_blank" href="http://' + m[i] + '">' +
  48. m[i] +
  49. '</a>';
  50. else
  51. html = '<a target="_blank" href="' + m[i] + '">' +
  52. m[i] +
  53. '</a>';
  54. i = i + 1;
  55. return html;
  56. });
  57. return content;
  58. };
  59. if (scope.msg.senderDisplayName === undefined || scope.msg.senderDisplayName == '')
  60. scope.msg.senderDisplayName = scope.msg.sender;
  61. var html = '';
  62. // 消息类型([1,文本消息],[2,图片消息],[3,文件消息], [4,位置消息],[5,语音消息])
  63. if (scope.appContent === undefined || scope.appContent.faceConfig === undefined || scope.appContent.faceConfig.sys === undefined) {
  64. html = '<span class="text-message">' + scope.msg.content + '</span>';
  65. } else if (scope.msg.contentType == 1) {
  66. //var style = { style: "normal", weight: "normal" };
  67. var style = scope.msg.style;
  68. html = '<span class="text-message"' + ' style="font:' + style.style + ' ' + style.weight + ' ' + style.size + 'pt' + ' ' + style.family + ';color:#' + style.color.toString(16) + '">' +
  69. replaceSystemFace(scope.msg.content) + '</span>';
  70. } else if (scope.msg.contentType == 2) {
  71. html = '<span class="text-message">' +
  72. '<a href="#" class="thumbnail" >' +
  73. '<img src="' + scope.msg.content + '" alt="通用的占位符缩略图" >' +
  74. '</a>' +
  75. '</span>';
  76. } else if (scope.msg.contentType == 3) {
  77. // element.css({
  78. // width: '300px'
  79. // });
  80. //element.addClass('file-message');
  81. var reg = /\?[\W\w]*/;
  82. var fileName = decodeURIComponent(reg.exec(scope.msg.content).toString().substr(1));
  83. html = '<div class="file-message" style="width:250px">' +
  84. '<img src="../img/unkown.png" onError= "this.src = \'../img/file/unkown.png\'">' +
  85. '<span style="float:left; margin:5px 0px 0px 0px">文件名:' + fileName + '<br/>大小:' + scope.msg.length + '</span>' +
  86. '<div class="p-t-sm text-right">' +
  87. '<a class="text-primary" role="button"><span>打开</span></a>&nbsp&nbsp' +
  88. '<a class="text-primary" role="button"><span>打开文件夹</span></a>' +
  89. '</div>' +
  90. '</div>';
  91. } else if (scope.msg.contentType == 4) {
  92. html = '<span class="text-message">' +
  93. '<iframe class="map" border=0 src="' + scope.msg.content + '" frameBorder=no></iframe>' +
  94. '</span>';
  95. } else if (scope.msg.contentType == 5) {
  96. html = '<span class="text-message">' +
  97. '<audio src="' + scope.msg.content + '" controls="controls">' +
  98. '</audio>' +
  99. '</span>';
  100. }
  101. var html_g = '<div class="feed-element">' +
  102. '<div class="media-body" id="loadmore">' +
  103. '<p><strong>' +
  104. scope.msg.senderDisplayName +
  105. '</strong><small class="text-muted">-2017-2-6 15:57:17&nbsp' +
  106. scope.msg.ts + '</small></p>' +
  107. '<div class="well m-l-xs m-t-xs fit-content" >' +
  108. '<div class="text-point"></div>' + html +
  109. '</div></div></div>';
  110. angular.element("#loadmore").prepend(html_g);
  111. $(function() {
  112. $("img.lazy").lazyload();
  113. });
  114. console.log(html_g);
  115. }
  116. }
  117. })();