Main.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227
  1. MWF.require("MWF.widget.UUID", null, false);
  2. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. MWF.xApplication.IMV2 = MWF.xApplication.IMV2 || {};
  5. MWF.xApplication.IMV2.options.multitask = false; //多窗口
  6. MWF.xApplication.IMV2.Main = new Class({
  7. Extends: MWF.xApplication.Common.Main,
  8. Implements: [Options, Events],
  9. options: {
  10. "style": "default",
  11. "name": "IMV2",
  12. "mvcStyle": "style.css",
  13. "icon": "icon.png",
  14. "width": "1024",
  15. "height": "768",
  16. "isResize": true,
  17. "isMax": true,
  18. "title": MWF.xApplication.IMV2.LP.title,
  19. "conversationId": "", // 传入的当前会话id
  20. "mode": "default" // 展现模式:default onlyChat 。 onlyChat的模式需要传入conversationId 会打开这个会话的聊天窗口并隐藏左边的会话列表
  21. },
  22. onQueryLoad: function () {
  23. this.lp = MWF.xApplication.IMV2.LP;
  24. this.app = this;
  25. this.conversationNodeItemList = [];
  26. this.messageList = [];
  27. this.emojiList = [];
  28. //添加87个表情
  29. for (var i = 1; i < 88; i++) {
  30. var emoji = {
  31. "key": i > 9 ? "[" + i + "]" : "[0" + i + "]",
  32. "path": i > 9 ? "/x_component_IMV2/$Main/emotions/im_emotion_" + i + ".png" : "/x_component_IMV2/$Main/emotions/im_emotion_0" + i + ".png",
  33. };
  34. this.emojiList.push(emoji);
  35. }
  36. if (!this.status) {
  37. this.conversationId = this.options.conversationId || "";
  38. this.mode = this.options.mode || "default";
  39. } else {
  40. this.conversationId = this.status.conversationId || "";
  41. this.mode = this.status.mode || "default";
  42. }
  43. },
  44. // 刷新的时候缓存数据
  45. recordStatus: function(){
  46. return {"conversationId": this.conversationId, "mode": this.mode};
  47. },
  48. onQueryClose: function () {
  49. // this.closeListening();
  50. },
  51. // 获取组件名称
  52. loadComponentName: function () {
  53. o2.Actions.load("x_component_assemble_control").ComponentAction.get("IMV2", function (json) {
  54. var imComponent = json.data;
  55. if (imComponent && imComponent.title) {
  56. this.setTitle(imComponent.title);
  57. }
  58. }.bind(this), function (err) {
  59. console.log(err);
  60. })
  61. },
  62. // 加载应用
  63. loadApplication: function (callback) {
  64. // 判断xadmin 打开聊天功能
  65. if (layout.session.user && layout.session.user.name == "xadmin") {
  66. console.log("xadmin can not open IMV2");
  67. this.app.notice(this.lp.messageXadminNotSupport, "error");
  68. return;
  69. }
  70. // 先加载配置文件 放入imConfig对象
  71. MWF.xDesktop.loadConfig(function () {
  72. this.imConfig = layout.config.imConfig || {}
  73. var url = this.path + this.options.style + "/im.html";
  74. this.content.loadHtml(url, { "bind": { "lp": this.lp, "data": {} }, "module": this }, function () {
  75. //设置content
  76. this.app.content = this.o2ImMainNode;
  77. // 给websocket 添加撤回消息回调函数
  78. if (layout.desktop && layout.desktop.socket && layout.desktop.socket.addImListener) {
  79. layout.desktop.socket.addImListener("im_revoke", this.revokeMsgCallback.bind(this));
  80. layout.desktop.socket.addImListener("im_create", this.createNewMsgCallback.bind(this));
  81. layout.desktop.socket.addImListener("im_conversation", this.conversationMsgCallback.bind(this));
  82. }
  83. //启动监听
  84. // this.startListening();
  85. // 处理窗口模式
  86. if (this.mode === "onlyChat" && this.conversationId != "") {
  87. this.o2ConversationListNode.setStyle("display", "none");
  88. this.chatNode.setStyle("margin-left", "2px");
  89. } else {
  90. this.o2ConversationListNode.setStyle("display", "flex");
  91. this.chatNode.setStyle("margin-left", "259px");
  92. }
  93. //获取会话列表
  94. this.conversationNodeItemList = [];
  95. o2.Actions.load("x_message_assemble_communicate").ImAction.myConversationList(function (json) {
  96. if (json.data && json.data instanceof Array) {
  97. this.loadConversationList(json.data);
  98. }
  99. }.bind(this));
  100. // 管理员可见设置按钮
  101. if (MWF.AC.isAdministrator()) {
  102. this.o2ImAdminSettingNode.setStyle("display", "block");
  103. } else {
  104. this.o2ImAdminSettingNode.setStyle("display", "none");
  105. }
  106. }.bind(this));
  107. }.bind(this));
  108. this.loadComponentName();
  109. },
  110. // 撤回消息回调
  111. revokeMsgCallback: function(msg) {
  112. if (this.chatNodeBox) {
  113. this.chatNodeBox._checkRevokeMsg(msg);
  114. }
  115. },
  116. // websocket过来的新消息回调
  117. createNewMsgCallback: function(msg) {
  118. this.reciveNewMessage();
  119. },
  120. // 接收新的消息 会话列表更新 或者 聊天窗口更新
  121. reciveNewMessage: function () {
  122. //查询会话数据
  123. this._checkConversationMessage();
  124. //查询聊天数据
  125. if (this.chatNodeBox) {
  126. this.chatNodeBox._checkNewMessage();
  127. }
  128. },
  129. // 收到会话变更或删除消息
  130. conversationMsgCallback: function(conv) {
  131. console.log("会话消息处理", conv);
  132. if (conv && conv.id) {
  133. // 查询会话
  134. o2.Actions.load("x_message_assemble_communicate").ImAction.conversation(conv.id, function (json) {
  135. if (json && json.data) {
  136. var newConv = json.data;
  137. var personList = newConv.personList || [];
  138. var distinguishedName = layout.session.user.distinguishedName;
  139. if (personList.indexOf(distinguishedName) > -1) { // 成员存在 更新会话
  140. for (var i = 0; i < this.conversationNodeItemList.length; i++) {
  141. var cv = this.conversationNodeItemList[i];
  142. if (cv.data.id == conv.id) {
  143. cv.refreshData(conv);
  144. }
  145. }
  146. } else { // 被踢出了 删除会话
  147. this._deleteConversation(conv)
  148. }
  149. }
  150. }.bind(this), function(err){
  151. console.error(err);
  152. // 出错 可能是会话删除了
  153. this._deleteConversation(conv);
  154. return true;
  155. }.bind(this));
  156. }
  157. },
  158. // 删除会话
  159. _deleteConversation(conv) {
  160. for (var i = 0; i < this.conversationNodeItemList.length; i++) {
  161. var item = this.conversationNodeItemList[i];
  162. if (item.data.id === conv.id) {
  163. item.node.destroy();
  164. this.conversationNodeItemList.splice(i, 1);
  165. break;
  166. }
  167. }
  168. // 当前聊天窗口 关闭
  169. if (this.conversationId && this.conversationId === conv.id) {
  170. this.chatNode.empty();
  171. this.conversationId = null;
  172. }
  173. },
  174. //加载会话列表
  175. loadConversationList: function (list) {
  176. for (var i = 0; i < list.length; i++) {
  177. var chat = list[i];
  178. var itemNode = this._createConvItemNode(chat);
  179. this.conversationNodeItemList.push(itemNode);
  180. if (this.conversationId && this.conversationId == chat.id) {
  181. this.tapConv(chat);
  182. }
  183. }
  184. },
  185. // 点击设置按钮
  186. tapOpenSettings: function() {
  187. this.openSettingsDialog();
  188. },
  189. // 打开IM配置文件
  190. openSettingsDialog: function () {
  191. var settingNode = new Element("div", {"style":"padding:10px;background-color:#fff;"});
  192. var lineNode = new Element("div", {"style":"height:24px;line-height: 24px;"}).inject(settingNode);
  193. var isClearEnableNode = new Element("input", {"type":"checkbox", "checked": this.imConfig.enableClearMsg || false, "name": "clearEnable"}).inject(lineNode);
  194. new Element("span", { "text": this.lp.settingsClearMsg}).inject(lineNode);
  195. var line2Node = new Element("div", {"style":"height:24px;line-height: 24px;"}).inject(settingNode);
  196. var isRevokeEnableNode = new Element("input", {"type":"checkbox", "checked": this.imConfig.enableRevokeMsg || false, "name": "revokeEnable"}).inject(line2Node);
  197. new Element("span", { "text": this.lp.settingsRevokeMsg}).inject(line2Node);
  198. var dlg = o2.DL.open({
  199. "title": this.lp.setting,
  200. "mask": true,
  201. "width": '500',
  202. "height": "210",
  203. "content": settingNode,
  204. "onQueryClose": function () {
  205. settingNode.destroy();
  206. }.bind(this),
  207. "buttonList": [
  208. {
  209. "type": "ok",
  210. "text": this.lp.ok,
  211. "action": function () {
  212. this.imConfig.enableClearMsg = isClearEnableNode.get("checked");
  213. this.imConfig.enableRevokeMsg = isRevokeEnableNode.get("checked");
  214. this.postIMConfig(this.imConfig);
  215. // 保存配置文件
  216. dlg.close();
  217. }.bind(this)
  218. },
  219. {
  220. "type": "cancel",
  221. "text": this.lp.close,
  222. "action": function () { dlg.close(); }
  223. }
  224. ],
  225. "onPostShow": function () {
  226. dlg.reCenter();
  227. }.bind(this),
  228. "onPostClose": function(){
  229. dlg = null;
  230. }.bind(this)
  231. });
  232. },
  233. // 保存IM配置文件
  234. postIMConfig: function (imConfig) {
  235. o2.Actions.load("x_message_assemble_communicate").ImAction.config(imConfig, function (json) {
  236. this.refresh();//重新加载整个IM应用
  237. }.bind(this), function (error) {
  238. console.log(error);
  239. this.app.notice(error, "error", this.app.content);
  240. }.bind(this));
  241. },
  242. //点击会话
  243. tapConv: function (conv) {
  244. this._setCheckNode(conv);
  245. this.conversationId = conv.id;
  246. // new ChatNodeBox
  247. this.chatNodeBox = new MWF.xApplication.IMV2.ChatNodeBox(conv, this);
  248. },
  249. //点击创建单聊按钮
  250. tapCreateSingleConv: function () {
  251. // var form = new MWF.xApplication.IMV2.SingleForm(this, {}, {}, { app: this.app });
  252. // form.create()
  253. var form = new MWF.xApplication.IMV2.CreateConversationForm(this, {}, { "title": this.lp.createSingle, "personCount": 1 }, { app: this.app });
  254. form.create()
  255. },
  256. //点击创建群聊按钮
  257. tapCreateGroupConv: function () {
  258. var form = new MWF.xApplication.IMV2.CreateConversationForm(this, {}, { "title": this.lp.createGroup, "personCount": 0, "personSelected": [] }, { app: this.app });
  259. form.create()
  260. },
  261. //更新群名
  262. updateConversationTitle: function (title, convId) {
  263. var conv = {
  264. id: convId,
  265. title: title,
  266. };
  267. var _self = this;
  268. o2.Actions.load("x_message_assemble_communicate").ImAction.update(conv, function (json) {
  269. var newConv = json.data;
  270. //点击会话 刷新聊天界面
  271. // _self.tapConv(newConv);
  272. // //刷新会话列表的title
  273. // for (var i = 0; i < this.conversationNodeItemList.length; i++) {
  274. // var cv = this.conversationNodeItemList[i];
  275. // if (cv.data.id == convId) {
  276. // //刷新
  277. // cv.refreshConvTitle(title);
  278. // }
  279. // }
  280. // 列表上的数据也要刷新
  281. _self.reciveNewMessage();
  282. }.bind(this), function (error) {
  283. console.log(error);
  284. }.bind(this))
  285. },
  286. //更新群成员
  287. updateConversationMembers: function (members, convId) {
  288. var conv = {
  289. id: convId,
  290. personList: members,
  291. };
  292. var _self = this;
  293. o2.Actions.load("x_message_assemble_communicate").ImAction.update(conv, function (json) {
  294. var newConv = json.data;
  295. //_self.tapConv(newConv);
  296. // 列表上的数据也要刷新
  297. _self.reciveNewMessage();
  298. }.bind(this), function (error) {
  299. console.log(error);
  300. }.bind(this))
  301. },
  302. /**
  303. * 创建会话
  304. * @param {*} persons 人员列表
  305. * @param {*} cType 会话类型 "single" "group"
  306. */
  307. newConversation: function (persons, cType) {
  308. var conv = {
  309. type: cType,
  310. personList: persons,
  311. };
  312. var _self = this;
  313. o2.Actions.load("x_message_assemble_communicate").ImAction.create(conv, function (json) {
  314. var newConv = json.data;
  315. var isOld = false;
  316. for (var i = 0; i < _self.conversationNodeItemList.length; i++) {
  317. var c = _self.conversationNodeItemList[i];
  318. if (newConv.id == c.data.id) {
  319. isOld = true;
  320. _self.tapConv(c.data);
  321. break;
  322. }
  323. }
  324. if (!isOld) {
  325. newConv.isNew = true; // 新建的 放在列表的前面
  326. var itemNode = _self._createConvItemNode(newConv);
  327. _self.conversationNodeItemList.unshift(itemNode);
  328. _self.tapConv(newConv);
  329. }
  330. }.bind(this), function (error) {
  331. console.log(error);
  332. }.bind(this))
  333. },
  334. //创建会话ItemNode
  335. _createConvItemNode: function (conv) {
  336. return new MWF.xApplication.IMV2.ConversationItem(conv, this);
  337. },
  338. //会话ItemNode 点击背景色
  339. _setCheckNode: function (conv) {
  340. for (var i = 0; i < this.conversationNodeItemList.length; i++) {
  341. var item = this.conversationNodeItemList[i];
  342. if (item.data.id == conv.id) {
  343. item.addCheckClass();
  344. } else {
  345. item.removeCheckClass();
  346. }
  347. }
  348. },
  349. //刷新会话Item里面的最后消息内容
  350. _refreshConvMessage: function (msg) {
  351. for (var i = 0; i < this.conversationNodeItemList.length; i++) {
  352. var node = this.conversationNodeItemList[i];
  353. if (node.data.id == this.conversationId) {
  354. node.refreshLastMsg(msg);
  355. }
  356. }
  357. },
  358. //检查会话列表是否有更新
  359. _checkConversationMessage: function () {
  360. o2.Actions.load("x_message_assemble_communicate").ImAction.myConversationList(function (json) {
  361. if (json.data && json.data instanceof Array) {
  362. var newConList = json.data;
  363. for (var j = 0; j < newConList.length; j++) {
  364. var nCv = newConList[j];
  365. var isNew = true;
  366. for (var i = 0; i < this.conversationNodeItemList.length; i++) {
  367. var cv = this.conversationNodeItemList[i];
  368. if (cv.data.id == nCv.id) {
  369. isNew = false;
  370. //刷新
  371. cv.refreshLastMsg(nCv.lastMessage);
  372. cv.refreshData(nCv);
  373. // if (this.conversationId === nCv.id) {
  374. // this.tapConv(nCv);
  375. // }
  376. }
  377. }
  378. //新会话 创建
  379. if (isNew) {
  380. nCv.isNew = true; // 新建的 放在列表的前面
  381. var itemNode = this._createConvItemNode(nCv);
  382. this.conversationNodeItemList.unshift(itemNode);
  383. }
  384. }
  385. //this.loadConversationList(json.data);
  386. }
  387. }.bind(this));
  388. },
  389. //用户头像
  390. _getIcon: function (id) {
  391. var orgAction = MWF.Actions.get("x_organization_assemble_control")
  392. var url = (id) ? orgAction.getPersonIcon(id) : "../x_component_IMV2/$Main/default/icons/group.png";
  393. return url + "?" + (new Date().getTime());
  394. },
  395. //输出特殊的时间格式
  396. _friendlyTime: function (date) {
  397. var day = date.getDate();
  398. var monthIndex = date.getMonth();
  399. var year = date.getFullYear();
  400. var time = date.getTime();
  401. var today = new Date();
  402. var todayDay = today.getDate();
  403. var todayMonthIndex = today.getMonth();
  404. var todayYear = today.getFullYear();
  405. var todayTime = today.getTime();
  406. var retTime = "";
  407. //同一天
  408. if (day === todayDay && monthIndex === todayMonthIndex && year === todayYear) {
  409. var hour = 0;
  410. if (todayTime > time) {
  411. hour = parseInt((todayTime - time) / 3600000);
  412. if (hour == 0) {
  413. retTime = Math.max(parseInt((todayTime - time) / 60000), 1) + this.lp.minutesBefore
  414. } else {
  415. retTime = hour + this.lp.hoursBefore
  416. }
  417. }
  418. return retTime;
  419. }
  420. var dates = parseInt(time / 86400000);
  421. var todaydates = parseInt(todayTime / 86400000);
  422. if (todaydates > dates) {
  423. var days = (todaydates - dates);
  424. if (days == 1) {
  425. retTime = this.lp.yesterday;
  426. } else if (days == 2) {
  427. retTime = this.lp.beforeYesterday;
  428. } else if (days > 2 && days < 31) {
  429. retTime = days + this.lp.daysBefore;
  430. } else if (days >= 31 && days <= 2 * 31) {
  431. retTime = this.lp.monthAgo;
  432. } else if (days > 2 * 31 && days <= 3 * 31) {
  433. retTime = this.lp.towMonthAgo;
  434. } else if (days > 3 * 31 && days <= 4 * 31) {
  435. retTime = this.lp.threeMonthAgo;
  436. } else {
  437. retTime = this._formatDate(date);
  438. }
  439. }
  440. return retTime;
  441. },
  442. //yyyy-MM-dd
  443. _formatDate: function (date) {
  444. var month = date.getMonth() + 1;
  445. var day = date.getDate();
  446. month = (month.toString().length == 1) ? ("0" + month) : month;
  447. day = (day.toString().length == 1) ? ("0" + day) : day;
  448. return date.getFullYear() + '-' + month + '-' + day;
  449. }
  450. });
  451. // 聊天窗口
  452. MWF.xApplication.IMV2.ChatNodeBox = new Class({
  453. initialize: function (data, main) {
  454. this.data = data;
  455. this.main = main;
  456. this.container = this.main.chatNode;
  457. this.lp = this.main.lp;
  458. this.path = this.main.path;
  459. this.options = this.main.options;
  460. this.pageSize = 20;
  461. this.page = 1;
  462. this.isLoading = false; // 正在加载
  463. this.hasMoreMsgData = false; // 是否还有更多的消息 翻页
  464. this.load();
  465. },
  466. htmlSymbols: function() {
  467. return {
  468. '"': '&quot;',
  469. '\'': '&#039;',
  470. '>': '&gt;',
  471. '¡': '&iexcl;',
  472. '£': '&pound;',
  473. '¥': '&yen;',
  474. '§': '&sect;',
  475. '©': '&copy;',
  476. '«': '&laquo;',
  477. '®': '&reg;',
  478. '¯': '&macr;',
  479. '±': '&plusmn;',
  480. '³': '&sup3;',
  481. 'µ': '&micro;',
  482. '·': '&middot;',
  483. '¹': '&sup1;',
  484. '»': '&raquo;',
  485. '½': '&frac12;',
  486. '¿': '&iquest;',
  487. 'Á': '&Aacute;',
  488. 'Ã': '&Atilde;',
  489. 'Å': '&Aring;',
  490. 'Ç': '&Ccedil;',
  491. 'É': '&Eacute;',
  492. 'Ë': '&Euml;',
  493. 'Í': '&Iacute;',
  494. 'Ï': '&Iuml;',
  495. 'Ñ': '&Ntilde;',
  496. 'Ó': '&Oacute;',
  497. 'Õ': '&Otilde;',
  498. '×': '&times;',
  499. 'Ù': '&Ugrave;',
  500. 'Û': '&Ucirc;',
  501. 'Ý': '&Yacute;',
  502. 'ß': '&szlig;',
  503. 'á': '&aacute;',
  504. 'ã': '&atilde;',
  505. 'å': '&aring;',
  506. 'ç': '&ccedil;',
  507. 'é': '&eacute;',
  508. 'ë': '&euml;',
  509. 'í': '&iacute;',
  510. 'ï': '&iuml;',
  511. 'ñ': '&ntilde;',
  512. 'ó': '&oacute;',
  513. 'õ': '&otilde;',
  514. '÷': '&divide;',
  515. 'ù': '&ugrave;',
  516. 'û': '&ucirc;',
  517. 'ý': '&yacute;',
  518. 'ÿ': '&yuml;',
  519. 'œ': '&oelig;',
  520. 'š': '&scaron;',
  521. 'ƒ': '&fnof;',
  522. '˜': '&tilde;',
  523. 'Β': '&Beta;',
  524. 'Δ': '&Delta;',
  525. 'Ζ': '&Zeta;',
  526. 'Θ': '&Theta;',
  527. 'Κ': '&Kappa;',
  528. 'Μ': '&Mu;',
  529. 'Ξ': '&Xi;',
  530. 'Π': '&Pi;',
  531. 'Σ': '&Sigma;',
  532. 'Υ': '&Upsilon;',
  533. 'Χ': '&Chi;',
  534. 'Ω': '&Omega;',
  535. 'β': '&beta;',
  536. 'δ': '&delta;',
  537. 'ζ': '&zeta;',
  538. 'θ': '&theta;',
  539. 'κ': '&kappa;',
  540. 'μ': '&mu;',
  541. 'ξ': '&xi;',
  542. 'π': '&pi;',
  543. 'ς': '&sigmaf;',
  544. 'τ': '&tau;',
  545. 'φ': '&phi;',
  546. 'ψ': '&psi;',
  547. 'ϑ': '&thetasym;',
  548. 'ϖ': '&piv;',
  549. '–': '&ndash;',
  550. '‘': '&lsquo;',
  551. '‚': '&sbquo;',
  552. '”': '&rdquo;',
  553. '†': '&dagger;',
  554. '•': '&bull;',
  555. '‰': '&permil;',
  556. '″': '&Prime;',
  557. '›': '&rsaquo;',
  558. '⁄': '&frasl;',
  559. 'ℑ': '&image;',
  560. 'ℜ': '&real;',
  561. 'ℵ': '&alefsym;',
  562. '↑': '&uarr;',
  563. '↓': '&darr;',
  564. '↵': '&crarr;',
  565. '⇑': '&uArr;',
  566. '⇓': '&dArr;',
  567. '∀': '&forall;',
  568. '∃': '&exist;',
  569. '∇': '&nabla;',
  570. '∉': '&notin;',
  571. '∏': '&prod;',
  572. '−': '&minus;',
  573. '√': '&radic;',
  574. '∞': '&infin;',
  575. '∧': '&and;',
  576. '∩': '&cap;',
  577. '∫': '&int;',
  578. '∼': '&sim;',
  579. '≈': '&asymp;',
  580. '≡': '&equiv;',
  581. '≥': '&ge;',
  582. '⊃': '&sup;',
  583. '⊆': '&sube;',
  584. '⊕': '&oplus;',
  585. '⊥': '&perp;',
  586. '⌈': '&lceil;',
  587. '⌊': '&lfloor;',
  588. '⟨': '&lang;',
  589. '◊': '&loz;',
  590. '♣': '&clubs;',
  591. '♦': '&diams;',
  592. '&': '&amp;',
  593. '<': '&lt;',
  594. ' ': '&nbsp;',
  595. '¢': '&cent;',
  596. '¤': '&curren;',
  597. '¦': '&brvbar;',
  598. '¨': '&uml;',
  599. 'ª': '&ordf;',
  600. '¬': '&not;',
  601. '°': '&deg;',
  602. '²': '&sup2;',
  603. '´': '&acute;',
  604. '¶': '&para;',
  605. '¸': '&cedil;',
  606. 'º': '&ordm;',
  607. '¼': '&frac14;',
  608. '¾': '&frac34;',
  609. 'À': '&Agrave;',
  610. 'Â': '&Acirc;',
  611. 'Ä': '&Auml;',
  612. 'Æ': '&AElig;',
  613. 'È': '&Egrave;',
  614. 'Ê': '&Ecirc;',
  615. 'Ì': '&Igrave;',
  616. 'Î': '&Icirc;',
  617. 'Ð': '&ETH;',
  618. 'Ò': '&Ograve;',
  619. 'Ô': '&Ocirc;',
  620. 'Ö': '&Ouml;',
  621. 'Ø': '&Oslash;',
  622. 'Ú': '&Uacute;',
  623. 'Ü': '&Uuml;',
  624. 'Þ': '&THORN;',
  625. 'à': '&agrave;',
  626. 'â': '&acirc;',
  627. 'ä': '&auml;',
  628. 'æ': '&aelig;',
  629. 'è': '&egrave;',
  630. 'ê': '&ecirc;',
  631. 'ì': '&igrave;',
  632. 'î': '&icirc;',
  633. 'ð': '&eth;',
  634. 'ò': '&ograve;',
  635. 'ô': '&ocirc;',
  636. 'ö': '&ouml;',
  637. 'ø': '&oslash;',
  638. 'ú': '&uacute;',
  639. 'ü': '&uuml;',
  640. 'þ': '&thorn;',
  641. 'Œ': '&OElig;',
  642. 'Š': '&Scaron;',
  643. 'Ÿ': '&Yuml;',
  644. 'ˆ': '&circ;',
  645. 'Α': '&Alpha;',
  646. 'Γ': '&Gamma;',
  647. 'Ε': '&Epsilon;',
  648. 'Η': '&Eta;',
  649. 'Ι': '&Iota;',
  650. 'Λ': '&Lambda;',
  651. 'Ν': '&Nu;',
  652. 'Ο': '&Omicron;',
  653. 'Ρ': '&Rho;',
  654. 'Τ': '&Tau;',
  655. 'Φ': '&Phi;',
  656. 'Ψ': '&Psi;',
  657. 'α': '&alpha;',
  658. 'γ': '&gamma;',
  659. 'ε': '&epsilon;',
  660. 'η': '&eta;',
  661. 'ι': '&iota;',
  662. 'λ': '&lambda;',
  663. 'ν': '&nu;',
  664. 'ο': '&omicron;',
  665. 'ρ': '&rho;',
  666. 'σ': '&sigma;',
  667. 'υ': '&upsilon;',
  668. 'χ': '&chi;',
  669. 'ω': '&omega;',
  670. 'ϒ': '&upsih;',
  671. '—': '&mdash;',
  672. '’': '&rsquo;',
  673. '“': '&ldquo;',
  674. '„': '&bdquo;',
  675. '‡': '&Dagger;',
  676. '…': '&hellip;',
  677. '′': '&prime;',
  678. '‹': '&lsaquo;',
  679. '‾': '&oline;',
  680. '€': '&euro;',
  681. '℘': '&weierp;',
  682. '™': '&trade;',
  683. '←': '&larr;',
  684. '→': '&rarr;',
  685. '↔': '&harr;',
  686. '⇐': '&lArr;',
  687. '⇒': '&rArr;',
  688. '⇔': '&hArr;',
  689. '∂': '&part;',
  690. '∅': '&empty;',
  691. '∈': '&isin;',
  692. '∋': '&ni;',
  693. '∑': '&sum;',
  694. '∗': '&lowast;',
  695. '∝': '&prop;',
  696. '∠': '&ang;',
  697. '∨': '&or;',
  698. '∪': '&cup;',
  699. '∴': '&there4;',
  700. '≅': '&cong;',
  701. '≠': '&ne;',
  702. '≤': '&le;',
  703. '⊂': '&sub;',
  704. '⊄': '&nsub;',
  705. '⊇': '&supe;',
  706. '⊗': '&otimes;',
  707. '⋅': '&sdot;',
  708. '⌉': '&rceil;',
  709. '⌋': '&rfloor;',
  710. '⟩': '&rang;',
  711. '♠': '&spades;',
  712. '♥': '&hearts;'
  713. };
  714. },
  715. contentEscapeBackToSymbol: function(text) {
  716. if (!text || text === "") {
  717. return "";
  718. }
  719. var newText = text+"";
  720. for (const [key, value] of Object.entries(this.htmlSymbols())) {
  721. if (newText.includes(value)) {
  722. newText = newText.replaceAll(value, key);
  723. }
  724. }
  725. return newText;
  726. },
  727. // 创建聊天窗口
  728. load: function() {
  729. var url = this.path + this.options.style + "/chat.html";
  730. this.conversationId = this.data.id;
  731. this.container.empty();
  732. if (this.emojiBoxNode) {
  733. this.emojiBoxNode.destroy();
  734. this.emojiBoxNode = null;
  735. }
  736. this.container.loadHtml(url, { "bind": { "convName": this.data.title, "lp": this.lp }, "module": this }, function () {
  737. var me = layout.session.user.distinguishedName;
  738. if (this.data.type === "group") {
  739. this.chatTitleMoreBtnNode.setStyle("display", "block");
  740. this.chatTitleMoreBtnNode.addEvents({
  741. "click": function (e) {
  742. var display = this.chatTitleMoreMenuNode.getStyle("display");
  743. if (display === "none") {
  744. this.chatTitleMoreMenuNode.setStyle("display", "block");
  745. this.chatTitleMoreMenuItem4Node.setStyle("display", "block");
  746. if (me === this.data.adminPerson) { // 群主有操作权限
  747. this.chatTitleMoreMenuItem1Node.setStyle("display", "block");
  748. this.chatTitleMoreMenuItem2Node.setStyle("display", "block");
  749. if (this.main.imConfig.enableClearMsg) {
  750. this.chatTitleMoreMenuItem3Node.setStyle("display", "block");
  751. } else {
  752. this.chatTitleMoreMenuItem3Node.setStyle("display", "none");
  753. }
  754. } else {
  755. this.chatTitleMoreMenuItem1Node.setStyle("display", "none");
  756. this.chatTitleMoreMenuItem2Node.setStyle("display", "none");
  757. this.chatTitleMoreMenuItem3Node.setStyle("display", "none");
  758. }
  759. } else {
  760. this.chatTitleMoreMenuNode.setStyle("display", "none");
  761. }
  762. }.bind(this)
  763. });
  764. } else if (this.data.type !== "group") {
  765. if (this.main.imConfig.enableClearMsg) {
  766. this.chatTitleMoreBtnNode.setStyle("display", "block");
  767. this.chatTitleMoreBtnNode.addEvents({
  768. "click": function (e) {
  769. var display = this.chatTitleMoreMenuNode.getStyle("display");
  770. if (display === "none") {
  771. this.chatTitleMoreMenuNode.setStyle("display", "block");
  772. this.chatTitleMoreMenuItem4Node.setStyle("display", "none");
  773. this.chatTitleMoreMenuItem1Node.setStyle("display", "none");
  774. this.chatTitleMoreMenuItem2Node.setStyle("display", "none");
  775. this.chatTitleMoreMenuItem3Node.setStyle("display", "block");
  776. } else {
  777. this.chatTitleMoreMenuNode.setStyle("display", "none");
  778. }
  779. }.bind(this)
  780. });
  781. } else {
  782. this.chatTitleMoreBtnNode.setStyle("display", "none");
  783. }
  784. }
  785. //获取聊天信息
  786. this.page = 1;
  787. this.loadMsgListByPage();
  788. var scrollFx = new Fx.Scroll(this.chatContentNode);
  789. scrollFx.toBottom();
  790. // 绑定事件
  791. this.chatBottomAreaTextareaNode.addEvents({
  792. "keyup": function (e) {
  793. // debugger;
  794. if (e.code === 13) {
  795. if (e.control === true) {
  796. var text = this.chatBottomAreaTextareaNode.value;
  797. this.chatBottomAreaTextareaNode.value = text + "\n";
  798. } else {
  799. this.sendMsg();
  800. }
  801. e.stopPropagation();
  802. }
  803. }.bind(this)
  804. });
  805. // 绑定时间
  806. this.chatContentNode.addEvents({
  807. "scroll": function(e) {
  808. //滑到顶部时触发下次数据加载
  809. if (this.chatContentNode.scrollTop == 0) {
  810. if (this.hasMoreMsgData) { // 有更多数据
  811. // 间隔1秒 防止频繁
  812. setTimeout(() => {
  813. //将scrollTop置为10以便下次滑到顶部
  814. this.chatContentNode.scrollTop = 10;
  815. //加载数据
  816. this.loadMoreMsgList();
  817. }, 1000);
  818. }
  819. }
  820. }.bind(this)
  821. });
  822. // 显示业务图标
  823. this.loadBusinessIcon();
  824. }.bind(this));
  825. },
  826. // 如果有业务数据 头部展现应用图标 可以点击打开
  827. loadBusinessIcon: function() {
  828. if (this.data.businessId && this.data.businessBody) {
  829. if (this.data.businessType && this.data.businessType === "process") {
  830. var work = JSON.parse(this.data.businessBody);
  831. var applicationId = work.application;
  832. this.chatTitleBusinessBtnNode.setStyles({"background-image": "url(../x_component_process_ApplicationExplorer/$Main/default/icon/application.png)", "display":"block"});
  833. this.chatTitleBusinessBtnNode.store("work", work);
  834. this.chatTitleBusinessBtnNode.addEvents({
  835. "click": function(e) {
  836. this.loadProcessWork(e.target.retrieve("work"));
  837. e.preventDefault();
  838. }.bind(this),
  839. "mouseover": function() {
  840. if (this.businessTipsNode) {
  841. this.businessTipsNode.setStyle("display", "block");
  842. } else {
  843. this.businessTipsNode = new Element("div", {
  844. "style": "position: absolute;right: 0;top: 30px;width: 200px;border: 1px solid #dedede;border-radius: 5px;padding: 8px;background: #ffffff;color: #666;text-align: left;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;"
  845. }).inject(this.chatTitleBusinessBtnNode);
  846. var work = this.chatTitleBusinessBtnNode.retrieve("work")
  847. this.businessTipsNode.set("text", this.lp.chooseBusinessWorkTitle + "【"+work.processName+"】"+work.title);
  848. this.businessTipsNode.setStyle("display", "block");
  849. }
  850. }.bind(this),
  851. "mouseout": function() {
  852. if (this.businessTipsNode) {this.businessTipsNode.setStyle("display", "none");}
  853. }.bind(this)
  854. });
  855. o2.Actions.load("x_processplatform_assemble_surface").ApplicationAction.getIcon(applicationId, function(json) {
  856. if (json.data && json.data.icon) {
  857. this.chatTitleBusinessBtnNode.setStyles({"background-image": "url(data:image/png;base64," + json.data.icon + ")", "display":"block"});
  858. }
  859. }.bind(this));
  860. }
  861. }
  862. },
  863. // 获取工作对象
  864. loadProcessWork(work) {
  865. if (work && work.job) {
  866. o2.Actions.load("x_processplatform_assemble_surface").JobAction.findWorkWorkCompleted(work.job, function(json){
  867. if (json.data ) {
  868. var workList = [];
  869. if (json.data.workList && json.data.workList.length > 0) {
  870. workList = json.data.workList
  871. }
  872. var workCompletedList = [];
  873. if (json.data.workCompletedList && json.data.workCompletedList.length > 0) {
  874. workCompletedList = json.data.workCompletedList
  875. }
  876. this.showProcessWorkDialog(workList, workCompletedList);
  877. }
  878. }.bind(this), function(error){
  879. console.log(error);
  880. }.bind(this));
  881. }
  882. },
  883. // 打开关联工作
  884. showProcessWorkDialog: function(workList, workCompletedList) {
  885. if (workList.length > 0 || workCompletedList.length > 0) {
  886. var url = this.path + this.options.style + "/chooseBusinessWork.html";
  887. this.container.loadHtml(url, { "bind": { "lp": this.lp }, "module": this }, function(){
  888. // 工作展现
  889. if (workList.length > 0) {
  890. for (let index = 0; index < workList.length; index++) {
  891. const work = workList[index];
  892. var workItemNode = new Element("div", {"class":"business-work-item"}).inject(this.businessWorkListNode);
  893. var workProcessNameNode = new Element("div", {"style":"flex: 1;"}).inject(workItemNode);
  894. var title = work.title
  895. if (title === "") {
  896. title = this.lp.noTitle
  897. }
  898. workProcessNameNode.set("text", "【"+work.processName+"】" + title);
  899. var openBtnNode = new Element("div", {"class":"business-work-item-btn"}).inject(workItemNode);
  900. openBtnNode.store("work", work);
  901. openBtnNode.set("text", this.lp.open);
  902. openBtnNode.addEvents({
  903. "click": function(e) {
  904. var thisWork = e.target.retrieve("work");
  905. if (thisWork) {
  906. // var opotions = {
  907. // "workId": thisWork.id,
  908. // }
  909. // layout.openApplication(null, "process.Work", opotions);
  910. o2.api.form.openWork(thisWork.id, "", thisWork.title || "" );
  911. }
  912. this.closeProcessWorkDialog();
  913. e.preventDefault();
  914. }.bind(this)
  915. })
  916. }
  917. }
  918. if (workCompletedList.length > 0) {
  919. for (let index = 0; index < workCompletedList.length; index++) {
  920. const workCompleted = workCompletedList[index];
  921. var workItemNode = new Element("div", {"class":"business-work-item"}).inject(this.businessWorkListNode);
  922. var workProcessNameNode = new Element("div", {"style":"flex: 1;"}).inject(workItemNode);
  923. var title = workCompleted.title
  924. if (title === "") {
  925. title = this.lp.noTitle
  926. }
  927. workProcessNameNode.set("text", "【"+workCompleted.processName+"】" + title);
  928. var openBtnNode = new Element("div", {"class":"business-work-item-btn"}).inject(workItemNode);
  929. openBtnNode.store("work", workCompleted);
  930. openBtnNode.set("text", this.lp.open);
  931. openBtnNode.addEvents({
  932. "click": function(e) {
  933. var thisWork = e.target.retrieve("work");
  934. if (thisWork) {
  935. // var opotions = {
  936. // "workCompletedId": thisWork.id,
  937. // }
  938. // layout.openApplication(null, "process.Work", opotions);
  939. o2.api.form.openWork(thisWork.id, "", thisWork.title || "" );
  940. }
  941. this.closeProcessWorkDialog();
  942. e.preventDefault();
  943. }.bind(this)
  944. })
  945. }
  946. }
  947. // 关闭
  948. this.businessWorkChooseCloseBtnNode.addEvents({
  949. "click": function(e) {
  950. this.closeProcessWorkDialog();
  951. e.preventDefault();
  952. }.bind(this)
  953. })
  954. }.bind(this));
  955. }
  956. },
  957. //
  958. closeProcessWorkDialog: function() {
  959. if (this.businessWorkChooseDialogNode) {
  960. this.businessWorkChooseDialogNode.destroy();
  961. this.businessWorkChooseDialogNode = null;
  962. }
  963. },
  964. //检查是否有新消息
  965. _checkNewMessage: function () {
  966. if (this.conversationId && this.conversationId != "") {//是否有会话窗口
  967. var data = { "conversationId": this.conversationId };
  968. o2.Actions.load("x_message_assemble_communicate").ImAction.msgListByPaging(1, 10, data, function (json) {
  969. var list = json.data;
  970. if (list && list.length > 0) {
  971. var msg = list[0];
  972. //检查聊天框是否有变化
  973. if (this.conversationId == msg.conversationId) {
  974. for (var i = 0; i < list.length; i++) {
  975. var isnew = true;
  976. var m = list[i];
  977. for (var j = 0; j < this.messageList.length; j++) {
  978. if (this.messageList[j].id == m.id) {
  979. isnew = false;
  980. }
  981. }
  982. if (isnew) {
  983. this.messageList.push(m);
  984. this._buildMsgNode(m, false);
  985. // this._refreshConvMessage(m);
  986. }
  987. }
  988. }
  989. }
  990. }.bind(this), function (error) {
  991. console.log(error);
  992. }.bind(this), false);
  993. }
  994. },
  995. // 撤回消息
  996. _checkRevokeMsg: function(msg) {
  997. if (this.conversationId && this.conversationId != "") {//是否有会话窗口
  998. if (msg.conversationId && msg.conversationId == this.conversationId) {
  999. // 删除数据
  1000. this.messageList.splice(this.messageList.findIndex(e => e.id === msg.id), 1);
  1001. this._removeMsgNode(msg);
  1002. }
  1003. }
  1004. },
  1005. // 加载更多
  1006. loadMoreMsgList: function() {
  1007. this.page += 1;
  1008. this.loadMsgListByPage();
  1009. },
  1010. //分页获取会话的消息列表数据
  1011. loadMsgListByPage: function () {
  1012. if (this.isLoading) {
  1013. console.log("正在加载中。。。。。。");
  1014. return ;
  1015. }
  1016. var data = { "conversationId": this.conversationId };
  1017. this.isLoading = true;
  1018. if (this.page === 1) {
  1019. this.messageList = [];
  1020. }
  1021. o2.Actions.load("x_message_assemble_communicate").ImAction.msgListByPaging(this.page, this.pageSize, data, function (json) {
  1022. var list = json.data;
  1023. var size = 0;
  1024. if (list && list.length > 0) {
  1025. size = list.length;
  1026. for (var i = 0; i < list.length; i++) {
  1027. if (this.page == 1) {
  1028. this.messageList.push(list[i]);
  1029. } else {
  1030. this.messageList.unshift(list[i]);
  1031. }
  1032. this._buildMsgNode(list[i], true);
  1033. }
  1034. }
  1035. this.isLoading = false;
  1036. if (size < this.pageSize) { // 没有更多数据了
  1037. this.noMoreDataNode = new Element("div", {"class": "chat-no-more-data"}).inject(this.chatContentNode, "top");
  1038. this.noMoreDataNode.set("text", this.lp.msgLoadNoMoreData);
  1039. this.hasMoreMsgData = false;
  1040. } else {
  1041. if (this.noMoreDataNode) {
  1042. this.noMoreDataNode.destroy();
  1043. this.noMoreDataNode = null;
  1044. }
  1045. this.hasMoreMsgData = true;
  1046. }
  1047. }.bind(this), function (error) {
  1048. console.log(error);
  1049. this.isLoading = false;
  1050. }.bind(this), false);
  1051. },
  1052. // 群信息
  1053. tapConvInfo: function() {
  1054. this.chatTitleMoreMenuNode.setStyle("display", "none");
  1055. var convObj = null;
  1056. for (var i = 0; i < this.main.conversationNodeItemList.length; i++) {
  1057. var c = this.main.conversationNodeItemList[i];
  1058. if (this.conversationId == c.data.id) {
  1059. convObj = c.data;
  1060. }
  1061. }
  1062. if (convObj) {
  1063. var infoContainerNode = new Element("div", {"style":"padding:10px;background-color:#fff;overflow:auto;"});
  1064. new Element("div", {"style":"font-size: 16px;line-height: 32px;margin: 10px 0 0;", "text": this.lp.groupName}).inject(infoContainerNode);
  1065. new Element("div", {"style":"font-size: 14px;line-height: 26px;margin: 10px 20px 0;", "text": convObj.title}).inject(infoContainerNode);
  1066. new Element("div", {"style":"font-size: 16px;line-height: 32px;margin: 10px 0 0;", "text": this.lp.groupMemberAdmin}).inject(infoContainerNode);
  1067. var adminPerson = convObj.adminPerson || "";
  1068. var adminName = adminPerson;
  1069. if (adminPerson.indexOf("@") != -1) {
  1070. adminName = adminPerson.substring(0, adminPerson.indexOf("@"));
  1071. }
  1072. new Element("div", {"style":"font-size: 14px;line-height: 26px;margin: 10px 20px 0;", "text": adminName}).inject(infoContainerNode);
  1073. new Element("div", {"style":"font-size: 16px;line-height: 32px;margin: 10px 0 0;", "text": this.lp.groupMember}).inject(infoContainerNode);
  1074. var memberListContainer = new Element("div", {"style":"margin: 10px 20px;display:flex; flex-wrap:wrap;"}).inject(infoContainerNode);
  1075. var personList = convObj.personList || [];
  1076. for (let index = 0; index < personList.length; index++) {
  1077. const person = personList[index];
  1078. var memberDiv = new Element("div", {"style":"display:flex; flex-direction: column;padding: 10px;align-items: center;"}).inject(memberListContainer);
  1079. var avatarUrl = this.main._getIcon(person);
  1080. new Element("img", { "src": avatarUrl, "style": "width:40px;height:40px;" }).inject(memberDiv);
  1081. var name = person;
  1082. if (person.indexOf("@") != -1) {
  1083. name = name.substring(0, person.indexOf("@"));
  1084. }
  1085. new Element("div", { "text": name, "style": "margin-top:10px;" }).inject(memberDiv);
  1086. }
  1087. var dlg = o2.DL.open({
  1088. "title": this.lp.openGroupInfo,
  1089. "mask": true,
  1090. "width": "500",
  1091. "height": "430",
  1092. "content": infoContainerNode,
  1093. "onQueryClose": function () {
  1094. infoContainerNode.destroy();
  1095. }.bind(this),
  1096. "buttonList": [
  1097. {
  1098. "type": "ok",
  1099. "text": this.lp.ok,
  1100. "action": function () {
  1101. dlg.close();
  1102. }.bind(this)
  1103. }
  1104. ],
  1105. "onPostShow": function () {
  1106. dlg.reCenter();
  1107. }.bind(this),
  1108. "onPostClose": function(){
  1109. dlg = null;
  1110. }.bind(this)
  1111. });
  1112. }
  1113. },
  1114. //修改群名
  1115. tapUpdateConvTitle: function () {
  1116. this.chatTitleMoreMenuNode.setStyle("display", "none");
  1117. var title = "";
  1118. for (var i = 0; i < this.main.conversationNodeItemList.length; i++) {
  1119. var c = this.main.conversationNodeItemList[i];
  1120. if (this.conversationId == c.data.id) {
  1121. title = c.data.title;
  1122. }
  1123. }
  1124. var form = new MWF.xApplication.IMV2.UpdateConvTitleForm(this.main, {}, {"defaultValue": title}, { app: this.main.app });
  1125. form.create();
  1126. },
  1127. //修改群成员
  1128. tapUpdateConvMembers: function () {
  1129. this.chatTitleMoreMenuNode.setStyle("display", "none");
  1130. var members = [];
  1131. for (var i = 0; i < this.main.conversationNodeItemList.length; i++) {
  1132. var c = this.main.conversationNodeItemList[i];
  1133. if (this.conversationId == c.data.id) {
  1134. members = c.data.personList;
  1135. }
  1136. }
  1137. var form = new MWF.xApplication.IMV2.CreateConversationForm(this.main, {}, { "title": this.lp.modifyMember, "personCount": 0, "personSelected": members, "isUpdateMember": true }, { app: this.main.app });
  1138. form.create()
  1139. },
  1140. // 点击菜单 删除会话
  1141. tapDeleteConversation: function(e) {
  1142. var _self = this;
  1143. var con = null;
  1144. for (var i = 0; i < this.main.conversationNodeItemList.length; i++) {
  1145. var c = this.main.conversationNodeItemList[i];
  1146. if (this.conversationId == c.data.id) {
  1147. con = c.data;
  1148. break;
  1149. }
  1150. }
  1151. if (con) {
  1152. var msg = this.lp.messageDeleteSingleConversationAlert;
  1153. if (con.type === "single") {
  1154. msg = this.lp.messageDeleteSingleConversationAlert;
  1155. } else {
  1156. msg = this.lp.messageDeleteGroupConversationAlert;
  1157. }
  1158. MWF.xDesktop.confirm("info", this.chatTitleNode, this.lp.alert, msg, 400, 150, function() {
  1159. if (con.type === "single") {
  1160. _self.deleteSingleConversation();
  1161. } else {
  1162. _self.deleteGroupConversation();
  1163. }
  1164. this.close();
  1165. }, function(){
  1166. this.close();
  1167. }, null, null, "o2");
  1168. } else {
  1169. console.error('没有找到会话对象。。。。。');
  1170. }
  1171. },
  1172. // 删除群聊
  1173. deleteGroupConversation: function() {
  1174. o2.Actions.load("x_message_assemble_communicate").ImAction.deleteGroupConversation(this.conversationId, function (json) {
  1175. this.main.refresh();
  1176. }.bind(this), function (error) {
  1177. console.error(error);
  1178. this.app.notice(error, "error", this.app.content);
  1179. }.bind(this));
  1180. },
  1181. deleteSingleConversation: function() {
  1182. o2.Actions.load("x_message_assemble_communicate").ImAction.deleteSingleConversation(this.conversationId, function (json) {
  1183. this.main.refresh();
  1184. }.bind(this), function (error) {
  1185. console.error(error);
  1186. this.app.notice(error, "error", this.app.content);
  1187. }.bind(this));
  1188. },
  1189. //点击表情按钮
  1190. showEmojiBox: function () {
  1191. if (!this.emojiBoxNode) {
  1192. this.emojiBoxNode = new Element("div", { "class": "chat-emoji-box" }).inject(this.container);
  1193. var _self = this;
  1194. for (var i = 0; i < this.main.emojiList.length; i++) {
  1195. var emoji = this.main.emojiList[i];
  1196. var emojiNode = new Element("img", { "src": emoji.path, "class": "chat-emoji-img" }).inject(this.emojiBoxNode);
  1197. emojiNode.addEvents({
  1198. "mousedown": function (ev) {
  1199. _self.sendEmojiMsg(this.emoji);
  1200. _self.hideEmojiBox();
  1201. }.bind({ emoji: emoji })
  1202. });
  1203. }
  1204. }
  1205. this.emojiBoxNode.setStyle("display", "block");
  1206. this.hideFun = this.hideEmojiBox.bind(this);
  1207. document.body.addEvent("mousedown", this.hideFun);
  1208. },
  1209. _reclickConv: function() {
  1210. for (var i = 0; i < this.main.conversationNodeItemList.length; i++) {
  1211. var c = this.main.conversationNodeItemList[i];
  1212. if (this.conversationId == c.data.id) {
  1213. this.main.tapConv(c.data);
  1214. }
  1215. }
  1216. },
  1217. //创建图片或文件消息
  1218. _newImageOrFileMsgAndSend: function (type, fileId, fileName, fileExt) {
  1219. var distinguishedName = layout.session.user.distinguishedName;
  1220. var time = this._currentTime();
  1221. var body = {
  1222. "body": this.lp.file,
  1223. "type": type,
  1224. "fileId": fileId,
  1225. "fileExtension": fileExt,
  1226. "fileName": fileName
  1227. };
  1228. var bodyJson = JSON.stringify(body);
  1229. var uuid = new MWF.widget.UUID().createTrueUUID();
  1230. var message = {
  1231. "id": uuid,
  1232. "conversationId": this.conversationId,
  1233. "body": bodyJson,
  1234. "createPerson": distinguishedName,
  1235. "createTime": time,
  1236. "sendStatus": 1
  1237. };
  1238. o2.Actions.load("x_message_assemble_communicate").ImAction.msgCreate(message,
  1239. function (json) {
  1240. console.log(this.lp.sendSuccess);
  1241. }.bind(this),
  1242. function (error) {
  1243. console.log(error);
  1244. }.bind(this));
  1245. this.messageList.push(message);
  1246. this._buildReceiver(body, distinguishedName, false, message);
  1247. this.main._refreshConvMessage(message);
  1248. },
  1249. //创建文本消息 并发送
  1250. _newAndSendTextMsg: function (text, type) {
  1251. var distinguishedName = layout.session.user.distinguishedName;
  1252. var time = this._currentTime();
  1253. var body = { "body": text, "type": type };
  1254. var bodyJson = JSON.stringify(body);
  1255. var uuid = new MWF.widget.UUID().createTrueUUID();
  1256. var textMessage = {
  1257. "id": uuid,
  1258. "conversationId": this.conversationId,
  1259. "body": bodyJson,
  1260. "createPerson": distinguishedName,
  1261. "createTime": time,
  1262. "sendStatus": 1
  1263. };
  1264. o2.Actions.load("x_message_assemble_communicate").ImAction.msgCreate(textMessage,
  1265. function (json) {
  1266. //data = json.data;
  1267. console.log(this.lp.sendSuccess);
  1268. }.bind(this),
  1269. function (error) {
  1270. console.log(error);
  1271. }.bind(this));
  1272. this.messageList.push(textMessage);
  1273. this._buildReceiver(body, distinguishedName, false, textMessage);
  1274. this.main._refreshConvMessage(textMessage);
  1275. },
  1276. //点击发送消息
  1277. sendMsg: function () {
  1278. var text = this.chatBottomAreaTextareaNode.value;
  1279. if (text) {
  1280. this.chatBottomAreaTextareaNode.value = "";
  1281. this._newAndSendTextMsg(text, "text");
  1282. } else {
  1283. console.log(this.lp.noMessage);
  1284. this.app.notice(this.lp.noMessage, "error", this.app.content);
  1285. }
  1286. },
  1287. // 点击发送文件消息
  1288. showChooseFile: function () {
  1289. if (!this.uploadFileAreaNode) {
  1290. this.createUploadFileNode();
  1291. }
  1292. this.fileUploadNode.click();
  1293. },
  1294. //创建文件选择框
  1295. createUploadFileNode: function () {
  1296. this.uploadFileAreaNode = new Element("div");
  1297. var html = "<input name=\"file\" type=\"file\" multiple/>";
  1298. this.uploadFileAreaNode.set("html", html);
  1299. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  1300. this.fileUploadNode.addEvent("change", function () {
  1301. var files = this.fileUploadNode.files;
  1302. if (files.length) {
  1303. var file = files.item(0);
  1304. var formData = new FormData();
  1305. formData.append('file', file);
  1306. formData.append('fileName', file.name);
  1307. var fileExt = file.name.substring(file.name.lastIndexOf("."));
  1308. // 图片消息
  1309. var type = "file"
  1310. if (fileExt.toLowerCase() == ".bmp" || fileExt.toLowerCase() == ".jpeg"
  1311. || fileExt.toLowerCase() == ".png" || fileExt.toLowerCase() == ".jpg") {
  1312. type = "image"
  1313. } else { // 文件消息
  1314. type = "file"
  1315. }
  1316. //上传文件
  1317. o2.Actions.load("x_message_assemble_communicate").ImAction.uploadFile(this.conversationId, type, formData, "{}", function (json) {
  1318. if (json.data) {
  1319. var fileId = json.data.id
  1320. var fileExtension = json.data.fileExtension
  1321. var fileName = json.data.fileName
  1322. this._newImageOrFileMsgAndSend(type, fileId, fileName, fileExtension)
  1323. }
  1324. }.bind(this), function (error) {
  1325. console.log(error);
  1326. }.bind(this))
  1327. }
  1328. }.bind(this));
  1329. },
  1330. hideEmojiBox: function () {
  1331. //关闭emojiBoxNode
  1332. this.emojiBoxNode.setStyle("display", "none");
  1333. document.body.removeEvent("mousedown", this.hideFun);
  1334. },
  1335. //发送表情消息
  1336. sendEmojiMsg: function (emoji) {
  1337. this._newAndSendTextMsg(emoji.key, "emoji");
  1338. },
  1339. // 撤回、删除 消息
  1340. _removeMsgNode: function(msg) {
  1341. var itemNode = this.chatContentNode.getElement("#"+msg.id);
  1342. if (itemNode) {
  1343. var beforeNode = itemNode.getPrevious();
  1344. itemNode.destroy();
  1345. if (beforeNode) {
  1346. beforeNode.destroy();
  1347. }
  1348. }
  1349. },
  1350. //创建消息html节点
  1351. _buildMsgNode: function (msg, isTop) {
  1352. var createPerson = msg.createPerson;
  1353. var jsonbody = msg.body;
  1354. var body = JSON.parse(jsonbody);
  1355. var distinguishedName = layout.session.user.distinguishedName;
  1356. if (createPerson != distinguishedName) {
  1357. this._buildSender(body, createPerson, isTop, msg);
  1358. } else {
  1359. this._buildReceiver(body, createPerson, isTop, msg);
  1360. }
  1361. },
  1362. /**
  1363. * 消息接收对象
  1364. * 这里的方法名错了两者互换了无需理会
  1365. * @param msgBody 消息体
  1366. * @param createPerson 消息人员
  1367. * @param isTop 是否放在顶部
  1368. * @param msg 消息对象
  1369. */
  1370. _buildSender: function (msgBody, createPerson, isTop, msg) {
  1371. if (!isTop) {
  1372. // 添加消息时间
  1373. this._buildMsgTime(isTop, msg);
  1374. }
  1375. var receiverBodyNode = new Element("div", { "class": "chat-sender", "id": msg.id}).inject(this.chatContentNode, isTop ? "top" : "bottom");
  1376. this._addContextMenuEvent(receiverBodyNode, msg);
  1377. var avatarNode = new Element("div", {"class": "chat-sender-avatar"}).inject(receiverBodyNode);
  1378. var avatarUrl = this.main._getIcon(createPerson);
  1379. var name = createPerson;
  1380. if (createPerson.indexOf("@") != -1) {
  1381. name = name.substring(0, createPerson.indexOf("@"));
  1382. }
  1383. var avatarImg = new Element("img", { "src": avatarUrl }).inject(avatarNode);
  1384. var nameNode = new Element("div", { "text": name , "class": "chat-sender-name"}).inject(receiverBodyNode);
  1385. var lastNodeClass = "chat-sender-box"
  1386. if (msgBody.type == "process" || msgBody.type == "cms") {
  1387. lastNodeClass = "chat-sender-card-box"
  1388. }
  1389. var lastNode = new Element("div", {"class": lastNodeClass}).inject(receiverBodyNode);
  1390. var lastFirstNode = new Element("div", { "class": "chat-left_triangle" }).inject(lastNode);
  1391. //text
  1392. if (msgBody.type == "emoji") { // 表情
  1393. var img = "";
  1394. for (var i = 0; i < this.main.emojiList.length; i++) {
  1395. if (msgBody.body == this.main.emojiList[i].key) {
  1396. img = this.main.emojiList[i].path;
  1397. }
  1398. }
  1399. new Element("img", { "src": img, "class": "chat-content-emoji" }).inject(lastNode);
  1400. } else if (msgBody.type == "image") {//image
  1401. var imgBox = new Element("div", { "class": "img-chat" }).inject(lastNode);
  1402. var url = this._getFileUrlWithWH(msgBody.fileId, 144, 192);
  1403. new Element("img", { "src": url }).inject(imgBox);
  1404. imgBox.addEvents({
  1405. "click": function (e) {
  1406. var downloadUrl = this._getFileDownloadUrl(msgBody.fileId);
  1407. window.open(downloadUrl);
  1408. }.bind(this)
  1409. });
  1410. } else if (msgBody.type == "audio") {
  1411. var url = this._getFileDownloadUrl(msgBody.fileId);
  1412. new Element("audio", { "src": url, "controls": "controls", "preload": "preload" }).inject(lastNode);
  1413. } else if (msgBody.type == "location") {
  1414. var mapBox = new Element("span").inject(lastNode);
  1415. new Element("img", { "src": "../x_component_IMV2/$Main/default/icons/location.png", "width": 24, "height": 24 }).inject(mapBox);
  1416. var url = this._getBaiduMapUrl(msgBody.latitude, msgBody.longitude, msgBody.address, msgBody.addressDetail);
  1417. new Element("a", { "href": url, "target": "_blank", "text": msgBody.address }).inject(mapBox);
  1418. } else if (msgBody.type == "file") { //文件
  1419. var mapBox = new Element("span").inject(lastNode);
  1420. var fileIcon = this._getFileIcon(msgBody.fileExtension);
  1421. new Element("img", { "src": "../x_component_IMV2/$Main/file_icons/" + fileIcon, "width": 48, "height": 48 }).inject(mapBox);
  1422. var downloadUrl = this._getFileDownloadUrl(msgBody.fileId);
  1423. new Element("a", { "href": downloadUrl, "target": "_blank", "text": msgBody.fileName }).inject(mapBox);
  1424. } else if (msgBody.type == "process") {
  1425. var cardNode = new Element("div", {"class": "chat-card"}).inject(lastNode);
  1426. // 流程名称
  1427. new Element("div", {"class": "chat-card-type", "text": "【"+msgBody.processName+"】"}).inject(cardNode);
  1428. // 工作标题
  1429. var title = msgBody.title;
  1430. if (title == null || title == "") {
  1431. title = "【"+msgBody.processName+"】- " + this.lp.noTitle;
  1432. }
  1433. new Element("div", {"class": "chat-card-body", "text":title}).inject(cardNode);
  1434. var cardFooter = new Element("div", {"class": "chat-card-bottom"}).inject(cardNode);
  1435. var appIconNode = new Element("img", {"class": "chat-card-bottom-icon"}).inject(cardFooter);
  1436. this._loadProcessApplicationIcon(msgBody.application, function(appIcon) {
  1437. if (appIcon && appIcon.icon) {
  1438. appIconNode.set("src", "data:image/png;base64," + appIcon.icon);
  1439. } else {
  1440. console.log('没有找到应用图标');
  1441. appIconNode.set("src", "../x_component_process_ApplicationExplorer/$Main/default/icon/application.png");
  1442. }
  1443. })
  1444. new Element("div", { "class": "chat-card-bottom-name", "text": msgBody.applicationName }).inject(cardFooter);
  1445. cardNode.addEvents({
  1446. "click": function() {
  1447. // layout.openApplication(null, "process.Work", {"workId": msgBody.work});
  1448. o2.api.form.openWork(msgBody.work, "", title || "" );
  1449. }
  1450. });
  1451. } else if (msgBody.type == "cms") {
  1452. } else {//text
  1453. new Element("span", { "text": this.contentEscapeBackToSymbol(msgBody.body) }).inject(lastNode);
  1454. }
  1455. if (isTop) {
  1456. // 添加消息时间
  1457. this._buildMsgTime(isTop, msg);
  1458. }
  1459. if (!isTop) {
  1460. var scrollFx = new Fx.Scroll(this.chatContentNode);
  1461. scrollFx.toBottom();
  1462. }
  1463. },
  1464. /**
  1465. * 消息发送对象
  1466. * 这里的方法名错了两者互换了无需理会
  1467. * @param msgBody
  1468. * @param createPerson 消息人员
  1469. * @param isTop 是否放在顶部
  1470. * @param msg 消息对象
  1471. */
  1472. _buildReceiver: function (msgBody, createPerson, isTop, msg) {
  1473. if (!isTop) {
  1474. // 添加消息时间
  1475. this._buildMsgTime(isTop, msg);
  1476. }
  1477. var receiverBodyNode = new Element("div", { "class": "chat-receiver", "id": msg.id}).inject(this.chatContentNode, isTop ? "top" : "bottom");
  1478. this._addContextMenuEvent(receiverBodyNode, msg);
  1479. var avatarNode = new Element("div", {"class": "chat-receiver-avatar"}).inject(receiverBodyNode);
  1480. var avatarUrl = this.main._getIcon(createPerson);
  1481. var name = createPerson;
  1482. if (createPerson.indexOf("@") != -1) {
  1483. name = name.substring(0, createPerson.indexOf("@"));
  1484. }
  1485. var avatarImg = new Element("img", { "src": avatarUrl }).inject(avatarNode);
  1486. var nameNode = new Element("div", { "text": name , "class": "chat-receiver-name"}).inject(receiverBodyNode);
  1487. var lastNodeClass = "chat-receiver-box"
  1488. if (msgBody.type == "process" || msgBody.type == "cms") {
  1489. lastNodeClass = "chat-receiver-card-box"
  1490. }
  1491. var lastNode = new Element("div", {"class": lastNodeClass}).inject(receiverBodyNode);
  1492. var lastFirstNode = new Element("div", { "class": "chat-right_triangle" }).inject(lastNode);
  1493. if (msgBody.type == "emoji") { // 表情
  1494. var img = "";
  1495. for (var i = 0; i < this.main.emojiList.length; i++) {
  1496. if (msgBody.body == this.main.emojiList[i].key) {
  1497. img = this.main.emojiList[i].path;
  1498. }
  1499. }
  1500. new Element("img", { "src": img, "class": "chat-content-emoji" }).inject(lastNode);
  1501. } else if (msgBody.type == "image") {//image
  1502. var imgBox = new Element("div", { "class": "img-chat" }).inject(lastNode);
  1503. var url = this._getFileUrlWithWH(msgBody.fileId, 144, 192);
  1504. new Element("img", { "src": url }).inject(imgBox);
  1505. imgBox.addEvents({
  1506. "click": function (e) {
  1507. var downloadUrl = this._getFileDownloadUrl(msgBody.fileId);
  1508. window.open(downloadUrl);
  1509. }.bind(this)
  1510. });
  1511. } else if (msgBody.type == "audio") {
  1512. var url = this._getFileDownloadUrl(msgBody.fileId);
  1513. new Element("audio", { "src": url, "controls": "controls", "preload": "preload" }).inject(lastNode);
  1514. } else if (msgBody.type == "location") {
  1515. var mapBox = new Element("span").inject(lastNode);
  1516. new Element("img", { "src": "../x_component_IMV2/$Main/default/icons/location.png", "width": 24, "height": 24 }).inject(mapBox);
  1517. var url = this._getBaiduMapUrl(msgBody.latitude, msgBody.longitude, msgBody.address, msgBody.addressDetail);
  1518. new Element("a", { "href": url, "target": "_blank", "text": msgBody.address }).inject(mapBox);
  1519. } else if (msgBody.type == "file") { //文件
  1520. var mapBox = new Element("span").inject(lastNode);
  1521. var fileIcon = this._getFileIcon(msgBody.fileExtension);
  1522. new Element("img", { "src": "../x_component_IMV2/$Main/file_icons/" + fileIcon, "width": 48, "height": 48 }).inject(mapBox);
  1523. var downloadUrl = this._getFileDownloadUrl(msgBody.fileId);
  1524. new Element("a", { "href": downloadUrl, "target": "_blank", "text": msgBody.fileName }).inject(mapBox);
  1525. } else if (msgBody.type == "process") {
  1526. var cardNode = new Element("div", {"class": "chat-card"}).inject(lastNode);
  1527. // 流程名称
  1528. new Element("div", {"class": "chat-card-type", "text": "【"+msgBody.processName+"】"}).inject(cardNode);
  1529. // 工作标题
  1530. var title = msgBody.title;
  1531. if (title == null || title == "") {
  1532. title = "【"+msgBody.processName+"】- " + this.lp.noTitle;
  1533. }
  1534. new Element("div", {"class": "chat-card-body", "text":title}).inject(cardNode);
  1535. var cardFooter = new Element("div", {"class": "chat-card-bottom"}).inject(cardNode);
  1536. var appIconNode = new Element("img", {"class": "chat-card-bottom-icon"}).inject(cardFooter);
  1537. this._loadProcessApplicationIcon(msgBody.application, function(appIcon) {
  1538. if (appIcon && appIcon.icon) {
  1539. appIconNode.set("src", "data:image/png;base64," + appIcon.icon);
  1540. } else {
  1541. console.log('没有找到应用图标');
  1542. appIconNode.set("src", "../x_component_process_ApplicationExplorer/$Main/default/icon/application.png");
  1543. }
  1544. })
  1545. new Element("div", { "class": "chat-card-bottom-name", "text": msgBody.applicationName }).inject(cardFooter);
  1546. cardNode.addEvents({
  1547. "click": function() {
  1548. // layout.openApplication(null, "process.Work", {"workId": msgBody.work});
  1549. o2.api.form.openWork(msgBody.work, "", title || "" );
  1550. }
  1551. });
  1552. } else if (msgBody.type == "cms") {
  1553. } else {//text
  1554. new Element("span", { "text": this.contentEscapeBackToSymbol(msgBody.body) }).inject(lastNode);
  1555. }
  1556. if (isTop) {
  1557. // 添加消息时间
  1558. this._buildMsgTime(isTop, msg);
  1559. }
  1560. if (!isTop) {
  1561. var scrollFx = new Fx.Scroll(this.chatContentNode);
  1562. scrollFx.toBottom();
  1563. }
  1564. },
  1565. // 获取流程应用图标
  1566. _loadProcessApplicationIcon: function(appId, callback) {
  1567. if (!this.processApplications) {
  1568. this.processApplications = [];
  1569. }
  1570. if (this.processApplications[appId]) {
  1571. if (callback) callback(this.processApplications[appId]);
  1572. } else {
  1573. o2.Actions.load("x_processplatform_assemble_surface").ApplicationAction. getIcon(appId, function (json) {
  1574. if(json && json.data) {
  1575. this.processApplications[appId] = json.data;
  1576. if (callback) callback(json.data);
  1577. } else {
  1578. if (callback) callback();
  1579. }
  1580. }.bind(this), function (error) {
  1581. console.log(error);
  1582. if (callback) callback();
  1583. }.bind(this))
  1584. }
  1585. },
  1586. // 消息体上是否显示消息时间
  1587. _buildMsgTime: function(isTop, msg) {
  1588. var timeNode = new Element("div", { "class": "chat-msg-time"}).inject(this.chatContentNode, isTop ? "top" : "bottom");
  1589. timeNode.set("text", this._msgShowTime(o2.common.toDate(msg.createTime)))
  1590. },
  1591. // 消息时间
  1592. _msgShowTime: function (date) {
  1593. var day = date.getDate();
  1594. var monthIndex = date.getMonth();
  1595. var year = date.getFullYear();
  1596. var time = date.getTime();
  1597. var today = new Date();
  1598. var todayDay = today.getDate();
  1599. var todayMonthIndex = today.getMonth();
  1600. var todayYear = today.getFullYear();
  1601. var todayTime = today.getTime();
  1602. var retTime = "";
  1603. //同一天
  1604. if (day === todayDay && monthIndex === todayMonthIndex && year === todayYear) {
  1605. var hour = date.getHours() > 9 ? ""+date.getHours() : "0" + date.getHours();
  1606. var minute = date.getMinutes() > 9 ? ""+date.getMinutes() : "0" + date.getMinutes();
  1607. retTime = hour + ":" +minute;
  1608. return retTime;
  1609. }
  1610. var dates = parseInt(time / 86400000);
  1611. var todaydates = parseInt(todayTime / 86400000);
  1612. if (todaydates > dates) {
  1613. var days = (todaydates - dates);
  1614. if (days == 1) {
  1615. var hour = date.getHours() > 9 ? ""+date.getHours() : "0" + date.getHours();
  1616. var minute = date.getMinutes() > 9 ? ""+date.getMinutes() : "0" + date.getMinutes();
  1617. retTime = this.lp.yesterday + " " + hour + ":" +minute;
  1618. } else if (days == 2) {
  1619. var hour = date.getHours() > 9 ? ""+date.getHours() : "0" + date.getHours();
  1620. var minute = date.getMinutes() > 9 ? ""+date.getMinutes() : "0" + date.getMinutes();
  1621. retTime = this.lp.beforeYesterday + " " + hour + ":" +minute;
  1622. }else {
  1623. var month = date.getMonth() + 1;
  1624. var day = date.getDate();
  1625. month = (month.toString().length == 1) ? ("0" + month) : month;
  1626. day = (day.toString().length == 1) ? ("0" + day) : day;
  1627. var hour = date.getHours() > 9 ? ""+date.getHours() : "0" + date.getHours();
  1628. var minute = date.getMinutes() > 9 ? ""+date.getMinutes() : "0" + date.getMinutes();
  1629. retTime = month + '-' + day + " " + hour + ":" +minute;
  1630. }
  1631. }
  1632. return retTime;
  1633. },
  1634. // 绑定右键事件
  1635. _addContextMenuEvent: function(receiverBodyNode, msg) {
  1636. receiverBodyNode.store("msg", msg);
  1637. receiverBodyNode.addEvents({
  1638. "contextmenu": function(e) {
  1639. //取消默认的浏览器自带右键 很重要!!
  1640. e.preventDefault();
  1641. var menuleft=e.client.x+'px';
  1642. var menutop=e.client.y+'px';
  1643. var m = receiverBodyNode.retrieve("msg");
  1644. this._createMsgContextMenu(m, menuleft, menutop);
  1645. }.bind(this)
  1646. });
  1647. },
  1648. // 打开 消息体上 右键菜单
  1649. _createMsgContextMenu: function(msg, menuleft, menutop) {
  1650. var createPerson = msg.createPerson;
  1651. var distinguishedName = layout.session.user.distinguishedName;
  1652. var list = []; // 菜单列表
  1653. if (this.main.imConfig.enableRevokeMsg) { // 是否启用撤回消息
  1654. if (createPerson != distinguishedName) {
  1655. // 判断是否群主
  1656. var isGroupAdmin = false;
  1657. for (var i = 0; i < this.main.conversationNodeItemList.length; i++) {
  1658. var c = this.main.conversationNodeItemList[i];
  1659. if (this.conversationId == c.data.id) {
  1660. if (c.data.type === "group" && distinguishedName === c.data.adminPerson) {
  1661. isGroupAdmin = true;
  1662. }
  1663. }
  1664. }
  1665. if (isGroupAdmin) {
  1666. list.push({"id":"revokeMemberMsg", "text": this.lp.msgMenuItemRevokeMemberMsg});
  1667. }
  1668. } else {
  1669. list.push({"id":"revokeMsg", "text": this.lp.msgMenuItemRevokeMsg});
  1670. }
  1671. }
  1672. if (this.menuNode) {
  1673. this.menuNode.destroy();
  1674. this.menuNode = null;
  1675. }
  1676. if (list.length > 0) {
  1677. // 生成菜单
  1678. this.menuNode = new Element("ul", {"class": "chat-menulist", "styles": { "position": "fixed", "z-index": "9999", "top": menutop, "left": menuleft } }).inject(this.container);
  1679. for (let index = 0; index < list.length; index++) {
  1680. const element = list[index];
  1681. var menuItemNode = new Element("li", {"text": element.text}).inject(this.menuNode);
  1682. menuItemNode.store('menuItemData', element);
  1683. menuItemNode.store('menuItemMsgData', msg);
  1684. menuItemNode.addEvents({
  1685. "click": function(e) {
  1686. var menuItemData = menuItemNode.retrieve('menuItemData'); // 菜单项数据
  1687. var menuItemMsgData = menuItemNode.retrieve('menuItemMsgData'); // 消息数据
  1688. this._clickMsgContextMenuItem(menuItemData, menuItemMsgData);
  1689. e.preventDefault();
  1690. }.bind(this)
  1691. });
  1692. }
  1693. // 添加关闭菜单事件
  1694. this.closeMsgContextMenuFun = function(e) {
  1695. if (this.menuNode) {
  1696. this.menuNode.destroy();
  1697. this.menuNode = null;
  1698. }
  1699. e.preventDefault();
  1700. if( this.closeMsgContextMenuFun )this.main.app.content.removeEvent( "click", this.closeMsgContextMenuFun );
  1701. }.bind(this);
  1702. this.main.app.content.addEvents({
  1703. "click": this.closeMsgContextMenuFun
  1704. });
  1705. }
  1706. },
  1707. // 点击 右键菜单项
  1708. _clickMsgContextMenuItem: function(menuItemData, menuItemMsgData) {
  1709. // 关闭菜单
  1710. if (this.menuNode) {
  1711. this.menuNode.destroy();
  1712. this.menuNode = null;
  1713. }
  1714. // 根据菜单不同处理不同内容
  1715. // 撤回
  1716. if (menuItemData.id === "revokeMemberMsg" || menuItemData.id === "revokeMsg") {
  1717. this._revokeMsg(menuItemMsgData);
  1718. }
  1719. },
  1720. // 撤回消息
  1721. _revokeMsg: function(msg) {
  1722. o2.Actions.load("x_message_assemble_communicate").ImAction.msgRevoke(msg.id, function(json) {
  1723. console.log("撤回消息:", json);
  1724. // 删除消息
  1725. $(msg.id).destroy();
  1726. }.bind(this));
  1727. },
  1728. //图片 根据大小 url
  1729. _getFileUrlWithWH: function (id, width, height) {
  1730. var action = MWF.Actions.get("x_message_assemble_communicate").action;
  1731. var url = action.getAddress() + action.actions.imgFileDownloadWithWH.uri;
  1732. url = url.replace("{id}", encodeURIComponent(id));
  1733. url = url.replace("{width}", encodeURIComponent(width));
  1734. url = url.replace("{height}", encodeURIComponent(height));
  1735. return url;
  1736. },
  1737. //file 下载的url
  1738. _getFileDownloadUrl: function (id) {
  1739. var action = MWF.Actions.get("x_message_assemble_communicate").action;
  1740. var url = action.getAddress() + action.actions.imgFileDownload.uri;
  1741. url = url.replace("{id}", encodeURIComponent(id));
  1742. return url;
  1743. },
  1744. //百度地图打开地址
  1745. _getBaiduMapUrl: function (lat, longt, address, content) {
  1746. var url = "https://api.map.baidu.com/marker?location=" + lat + "," + longt + "&title=" + address + "&content=" + content + "&output=html&src=net.o2oa.map";
  1747. return url;
  1748. },
  1749. // 文件类型icon图
  1750. _getFileIcon: function (ext) {
  1751. if (ext) {
  1752. if (ext === "jpg" || ext === "jpeg") {
  1753. return "icon_file_jpeg.png";
  1754. } else if (ext === "gif") {
  1755. return "icon_file_gif.png";
  1756. } else if (ext === "png") {
  1757. return "icon_file_png.png";
  1758. } else if (ext === "tiff") {
  1759. return "icon_file_tiff.png";
  1760. } else if (ext === "bmp" || ext === "webp") {
  1761. return "icon_file_img.png";
  1762. } else if (ext === "ogg" || ext === "mp3" || ext === "wav" || ext === "wma") {
  1763. return "icon_file_mp3.png";
  1764. } else if (ext === "mp4") {
  1765. return "icon_file_mp4.png";
  1766. } else if (ext === "avi") {
  1767. return "icon_file_avi.png";
  1768. } else if (ext === "mov" || ext === "rm" || ext === "mkv") {
  1769. return "icon_file_rm.png";
  1770. } else if (ext === "doc" || ext === "docx") {
  1771. return "icon_file_word.png";
  1772. } else if (ext === "xls" || ext === "xlsx") {
  1773. return "icon_file_excel.png";
  1774. } else if (ext === "ppt" || ext === "pptx") {
  1775. return "icon_file_ppt.png";
  1776. } else if (ext === "html") {
  1777. return "icon_file_html.png";
  1778. } else if (ext === "pdf") {
  1779. return "icon_file_pdf.png";
  1780. } else if (ext === "txt" || ext === "json") {
  1781. return "icon_file_txt.png";
  1782. } else if (ext === "zip") {
  1783. return "icon_file_zip.png";
  1784. } else if (ext === "rar") {
  1785. return "icon_file_rar.png";
  1786. } else if (ext === "7z") {
  1787. return "icon_file_arch.png";
  1788. } else if (ext === "ai") {
  1789. return "icon_file_ai.png";
  1790. } else if (ext === "att") {
  1791. return "icon_file_att.png";
  1792. } else if (ext === "au") {
  1793. return "icon_file_au.png";
  1794. } else if (ext === "cad") {
  1795. return "icon_file_cad.png";
  1796. } else if (ext === "cdr") {
  1797. return "icon_file_cdr.png";
  1798. } else if (ext === "eps") {
  1799. return "icon_file_eps.png";
  1800. } else if (ext === "exe") {
  1801. return "icon_file_exe.png";
  1802. } else if (ext === "iso") {
  1803. return "icon_file_iso.png";
  1804. } else if (ext === "link") {
  1805. return "icon_file_link.png";
  1806. } else if (ext === "swf") {
  1807. return "icon_file_flash.png";
  1808. } else if (ext === "psd") {
  1809. return "icon_file_psd.png";
  1810. } else if (ext === "tmp") {
  1811. return "icon_file_tmp.png";
  1812. } else {
  1813. return "icon_file_unkown.png";
  1814. }
  1815. } else {
  1816. return "icon_file_unkown.png";
  1817. }
  1818. },
  1819. //当前时间 yyyy-MM-dd HH:mm:ss
  1820. _currentTime: function () {
  1821. var today = new Date();
  1822. var year = today.getFullYear(); //得到年份
  1823. var month = today.getMonth();//得到月份
  1824. var date = today.getDate();//得到日期
  1825. var hour = today.getHours();//得到小时
  1826. var minu = today.getMinutes();//得到分钟
  1827. var sec = today.getSeconds();//得到秒
  1828. month = month + 1;
  1829. if (month < 10) month = "0" + month;
  1830. if (date < 10) date = "0" + date;
  1831. if (hour < 10) hour = "0" + hour;
  1832. if (minu < 10) minu = "0" + minu;
  1833. if (sec < 10) sec = "0" + sec;
  1834. return year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec;
  1835. }
  1836. });
  1837. // 会话对象
  1838. MWF.xApplication.IMV2.ConversationItem = new Class({
  1839. initialize: function (data, main) {
  1840. this.data = data;
  1841. this.main = main;
  1842. this.container = this.main.chatItemListNode;
  1843. this.load();
  1844. },
  1845. load: function () {
  1846. var avatarDefault = this.main._getIcon();
  1847. var convData = {
  1848. "id": this.data.id,
  1849. "avatarUrl": avatarDefault,
  1850. "title": this.data.title,
  1851. "time": "",
  1852. "lastMessage": "",
  1853. "lastMessageType": "text"
  1854. };
  1855. var distinguishedName = layout.session.user.distinguishedName;
  1856. if (this.data.type && this.data.type === "single") {
  1857. var chatPerson = "";
  1858. if (this.data.personList && this.data.personList instanceof Array) {
  1859. for (var j = 0; j < this.data.personList.length; j++) {
  1860. var person = this.data.personList[j];
  1861. if (person !== distinguishedName) {
  1862. chatPerson = person;
  1863. }
  1864. }
  1865. }
  1866. convData.avatarUrl = this.main._getIcon(chatPerson);
  1867. var name = chatPerson;
  1868. if (chatPerson.indexOf("@") != -1) {
  1869. name = name.substring(0, chatPerson.indexOf("@"));
  1870. }
  1871. convData.title = name;
  1872. }
  1873. if (this.data.lastMessage) {
  1874. //todo 其它消息类型
  1875. var mBody = JSON.parse(this.data.lastMessage.body);
  1876. convData.lastMessage = mBody.body;
  1877. if (this.data.lastMessage.createTime) {
  1878. var time = this.main._friendlyTime(o2.common.toDate(this.data.lastMessage.createTime));
  1879. convData.time = time;
  1880. }
  1881. if (mBody.type) {
  1882. convData.lastMessageType = mBody.type;
  1883. if (mBody.type == "process") {
  1884. var title = mBody.title;
  1885. if (title == null || title == "") {
  1886. title = "【" + mBody.processName + "】- " + this.lp.noTitle;
  1887. }
  1888. convData.lastMessage = title;
  1889. } else if (mBody.type == "cms") {
  1890. convData.lastMessage = mBody.title || "";
  1891. }
  1892. }
  1893. }
  1894. this.node = new Element("div", { "class": "item" }).inject(this.container, this.data.isNew ? 'top' : '');
  1895. this.nodeBaseItem = new Element("div", { "class": "base" }).inject(this.node);
  1896. var avatarNode = new Element("div", { "class": "avatar" }).inject(this.nodeBaseItem);
  1897. new Element("img", { "src": convData.avatarUrl, "class": "img" }).inject(avatarNode);
  1898. var bodyNode = new Element("div", { "class": "body" }).inject(this.nodeBaseItem);
  1899. var bodyUpNode = new Element("div", { "class": "body_up" }).inject(bodyNode);
  1900. this.titleNode = new Element("div", { "class": "body_title", "text": convData.title }).inject(bodyUpNode);
  1901. this.messageTimeNode = new Element("div", { "class": "body_time", "text": convData.time }).inject(bodyUpNode);
  1902. if (convData.lastMessageType == "emoji") {
  1903. this.lastMessageNode = new Element("div", { "class": "body_down" }).inject(bodyNode);
  1904. var imgPath = "";
  1905. for (var i = 0; i < this.main.emojiList.length; i++) {
  1906. var emoji = this.main.emojiList[i];
  1907. if (emoji.key == convData.lastMessage) {
  1908. imgPath = emoji.path;
  1909. }
  1910. }
  1911. new Element("img", { "src": imgPath, "style": "width: 16px;height: 16px;" }).inject(this.lastMessageNode);
  1912. } else {
  1913. this.lastMessageNode = new Element("div", { "class": "body_down", "text": convData.lastMessage }).inject(bodyNode);
  1914. }
  1915. var _self = this;
  1916. this.node.addEvents({
  1917. "click": function () {
  1918. _self.main.tapConv(_self.data);
  1919. }
  1920. });
  1921. },
  1922. /**
  1923. *
  1924. * 刷新会话列表的最后消息内容
  1925. * @param {*} lastMessage
  1926. */
  1927. refreshLastMsg: function (lastMessage) {
  1928. if (lastMessage) {
  1929. //目前是text 类型的消息
  1930. var jsonbody = lastMessage.body;
  1931. var body = JSON.parse(jsonbody);
  1932. if (this.lastMessageNode) {
  1933. if (body.type == "emoji") { //表情 消息
  1934. var imgPath = "";
  1935. for (var i = 0; i < this.main.emojiList.length; i++) {
  1936. var emoji = this.main.emojiList[i];
  1937. if (emoji.key == body.body) {
  1938. imgPath = emoji.path;
  1939. }
  1940. }
  1941. this.lastMessageNode.empty();
  1942. new Element("img", { "src": imgPath, "style": "width: 16px;height: 16px;" }).inject(this.lastMessageNode);
  1943. } else { //文本消息
  1944. this.lastMessageNode.empty();
  1945. this.lastMessageNode.set('text', body.body);
  1946. }
  1947. }
  1948. var time = this.main._friendlyTime(o2.common.toDate(lastMessage.createTime));
  1949. if (this.messageTimeNode) {
  1950. this.messageTimeNode.set("text", time);
  1951. }
  1952. }
  1953. },
  1954. // 更新聊天窗口上的标题 修改标题的时候使用 @Disuse 使用refreshData
  1955. refreshConvTitle: function (title) {
  1956. this.titleNode.set("text", title);
  1957. },
  1958. // 更新会话数据
  1959. refreshData: function (data) {
  1960. this.data = data;
  1961. // 更新聊天窗口上的标题 修改标题的时候使用
  1962. this.titleNode.set("text", data.title);
  1963. },
  1964. addCheckClass: function () {
  1965. if (this.nodeBaseItem) {
  1966. if (!this.nodeBaseItem.hasClass("check")) {
  1967. this.nodeBaseItem.addClass("check");
  1968. }
  1969. }
  1970. },
  1971. removeCheckClass: function () {
  1972. if (this.nodeBaseItem) {
  1973. if (this.nodeBaseItem.hasClass("check")) {
  1974. this.nodeBaseItem.removeClass("check");
  1975. }
  1976. }
  1977. }
  1978. });
  1979. //弹出窗 表单 单聊创建的form
  1980. MWF.xApplication.IMV2.SingleForm = new Class({
  1981. Extends: MPopupForm,
  1982. Implements: [Options, Events],
  1983. options: {
  1984. "style": "minder",
  1985. "width": 700,
  1986. //"height": 300,
  1987. "height": "200",
  1988. "hasTop": true,
  1989. "hasIcon": false,
  1990. "draggable": true,
  1991. "title": MWF.xApplication.IMV2.LP.createSingle
  1992. },
  1993. _createTableContent: function () {
  1994. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  1995. "<tr><td styles='formTableTitle' lable='person' width='25%'></td>" +
  1996. " <td styles='formTableValue14' item='person' colspan='3'></td></tr>" +
  1997. "</table>";
  1998. this.formTableArea.set("html", html);
  1999. var me = layout.session.user.distinguishedName;
  2000. var exclude = [];
  2001. if (me) {
  2002. exclude = [me];
  2003. }
  2004. this.form = new MForm(this.formTableArea, this.data || {}, {
  2005. isEdited: true,
  2006. style: "minder",
  2007. hasColon: true,
  2008. itemTemplate: {
  2009. person: { text: MWF.xApplication.IMV2.LP.selectPerson, type: "org", orgType: "person", count: 0, notEmpty: true, exclude: exclude },
  2010. }
  2011. }, this.app);
  2012. this.form.load();
  2013. },
  2014. _createBottomContent: function () {
  2015. if (this.isNew || this.isEdited) {
  2016. this.okActionNode = new Element("button.inputOkButton", {
  2017. "styles": this.css.inputOkButton,
  2018. "text": MWF.xApplication.IMV2.LP.ok
  2019. }).inject(this.formBottomNode);
  2020. this.okActionNode.addEvent("click", function (e) {
  2021. this.save(e);
  2022. }.bind(this));
  2023. }
  2024. this.cancelActionNode = new Element("button.inputCancelButton", {
  2025. "styles": (this.isEdited || this.isNew || this.getEditPermission()) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  2026. "text": MWF.xApplication.IMV2.LP.close
  2027. }).inject(this.formBottomNode);
  2028. this.cancelActionNode.addEvent("click", function (e) {
  2029. this.close(e);
  2030. }.bind(this));
  2031. },
  2032. save: function () {
  2033. var data = this.form.getResult(true, null, true, false, true);
  2034. if (data) {
  2035. this.app.newConversation(data.person, "single");
  2036. this.close();
  2037. }
  2038. }
  2039. });
  2040. //创建聊天 弹出窗表单
  2041. MWF.xApplication.IMV2.CreateConversationForm = new Class({
  2042. Extends: MPopupForm,
  2043. Implements: [Options, Events],
  2044. options: {
  2045. "style": "minder",
  2046. "width": 700,
  2047. "height": "200",
  2048. "hasTop": true,
  2049. "hasIcon": false,
  2050. "draggable": true,
  2051. "title": MWF.xApplication.IMV2.LP.createSingle,
  2052. "personCount": 1, //1 是单选 0 是多选,
  2053. "personSelected": [],
  2054. "isUpdateMember": false
  2055. },
  2056. _createTableContent: function () {
  2057. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  2058. "<tr><td styles='formTableTitle' lable='person' width='25%'></td>" +
  2059. " <td styles='formTableValue14' item='person' colspan='3'></td></tr>" +
  2060. "</table>";
  2061. this.formTableArea.set("html", html);
  2062. var me = layout.session.user.distinguishedName;
  2063. var exclude = [];
  2064. if (me) {
  2065. exclude = [me];
  2066. }
  2067. this.form = new MForm(this.formTableArea, this.data || {}, {
  2068. isEdited: true,
  2069. style: "minder",
  2070. hasColon: true,
  2071. itemTemplate: {
  2072. person: { text: MWF.xApplication.IMV2.LP.selectPerson, type: "org", orgType: "person", count: this.options["personCount"], notEmpty: true, exclude: exclude, value: this.options["personSelected"] },
  2073. }
  2074. }, this.app);
  2075. this.form.load();
  2076. },
  2077. _createBottomContent: function () {
  2078. if (this.isNew || this.isEdited) {
  2079. this.okActionNode = new Element("button.inputOkButton", {
  2080. "styles": this.css.inputOkButton,
  2081. "text": MWF.xApplication.IMV2.LP.ok
  2082. }).inject(this.formBottomNode);
  2083. this.okActionNode.addEvent("click", function (e) {
  2084. this.save(e);
  2085. }.bind(this));
  2086. }
  2087. this.cancelActionNode = new Element("button.inputCancelButton", {
  2088. "styles": (this.isEdited || this.isNew || this.getEditPermission()) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  2089. "text": MWF.xApplication.IMV2.LP.close
  2090. }).inject(this.formBottomNode);
  2091. this.cancelActionNode.addEvent("click", function (e) {
  2092. this.close(e);
  2093. }.bind(this));
  2094. },
  2095. save: function () {
  2096. var data = this.form.getResult(true, null, true, false, true);
  2097. if (data) {
  2098. if (this.options["isUpdateMember"] === true) {
  2099. this.app.updateConversationMembers(data.person, this.app.conversationId);
  2100. } else {
  2101. this.app.newConversation(data.person, this.options["personCount"] === 1 ? "single" : "group");
  2102. }
  2103. this.close();
  2104. }
  2105. }
  2106. });
  2107. //修改群名
  2108. MWF.xApplication.IMV2.UpdateConvTitleForm = new Class({
  2109. Extends: MPopupForm,
  2110. Implements: [Options, Events],
  2111. options: {
  2112. "style": "minder",
  2113. "width": 500,
  2114. "height": "200",
  2115. "hasTop": true,
  2116. "hasIcon": false,
  2117. "draggable": true,
  2118. "defaultValue": "", // 默认值
  2119. "title": MWF.xApplication.IMV2.LP.modifyGroupName
  2120. },
  2121. _createTableContent: function () {
  2122. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  2123. "<tr><td styles='formTableTitle' lable='title' width='25%'></td>" +
  2124. " <td styles='formTableValue14' item='title' colspan='3'></td></tr>" +
  2125. "</table>";
  2126. this.formTableArea.set("html", html);
  2127. this.form = new MForm(this.formTableArea, this.data || {}, {
  2128. isEdited: true,
  2129. style: "minder",
  2130. hasColon: true,
  2131. itemTemplate: {
  2132. title: { text: MWF.xApplication.IMV2.LP.groupName, type: "text", notEmpty: true, value: this.options["defaultValue"] },
  2133. }
  2134. }, this.app);
  2135. this.form.load();
  2136. },
  2137. _createBottomContent: function () {
  2138. if (this.isNew || this.isEdited) {
  2139. this.okActionNode = new Element("button.inputOkButton", {
  2140. "styles": this.css.inputOkButton,
  2141. "text": MWF.xApplication.IMV2.LP.ok
  2142. }).inject(this.formBottomNode);
  2143. this.okActionNode.addEvent("click", function (e) {
  2144. this.save(e);
  2145. }.bind(this));
  2146. }
  2147. this.cancelActionNode = new Element("button.inputCancelButton", {
  2148. "styles": (this.isEdited || this.isNew || this.getEditPermission()) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  2149. "text": MWF.xApplication.IMV2.LP.close
  2150. }).inject(this.formBottomNode);
  2151. this.cancelActionNode.addEvent("click", function (e) {
  2152. this.close(e);
  2153. }.bind(this));
  2154. },
  2155. save: function () {
  2156. var data = this.form.getResult(true, null, true, false, true);
  2157. if (data) {
  2158. this.app.updateConversationTitle(data.title, this.app.conversationId);
  2159. this.close();
  2160. }
  2161. }
  2162. });