123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- //轮训处理
- Namespace.register("U.MD.O.P");
- //设置是否允许连接
- U.MD.O.P.isconnect = true;
- /*
- * 链接后台,并发送请求
- */
- U.MD.O.P.connect = function () {
- if (US.userInfo.userid) { //判断用户是否登录
- U.MD.O.P.polling(["login", JSON.stringify({ //发送登录请求
- pageId: US.pageId,
- userId: US.userInfo.userid,
- userName: US.userInfo.username,
- type: US.systemId
- })]);
- }
- };
- /*
- * 数据处理
- */
- U.MD.O.P.dataAsyn = function () {
- }
- /*
- * 发送请求进入轮训
- */
- U.MD.O.P.polling = function (params) {
- if (U.MD.O.P.isconnect) {
- U.MD.O.P.isconnect = false;
- params = params || ["polling", US.userInfo.userid, US.pageId, US.systemId]
- var start = 0;
- var delimiter = "\r\n"
- var end = 0;
- var text = "";
- var xhr = new XMLHttpRequest();
- var data = "";
- //var time = null;
- //
- var fun = function () {
- //clearTimeout(time)
- text = xhr.responseText;
- var istrue = true;
- while (start < text.length && istrue) {
- end = text.indexOf(delimiter, start);//获取数据的是否已经结束
- if (end > -1) {
- data += text.substring(start, end);
- start = end + delimiter.length;
- try {
- U.MD.O.P.pollingAsyn({ value: JSON.parse(data) })
- }
- catch (e) {
- console.log(e);
- }
- data = "";
- }
- else {
- istrue = false;
- //time = setTimeout(fun, 500);//
- }
- }
- };
- xhr.open("POST", US.SCOKET, true);
- xhr.onreadystatechange = function () {
- //获取数据
- if (xhr.readyState == 3 && xhr.status == 200) {
- fun();
- }
- //结束重连
- else if (xhr.readyState == 4) {
- console.log(xhr);
- U.MD.O.P.isconnect = true;
- U.MD.O.P.connect();
- }
- };
- //超时重新连接
- xhr.onerror = function (err) {
- console.log(err);
- };
- try {
- //发送请求
- xhr.send(U.A.Request.toAjaxFormat(params));
- }
- catch (e) {
- console.log(e);
- }
- }
- }
- /*
- * 处理从后台返回的数据
- *
- */
- U.MD.O.P.pollingAsyn = function (r) {
- r = r.value;
- if (r) { //r是否有值
- if (r[0] instanceof Array) {
- r = r[0];
- }
- // console.log('获取到的数据:', r)
- var _i, _message, _iframe, _contentWindow;
- for (_i = 0; _i < r.length; _i++) {
- _message = r[_i];
- switch (_message.type) {
- case 'us.word': //判断是否是word 的消息
- // _iframe = $('#UD_Word' + _message.messageInfo.docId + ' iframe')[0];
- _iframe = $('#doc iframe')[0];
- if (_iframe) {
- _contentWindow = _iframe.contentWindow;
- if (_message.messageInfo.type == "updateName") {
- $('#UD_Word' + _message.messageInfo.docId + ' .U_MD_O_H_head_navigation_Title')[0].value = _message.messageInfo.name;
- }
- else if (_message.messageInfo.type == "insertModifyRecord") {
- _contentWindow.U.MD.O.W.Panel.syncHistory(_message.sendId, _message.messageInfo.historyid);
- }
- else if (_message.messageInfo.type == "addUser") {
- _contentWindow.U.MD.O.W.Panel.syncAddUser(_message.messageInfo.userIds, _message.sendId);
- }
- else {// if ($('#UD_Word' + _message.messageInfo.docId).css('display') == 'block')
- switch (_message.messageInfo.type) {// 判断消息种类
- case 'update':
- _contentWindow.U.MD.O.W.E.updateEditorLine(_message.messageInfo);
- break;
- case 'add':
- _contentWindow.U.MD.O.W.E.addEditorLine(_message.messageInfo);
- break;
- case 'delete':
- _contentWindow.U.MD.O.W.E.deleteEditorLine(_message.messageInfo);
- break;
- }
- }
- }
- break;
- case 'us.nav':
- _iframe = $('#UD_Word' + _message.messageInfo.docId + ' iframe')[0];
- if (_message.messageInfo.type == "updateName") {
- $('#UD_Word' + _message.messageInfo.docId + ' .U_MD_O_H_head_navigation_Title')[0].value = _message.messageInfo.name;
- } else if (_message.messageInfo.type == "addUser") {
- _contentWindow.U.MD.O.W.Panel.syncAddUser(_message.messageInfo.userIds, _message.sendId);
- }
- else if ($('#UD_Word' + _message.messageInfo.docId).css('display') == 'block') {
- _contentWindow = _iframe.contentWindow;
- switch (_message.messageInfo.type) {// 判断消息种类
- case 'update':
- _contentWindow.U.MD.O.W.T.N.nowNavId == _message.messageInfo.navId && _contentWindow.U.MD.O.W.E.updateEditorLine(_message.messageInfo);
- break;
- case 'add':
- _contentWindow.U.MD.O.W.T.N.nowNavId == _message.messageInfo.navId && _contentWindow.U.MD.O.W.E.addEditorLine(_message.messageInfo);
- break;
- case 'delete':
- _contentWindow.U.MD.O.W.T.N.nowNavId == _message.messageInfo.navId && _contentWindow.U.MD.O.W.E.deleteEditorLine(_message.messageInfo);
- break;
- case 'addNav':
- _contentWindow.U.MD.O.W.T.N.Poll.addNav(_message.messageInfo);
- break;
- case 'updateNav':
- _contentWindow.U.MD.O.W.T.N.Poll.updateNav(_message.messageInfo);
- break;
- case 'deleteNav':
- _contentWindow.U.MD.O.W.T.N.Poll.deleteNav(_message.messageInfo);
- break;
- case 'updateLogo':
- _contentWindow.U.MD.O.W.T.N.Poll.updateLogo(_message.messageInfo);
- break;
- }
- }
- break;
- case 'us.excel': //判断是否是word 的消息
- _iframe = $('#UD_Excel' + _message.messageInfo.docId + ' iframe')[0];
- if (_iframe) {
- if (_message.messageInfo.type == "updateName") {
- $('#UD_Excel' + _message.messageInfo.docId + ' .U_MD_O_H_head_navigation_Title')[0].value = _message.messageInfo.name;
- }
- else if (_message.messageInfo.type == "addUser") {
- }
- else {
- _contentWindow = _iframe.contentWindow;
- switch (_message.messageInfo.type) {// 判断消息种类
- case 'blur':
- _contentWindow.U.MD.O.E.Receiver.Blur(_message.messageInfo);
- break;
- case 'setBorder':
- _contentWindow.U.MD.O.E.Receiver.setBorder(_message.messageInfo);
- break;
- case "addLine":
- _contentWindow.U.MD.O.E.Receiver.addLine(_message.messageInfo);
- //添加行
- break;
- case "delLine":
- _contentWindow.U.MD.O.E.Receiver.delLine(_message.messageInfo);
- //刪除行
- break;
- case "addCol":
- _contentWindow.U.MD.O.E.Receiver.addCol(_message.messageInfo);
- //添加列
- break;
- case "delCol":
- _contentWindow.U.MD.O.E.Receiver.delCol(_message.messageInfo);
- //刪除列
- break;
- case "merge":
- _contentWindow.U.MD.O.E.Receiver.merge(_message.messageInfo);
- //合并单元格
- break;
- case "splitCells":
- _contentWindow.U.MD.O.E.Receiver.splitCells(_message.messageInfo);
- //拆分单元格
- break;
- case "rowExpanding":
- _contentWindow.U.MD.O.E.Receiver.rowExpanding(_message.messageInfo);
- //行板拉伸
- break;
- case "colExpanding":
- _contentWindow.U.MD.O.E.Receiver.colExpanding(_message.messageInfo);
- //列板拉伸
- break;
- case "addTask":
- _contentWindow.U.MD.O.E.Receiver.addTask(_message.messageInfo);
- break;
- case "deleteTask":
- _contentWindow.U.MD.O.E.Receiver.deleteTask(_message.messageInfo);
- break;
- case "reNameTask":
- _contentWindow.U.MD.O.E.Receiver.reNameTask(_message.messageInfo);
- break;
- case "img":
- _contentWindow.U.MD.O.E.Receiver.img(_message.messageInfo);
- //插入图片
- break;
- case "imgChange": //图片拉伸及拖拽
- _contentWindow.U.MD.O.E.Receiver.imgChange(_message.messageInfo);
- break;
- case "excelAddHref": //插入链接
- _contentWindow.U.MD.O.E.Receiver.excelAddHref(_message.messageInfo);
- break;
- case "clearAContent": //删除链接
- _contentWindow.U.MD.O.E.Receiver.clearAContent(_message.messageInfo);
- break;
- }
- }
- }
- break;
- case 'us.mindNetwork':
- // _iframe = $('#mindNetwork' + _message.messageInfo.docId)[0];
- _iframe = $('#mindNetwork iframe')[0];
- if (_iframe) {
- _contentWindow = _iframe.contentWindow;
- // if (_message.messageInfo.type == "addUser") {
- // _contentWindow.postMessage({ cid: cid, type: "mindNetwork_addUser" }, "*")
- // }
- // else
- // if ($('#mindNetwork' + _message.messageInfo.docId).css('display') == 'block') {
- switch (_message.messageInfo.type) {// 判断消息种类
- case 'update':
- _contentWindow.postMessage({ info: _message.messageInfo, type: "mindNetwork_update" }, "*")
- break;
- case 'delete':
- _contentWindow.postMessage({ info: _message.messageInfo, type: "mindNetwork_delete" }, "*")
- break;
- case 'move':
- _contentWindow.postMessage({ info: _message.messageInfo, type: "mindNetwork_move" }, "*")
- break;
- }
- // }
- }
- break;
- case 'us.realTimeClass':
- _iframe = $('#studentClassRoom iframe')[0];
- if (_iframe) {
- _contentWindow = _iframe.contentWindow;
- switch (_message.messageInfo.type) {// 判断消息种类
- case 'update'://修改页码
- _contentWindow.postMessage({ info: _message.messageInfo, type: "realTimeClass_update" }, "*")
- break;
- }
- // }
- }
- break;
- case 'us.cscl':
- _iframe = $('#futureClass iframe')[0];
- if (_iframe) {
- _contentWindow = _iframe.contentWindow;
- _contentWindow.postMessage({ info: _message.messageInfo, type: _message.messageInfo.type }, "*");
- }
- break;
- }
- }
- }
- //U.MD.O.P.polling(); //进入轮循
- }
|