Main.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. MWF.xApplication.IMV2.options.multitask = true;
  2. MWF.xApplication.IMV2.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "IMV2",
  8. "mvcStyle": "style.css",
  9. "icon": "icon.png",
  10. "width": "1200",
  11. "height": "700",
  12. "isResize": true,
  13. "isMax": true,
  14. "title": MWF.xApplication.IMV2.LP.title
  15. },
  16. onQueryLoad: function () {
  17. this.lp = MWF.xApplication.IMV2.LP;
  18. this.conversationList = [];
  19. },
  20. loadApplication: function (callback) {
  21. var url = this.path + this.options.style + "/im.html";
  22. this.content.loadHtml(url, { "bind": { "lp": this.lp, "data": {} }, "module": this }, function () {
  23. //获取会话列表
  24. o2.Actions.load("x_message_assemble_communicate").ImAction.myConversationList(function (json) {
  25. if (json.data && json.data instanceof Array) {
  26. this.conversationList = json.data;
  27. this.loadConversationList(json.data);
  28. }
  29. }.bind(this));
  30. }.bind(this));
  31. },
  32. //加载会话列表
  33. loadConversationList: function (list) {
  34. for (var i = 0; i < list.length; i++) {
  35. var chat = list[i];
  36. var url = this.path + this.options.style + "/conversationItem.html";
  37. var avatarDefault = this._getIcon();
  38. var data = {
  39. "id": chat.id,
  40. "avatarUrl": avatarDefault,
  41. "title": chat.title,
  42. "time": "",
  43. "lastMessage": ""
  44. };
  45. var distinguishedName = layout.session.user.distinguishedName;
  46. if (chat.type && chat.type === "single") {
  47. var chatPerson = "";
  48. if (chat.personList && chat.personList instanceof Array) {
  49. for (var i = 0; i < chat.personList.length; i++) {
  50. var person = chat.personList[i];
  51. if (person !== distinguishedName) {
  52. chatPerson = person;
  53. }
  54. }
  55. }
  56. data.avatarUrl = this._getIcon(chatPerson);
  57. var name = chatPerson;
  58. if (chatPerson.indexOf("@") != -1) {
  59. name = name.substring(0, chatPerson.indexOf("@"));
  60. }
  61. data.title = name;
  62. }
  63. if (chat.lastMessage) {
  64. //todo 其它消息类型
  65. var mBody = JSON.parse(chat.lastMessage.body);
  66. data.lastMessage = mBody.body;
  67. if (chat.lastMessage.createTime) {
  68. var time = this._friendlyTime(o2.common.toDate(chat.lastMessage.createTime));
  69. data.time = time;
  70. }
  71. }
  72. this.chatItemListNode.loadHtml(url, { "bind": data, "module": this }, function (html) {
  73. //bind event
  74. console.log(html);
  75. }.bind(this));
  76. }
  77. console.log("结束");
  78. },
  79. //点击
  80. tapConv: function (e) {
  81. console.log("clickConversationvvvvvv");
  82. console.log(e);
  83. var url = this.path + this.options.style + "/chat.html";
  84. this.chatNode.loadHtml(url, { "bind": {}, "module": this }, function () {
  85. }.bind(this));
  86. },
  87. _getIcon: function (id) {
  88. var orgAction = MWF.Actions.get("x_organization_assemble_control")
  89. var url = (id) ? orgAction.getPersonIcon(id) : "/x_component_IMV2/$Main/default/icons/group.png";
  90. return url + "?" + (new Date().getTime());
  91. },
  92. //输出特殊的时间格式
  93. _friendlyTime: function (date) {
  94. var day = date.getDate();
  95. var monthIndex = date.getMonth();
  96. var year = date.getFullYear();
  97. var time = date.getTime();
  98. var today = new Date();
  99. var todayDay = today.getDate();
  100. var todayMonthIndex = today.getMonth();
  101. var todayYear = today.getFullYear();
  102. var todayTime = today.getTime();
  103. var retTime = "";
  104. //同一天
  105. if (day === todayDay && monthIndex === todayMonthIndex && year === todayYear) {
  106. var hour = 0;
  107. if (todayTime > time) {
  108. hour = parseInt((todayTime - time) / 3600000);
  109. if (hour == 0) {
  110. retTime = Math.max(parseInt((todayTime - time) / 60000), 1) + "分钟前"
  111. } else {
  112. retTime = hour + "小时前"
  113. }
  114. }
  115. return retTime;
  116. }
  117. var dates = parseInt(time / 86400000);
  118. var todaydates = parseInt(todayTime / 86400000);
  119. if (todaydates > dates) {
  120. var days = (todaydates - dates);
  121. if (days == 1) {
  122. retTime = "昨天";
  123. } else if (days == 2) {
  124. retTime = "前天 ";
  125. } else if (days > 2 && days < 31) {
  126. retTime = days + "天前";
  127. } else if (days >= 31 && days <= 2 * 31) {
  128. retTime = "一个月前";
  129. } else if (days > 2 * 31 && days <= 3 * 31) {
  130. retTime = "2个月前";
  131. } else if (days > 3 * 31 && days <= 4 * 31) {
  132. retTime = "3个月前";
  133. } else {
  134. retTime = this._formatDate(date);
  135. }
  136. }
  137. return retTime;
  138. },
  139. //yyyy-MM-dd
  140. _formatDate: function (date) {
  141. var month = date.getMonth() + 1;
  142. var day = date.getDate();
  143. month = (month.toString().length == 1) ? ("0" + month) : month;
  144. day = (day.toString().length == 1) ? ("0" + day) : day;
  145. return date.getFullYear() + '-' + month + '-' + day;
  146. }
  147. });