Răsfoiți Sursa

IM聊天-文件消息支持

fancy 5 ani în urmă
părinte
comite
0562a73980
35 a modificat fișierele cu 120 adăugiri și 4 ștergeri
  1. 20 2
      o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ActionMsgCreate.java
  2. 12 0
      o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ActionUploadFile.java
  3. 4 0
      o2web/source/x_component_IMV2/$Main/default/style.css
  4. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_ai.png
  5. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_arch.png
  6. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_att.png
  7. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_au.png
  8. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_avi.png
  9. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_cad.png
  10. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_cdr.png
  11. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_eps.png
  12. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_excel.png
  13. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_exe.png
  14. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_flash.png
  15. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_gif.png
  16. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_html.png
  17. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_img.png
  18. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_iso.png
  19. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_jpeg.png
  20. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_link.png
  21. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_mp3.png
  22. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_mp4.png
  23. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_pdf.png
  24. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_png.png
  25. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_ppt.png
  26. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_psd.png
  27. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_rar.png
  28. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_rm.png
  29. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_tiff.png
  30. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_tmp.png
  31. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_txt.png
  32. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_unkown.png
  33. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_word.png
  34. BIN
      o2web/source/x_component_IMV2/$Main/file_icons/icon_file_zip.png
  35. 84 2
      o2web/source/x_component_IMV2/Main.js

+ 20 - 2
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ActionMsgCreate.java

