Poll.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //轮训处理
  2. Namespace.register("U.MD.O.P");
  3. /*
  4. * 链接后台,并发送请求
  5. */
  6. U.MD.O.P.connect = function () {
  7. if (US.userInfo.userid) { //判断用户是否登录
  8. U.A.Request(US.SCOKET, ["login", JSON.stringify({ //发送登录请求
  9. pageId: US.pageId,
  10. userId: US.userInfo.userid,
  11. userName: US.userInfo.UserName,
  12. type: US.systemId
  13. })], U.MD.O.P.pollingAsyn); //回调进 U.MD.O.P.pollingAsyn 函数
  14. }
  15. };
  16. /*
  17. * 发送请求进入轮训
  18. */
  19. U.MD.O.P.polling = function () {
  20. U.A.Request(US.SCOKET, ["polling", US.userInfo.userid, US.pageId, US.systemId], U.MD.O.P.pollingAsyn);
  21. //发送轮循 回调进 U.MD.O.P.pollingAsyn函数
  22. }
  23. /*
  24. * 处理从后台返回的数据
  25. *
  26. */
  27. U.MD.O.P.pollingAsyn = function (r) {
  28. r = r.value;
  29. if (r) { //r是否有值
  30. if (r[0] instanceof Array) {
  31. r = r[0];
  32. }
  33. // console.log('获取到的数据:', r)
  34. var _i, _message, _iframe, _contentWindow;
  35. for (_i = 0; _i < r.length; _i++) {
  36. _message = r[_i];
  37. switch (_message.type) {
  38. case 'us.word': //判断是否是word 的消息
  39. // _iframe = $('#UD_Word' + _message.messageInfo.docId + ' iframe')[0];
  40. _iframe = $('#doc iframe')[0];
  41. if (_iframe) {
  42. _contentWindow = _iframe.contentWindow;
  43. if (_message.messageInfo.type == "updateName") {
  44. $('#UD_Word' + _message.messageInfo.docId + ' .U_MD_O_H_head_navigation_Title')[0].value = _message.messageInfo.name;
  45. }
  46. else if (_message.messageInfo.type == "insertModifyRecord") {
  47. _contentWindow.U.MD.O.W.Panel.syncHistory(_message.sendId, _message.messageInfo.historyid);
  48. }
  49. else if (_message.messageInfo.type == "addUser") {
  50. _contentWindow.U.MD.O.W.Panel.syncAddUser(_message.messageInfo.userIds, _message.sendId);
  51. }
  52. else {// if ($('#UD_Word' + _message.messageInfo.docId).css('display') == 'block')
  53. switch (_message.messageInfo.type) {// 判断消息种类
  54. case 'update':
  55. _contentWindow.U.MD.O.W.E.updateEditorLine(_message.messageInfo);
  56. break;
  57. case 'add':
  58. _contentWindow.U.MD.O.W.E.addEditorLine(_message.messageInfo);
  59. break;
  60. case 'delete':
  61. _contentWindow.U.MD.O.W.E.deleteEditorLine(_message.messageInfo);
  62. break;
  63. }
  64. }
  65. }
  66. break;
  67. case 'us.nav':
  68. _iframe = $('#UD_Word' + _message.messageInfo.docId + ' iframe')[0];
  69. if (_message.messageInfo.type == "updateName") {
  70. $('#UD_Word' + _message.messageInfo.docId + ' .U_MD_O_H_head_navigation_Title')[0].value = _message.messageInfo.name;
  71. } else if (_message.messageInfo.type == "addUser") {
  72. _contentWindow.U.MD.O.W.Panel.syncAddUser(_message.messageInfo.userIds, _message.sendId);
  73. }
  74. else if ($('#UD_Word' + _message.messageInfo.docId).css('display') == 'block') {
  75. _contentWindow = _iframe.contentWindow;
  76. switch (_message.messageInfo.type) {// 判断消息种类
  77. case 'update':
  78. _contentWindow.U.MD.O.W.T.N.nowNavId == _message.messageInfo.navId && _contentWindow.U.MD.O.W.E.updateEditorLine(_message.messageInfo);
  79. break;
  80. case 'add':
  81. _contentWindow.U.MD.O.W.T.N.nowNavId == _message.messageInfo.navId && _contentWindow.U.MD.O.W.E.addEditorLine(_message.messageInfo);
  82. break;
  83. case 'delete':
  84. _contentWindow.U.MD.O.W.T.N.nowNavId == _message.messageInfo.navId && _contentWindow.U.MD.O.W.E.deleteEditorLine(_message.messageInfo);
  85. break;
  86. case 'addNav':
  87. _contentWindow.U.MD.O.W.T.N.Poll.addNav(_message.messageInfo);
  88. break;
  89. case 'updateNav':
  90. _contentWindow.U.MD.O.W.T.N.Poll.updateNav(_message.messageInfo);
  91. break;
  92. case 'deleteNav':
  93. _contentWindow.U.MD.O.W.T.N.Poll.deleteNav(_message.messageInfo);
  94. break;
  95. case 'updateLogo':
  96. _contentWindow.U.MD.O.W.T.N.Poll.updateLogo(_message.messageInfo);
  97. break;
  98. }
  99. }
  100. break;
  101. case 'us.excel': //判断是否是word 的消息
  102. _iframe = $('#UD_Excel' + _message.messageInfo.docId + ' iframe')[0];
  103. if (_iframe) {
  104. if (_message.messageInfo.type == "updateName") {
  105. $('#UD_Excel' + _message.messageInfo.docId + ' .U_MD_O_H_head_navigation_Title')[0].value = _message.messageInfo.name;
  106. }
  107. else if (_message.messageInfo.type == "addUser") {
  108. }
  109. else {
  110. _contentWindow = _iframe.contentWindow;
  111. switch (_message.messageInfo.type) {// 判断消息种类
  112. case 'blur':
  113. _contentWindow.U.MD.O.E.Receiver.Blur(_message.messageInfo);
  114. break;
  115. case 'setBorder':
  116. _contentWindow.U.MD.O.E.Receiver.setBorder(_message.messageInfo);
  117. break;
  118. case "addLine":
  119. _contentWindow.U.MD.O.E.Receiver.addLine(_message.messageInfo);
  120. //添加行
  121. break;
  122. case "delLine":
  123. _contentWindow.U.MD.O.E.Receiver.delLine(_message.messageInfo);
  124. //刪除行
  125. break;
  126. case "addCol":
  127. _contentWindow.U.MD.O.E.Receiver.addCol(_message.messageInfo);
  128. //添加列
  129. break;
  130. case "delCol":
  131. _contentWindow.U.MD.O.E.Receiver.delCol(_message.messageInfo);
  132. //刪除列
  133. break;
  134. case "merge":
  135. _contentWindow.U.MD.O.E.Receiver.merge(_message.messageInfo);
  136. //合并单元格
  137. break;
  138. case "splitCells":
  139. _contentWindow.U.MD.O.E.Receiver.splitCells(_message.messageInfo);
  140. //拆分单元格
  141. break;
  142. case "rowExpanding":
  143. _contentWindow.U.MD.O.E.Receiver.rowExpanding(_message.messageInfo);
  144. //行板拉伸
  145. break;
  146. case "colExpanding":
  147. _contentWindow.U.MD.O.E.Receiver.colExpanding(_message.messageInfo);
  148. //列板拉伸
  149. break;
  150. case "addTask":
  151. _contentWindow.U.MD.O.E.Receiver.addTask(_message.messageInfo);
  152. break;
  153. case "deleteTask":
  154. _contentWindow.U.MD.O.E.Receiver.deleteTask(_message.messageInfo);
  155. break;
  156. case "reNameTask":
  157. _contentWindow.U.MD.O.E.Receiver.reNameTask(_message.messageInfo);
  158. break;
  159. case "img":
  160. _contentWindow.U.MD.O.E.Receiver.img(_message.messageInfo);
  161. //插入图片
  162. break;
  163. case "imgChange": //图片拉伸及拖拽
  164. _contentWindow.U.MD.O.E.Receiver.imgChange(_message.messageInfo);
  165. break;
  166. case "excelAddHref": //插入链接
  167. _contentWindow.U.MD.O.E.Receiver.excelAddHref(_message.messageInfo);
  168. break;
  169. case "clearAContent": //删除链接
  170. _contentWindow.U.MD.O.E.Receiver.clearAContent(_message.messageInfo);
  171. break;
  172. }
  173. }
  174. }
  175. break;
  176. case 'us.mindNetwork':
  177. // _iframe = $('#mindNetwork' + _message.messageInfo.docId)[0];
  178. _iframe = $('#mindNetwork iframe')[0];
  179. if (_iframe) {
  180. _contentWindow = _iframe.contentWindow;
  181. // if (_message.messageInfo.type == "addUser") {
  182. // _contentWindow.postMessage({ cid: cid, type: "mindNetwork_addUser" }, "*")
  183. // }
  184. // else
  185. // if ($('#mindNetwork' + _message.messageInfo.docId).css('display') == 'block') {
  186. switch (_message.messageInfo.type) {// 判断消息种类
  187. case 'update':
  188. _contentWindow.postMessage({ info: _message.messageInfo, type: "mindNetwork_update" }, "*")
  189. break;
  190. case 'delete':
  191. _contentWindow.postMessage({ info: _message.messageInfo, type: "mindNetwork_delete" }, "*")
  192. break;
  193. case 'move':
  194. _contentWindow.postMessage({ info: _message.messageInfo, type: "mindNetwork_move" }, "*")
  195. break;
  196. }
  197. // }
  198. }
  199. break;
  200. case 'us.realTimeClass':
  201. _iframe = $('#studentClassRoom iframe')[0];
  202. if (_iframe) {
  203. _contentWindow = _iframe.contentWindow;
  204. switch (_message.messageInfo.type) {// 判断消息种类
  205. case 'update'://修改页码
  206. _contentWindow.postMessage({ info: _message.messageInfo, type: "realTimeClass_update" }, "*")
  207. break;
  208. }
  209. // }
  210. }
  211. break;
  212. }
  213. }
  214. }
  215. U.MD.O.P.polling(); //进入轮循
  216. }