'use strict'; var appMessage = angular.module('appMessage', ['luegg.directives']); 'use strict'; angular.module('appMessage').controller('MessageController', ['$scope', function ($scope) { lxtalkClient.Invoke('{15180DEF-D508-45F7-BAEB-6486CD8752C8}', '_Register', '', $scope); $scope.glued = true; $scope.items = [{ "uid": "2636765", "senderDisplayName": "陆趣趣", "sender": "0578+002682BECE10-lqq", "msgType": 0, "networkType": 1, "isDes": false, "length": 0, "isReaded": false, "contentType": 1, "receiver": "0578+002682BECE10-lsws", "fromClient": 0, "ts": 1483494160000, "id": 0, "content": "111111", "style": "" }, { content: "消息内容", style: '字体', fromClient: 2, //消息来源([0:PC],[1:iOS],[2:Android] id: "616ebe69e1c04c2ea9740a14457aaca6", isDes: 0, //是否加密消息 contentType: 1, // 消息类型([1,文本消息],[2,图片消息],[3,文件消息],[4,语音消息], [5,位置消息]) networkType: 1, //网络类型([1:wifi],[2:2G],[3:3G],[4:4G]) sender: "0578+0-ls_xxj1", senderDisplayName: "陆趣趣", length: 12312, ts: 12312312412 //时间搓 }, { content: "http://202.107.249.133:8125/e/8/2/4/f/e824fa94cbacff419a0ad611926710f9.dat?下载文件.docx", fromClient: 2, id: "253db476c6d140f0a1b4d4af5fcf2016", isDes: 0, contentType: 3, networkType: 1, sender: "0578+0-ls_xxj1", senderDisplayName: "陆趣趣", length: 17359 }, { content: "../img/DefaultHeadImage_96.png", fromClient: 2, id: "253db476c6d140f0a1b4d4af5fcf2016", isDes: 0, contentType: 2, networkType: 1, sender: "0578+0-ls_xxj1", senderDisplayName: "陆趣趣", length: 17359 }]; $scope.appContent = {}; // $scope.guid = lxtalkClient.Invoke('register', 'talkview', $scope); $scope.addMessage = function () { scroll(0, document.body.scrollHeight); } $scope.showMessage = function (jsonStr) { console.log(jsonStr); var msg = JSON.parse(jsonStr); $scope.items.push(msg); } $scope.showHistoryMessage = function (jsonStr) { var msg = JOSN.parse(jsonStr); $scope.items.unshift(msg); } $scope.initAppContent = function(appContentJson){ // console.log(appContentJson); $scope.appContent = JSON.parse(appContentJson); } }]); (function () { 'use strict'; angular .module('appMessage') .directive('ngMsg', Directive); Directive.inject = []; function Directive() { var directive = { link: link, restrict: 'A', scope: { msg: '=ngMsg', appContent: '=ngAppContent' } }; return directive; function link(scope, element, attrs) { var replaceSystemFace = function(content){ scope.appContent.faceConfig.sys.forEach(function(element) { content = content.replace(element.shortcut,''); }, this); // var reg = /[(\w+)-src="(http://[\w\W]+?)"]/; // var reg = new RegExp('\\[(\\w+)\\-src=\\"(http://[\\w\\W]+?)\\"\\]', "i"); var reg = new RegExp('\\[image\\-src=\\"([\\w\\W]+?)\\"\\]', "i"); var g = reg.exec(content); console.log(JSON.stringify(g)); for(var i = 0; i <= g.length - 1; i++){ console.log(g[i]); } return content; }; var replaceImage = function(content){ } var html = ''; // 消息类型([1,文本消息],[2,图片消息],[3,文件消息],[4,语音消息], [5,位置消息]) if (scope.appContent === undefined || scope.appContent.faceConfig ===undefined || scope.appContent.faceConfig.sys === undefined){ html = '' + scope.msg.content + ''; } else if (scope.msg.contentType == 1) { html = '' + replaceSystemFace(scope.msg.content) + ''; } else if (scope.msg.contentType == 2) { html = '' + '' + '通用的占位符缩略图' + '' + ''; } else if (scope.msg.contentType == 3) { element.css({ width: '300px' }); element.addClass('file-message'); var reg = /\?[\W\w]*/; var fileName = decodeURIComponent(reg.exec(scope.msg.content).toString().substr(1)); html = '' + '文件名:' + fileName + '
大小:' + scope.msg.length + '
' + '
' + '打开' + '打开文件夹' + '
'; } else if (scope.msg.contentType == 4) { html = '' + '' + ''; } else if (scope.msg.contentType == 5) { html = '' + '' + ''; } var newElement = angular.element(html); element.append(newElement); } } })();