@@ -102,10 +102,20 @@ public class ActionMsgCreate extends BaseAction {
     private String imMessageBody(IMMsg msg) {
         String json  = msg.getBody();
         IMMessageBody body = gson.fromJson(json, IMMessageBody.class);
-        if ("emoji".equals(body.getType())) {
+        if ("text".equals(body.getType())) {
+            return body.getBody();
+        }else if ("emoji".equals(body.getType())) {
             return "[表情]";
+        }else if ("image".equals(body.getType())) {
+            return "[图片]";
+        }else if ("audio".equals(body.getType())) {
+            return "[声音]";
+        }else if ("location".equals(body.getType())) {
+            return "[位置]";
+        }else if ("file".equals(body.getType())) {
+            return "[文件]";
         }else {
-            return body.getBody();
+            return "[其它]";
         }
     }
 
@@ -119,6 +129,14 @@ public class ActionMsgCreate extends BaseAction {
     }
 
     public static class IMMessageBody {
+        /**
+         *     text
+         *     emoji
+         *     image
+         *     audio
+         *     location
+         *     file
+         */
         private String type;
         private String body;
 

+ 12 - 0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/im/ActionUploadFile.java

@@ -71,6 +71,7 @@ public class ActionUploadFile extends BaseAction {
             Wo wo = new Wo();
             wo.setId(file.getId());
             wo.setFileExtension(file.getExtension());
+            wo.setFileName(fileName);
             result.setData(wo);
             return result;
         }
@@ -84,6 +85,9 @@ public class ActionUploadFile extends BaseAction {
         @FieldDescribe( "文件扩展名" )
         private String fileExtension;
 
+        @FieldDescribe( "文件名" )
+        private String fileName;
+
         public String getFileExtension() {
             return fileExtension;
         }
@@ -91,5 +95,13 @@ public class ActionUploadFile extends BaseAction {
         public void setFileExtension(String fileExtension) {
             this.fileExtension = fileExtension;
         }
+
+        public String getFileName() {
+            return fileName;
+        }
+
+        public void setFileName(String fileName) {
+            this.fileName = fileName;
+        }
     }
 }

+ 4 - 0
o2web/source/x_component_IMV2/$Main/default/style.css

@@ -322,6 +322,8 @@
   .chat-sender {
     clear: both;
     /* font-size: 80%; */
+    float: left;
+    width: 75%;
   }
 
   .chat-sender div:nth-of-type(1) {
@@ -360,6 +362,8 @@
   .chat-receiver {
     clear: both;
     /* font-size: 80%; */
+    float: right;
+    width: 75%;
   }
 
   .chat-receiver div:nth-of-type(1) {

BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_ai.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_arch.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_att.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_au.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_avi.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_cad.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_cdr.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_eps.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_excel.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_exe.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_flash.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_gif.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_html.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_img.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_iso.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_jpeg.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_link.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_mp3.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_mp4.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_pdf.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_png.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_ppt.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_psd.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_rar.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_rm.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_tiff.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_tmp.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_txt.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_unkown.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_word.png


BIN
o2web/source/x_component_IMV2/$Main/file_icons/icon_file_zip.png


+ 84 - 2
o2web/source/x_component_IMV2/Main.js

@@ -435,6 +435,12 @@ MWF.xApplication.IMV2.Main = new Class({
 			new Element("img", { "src": "../x_component_IMV2/$Main/default/icons/location.png", "width": 24, "height": 24 }).inject(mapBox);
 			var url = this._getBaiduMapUrl(msgBody.latitude, msgBody.longitude, msgBody.address, msgBody.addressDetail);
 			new Element("a", { "href": url, "target": "_blank", "text": msgBody.address }).inject(mapBox);
+		} else if (msgBody.type == "file") { //文件
+			var mapBox = new Element("span").inject(lastNode);
+			var fileIcon = this._getFileIcon(msgBody.fileExtension);
+			new Element("img", { "src": "../x_component_IMV2/$Main/file_icons/"+fileIcon, "width": 48, "height": 48 }).inject(mapBox);
+			var downloadUrl = this._getFileDownloadUrl(msgBody.fileId);
+			new Element("a", { "href": downloadUrl, "target": "_blank", "text": msgBody.fileName }).inject(mapBox);
 		} else {//text
 			new Element("span", { "text": msgBody.body }).inject(lastNode);
 		}
@@ -489,6 +495,12 @@ MWF.xApplication.IMV2.Main = new Class({
 			new Element("img", { "src": "../x_component_IMV2/$Main/default/icons/location.png", "width": 24, "height": 24 }).inject(mapBox);
 			var url = this._getBaiduMapUrl(msgBody.latitude, msgBody.longitude, msgBody.address, msgBody.addressDetail);
 			new Element("a", { "href": url, "target": "_blank", "text": msgBody.address }).inject(mapBox);
+		} else if (msgBody.type == "file") { //文件
+			var mapBox = new Element("span").inject(lastNode);
+			var fileIcon = this._getFileIcon(msgBody.fileExtension);
+			new Element("img", { "src": "../x_component_IMV2/$Main/file_icons/"+fileIcon, "width": 48, "height": 48 }).inject(mapBox);
+			var downloadUrl = this._getFileDownloadUrl(msgBody.fileId);
+			new Element("a", { "href": downloadUrl, "target": "_blank", "text": msgBody.fileName }).inject(mapBox);
 		} else {//text
 			new Element("span", { "text": msgBody.body }).inject(lastNode);
 		}
@@ -501,7 +513,7 @@ MWF.xApplication.IMV2.Main = new Class({
 	//图片 根据大小 url
 	_getFileUrlWithWH: function (id, width, height) {
 		var action = MWF.Actions.get("x_message_assemble_communicate").action;
-		var url = action.address + action.actions.imgFileDownloadWithWH.uri;
+		var url = action.getAddress() + action.actions.imgFileDownloadWithWH.uri;
 		url = url.replace("{id}", encodeURIComponent(id));
 		url = url.replace("{width}", encodeURIComponent(width));
 		url = url.replace("{height}", encodeURIComponent(height));
@@ -510,7 +522,7 @@ MWF.xApplication.IMV2.Main = new Class({
 	//file 下载的url
 	_getFileDownloadUrl: function (id) {
 		var action = MWF.Actions.get("x_message_assemble_communicate").action;
-		var url = action.address + action.actions.imgFileDownload.uri;
+		var url = action.getAddress() + action.actions.imgFileDownload.uri;
 		url = url.replace("{id}", encodeURIComponent(id));
 		return url;
 	},
@@ -525,6 +537,76 @@ MWF.xApplication.IMV2.Main = new Class({
 		var url = (id) ? orgAction.getPersonIcon(id) : "../x_component_IMV2/$Main/default/icons/group.png";
 		return url + "?" + (new Date().getTime());
 	},
+	// 文件类型icon图
+	_getFileIcon: function (ext) {
+		if (ext) {
+			if (ext === "jpg" || ext === "jpeg") {
+				return "icon_file_jpeg.png";
+			} else if (ext === "gif") {
+				return "icon_file_gif.png";
+			} else if (ext === "png") {
+				return "icon_file_png.png";
+			} else if (ext === "tiff") {
+				return "icon_file_tiff.png";
+			} else if (ext === "bmp" || ext === "webp") {
+				return "icon_file_img.png";
+			} else if (ext === "ogg" || ext === "mp3" || ext === "wav" || ext === "wma") {
+				return "icon_file_mp3.png";
+			} else if (ext === "mp4") {
+				return "icon_file_mp4.png";
+			} else if (ext === "avi") {
+				return "icon_file_avi.png";
+			} else if (ext === "mov" || ext === "rm" || ext === "mkv") {
+				return "icon_file_rm.png";
+			} else if (ext === "doc" || ext === "docx") {
+				return "icon_file_word.png";
+			} else if (ext === "xls" || ext === "xlsx") {
+				return "icon_file_excel.png";
+			} else if (ext === "ppt" || ext === "pptx") {
+				return "icon_file_ppt.png";
+			} else if (ext === "html") {
+				return "icon_file_html.png";
+			} else if (ext === "pdf") {
+				return "icon_file_pdf.png";
+			} else if (ext === "txt" || ext === "json") {
+				return "icon_file_txt.png";
+			} else if (ext === "zip") {
+				return "icon_file_zip.png";
+			} else if (ext === "rar") {
+				return "icon_file_rar.png";
+			} else if (ext === "7z") {
+				return "icon_file_arch.png";
+			} else if (ext === "ai") {
+				return "icon_file_ai.png";
+			} else if (ext === "att") {
+				return "icon_file_att.png";
+			} else if (ext === "au") {
+				return "icon_file_au.png";
+			} else if (ext === "cad") {
+				return "icon_file_cad.png";
+			} else if (ext === "cdr") {
+				return "icon_file_cdr.png";
+			} else if (ext === "eps") {
+				return "icon_file_eps.png";
+			} else if (ext === "exe") {
+				return "icon_file_exe.png";
+			} else if (ext === "iso") {
+				return "icon_file_iso.png";
+			} else if (ext === "link") {
+				return "icon_file_link.png";
+			} else if (ext === "swf") {
+				return "icon_file_flash.png";
+			} else if (ext === "psd") {
+				return "icon_file_psd.png";
+			} else if (ext === "tmp") {
+				return "icon_file_tmp.png";
+			}else {
+				return "icon_file_unkown.png";
+			}
+		}else {
+			return "icon_file_unkown.png";
+		}
+	},
 	//输出特殊的时间格式
 	_friendlyTime: function (date) {
 		var day = date.getDate();