message.js 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372
  1. var us = {}; //全局的命名空间
  2. us.cheerio = require("cheerio"); //dom处理类
  3. us.qs = require("querystring"); //引用文件解析包
  4. us.http = require("http"); //引用http server服务
  5. us.mysql = require("./mysql.js"); //引用执行存储过程包
  6. /**
  7. * 用户的链接池集合,以用户id作为搜索键
  8. **/
  9. us.connect = {
  10. //userguid:{pageid : us.userConnect, pageid : us.userConnect}
  11. }
  12. /**
  13. * 用户的数据集合集合,以用户id作为搜索键
  14. **/
  15. us.user = {
  16. //userId : userInfo //用户连接(请求), 这里可以是http短连接可以使socket长连接
  17. }
  18. /**
  19. * 未来课堂数据结构
  20. **/
  21. us.cscl = {
  22. //"nodes":[{"id":"9f6d7459-d376-4c0c-944b-a6b140085903","type":"icon-start","x":625,"y":145,"properties":{},"zIndex":1002,"text":{"x":625,"y":145,"value":"起始"}},{"id":"16e18308-7517-4162-8b32-a877b7cf42a0","type":"icon-card","x":325,"y":445,"properties":{},"zIndex":1002},{"id":"5c492b0d-092d-4d84-bd70-4d5734de9266","type":"icon-select","x":970,"y":510,"properties":{},"zIndex":1002}],
  23. //"edges":[],
  24. //"backgroundUrl":"img/bg.ccee1c62.png"
  25. }
  26. /**
  27. * 离线数据
  28. **/
  29. us.offLineMessage = {
  30. //pageId : us.userOffLineMessage
  31. }
  32. /**
  33. * 思维网格
  34. **/
  35. us.mindNetwork = {
  36. // mindid: {
  37. // }
  38. }
  39. /**
  40. * 同步课堂
  41. **/
  42. us.realTimeClass = {
  43. // mindid: {
  44. // }
  45. }
  46. //文档列表
  47. us.word = {
  48. //docId : {
  49. // user : {userId : [pageId, pageId],
  50. // userId : [pageId, pageId]},
  51. // content : docel,
  52. // history : [operand(操作信息对象), operand(操作信息对象)]
  53. // } //群信息结构
  54. //docId : {user : {userId : [pageId, pageId], userId : [pageId, pageId]}, content : docel, history : [operand(操作信息对象), operand(操作信息对象)] } //文档信息结构
  55. }
  56. //excel列表
  57. us.excel = {
  58. //excelId : {user : {userId : [pageId, pageId], userId : [pageId, pageId]}, content : docel, history : [operand(操作信息对象), operand(操作信息对象)], name : 文件名 } //群信息结构
  59. //excelId : {user : {userId : [pageId, pageId], userId : [pageId, pageId]}, content : docel, history : [operand(操作信息对象), operand(操作信息对象)], name : 文件名 } //群信息结构
  60. }
  61. //导航文件列表
  62. us.nav = {
  63. //fileId : {
  64. // user : {userId : [pageId, pageId], userId : [pageId, pageId]},
  65. // navInfo : {
  66. // logo : '',
  67. // nav : [ {pageId: '', name : ''}, {pageId: '', name : '', child :[ {pageId: '', name : ''} ]} ]
  68. // },
  69. // page : {pageId : pageContent, pageId : pageContent},
  70. // history : [operand(操作信息对象), operand(操作信息对象)]
  71. //} //导航文档数据结构
  72. }
  73. /**
  74. * 用户链接类
  75. *
  76. * @param {string} pageId 页面ID(用户登录唯一识别ID)
  77. * @param {object} response 对象
  78. **/
  79. us.userConnect = function (pageId, response) {
  80. return {
  81. "pageId": pageId, //登录用户唯一识别id
  82. "response": response, //这里可以是http短连接以后可以换成socket长连接
  83. "loginTime": new Date(), //用户登录时间
  84. "offLineTime": null //用户下线时间
  85. }
  86. }
  87. /**
  88. * 用户数据类
  89. *
  90. * @param {string} requset对象
  91. * @param {object} response对象
  92. **/
  93. us.userInfo = function (userid, username) {
  94. return {
  95. "userId": userid, //用户id
  96. "userName": username //用户名
  97. }
  98. }
  99. /**
  100. * 用户离线数据
  101. * @param {string} type 用户登录类型
  102. */
  103. us.userOffLineMessage = function (type) {
  104. return {
  105. "message": [], //用户的消息数组
  106. "type": type, //链接的端 pc或者pho
  107. "word": [], //word数据
  108. "excel": [], //excel数据
  109. "mindNetwork": [], //思维网格数据
  110. "realTimeClass": [], //实施课堂数据
  111. "cscl": [], //未来课堂数据
  112. "nav": [] //导航模式数据
  113. }
  114. }
  115. /**
  116. * 用户的离线消息结构
  117. *
  118. * @param {string} sendid 发送者id
  119. * @param {string} type 发送的类型, 俱乐部使用时用us开头,后面带用途。例如us.disk或者us.friend us.word
  120. * @param {string} messageinfo 的处理
  121. **/
  122. us.message = function (sendid, type, messageinfo) {
  123. return {
  124. "id": us.createGuid(), //新生成的guid
  125. "sendId": sendid, //发送消息人的id.
  126. "time": new Date(), //发送时间
  127. "type": type, //类型 俱乐部使用时用us开头,后面带用途。例如us.disk或者us.friend us.word
  128. "messageInfo": messageinfo //{消息结构} 此处为object 如类型为'us.word' 则消息结构为us.word
  129. }
  130. }
  131. /*
  132. messageinfo 消息结构的处理
  133. {
  134. id: string, //行id 多行时用逗号隔开的形式 guid,guid,guid,guid
  135. type: string, // 处理的类型 如:"add"||"delete"||"update"
  136. docId: string, // "guid" 文档id
  137. pageId: pageid, //页面唯一识别ID
  138. content: string // 变化的内容 add的时候为添加到添加行的下一行
  139. nextId : string //下一行id
  140. }
  141. */
  142. process.on('uncaughtException', (e) => {
  143. console.error('process error is:', e.message);
  144. });
  145. /**
  146. * 创建服务
  147. *
  148. * @param {object} requset 请求对象
  149. * @param {object} response 响应对象
  150. **/
  151. us.server = us.http.createServer(function (requset, response) {
  152. //设置跨域
  153. response.writeHead(200, {
  154. "Content-Type": "text/html;application/json;charset=utf-8",
  155. 'Access-Control-Allow-Origin': '*',
  156. 'Access-Control-Allow-Headers': 'Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With'
  157. });
  158. //设置参数,并执行回调
  159. us.unifyDispose(requset, response, function (param) {
  160. //console.log(param)
  161. if (param && param[0]) {
  162. //参数解码 us.parm为全局变量 记录所有参数
  163. var _userinfo,
  164. _funname = param[0],
  165. //参数解码 中文处理
  166. _param = param.splice(1);
  167. //执行回调函数
  168. switch (_funname) {
  169. //执行登录函数
  170. case 'login':
  171. _userinfo = JSON.parse(_param[0]); //登录用户的信息
  172. us.login(response, _userinfo.userId, _userinfo.pageId, _userinfo.userName, _userinfo.type);
  173. break;
  174. case 'logout':
  175. us.logout(response, _param[0], _param[1]);
  176. break;
  177. //执行轮询函数
  178. case 'polling':
  179. us.polling(response, _param[0], _param[1], _param[2], _param[3]);
  180. break;
  181. //获取文档信息
  182. case 'getWord':
  183. us.getWord(response, _param[0], _param[1], _param[2]);
  184. break;
  185. //获取Excel信息
  186. case 'getExcel':
  187. us.getExcel(response, _param[0], _param[1], _param[2]);
  188. break;
  189. //获取导航文件信息
  190. case 'getNav':
  191. us.getNav(response, _param[0], _param[1], _param[2]);
  192. break;
  193. //获取思维网格信息
  194. case 'getMindNetwork':
  195. us.getMindNetwork(response, _param[0], _param[1], _param[2]);
  196. break;
  197. //获取未来课堂信息
  198. case 'getcscl':
  199. us.getcscl(response, _param[0], _param[1], _param[2]);
  200. break;
  201. //获取文档信息
  202. case 'getRealTimeClass':
  203. us.getRealTimeClass(response, _param[0], _param[1], _param[2]);
  204. break;
  205. case 'getNavPageContent':
  206. us.getNavPageContent(response, _param[0], _param[1]);
  207. break;
  208. //执行发送函数
  209. case 'send':
  210. us.send(response, _param[0]);
  211. break;
  212. case 'quitOffice':
  213. us.quitOffice(response, _param[0]);
  214. break;
  215. case 'newWordSave':
  216. us.newWordSave(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
  217. break;
  218. case 'newExcelSave':
  219. us.newExcelSave(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
  220. break;
  221. //新建导航文件保存
  222. case 'newNavSave':
  223. //, _param[5], _param[6], _param[7]
  224. us.newNavSave(response, _param[0], _param[1], _param[2], _param[3], _param[4], _param[5], _param[6]);
  225. break;
  226. //加入文档编辑
  227. case 'addWord':
  228. //us.addWord(response, _param[0]);
  229. break;
  230. //加入Excel表格编辑
  231. case 'addExcel':
  232. us.addExcel(response, _param[0]);
  233. break;
  234. //加入导航文件
  235. case 'addNav':
  236. break;
  237. case 'copyPageContent':
  238. us.copyPageContent(response, _param[0], _param[1], _param[2], _param[3]);
  239. break;
  240. case 'updateName':
  241. us.updateName(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
  242. break;
  243. case 'insertModifyRecord':
  244. us.insertModifyRecord(response, _param[0], _param[1], _param[2], _param[3], _param[4], _param[4]);
  245. break;
  246. case 'addUser':
  247. us.addUser(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
  248. break;
  249. //其余执行
  250. default:
  251. response.end(0);
  252. }
  253. }
  254. else {
  255. response.end("");
  256. }
  257. });
  258. });
  259. /**
  260. * 协同历史(带保存功能,修改了存储过程 既添加历史也保存内容)
  261. *
  262. * @param {object} request 请求对象
  263. * @param {string} type 类型
  264. * @param {guid} fileid 文件id
  265. * @param {string} filename 文件名
  266. * @param {string} html 内容
  267. * @param {guid} userid 用户ID
  268. * @param {guid} pageid 页面ID
  269. **/
  270. us.insertModifyRecord = function (response, type, fileid, filename, html, userid, pageid) {
  271. var _html;
  272. if (us[type][fileid] && us[type][fileid].content) {
  273. _html = us[type][fileid].content('body').html().replace(/'/ig, "''").replace(/"/ig, "\\\"");
  274. } else {
  275. _html = html;
  276. }
  277. //发送保存文件请求
  278. us.mysql.usselect([
  279. '127.0.0.1',
  280. 'UseStudio_Office',
  281. 'InsertDocumentModifyRecord',
  282. userid,
  283. fileid,
  284. _html,
  285. filename
  286. ], function (ret) {
  287. if (ret) {
  288. var _historyid = JSON.parse(ret)[0][0].historyid;
  289. var _message = {};
  290. var _messageinfo = us.message(userid, 'us.' + type, {
  291. id: us.createGuid(),
  292. type: "insertModifyRecord",
  293. historyid: _historyid,
  294. docId: fileid
  295. });
  296. _message[fileid] = [_messageinfo];
  297. us.broadcast(_message, pageid, type);
  298. response.end(_historyid); //返回文档内容
  299. } else {
  300. response.end(ret); //返回文档内容
  301. }
  302. });
  303. }
  304. /**
  305. * 更新文件名
  306. *
  307. * @param {object} request 请求对象
  308. * @param {string} type 类型
  309. * @param {guid} fileid 文件id
  310. * @param {string} filename 文件名
  311. * @param {guid} userid 用户ID
  312. * @param {guid} pageid 页面ID
  313. **/
  314. us.updateName = function (response, type, fileid, filename, userid, pageid) {
  315. //发送保存文件请求
  316. us.mysql.usselect([
  317. 'sqlserver.1473.cn',
  318. 'UseStudio_Disk',
  319. 'UpdateFileInfo',
  320. fileid,
  321. filename
  322. ], function (ret) {
  323. if (ret) {
  324. var _message = {};
  325. var _messageinfo = us.message(userid, 'us.' + type, {
  326. id: us.createGuid(),
  327. type: "updateName",
  328. name: filename,
  329. docId: fileid
  330. });
  331. _message[fileid] = [_messageinfo];
  332. us.broadcast(_message, pageid, type);
  333. response.end('updateNameSuccess'); //返回文档内容
  334. } else {
  335. response.end('updateNameFail'); //返回文档内容
  336. }
  337. });
  338. }
  339. /**
  340. * 添加用户
  341. *
  342. * @param {object} request 请求对象
  343. * @param {string} type 类型
  344. * @param {guid} fileid 文件id
  345. * @param {string} userids 用户id(多个用逗号隔开)
  346. * @param {guid} userid 用户ID
  347. * @param {guid} pageid 页面ID
  348. **/
  349. us.addUser = function (response, type, fileid, userids, userid, pageid) {
  350. var _message = {};
  351. var _messageinfo = us.message(userid, 'us.' + type, {
  352. id: us.createGuid(),
  353. type: "addUser",
  354. userIds: userids,
  355. docId: fileid
  356. });
  357. _message[fileid] = [_messageinfo];
  358. us.broadcast(_message, pageid, type);
  359. response.end('addUserSuccess'); //返回文档内容
  360. }
  361. /**
  362. * 获取用户传参异步
  363. *
  364. * @param {object} request 请求对象
  365. * @param {function} cb 回调函数
  366. **/
  367. us.unifyDispose = function (req, res, cb) {
  368. var i, _param = "";
  369. //接收参数
  370. req.on("data", function (chunk) {
  371. _param += chunk;
  372. });
  373. //接收完毕
  374. req.on("end", function () {
  375. //console.log(_param)
  376. //前端传入的字符串转化成对象
  377. if (_param) {
  378. _param = us.qs.parse(_param);
  379. }
  380. //console.log(_param)
  381. //拆分参数
  382. try {
  383. _param = _param.mode.split(",")
  384. } catch (e) {
  385. _param = req.query;
  386. }
  387. if (_param) {
  388. //循环解析,由于前端发送过来的信息是经过url加密的,这里是解密
  389. for (i = 0; i < _param.length; i++) {
  390. _param[i] = decodeURIComponent(_param[i]); //解析
  391. }
  392. } else {
  393. _param = [];
  394. }
  395. //回调到指定处理
  396. cb(_param);
  397. });
  398. //请求超时处理
  399. res.on('timeout', function (e) {
  400. try {
  401. console.log('请求超时'); //错误消息的输出
  402. if (req.res) {
  403. req.res("abort");
  404. }
  405. res.end("false"); //返回值
  406. }
  407. catch (e) {
  408. console.error('process error is:', e.message);
  409. }
  410. });
  411. //设置30秒后超时
  412. res.setTimeout(30000, function () {
  413. try {
  414. console.log("响应超时.");
  415. res.end("false"); //返回值
  416. }
  417. catch (e) {
  418. console.error('process error is:', e.message);
  419. }
  420. });
  421. //错误处理
  422. req.on("error", function (e) {
  423. try {
  424. console.log('程序报错');
  425. res.end("false");
  426. }
  427. catch (e) {
  428. console.error('process error is:', e.message);
  429. }
  430. });
  431. }
  432. /**
  433. * 获取用户传参异步
  434. *
  435. * @param {object} response 响应对象
  436. * @param {array} userid 用户ID
  437. * @param {string} pageid 页面ID(登录唯一识别ID)
  438. * @param {string} username 用户名
  439. * @param {type} username 用户登录类型
  440. **/
  441. us.login = function (response, userid, pageid, username, type) {
  442. //console.log(userid);
  443. //用户登录信息表,以后移入redis
  444. //如果用户信息不存在则新建一个用户信息存入
  445. if (!us.user[userid]) {
  446. var _userinfo = us.userInfo(userid, username); //初始化用户信息
  447. us.user[userid] = _userinfo;
  448. }
  449. //console.log(us.user);
  450. //添加用户轮询列表
  451. us.polling(response, userid, pageid, type);
  452. }
  453. /**
  454. * 用户下线
  455. * @param {object} response 响应对象
  456. * @param {string} userid 用户ID
  457. * @param {string} pageid 页面ID(唯一识别ID)
  458. */
  459. us.offLine = function (response, userid, pageid) {
  460. //更新用户登出时间
  461. us.user[userid].offineTime = new Date();
  462. //获取用户连接的文档消息
  463. var _joinword = us.offLineMessage[pageid].word;
  464. var _joinexcel = us.offLineMessage[pageid].excel;
  465. var _docuser, _now; //记录用户在数组的位置
  466. var i, j, o; //定义循环变量
  467. //退出协同word
  468. for (i = 0; i < _joinword.length; i++) {
  469. _docuser = us.word[_joinword[i]].user[userid];
  470. _now = _docuser.indexOf(pageid);
  471. _now != -1 && us.word[_joinword[i]].user.splice(_now, 1);
  472. }
  473. //退出协同Excel
  474. for (j = 0; j < _joinexcel.length; j++) {
  475. _docuser = us.excel[_joinexcel[j]].user[userid];
  476. _now = _docuser.indexOf(pageid);
  477. _now != -1 && us.excel[_joinexcel[j]].user.splice(_now, 1);
  478. }
  479. //删除用户连接
  480. delete us.connect[userid][pageid];
  481. //删除用户离校消息记录
  482. delete us.offLineMessage[pageid];
  483. //相应退出
  484. response.end('offLine');
  485. }
  486. /**
  487. * 获取用户传参异步
  488. *
  489. * @param {object} response 响应对象
  490. * @param {string} userid 用户ID
  491. * @param {string} pageid 页面ID(用户登录唯一识别ID)
  492. **/
  493. us.polling = function (response, userid, pageid, type) {
  494. //判断轮询的用户是否在连接池中
  495. if (us.connect[userid]) {
  496. var _userarray = us.connect[userid], //用户连接池,获取制定用户连接的数量,
  497. _messagearray = us.offLineMessage[pageid] //用户离校消息
  498. ;
  499. //获取当前连接的用户,如果获取成功那么直接修改用户的连接
  500. if (_userarray[pageid]) {
  501. _userarray[pageid].response = response;
  502. // console.log(pageid);
  503. if (_messagearray && _messagearray.message.length > 0) {
  504. response.end(JSON.stringify(_messagearray.message));
  505. _messagearray.message = [];
  506. } else {
  507. us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
  508. }
  509. return;
  510. }
  511. //如果用户连接不存在
  512. _userarray[pageid] = us.userConnect(pageid, response); //那么直接添加用户连接 添加到用户连接数组里
  513. us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
  514. } else {
  515. var _userconect = us.userConnect(pageid, response); //创建用户连接对象
  516. us.connect[userid] = {}; //添加用户连接对象
  517. us.connect[userid][pageid] = _userconect;
  518. us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
  519. }
  520. //console.log(us.connect);
  521. }
  522. /**
  523. * 发送消息
  524. *
  525. * @param {object} response 响应对象
  526. * @param {array} messageinfo 参数数组
  527. **/
  528. us.send = function (response, messageinfo) {
  529. var i, j,
  530. _message,
  531. _messagelist = {},
  532. _messageobj = JSON.parse(messageinfo) //获取传入的json对象
  533. ;
  534. //循环用户的信息处理
  535. for (i in _messageobj) {
  536. //console.log(i);
  537. switch (i) {
  538. //思维网格交互
  539. case "us.mindNetwork":
  540. _messagearr = _messageobj[i]; //获取word消息
  541. //得到word所有的用户
  542. for (j = 0; j < _messagearr.length; j++) {
  543. //生成发送的消息结构体
  544. _message = us.message(_messagearr[j].sendId, "us.mindNetwork", _messagearr[j].messageInfo);
  545. //添加消息列表
  546. if (_messagelist[_messagearr[j].receiveId]) {
  547. _messagelist[_messagearr[j].receiveId].push(_message);
  548. } else {
  549. _messagelist[_messagearr[j].receiveId] = [_message];
  550. }
  551. us.mindNetwork[_message.messageInfo.docId] && us.mindNetwork[_message.messageInfo.docId].history.push(_message);
  552. us.updatemindNetwork(_message.messageInfo);
  553. }
  554. //调用群发函数
  555. _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'mindNetwork');
  556. break;
  557. //未来课堂交互
  558. case "us.cscl":
  559. // console.log("================aaaaa===================");
  560. // console.log(_messageobj[i]);
  561. _messagearr = _messageobj[i]; //获取word消息
  562. //得到word所有的用户
  563. for (j = 0; j < _messagearr.length; j++) {
  564. //生成发送的消息结构体
  565. _message = us.message(_messagearr[j].sendId, "us.cscl", _messagearr[j].messageInfo);
  566. //添加消息列表
  567. if (_messagelist[_messagearr[j].receiveId]) {
  568. _messagelist[_messagearr[j].receiveId].push(_message);
  569. }
  570. else {
  571. _messagelist[_messagearr[j].receiveId] = [_message];
  572. }
  573. us.cscl[_messagearr[j].receiveId] && us.cscl[_messagearr[j].receiveId].history.push(_message);
  574. us.updatecscl(_message.messageInfo, _messagearr[j].receiveId, _messagearr[j].type);
  575. }
  576. // console.log(_messagelist)
  577. // console.log(_messagearr)
  578. //调用群发函数
  579. _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].pageId, 'cscl');
  580. break;
  581. //同步课堂
  582. case "us.realTimeClass":
  583. //console.log("us.realTimeClass");
  584. _messagearr = _messageobj[i]; //获取word消息
  585. //得到word所有的用户
  586. for (j = 0; j < _messagearr.length; j++) {
  587. //生成发送的消息结构体
  588. _message = us.message(_messagearr[j].sendId, "us.realTimeClass", _messagearr[j].messageInfo);
  589. //console.log(_message)
  590. // console.log(_messagelist[_messagearr[j].receiveId])
  591. //添加消息列表
  592. if (_messagelist[_messagearr[j].receiveId]) {
  593. _messagelist[_messagearr[j].receiveId].push(_message);
  594. } else {
  595. _messagelist[_messagearr[j].receiveId] = [_message];
  596. }
  597. us.realTimeClass[_message.messageInfo.docId] && us.realTimeClass[_message.messageInfo.docId].history.push(_message);
  598. us.updaterealTimeClass(_message.messageInfo);
  599. }
  600. //调用群发函数
  601. _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'realTimeClass');
  602. break;
  603. //word信息交互
  604. case "us.word":
  605. try {
  606. _messagearr = _messageobj[i]; //获取word消息
  607. //得到word所有的用户
  608. for (j = 0; j < _messagearr.length; j++) {
  609. //生成发送的消息结构体
  610. _message = us.message(_messagearr[j].sendId, "us.word", _messagearr[j].messageInfo);
  611. //添加消息列表
  612. if (_messagelist[_messagearr[j].receiveId]) {
  613. _messagelist[_messagearr[j].receiveId].push(_message);
  614. } else {
  615. _messagelist[_messagearr[j].receiveId] = [_message];
  616. }
  617. us.word[_message.messageInfo.docId] && us.word[_message.messageInfo.docId].history.push(_message);
  618. us.updateWord(_message.messageInfo);
  619. }
  620. //由于不能同时操控多个word发送资料,所有信息只同步一个
  621. //_users = us.word[_messagearr[0].receiveId].user;
  622. //调用群发函数
  623. _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'word');
  624. }
  625. catch (e) {
  626. console.log(e)
  627. }
  628. break;
  629. //用户信息的交互
  630. case "us.excel":
  631. _messagearr = _messageobj[i]; //获取excel消息
  632. //得到excel所有的用户
  633. for (j = 0; j < _messagearr.length; j++) {
  634. //生成发送的消息结构体
  635. _message = us.message(_messagearr[j].sendId, _messagearr[j].type, _messagearr[j].messageInfo);
  636. //添加消息列表
  637. if (_messagelist[_messagearr[j].receiveId]) {
  638. _messagelist[_messagearr[j].receiveId].push(_message);
  639. } else {
  640. _messagelist[_messagearr[j].receiveId] = [_message];
  641. }
  642. us.excel[_message.messageInfo.docId] && us.excel[_message.messageInfo.docId].history.push(_message);
  643. us.updateExcel(_message.messageInfo);
  644. }
  645. //由于不能同时操控多个excel发送资料,所有信息只同步一个
  646. //_users = us.excel[_messagearr[0].receiveId].user;
  647. //调用群发函数
  648. us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'excel');
  649. break;
  650. case "us.nav":
  651. _messagearr = _messageobj[i]; //获取excel消息
  652. //得到excel所有的用户
  653. for (j = 0; j < _messagearr.length; j++) {
  654. //生成发送的消息结构体
  655. _message = us.message(_messagearr[j].sendId, "us.nav", _messagearr[j].messageInfo);
  656. //添加消息列表
  657. if (_messagelist[_messagearr[j].receiveId]) {
  658. _messagelist[_messagearr[j].receiveId].push(_message);
  659. } else {
  660. _messagelist[_messagearr[j].receiveId] = [_message];
  661. }
  662. us.nav[_message.messageInfo.docId] && us.nav[_message.messageInfo.docId].history.push(_message);
  663. us.updateNav(_message.messageInfo);
  664. }
  665. //调用群发函数
  666. us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'nav');
  667. break;
  668. }
  669. }
  670. response.end('send');
  671. }
  672. /**
  673. * 更新后台思维网格的内容
  674. * @param {object} message 消息信息
  675. */
  676. us.updatemindNetwork = function (messageInfo) {
  677. if (us.mindNetwork[messageInfo.docId]) {
  678. var $ = us.mindNetwork[messageInfo.docId].content;
  679. // console.log("---------------------------------------start")
  680. // console.log($);
  681. // console.log("---------------------------------------end")
  682. // console.log("---------------------------------------infostart")
  683. // console.log(messageInfo);
  684. // console.log("---------------------------------------infoend")
  685. if ($) {
  686. us.mindNetwork[messageInfo.docId].content[messageInfo.id] = messageInfo.content;
  687. }
  688. }
  689. }
  690. /**
  691. * 更新后台未来课堂内容
  692. * @param {object} message 消息信息
  693. */
  694. us.updatecscl = function (messageInfo, classId, ty) {
  695. messageInfo = messageInfo;
  696. if (us.cscl[classId]) {
  697. var i, j, _is;
  698. var _obj = us.cscl[classId].content;
  699. _obj.backgroundUrl = messageInfo.backgroundUrl;
  700. _obj.edges = _obj.edges || [];
  701. _obj.nodes = _obj.nodes || [];
  702. for (j = 0; j < messageInfo.edges.length; j++) {
  703. _is = true;
  704. for (i = 0; i < _obj.edges.length; i++) {
  705. if (_obj.edges[i].id == messageInfo.edges[j].id) {
  706. if (ty == "update") {
  707. _obj.edges[i] = messageInfo.edges[j];
  708. }
  709. else {
  710. _obj.edges.splice(i, 1);
  711. }
  712. _is = false;
  713. break;
  714. }
  715. }
  716. if (_is && ty == "update") {
  717. _obj.edges.push(messageInfo.edges[j])
  718. }
  719. }
  720. console.log("------------s------------");
  721. console.log(messageInfo.nodes);
  722. console.log(_obj.nodes);
  723. console.log(ty);
  724. for (j = 0; j < messageInfo.nodes.length; j++) {
  725. _is = true;
  726. for (i = 0; i < _obj.nodes.length; i++) {
  727. if (_obj.nodes[i].id == messageInfo.nodes[j].id) {
  728. if (ty == "update") {
  729. _obj.nodes[i] = messageInfo.nodes[j];
  730. }
  731. else {
  732. _obj.nodes.splice(i, 1);
  733. }
  734. _is = false;
  735. break;
  736. }
  737. }
  738. if (_is && ty == "update") {
  739. _obj.nodes.push(messageInfo.nodes[j])
  740. }
  741. }
  742. console.log(_obj);
  743. //如果不存在则去数据库查找
  744. us.mysql.usselect(['172.16.12.5', 'pbl', 'updateRoomData', JSON.stringify(_obj), classId],
  745. function (ret) {
  746. });
  747. //"nodes":[{"id":"9f6d7459-d376-4c0c-944b-a6b140085903","type":"icon-start","x":625,"y":145,"properties":{},"zIndex":1002,"text":{"x":625,"y":145,"value":"起始"}},{"id":"16e18308-7517-4162-8b32-a877b7cf42a0","type":"icon-card","x":325,"y":445,"properties":{},"zIndex":1002},{"id":"5c492b0d-092d-4d84-bd70-4d5734de9266","type":"icon-select","x":970,"y":510,"properties":{},"zIndex":1002}],
  748. //"edges":[],
  749. //"backgroundUrl":"img/bg.ccee1c62.png"
  750. // if (_obj) {
  751. // _obj[messageInfo.id] = messageInfo.content;
  752. // }
  753. }
  754. }
  755. /**
  756. * 更新后台实施课堂内容
  757. * @param {object} message 消息信息
  758. */
  759. us.updaterealTimeClass = function (messageInfo) {
  760. if (us.realTimeClass[messageInfo.docId]) {
  761. var $ = us.realTimeClass[messageInfo.docId].content;
  762. // console.log("---------------------------------------start")
  763. // console.log($);
  764. // console.log("---------------------------------------end")
  765. // console.log("---------------------------------------infostart")
  766. // console.log(messageInfo);
  767. // console.log("---------------------------------------infoend")
  768. if ($) {
  769. us.realTimeClass[messageInfo.docId].content[messageInfo.id] = messageInfo.content;
  770. }
  771. }
  772. }
  773. /**
  774. * 更新后台Word内容
  775. * @param {object} message 消息信息
  776. */
  777. us.updateWord = function (messageInfo) {
  778. if (us.word[messageInfo.docId]) {
  779. var $ = us.word[messageInfo.docId].content;
  780. if ($) {
  781. switch (messageInfo.type) { // 判断消息种类
  782. case 'update':
  783. us.updateEditorLine(messageInfo, $); //修改
  784. break;
  785. case 'add':
  786. us.addEditorLine(messageInfo, $); //添加
  787. break;
  788. case 'delete':
  789. us.deleteEditorLine(messageInfo, $); //删除
  790. break;
  791. }
  792. }
  793. }
  794. }
  795. /**
  796. * 更新后台Nav内容
  797. * @param {object} messageInfo 消息信息
  798. */
  799. us.updateNav = function (messageInfo) {
  800. var _fileinfo = us.nav[messageInfo.docId];
  801. if (_fileinfo) {
  802. switch (messageInfo.type) { // 判断消息种类
  803. case 'update': //修改行
  804. us.updateEditorLine(messageInfo, _fileinfo.page[messageInfo.navId]); //修改
  805. break;
  806. case 'add': //添加行
  807. us.addEditorLine(messageInfo, _fileinfo.page[messageInfo.navId]); //添加
  808. break;
  809. case 'delete': //删除行
  810. us.deleteEditorLine(messageInfo, _fileinfo.page[messageInfo.navId]); //删除
  811. break;
  812. case 'addNav': //添加导航
  813. us.updateNav.addNav(_fileinfo, messageInfo.parentId, messageInfo.index, messageInfo.addNav, messageInfo.content);
  814. break;
  815. case 'updateNav': //修改导航
  816. us.updateNav.updateNav(_fileinfo.navInfo.nav, messageInfo.navId, messageInfo.name);
  817. break;
  818. case 'deleteNav': //删除导航
  819. us.updateNav.deleteNav(_fileinfo, messageInfo.navId, messageInfo.parentId);
  820. break;
  821. case 'updateLogo': //修改logo
  822. _navinfo.logo = messageInfo.logo;
  823. break;
  824. }
  825. }
  826. }
  827. /**
  828. * 根据NavId查找对应的导航信息
  829. */
  830. us.selectByNavId = function (nowinfo, navid) {
  831. var i = 0;
  832. for (i = 0; i < nowinfo.length; i++) {
  833. object = nowinfo[i];
  834. if (object.pageId == navid) {
  835. return object;
  836. } else if (object.child) {
  837. return us.selectNav(object.child, navid);
  838. }
  839. }
  840. }
  841. /**
  842. * 添加Nav
  843. * @param {object} fileinfo 文件信息
  844. * @param {object} parentid 父级ID
  845. * @param {object} addnav 添加导航信息
  846. * @param {number} index 添加位置
  847. */
  848. us.updateNav.addNav = function (fileinfo, parentid, index, addnav, content) {
  849. var _nav = fileinfo.navInfo.nav;
  850. var _parent;
  851. if (parentid) {
  852. // 寻找父级
  853. _parent = us.selectByNavId(_nav, parentid);
  854. // 如果已存在子级处理
  855. if (_parent.child) {
  856. //插入指定位置
  857. _parent.child.splice(index, 0, addnav);
  858. } else {
  859. // 为存在子级则新建子级
  860. _parent.child = [addnav];
  861. }
  862. } else {
  863. _parent = _nav;
  864. _parent.splice(index, 0, addnav);
  865. }
  866. //添加内容
  867. fileinfo.page[addnav.pageId] = us.cheerio.load(content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""));
  868. }
  869. /**
  870. * 修改Nav
  871. * @param {object} nav 导航信息
  872. * @param {object} navid ID
  873. * @param {object} name 名字
  874. */
  875. us.updateNav.updateNav = function (nav, navid, name) {
  876. // 寻找需要修改导航信息
  877. var _nav = us.selectByNavId(nav, navid);
  878. if (_nav) { //存在导航
  879. _nav.name = name; //替换名字
  880. }
  881. }
  882. /**
  883. * 删除Nav
  884. * @param {object} fielinfo 文件信息
  885. * @param {object} navid ID
  886. * @param {object} name 名字
  887. */
  888. us.updateNav.deleteNav = function (fielinfo, deletenavid, parentid) {
  889. var _nav = fielinfo.navInfo.nav;
  890. var _parent;
  891. if (parentid) {
  892. // 寻找父级
  893. _parent = us.selectByNavId(_nav, parentid);
  894. } else {
  895. _parent = _nav;
  896. }
  897. if (_parent) {
  898. var _child = parentid ? _parent.child : _parent;
  899. _child.find(function (object, index) {
  900. if (object.pageId == deletenavid) {
  901. if (!object.child) {
  902. _child.splice(index, 1); //删除数据
  903. us.mysql.usselect([ //删除页面
  904. 'sqlserver.1473.cn',
  905. 'UseStudio_Office',
  906. 'DeletePage',
  907. deletenavid
  908. ], function (ret) {
  909. if (ret) {
  910. delete fielinfo.page[deletenavid]; //删除内容
  911. }
  912. });
  913. }
  914. return true;
  915. }
  916. });
  917. }
  918. }
  919. /**
  920. * 修改操作
  921. * @param {object} opera 操作信息对象
  922. * @param {element} $ 后台word元素形式
  923. */
  924. us.updateEditorLine = function (opera, $) {
  925. // $('#' + opera.id).prop('outerHTML', opera.content); //修改行
  926. $('#' + opera.id).replaceWith(opera.content);
  927. }
  928. /**
  929. * 删除操作
  930. * @param {object} opera 操作信息对象
  931. * @param {element} $ 后台word元素形式
  932. */
  933. us.deleteEditorLine = function (opera, $) {
  934. $('#' + opera.id).remove(); //删除行
  935. }
  936. /**
  937. * 添加操作
  938. * @param {object} opera 操作信息对象
  939. * @param {element} $ 后台word元素形式
  940. */
  941. us.addEditorLine = function (opera, $) {
  942. var _next; //创建记录变量
  943. if (opera.nextId && (_next = $('#' + opera.nextId))[0]) { //判断有没有nextid,nextid是否存在
  944. //如果存在则插入在nexid 元素前
  945. _next.before(opera.content);
  946. } else {
  947. $('body').append(opera.content); //没有就在最后插入
  948. }
  949. }
  950. /**
  951. * 更新后台Word内容
  952. * @param {object} message 消息信息
  953. */
  954. us.updateExcel = function (messageInfo) {
  955. var $ = us.excel[messageInfo.docId].content;
  956. if ($) {
  957. switch (messageInfo.type) { // 判断消息种类
  958. case 'blur':
  959. us.updateExcel.Blur(messageInfo, $); //失焦
  960. break;
  961. case "addLine":
  962. us.updateExcel.addLine(messageInfo, $); //添加行
  963. break;
  964. case "delLine":
  965. us.updateExcel.delLine(messageInfo, $); //刪除行
  966. break;
  967. case "addCol":
  968. us.updateExcel.addCol(messageInfo, $); //添加列
  969. break;
  970. case "delCol":
  971. us.updateExcel.delCol(messageInfo, $); //刪除列
  972. break;
  973. case "merge":
  974. us.updateExcel.merge(messageInfo, $); //合并单元格
  975. break;
  976. case "splitCells":
  977. us.updateExcel.splitCells(messageInfo, $); //拆分单元格
  978. break;
  979. case "rowExpanding":
  980. us.updateExcel.rowExpanding(messageInfo, $); //行板拉伸
  981. break;
  982. case "colExpanding":
  983. us.updateExcel.colExpanding(messageInfo, $); //列板拉伸
  984. break;
  985. case "addTask":
  986. us.updateExcel.addTask(messageInfo, $); //添加工作表
  987. break;
  988. case "deleteTask":
  989. us.updateExcel.deleteTask(messageInfo, $); //刪除工作表
  990. break;
  991. case "reNameTask":
  992. us.updateExcel.reNameTask(messageInfo, $); //刪除工作表
  993. break;
  994. case "img":
  995. us.updateExcel.img(messageInfo, $); //插入图片
  996. break;
  997. }
  998. }
  999. // console.log($);
  1000. }
  1001. /**
  1002. * 失焦處理
  1003. */
  1004. us.updateExcel.Blur = function (messageInfo, $) {
  1005. var _taskId = messageInfo.worksheetId, //如果有taskId传过来 则修改 data数据里 taskId里的数据 否则则修改当前工作表id里的数据
  1006. _excelData = $[_taskId], //获取taskId工作表的数据
  1007. _cellData = _excelData.cell, //获取该数据里的单元格数据
  1008. _content = messageInfo.content; //获取需要保存的json数据
  1009. _content.forEach(function (data) {
  1010. var _text = data.innerText.replace(/\s+/g, ""), //去掉空格 给下面做判断 如果内容为空 则删除该数据
  1011. _cellColList = _cellData[data.col], //获取该数据里的所有列
  1012. _cell = null;
  1013. if (!_cellColList) { //如果列不存在 则创建一个列
  1014. _cellColList = _cellData[data.col] = {};
  1015. }
  1016. if (!_cellColList[data.row]) { //如果该行_列 不存在单元格数据 则创建个json 给单元格添加数据
  1017. _cellColList[data.row] = {};
  1018. _cellColList[data.row].cssStyle = {}; //css样式
  1019. }
  1020. _cell = _cellColList[data.row]; //获取该单元格的数据 (json)
  1021. data.content ? _cell.innerHTML = data.content : ""; //修改该单元格的innerHTML
  1022. if (data.attr) { //如果存在样式
  1023. _cell.cssStyle[data.attr] = data.value;
  1024. if (!data.value) {
  1025. delete _cell.cssStyle[data.attr]
  1026. }
  1027. }
  1028. if (data.clearStyle) { //如果需要清除所有样式的话
  1029. data.cssStyle = {}
  1030. }
  1031. if (((!(_text) || _text === ("\u200D")) && !(_cell.endRow)) && !(us.jsonLen(_cell.cssStyle))) { //如果innerHTML为空格 或 不存在 并且 不是合并单元格元素 并且没有样式 则删除掉
  1032. delete (_cellColList[data.row]);
  1033. }
  1034. });
  1035. }
  1036. /*
  1037. 获取json的数量
  1038. */
  1039. us.jsonLen = function (json) {
  1040. var _json = json,
  1041. _len = 0;
  1042. for (var i in json) {
  1043. _len++;
  1044. }
  1045. return _len;
  1046. }
  1047. us.updateExcel.addLine = function (messageInfo, $) {
  1048. var _taskId = messageInfo.worksheetId, //单元格id
  1049. _content = messageInfo.content,
  1050. _excelData = $[_taskId],
  1051. _rowData = _excelData.row,
  1052. _cellData = _excelData.cell,
  1053. _start = _content.start, //开始行
  1054. _lineNum = _content.lineNum, //添加行的数量
  1055. _sizeChange = _content.sizeChange, //添加的行的高度
  1056. _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
  1057. _cellCol = null;
  1058. if (_mergeArr.length) {
  1059. _mergeArr.forEach(function (info) {
  1060. _cellData[info.col][info.row].endRow = _cellData[info.col][info.row].endRow + _lineNum;
  1061. });
  1062. }
  1063. for (var k in _cellData) {
  1064. _cellCol = _cellData[k]; //该列下的所有行
  1065. var temp = {};
  1066. for (var row in _cellCol) {
  1067. if (row > _start) {
  1068. temp[(+row) + _lineNum] = _cellCol[row];
  1069. temp[(+row) + _lineNum].endRow ? temp[(+row) + _lineNum].endRow = temp[(+row) + _lineNum].endRow + _lineNum : ""; //如果是合并单元格的元素 则将endRow + _lineNum;
  1070. } else {
  1071. temp[row] = _cellCol[row];
  1072. }
  1073. }
  1074. _cellData[k] = temp;
  1075. } /* 该处for循环是修改数据中单元格的行数 */
  1076. var _rowDataChange = _rowData.change, //获取数据表中 所有被改变高度的 行版信息
  1077. _temp = {},
  1078. _rowChange = null;
  1079. for (var k in _rowDataChange) {
  1080. _rowChange = _rowDataChange[k]; //该行板的所有被改动的行数据
  1081. if (k > _start) {
  1082. _temp[(+k) + _lineNum] = _rowChange;
  1083. } else {
  1084. _temp[k] = _rowChange;
  1085. }
  1086. } /* 该处for循环是修改数据中行版的行数 */
  1087. _rowData.change = _temp;
  1088. if (_sizeChange) {
  1089. for (var i = 1; i <= _lineNum; i++) {
  1090. _rowData.change[_start + i] = _sizeChange;
  1091. }
  1092. }
  1093. _rowData.num = _rowData.num + _lineNum; //行板数量 = 行板数量 + 添加行的数量
  1094. };
  1095. us.updateExcel.delLine = function (messageInfo, $) {
  1096. var _taskId = messageInfo.worksheetId, //单元格id
  1097. _excelData = $[_taskId],
  1098. _content = messageInfo.content,
  1099. _rowData = _excelData.row,
  1100. _cellData = _excelData.cell,
  1101. _start = _content.start, //被选中的第一行
  1102. _end = _content.end, //被选中的最后一行
  1103. _lineNum = _content.lineNum, //所删除的行数
  1104. _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
  1105. _cellCol = null;
  1106. for (var k in _cellData) {
  1107. _cellCol = _cellData[k];
  1108. var temp = {};
  1109. for (var row in _cellCol) {
  1110. if (row > _end) {
  1111. temp[(+row) - _lineNum] = _cellCol[row];
  1112. temp[(+row) - _lineNum].endRow ? temp[(+row) - _lineNum].endRow = temp[(+row) - _lineNum].endRow - _lineNum : ""; //如果是合并单元格的元素 则将endRow - _lineNum;
  1113. } else if (row < _start) {
  1114. temp[row] = _cellCol[row];
  1115. }
  1116. }
  1117. _cellData[k] = temp;
  1118. }
  1119. if (_mergeArr.length) {
  1120. var _cloneMessage = null;
  1121. _mergeArr.forEach(function (info) {
  1122. _cloneMessage = JSON.parse(JSON.stringify(messageInfo));
  1123. _cloneMessage.content = info;
  1124. us.updateExcel.merge(_cloneMessage, $);
  1125. });
  1126. }
  1127. var _rowDataChange = _rowData.change, //获取数据表中 所有被改变高度的 行版信息
  1128. _temp = {},
  1129. _rowChange = null;
  1130. for (var k in _rowDataChange) {
  1131. _rowChange = _rowDataChange[k]; //该行板的所有被改动的行数据
  1132. if (k < _start) { //如果大于结束行 则将该行下面的所有的数字信息 - 被删除的行
  1133. _temp[k] = _rowChange;
  1134. } else if (k > _end) {
  1135. _temp[(+k) - _lineNum] = _rowChange;
  1136. }
  1137. } /* 该处for循环是修改数据中行版的行数 */
  1138. _rowData.change = _temp;
  1139. _rowData.num = _rowData.num - _lineNum; //行板数量 = 行板数量 - 删除行的数量
  1140. };
  1141. us.updateExcel.addCol = function (messageInfo, $) {
  1142. var _taskId = messageInfo.worksheetId, //单元格id
  1143. _excelData = $[_taskId],
  1144. _content = messageInfo.content,
  1145. _colData = _excelData.column,
  1146. _cellData = _excelData.cell,
  1147. _start = _content.start, //被选中的第一列
  1148. _sizeChange = _content.sizeChange, //添加的列的宽度
  1149. _colNums = _content.colNums, //所添加的列数
  1150. _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
  1151. _cellCol = null,
  1152. _temp = {};
  1153. if (_mergeArr.length) {
  1154. _mergeArr.forEach(function (info) {
  1155. _cellData[info.col][info.row].endCol = _cellData[info.col][info.row].endCol + _colNums;
  1156. });
  1157. }
  1158. for (var k in _cellData) {
  1159. _cellCol = _cellData[k];
  1160. if (k > _start) {
  1161. _temp[+(k) + _colNums] = _cellCol;
  1162. var _temp2 = _temp[(+k) + _colNums];
  1163. for (var i in _temp2) {
  1164. _temp2[i].endCol ? _temp2[i].endCol = _temp2[i].endCol + _colNums : ""; //如果是合并单元格的元素 则将endCol + _colNums;
  1165. }
  1166. } else {
  1167. _temp[k] = _cellCol;
  1168. }
  1169. }
  1170. _excelData.cell = _temp;
  1171. var _colDataChange = _colData.change, //获取数据表中 所有被改变宽度的 列版信息
  1172. _temp = {},
  1173. _colChange = null;
  1174. for (var k in _colDataChange) {
  1175. _colChange = _colDataChange[k]; //该列板的所有被改动的列数据
  1176. if (k > _start) {
  1177. _temp[(+k) + _colNums] = _colChange;
  1178. } else {
  1179. _temp[k] = _colChange;
  1180. }
  1181. } /* 该处for循环是修改数据中行版的行数 */
  1182. _colData.change = _temp;
  1183. if (_sizeChange) {
  1184. for (var i = 1; i <= _colNums; i++) {
  1185. _colData.change[_start + i] = _sizeChange;
  1186. }
  1187. }
  1188. _colData.num = _colData.num + _colNums; //列板数量 = 列板数量 + 添加列的数量
  1189. };
  1190. us.updateExcel.delCol = function (messageInfo, $) {
  1191. var _taskId = messageInfo.worksheetId, //单元格id
  1192. _excelData = $[_taskId],
  1193. _content = messageInfo.content,
  1194. _colData = _excelData.column,
  1195. _cellData = _excelData.cell,
  1196. _start = _content.start, //被选中的第一行
  1197. _end = _content.end, //被选中的最后一行
  1198. _colNums = _content.colNums, //所删除的列数
  1199. _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
  1200. _cellCol = null,
  1201. _temp = {};
  1202. for (var k in _cellData) {
  1203. _cellCol = _cellData[k];
  1204. if (k > _end) {
  1205. _temp[+(k) - _colNums] = _cellCol;
  1206. var _temp2 = _temp[(+k) - _colNums];
  1207. for (var i in _temp2) {
  1208. _temp2[i].endCol ? _temp2[i].endCol = _temp2[i].endCol - _colNums : ""; //如果是合并单元格的元素 则将endCol - _colNums;
  1209. }
  1210. } else if (k < _start) {
  1211. _temp[k] = _cellCol;
  1212. }
  1213. }
  1214. _excelData.cell = _temp;
  1215. if (_mergeArr.length) {
  1216. var _cloneMessage = null;
  1217. _mergeArr.forEach(function (info) {
  1218. _cloneMessage = JSON.parse(JSON.stringify(messageInfo));
  1219. _cloneMessage.content = info;
  1220. us.updateExcel.merge(_cloneMessage, $);
  1221. });
  1222. }
  1223. var _colDataChange = _colData.change, //获取数据表中 所有被改变宽度的 列版信息
  1224. _temp = {},
  1225. _colChange;
  1226. for (var k in _colDataChange) {
  1227. _colChange = _colDataChange[k]; //该列板的所有被改动的列数据
  1228. if (k < _start) { //如果大于结束列 则将该列下面的所有的数字信息 - 被删除的列
  1229. _temp[k] = _colChange;
  1230. } else if (k > _end) {
  1231. _temp[(+k) - _colNums] = _colChange;
  1232. }
  1233. } /* 该处for循环是修改数据中行版的行数 */
  1234. _colData.change = _temp;
  1235. _colData.num = _colData.num - _colNums; //列板数量 = 列板数量 - 删除列的数量
  1236. };
  1237. us.updateExcel.merge = function (messageInfo, $) {
  1238. var _taskId = messageInfo.worksheetId, //单元格id
  1239. _excelData = $[_taskId],
  1240. _content = messageInfo.content,
  1241. _cellData = _excelData.cell,
  1242. _cellColList = _cellData[_content.col];
  1243. if (_content.row === _content.endRow && _content.col === _content.endCol) {
  1244. _cellData[_content.col][_content.row].endRow = "";
  1245. _cellData[_content.col][_content.row].endCol = ""
  1246. return;
  1247. }
  1248. if (!_cellColList) {
  1249. _cellColList = _cellData[_content.col] = {};
  1250. }
  1251. if (!_cellColList[_content.row]) {
  1252. _cellColList[_content.row] = {};
  1253. }
  1254. _cellColList[_content.row].innerHTML = _content.content;
  1255. _cellColList[_content.row].endRow = _content.endRow;
  1256. _cellColList[_content.row].endCol = _content.endCol;
  1257. };
  1258. us.updateExcel.splitCells = function (messageInfo, $) {
  1259. var _taskId = messageInfo.worksheetId, //单元格id
  1260. _excelData = $[_taskId],
  1261. _content = messageInfo.content,
  1262. _cellData = _excelData.cell,
  1263. _cell = _cellData[_content.col][_content.row]; //需要拆分的单元格
  1264. _cell.endRow = "";
  1265. _cell.endCol = "";
  1266. };
  1267. us.updateExcel.rowExpanding = function (messageInfo, $) {
  1268. var _taskId = messageInfo.worksheetId, //单元格id
  1269. _excelData = $[_taskId],
  1270. _content = messageInfo.content,
  1271. _rowData = _excelData.row;
  1272. _content.forEach(function (data) {
  1273. var _rowNum = data.rowName, //拉伸行的位置 (数字)
  1274. _rowHeight = data.height; //被拉伸后的高度
  1275. _rowData.change[_rowNum] = _rowHeight;
  1276. });
  1277. };
  1278. us.updateExcel.colExpanding = function (messageInfo, $) {
  1279. var _taskId = messageInfo.worksheetId, //单元格id
  1280. _excelData = $[_taskId],
  1281. _content = messageInfo.content,
  1282. _colData = _excelData.column; //该列的数据
  1283. _content.forEach(function (data) {
  1284. var _colNum = data.colName, //拉伸行的位置 (数字)
  1285. _colWidth = data.width; //被拉伸后的宽度
  1286. _colData.change[_colNum] = _colWidth;
  1287. });
  1288. };
  1289. /*添加工作表*/
  1290. us.updateExcel.addTask = function (messageInfo, $) {
  1291. var _content = messageInfo.content,
  1292. _taskId = _content.id;
  1293. $[_taskId] = _content.data;
  1294. };
  1295. /*刪除工作表*/
  1296. us.updateExcel.deleteTask = function (messageInfo, $) {
  1297. var _content = messageInfo.content,
  1298. _taskId = _content.id;
  1299. delete ($[_taskId]);
  1300. };
  1301. /*命名工作表*/
  1302. us.updateExcel.reNameTask = function (messageInfo, $) {
  1303. var _content = messageInfo.content,
  1304. _taskId = _content.id;
  1305. $[_taskId].taskName = _content.name;
  1306. };
  1307. us.updateExcel.img = function (messageInfo, $) { //此处修改
  1308. var _content = messageInfo.content,
  1309. _taskId = messageInfo.worksheetId,
  1310. _excelData = $[_taskId],
  1311. _imgData = _excelData.img;
  1312. _imgData.push(_content);
  1313. };
  1314. /**
  1315. * 用户群发处理
  1316. *
  1317. * @param {string} 接收信息的用户id
  1318. * @param {string} 发送的用户信息
  1319. **/
  1320. us.setword = function (messageinfo) {
  1321. // us.userConnect[userid].response.end(messageinfo);
  1322. }
  1323. /**
  1324. * 用户群发处理
  1325. *
  1326. * @param {string} userid 接收信息的用户id
  1327. * @param {string} messageinfo 发送的用户信息
  1328. **/
  1329. us.senduser = function (userid, messageinfo) {
  1330. us.userConnect[userid].response.end(messageinfo); //发送消息
  1331. }
  1332. /**
  1333. * 用户群发处理
  1334. *
  1335. * @param {object} messageinfo 发送消息的内容
  1336. * @param {guid} pageid 页面id
  1337. * @param {string} type 类型
  1338. **/
  1339. us.broadcast = function (messageinfo, pageid, type) {
  1340. var i, j, o, //循环变量
  1341. _messageinfo, //消息信息
  1342. _users, //用户ID集合
  1343. _pageids, //用户页面唯一识别集合
  1344. _recievedpageid, //接收用户的页面唯一识别ID
  1345. _issend, // 是否发送
  1346. _userconnect = us.connect; //用户连接池
  1347. for (i in messageinfo) {
  1348. _messageinfo = messageinfo[i]; //记录消息消息
  1349. _users = us[type][i] ? us[type][i].user : {}; //记录用户集合
  1350. // console.log("=================a=============");
  1351. // console.log(_users);
  1352. for (j in _users) { //循环处理每个用户处理 给每个用户集合下的用户发送消息
  1353. _pageids = _users[j]; //记录当前用户在每个端登录的页面唯一识别ID
  1354. // console.log("=================g=============");
  1355. // console.log(_pageids);
  1356. for (o = 0; o < _pageids.length; o++) { //循环发送给当前用户在每个端登录的用户
  1357. _recievedpageid = _pageids[o]; //记录接受者页面唯一识别ID 用于区分是否是发送用户
  1358. if (_recievedpageid != pageid) { //如果接受用户不等于发送用户则发送消息
  1359. try {
  1360. // console.log("=================b=============");
  1361. // console.log(_userconnect[j]);
  1362. if (_userconnect[j] && _userconnect[j][_recievedpageid]) {
  1363. _issend = _userconnect[j][_recievedpageid].response.end(JSON.stringify(_messageinfo)); //发送消息
  1364. if (!_issend) { //如果用户下线了,那么发送消息就会失败
  1365. us.offLineMessage[_recievedpageid].message.push(_messageinfo); //将消息加入用户离线消息中
  1366. }
  1367. }
  1368. }
  1369. catch (e) {
  1370. console.log(e)
  1371. }
  1372. }
  1373. }
  1374. }
  1375. }
  1376. }
  1377. /**
  1378. * 加入文档编辑
  1379. *
  1380. * @param {object} response 用户相应对象
  1381. * @param {string} wordinfo 文档信息 形如: {docId : 'guid,guid,guid', userId : guid, pageId : guid}
  1382. **/
  1383. us.addWord = function (response, wordinfo) {
  1384. //获取用户参数
  1385. wordinfo = JSON.parse(wordinfo);
  1386. var _docidarray = wordinfo.docId.split(','), //根据','号分割多个文档ID
  1387. _userid = wordinfo.userId, //用户ID
  1388. _pageid = wordinfo.pageId, //页面唯一识别ID
  1389. i, //定义循环变量
  1390. _docid, //记录文档ID变量
  1391. _docinfo; //记录文档信息变量
  1392. for (i = 0; i < _docidarray.length; i++) { //循环处理每一份问的加入请求
  1393. _docid = _docidarray[i]; //记录文档ID变量
  1394. _docinfo = us.word[_docid]; //记录文档信息变量
  1395. if (!_docinfo) { //判断群列表是否已存在不存在则创建
  1396. us.word[_docid] = {
  1397. user: {},
  1398. history: []
  1399. }; //创建word文档信息
  1400. us.word[_docid].user[_userid] = [_pageid]; //加入用户
  1401. } else if (!_docinfo.user[_userid]) { //判断文档的用户是否已登陆
  1402. _docinfo.user[_userid] = [_pageid];
  1403. } else if (_docinfo.user[_userid].indexOf(_pageid) == -1) { //将用户添加到群列表中
  1404. _docinfo.user[_userid].push(_pageid);
  1405. }
  1406. us.offLineMessage[_pageid].word.push(_docid); //添加到用户离线消息的连接wrod记录中
  1407. }
  1408. response.end('addword'); //即时相应请求成功
  1409. }
  1410. /**
  1411. * 退出文档编辑
  1412. *
  1413. * @param {object} response 用户相应对象
  1414. * @param {string} wordinfo 文档信息
  1415. **/
  1416. us.quitOffice = function (response, wordinfo) {
  1417. //获取用户参数
  1418. wordinfo = JSON.parse(wordinfo);
  1419. var _docid = wordinfo.docId,
  1420. _userid = wordinfo.userId,
  1421. _pageid = wordinfo.pageId,
  1422. _type = wordinfo.type,
  1423. _messagetype = 'us.' + _type;
  1424. var _docinfo = us[_type][_docid]; //获取文档信息
  1425. //判断是否存在文档信息
  1426. if (_docinfo) {
  1427. us.quitUserList(_docinfo, _userid, _pageid); //将用户在协同列表中删除
  1428. var _j, //创建循环变量
  1429. _message = us.offLineMessage[_pageid] ? us.offLineMessage[_pageid].message : []; //获取该用户的离线消息
  1430. for (_j = _message.length - 1; _j > -1; _j--) { //循环移除该文档的离线消息
  1431. if (_message[_j].type == _messagetype && _message[_j].messageInfo.docId == _docid) { //判断是否为word文档
  1432. _message.splice(_j, 1); //删除记录
  1433. }
  1434. }
  1435. us.insertHistory(_docinfo, _docid, _type);
  1436. }
  1437. response.end('quitOffice'); //响应退出请求
  1438. }
  1439. /**
  1440. * 将用户在协同列表中删除
  1441. *
  1442. * @param {object} docinfo 文档信息
  1443. * @param {string} userid 用户ID
  1444. * @param {string} pageid 用户页面唯一识别ID
  1445. */
  1446. us.quitUserList = function (docinfo, userid, pageid) {
  1447. var _users = docinfo.user[userid]; //记录文档的用户列表
  1448. //获取用户在文档用户列表的位置
  1449. if (_users) {
  1450. var _index = _users.indexOf(pageid);
  1451. // 如果存在则将该用户删除 表示退出协同
  1452. if (_index != -1) {
  1453. _users.splice(_index, 1); //删除该用户
  1454. //如果该用户的全部端用户已退出则删除用户的记录
  1455. if (_users.length == 0) {
  1456. delete docinfo.user[userid];
  1457. }
  1458. }
  1459. }
  1460. }
  1461. /**
  1462. * 插入文档操作历史到数据库
  1463. *
  1464. * @param {object} docinfo 文档信息
  1465. */
  1466. us.insertHistory = function (docinfo, docid, type) {
  1467. var i,
  1468. _info, //操作信息记录
  1469. _isuser = false;
  1470. for (i in docinfo.user) {
  1471. _isuser = true;
  1472. break;
  1473. }
  1474. //如果该文档没有协同用户
  1475. if (!_isuser) {
  1476. switch (type) {
  1477. case 'word':
  1478. var _content = docinfo.content ? docinfo.content('body').html().replace(/'/ig, '\\\'').replace(/"/ig, "\\\"") : "";
  1479. us.mysql.usselect(['sqlserver.1473.cn', 'UseStudio_Disk', 'SaveFileContent', docid, _content, ''],
  1480. function (ret) { });
  1481. break;
  1482. case 'nav':
  1483. us.mysql.usselect(['sqlserver.1473.cn', 'UseStudio_Disk', 'SaveFileContent', docid, JSON.stringify(docinfo.navInfo), ''],
  1484. function (ret) {
  1485. var _key;
  1486. for (_key in docinfo.page) {
  1487. //发送保存内容请求
  1488. var _content = docinfo.page[_key] ? docinfo.page[_key]('body').html().replace(/'/ig, '\\\'').replace(/"/ig, "\\\"") : "";
  1489. us.mysql.usselect(['sqlserver.1473.cn', 'UseStudio_Office', 'SaveNavPageContent', _key, _content], function (ret) { });
  1490. }
  1491. });
  1492. break;
  1493. }
  1494. }
  1495. }
  1496. /**
  1497. * 下线操作
  1498. * @param {object} response 响应对象
  1499. * @param {string} userid 用户ID
  1500. * @param {string} pageid 用户页面唯一识别ID
  1501. */
  1502. us.logout = function (response, userid, pageid) {
  1503. var i, j, _docinfo,
  1504. _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
  1505. _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
  1506. us.connect[userid][pageid].offLineTime = new Date();
  1507. for (i = 0; i < _wordids.length; i++) { //循环处理每一个文档
  1508. _docinfo = us.word[_wordids[i]]; //记录文档信息
  1509. if (_docinfo) { //如果存在文档信息
  1510. us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
  1511. delete us.offLineMessage[pageid]; //删除用户离线消息记录
  1512. us.insertHistory(_docinfo, 'word'); //插入历史
  1513. }
  1514. }
  1515. for (j = 0; i < _excelids.length; j++) {
  1516. _docinfo = us.excel[_excelids[j]]; //记录文档信息
  1517. if (_docinfo) { //如果存在文档信息
  1518. us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
  1519. delete us.offLineMessage[pageid]; //删除用户离线消息记录
  1520. us.insertHistory(_docinfo, 'excel'); //插入历史
  1521. }
  1522. }
  1523. response.end('logout'); //响应退出请求
  1524. }
  1525. /**
  1526. * 获取Excel,并生成后端数据
  1527. *
  1528. * @param {object} response 用户相应对象
  1529. * @param {string} docid 文档ID
  1530. * @param {guid} pageid 页面ID
  1531. * @param {guid} userid 用户ID
  1532. */
  1533. us.getExcel = function (response, docid, pageid, userid) {
  1534. //判断文档是否已在内层中存在
  1535. if (us.excel[docid]) {
  1536. //如果存在则直接返回内层的文档
  1537. if (!us.excel[docid].user[userid]) {
  1538. us.excel[docid].user[userid] = [pageid];
  1539. } else {
  1540. us.excel[docid].user[userid].push(pageid);
  1541. }
  1542. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
  1543. var _office = us.excel[docid].content;
  1544. response.end(JSON.stringify(_office));
  1545. } else {
  1546. us.excel[docid] = {
  1547. user: {},
  1548. history: []
  1549. };
  1550. us.excel[docid].user[userid] = [pageid];
  1551. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
  1552. //如果不存在则去数据库查找
  1553. us.mysql.usselect([
  1554. 'sqlserver.1473.cn',
  1555. 'UseStudio_Disk',
  1556. 'GetFileContent',
  1557. docid
  1558. ], function (ret) {
  1559. if (ret) {
  1560. var _office = JSON.parse(ret)[0][0].UsOffice;
  1561. us.excel[docid].content = JSON.parse(_office); //将文档添加到内层中
  1562. response.end(_office); //返回文档内容
  1563. } else {
  1564. us.excel[docid].content = ''; //将文档添加到内层中
  1565. response.end(''); //返回文档内容
  1566. }
  1567. });
  1568. }
  1569. }
  1570. /**
  1571. * 获取文档,并生成DOM
  1572. *
  1573. * @param {object} response 用户相应对象
  1574. * @param {string} fileid 导航文件ID
  1575. * @param {guid} pageid 页面ID
  1576. * @param {guid} userid 用户ID
  1577. */
  1578. us.getNav = function (response, fileid, pageid, userid) {
  1579. //判断文档是否已在内层中存在
  1580. if (us.nav[fileid]) {
  1581. //如果存在则直接返回内层的文档
  1582. if (!us.nav[fileid].user[userid]) {
  1583. us.nav[fileid].user[userid] = [pageid];
  1584. } else {
  1585. us.nav[fileid].user[userid].push(pageid);
  1586. }
  1587. us.offLineMessage[pageid].nav.indexOf(fileid) == -1 && us.offLineMessage[pageid].nav.push(fileid); //添加到用户离线消息的连接wrod记录中
  1588. response.end(JSON.stringify(us.nav[fileid].navInfo));
  1589. } else {
  1590. //如果不存在则去数据库查找
  1591. us.mysql.usselect([
  1592. 'sqlserver.1473.cn',
  1593. 'UseStudio_Disk',
  1594. 'GetFileContent',
  1595. fileid
  1596. ], function (ret) {
  1597. if (ret) {
  1598. var _navinfo = JSON.parse(ret)[0][0].UsOffice;
  1599. if (_navinfo) {
  1600. var _navdata = us.nav[fileid] = { //生成数据结构
  1601. user: {},
  1602. navInfo: JSON.parse(_navinfo),
  1603. page: {},
  1604. history: []
  1605. };
  1606. _navdata.user[userid] = [pageid]; //记录用户
  1607. us.offLineMessage[pageid].nav.indexOf(fileid) == -1 && us.offLineMessage[pageid].nav.push(fileid); //添加到用户离线消息的连接wrod记录中
  1608. response.end(JSON.stringify(_navinfo)); //返回文档内容
  1609. } else {
  1610. response.end(''); //查询不到文档
  1611. }
  1612. } else {
  1613. response.end(''); //返回文档内容
  1614. }
  1615. });
  1616. }
  1617. }
  1618. /**
  1619. * 获取导航页面内容
  1620. * @param {object} response 用户相应对象
  1621. * @param {guid} fileid 文档ID
  1622. * @param {string} navid 文档内容
  1623. * @param {string} name 文档名
  1624. */
  1625. us.getNavPageContent = function (response, fileid, navid) {
  1626. if (us.nav[fileid] && us.nav[fileid].page[navid]) {
  1627. response.end(us.nav[fileid].page[navid]('body').html()); //后台直接返回
  1628. } else {
  1629. //如果不存在则去数据库查找
  1630. us.mysql.usselect([
  1631. 'sqlserver.1473.cn',
  1632. 'UseStudio_Office',
  1633. 'GetNavPageContent',
  1634. navid
  1635. ], function (ret) {
  1636. if (ret && JSON.parse(ret)[0][0]) {
  1637. var _content = JSON.parse(ret)[0][0].content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""); //记录查找内容
  1638. us.nav[fileid] && (us.nav[fileid].page[navid] = us.cheerio.load(_content)); //将文档添加到内层中
  1639. response.end(_content); //查询不到文档
  1640. } else {
  1641. response.end(''); //返回文档内容
  1642. }
  1643. });
  1644. }
  1645. }
  1646. /**
  1647. * 新建文档保存内容并加入协同
  1648. * @param {object} response 用户相应对象
  1649. * @param {guid} docid 文档ID
  1650. * @param {string} content 文档内容
  1651. * @param {string} name 文档名
  1652. * @param {guid} userid 用户ID
  1653. * @param {guid} pageid 页面唯一识别ID
  1654. */
  1655. us.newWordSave = function (response, docid, content, name, userid, pageid) {
  1656. us.word[docid] = {
  1657. user: {},
  1658. history: []
  1659. }; //创建Word类
  1660. us.word[docid].user[userid] = [pageid]; //将用户加入协同记录数组
  1661. us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  1662. //发送保存请求
  1663. us.mysql.usselect([
  1664. 'sqlserver.1473.cn',
  1665. 'UseStudio_Disk',
  1666. 'SaveFileContent',
  1667. docid,
  1668. content,
  1669. name
  1670. ], function (ret) {
  1671. if (ret) {
  1672. //设置内容
  1673. us.word[docid].content = us.cheerio.load(content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\"")); //将文档添加到内层中
  1674. response.end('save'); //返回保存成功
  1675. } else {
  1676. response.end('fail'); //返回文档内容
  1677. }
  1678. });
  1679. }
  1680. /**
  1681. * 新建文档保存内容并加入协同
  1682. * @param {object} response 用户相应对象
  1683. * @param {guid} docid 文档ID
  1684. * @param {string} content 文档内容
  1685. * @param {string} name 文档名
  1686. * @param {guid} userid 用户ID
  1687. * @param {guid} pageid 页面唯一识别ID
  1688. */
  1689. us.newExcelSave = function (response, docid, content, name, userid, pageid) {
  1690. us.excel[docid] = {
  1691. user: {},
  1692. history: []
  1693. }; //创建excel类
  1694. us.excel[docid].user[userid] = [pageid]; //将用户加入协同记录数组
  1695. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  1696. //发送保存请求
  1697. us.mysql.usselect([
  1698. 'sqlserver.1473.cn',
  1699. 'UseStudio_Disk',
  1700. 'SaveFileContent',
  1701. docid,
  1702. content,
  1703. name
  1704. ], function (ret) {
  1705. if (ret) {
  1706. //设置内容
  1707. us.excel[docid].content = JSON.parse(content); //将文档添加到内层中
  1708. response.end('saveOk'); //返回保存成功
  1709. } else {
  1710. response.end('fail'); //返回文档内容
  1711. }
  1712. });
  1713. }
  1714. /**
  1715. * 新建导航文件保存
  1716. * @param {object} response 用户相应对象
  1717. * @param {guid} fileid 文档ID
  1718. * @param {string} navinfo 导航信息
  1719. * @param {string} nowpageid 当前页面ID
  1720. * @param {string} nowpagecontent 当前页面内容
  1721. * @param {string} name 文档名
  1722. * @param {guid} userid 用户ID
  1723. * @param {guid} pageid 页面唯一识别ID
  1724. */
  1725. us.newNavSave = function (response, fileid, navinfo, name, nowpageid, nowpagecontent, userid, pageid) {
  1726. //发送保存文件请求
  1727. us.mysql.usselect([
  1728. 'sqlserver.1473.cn',
  1729. 'UseStudio_Disk',
  1730. 'SaveFileContent',
  1731. fileid,
  1732. navinfo,
  1733. name
  1734. ], function (ret) {
  1735. if (ret) {
  1736. var _navinfo = JSON.parse(navinfo);
  1737. if (!us.nav[fileid]) {
  1738. us.nav[fileid] = {
  1739. user: {},
  1740. navInfo: _navinfo,
  1741. page: {},
  1742. history: []
  1743. };
  1744. } else {
  1745. us.nav[fileid].navInfo = _navinfo;
  1746. }
  1747. var _navdata = us.nav[fileid];
  1748. _navdata.user[userid] = [pageid]; //将用户加入协同记录数组
  1749. us.offLineMessage[pageid].nav.indexOf(fileid) == -1 && us.offLineMessage[pageid].nav.push(fileid); //添加到用户离线消息的连接wrod记录中
  1750. if (nowpageid) {
  1751. us.SaveNavPageContent(response, fileid, nowpageid, nowpagecontent);
  1752. } else {
  1753. response.end('saveContentSuccess'); //返回文档内容
  1754. }
  1755. } else {
  1756. response.end('saveNavFail'); //返回文档内容
  1757. }
  1758. });
  1759. }
  1760. us.SaveNavPageContent = function (response, fileid, nowpageid, nowpagecontent) {
  1761. var _navdata = us.nav[fileid];
  1762. //发送保存内容请求
  1763. us.mysql.usselect([
  1764. 'sqlserver.1473.cn',
  1765. 'UseStudio_Office',
  1766. 'SaveNavPageContent',
  1767. nowpageid,
  1768. nowpagecontent
  1769. ], function (ret) {
  1770. if (ret) {
  1771. _navdata.page[nowpageid] = us.cheerio.load(nowpagecontent.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""));
  1772. response.end('saveContentSuccess'); //返回文档内容
  1773. } else {
  1774. response.end('saveContentFail'); //返回文档内容
  1775. }
  1776. });
  1777. }
  1778. /**
  1779. * 新建导航页面
  1780. * @param {object} response 用户相应对象
  1781. * @param {string} nowpageid 当前页面ID
  1782. * @param {string} nowpagecontent 当前页面内容
  1783. */
  1784. us.copyPageContent = function (response, fileid, nowpageid, nowpagecontent, copypageid) {
  1785. if (!us.nav[fileid]) {
  1786. us.nav[fileid] = {
  1787. user: {},
  1788. navInfo: "",
  1789. page: {},
  1790. history: []
  1791. };
  1792. }
  1793. var _navdata = us.nav[fileid];
  1794. //发送保存内容请求
  1795. us.mysql.usselect([
  1796. 'sqlserver.1473.cn',
  1797. 'UseStudio_Office',
  1798. 'CopyPageContent',
  1799. nowpageid,
  1800. nowpagecontent,
  1801. copypageid
  1802. ], function (ret) {
  1803. if (ret) {
  1804. nowpagecontent == "" && (nowpagecontent = JSON.parse(ret)[0][0].content);
  1805. _navdata.page[nowpageid] = us.cheerio.load(nowpagecontent.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""));
  1806. response.end('saveContentSuccess'); //返回文档内容
  1807. } else {
  1808. response.end('saveContentFail'); //返回文档内容
  1809. }
  1810. });
  1811. }
  1812. /**
  1813. * 加入文档编辑 该函数暂无使用
  1814. *
  1815. * @param {object} response 用户相应对象
  1816. * @param {string} wordinfo 文档信息 形如: {docId : 'guid,guid,guid', userId : guid, pageId : guid}
  1817. **/
  1818. us.addWord = function (response, wordinfo) {
  1819. //获取用户参数
  1820. wordinfo = JSON.parse(wordinfo);
  1821. var _docidarray = wordinfo.docId.split(','), //根据','号分割多个文档ID
  1822. _userid = wordinfo.userId, //用户ID
  1823. _pageid = wordinfo.pageId, //页面唯一识别ID
  1824. i, //定义循环变量
  1825. _docid, //记录文档ID变量
  1826. _docinfo; //记录文档信息变量
  1827. for (i = 0; i < _docidarray.length; i++) { //循环处理每一份问的加入请求
  1828. _docid = _docidarray[i]; //记录文档ID变量
  1829. _docinfo = us.word[_docid]; //记录文档信息变量
  1830. if (!_docinfo) { //判断群列表是否已存在不存在则创建
  1831. us.word[_docid] = {
  1832. user: {},
  1833. history: []
  1834. }; //创建word文档信息
  1835. us.word[_docid].user[_userid] = [_pageid]; //加入用户
  1836. } else if (!_docinfo.user[_userid]) { //判断文档的用户是否已登陆
  1837. _docinfo.user[_userid] = [_pageid];
  1838. } else if (_docinfo.user[_userid].indexOf(_pageid) == -1) { //将用户添加到群列表中
  1839. _docinfo.user[_userid].push(_pageid);
  1840. }
  1841. us.offLineMessage[_pageid].word.push(_docid); //添加到用户离线消息的连接wrod记录中
  1842. }
  1843. response.end('addword'); //即时相应请求成功
  1844. }
  1845. /**
  1846. * 加入Excel编辑
  1847. *
  1848. * @param {object} response 用户相应对象
  1849. * @param {string} excelinfo 表格信息
  1850. **/
  1851. us.addExcel = function (response, excelinfo) {
  1852. //获取用户id
  1853. //获取用户id
  1854. excelinfo = JSON.parse(excelinfo);
  1855. var _excelinfo = us.excel[excelinfo.docId],
  1856. _userid = excelinfo.userId,
  1857. _pageid = excelinfo.pageId,
  1858. _docid = excelinfo.docId;
  1859. if (!_excelinfo) { //判断群列表是否已存在不存在则创建
  1860. us.excel[_docid] = {
  1861. user: {},
  1862. history: []
  1863. };
  1864. us.excel[_docid].user[_userid] = [_pageid];
  1865. } else if (!_excelinfo.user[_userid]) { //判断文档的用户是否已登陆 如果只有1个页面 则直接添加
  1866. _excelinfo.user[_userid] = [_pageid];
  1867. } else if (_excelinfo.user[_userid].indexOf(_pageid) == -1) { //将用户添加到群列表中 假如是一个用户多个页面 这里 则就是将每个页面添加到该用户下
  1868. _excelinfo.user[_userid].push(_pageid);
  1869. }
  1870. us.offLineMessage[_pageid].excel.push(_docid); //添加到用户离线消息的连接excel记录中
  1871. response.end('OK'); //返回到前台
  1872. }
  1873. /**
  1874. * 初始化获取未来课堂数据
  1875. *
  1876. */
  1877. us.getcscl = function (response, calssid, pageid, userid) {
  1878. //判断文档是否已在内层中存在
  1879. if (us.cscl[calssid]) {
  1880. // console.log("------------------------ssss----------")
  1881. // console.log(userid)
  1882. // console.log(us.cscl[calssid].user[userid])
  1883. //如果存在则直接返回内层的文档
  1884. if (!us.cscl[calssid].user[userid]) {
  1885. us.cscl[calssid].user[userid] = [pageid];
  1886. }
  1887. else if (us.cscl[calssid].user[userid].indexOf(pageid) == -1) {
  1888. us.cscl[calssid].user[userid].push(pageid);
  1889. }
  1890. try {
  1891. us.offLineMessage[pageid].cscl.indexOf(calssid) == -1 && us.offLineMessage[pageid].cscl.push(calssid); //添加到用户离线消息的连接wrod记录中
  1892. }
  1893. catch (e) {
  1894. }
  1895. console.log(us.cscl[calssid])
  1896. //如果不存在则去数据库查找
  1897. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', calssid],
  1898. function (ret) {
  1899. if (ret) {
  1900. console.log(ret[0][0].data)
  1901. ret[0][0].data = us.cscl[calssid].content; //把思维网格的内容转化成数组
  1902. response.end(JSON.stringify(ret)); //返回文档内容
  1903. }
  1904. else {
  1905. response.end(''); //返回文档内容
  1906. }
  1907. });
  1908. }
  1909. else {
  1910. us.cscl[calssid] = {
  1911. user: {},
  1912. history: []
  1913. };
  1914. us.cscl[calssid].user[userid] = [pageid];
  1915. if (us.offLineMessage[pageid]) {
  1916. us.offLineMessage[pageid].cscl.indexOf(calssid) == -1 && us.offLineMessage[pageid].cscl.push(calssid); //添加到用户离线消息的连接wrod记录中
  1917. }
  1918. // console.log("------------------------ggggg----------");
  1919. // console.log(us.cscl[calssid])
  1920. //如果不存在则去数据库查找
  1921. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', calssid],
  1922. function (ret) {
  1923. if (ret) {
  1924. console.log(ret[0][0].data)
  1925. us.cscl[calssid].content = JSON.parse(ret[0][0].data); //把思维网格的内容转化成数组
  1926. response.end(JSON.stringify(ret)); //返回文档内容
  1927. }
  1928. else {
  1929. us.cscl[calssid].content = {}; //创建一个空数组
  1930. response.end(''); //返回文档内容
  1931. }
  1932. });
  1933. }
  1934. }
  1935. /**
  1936. * 获取思维网格数据,转成成数组
  1937. *
  1938. */
  1939. us.getMindNetwork = function (response, docid, pageid, userid) {
  1940. //判断文档是否已在内层中存在
  1941. if (us.mindNetwork[docid]) {
  1942. //如果存在则直接返回内层的文档
  1943. if (!us.mindNetwork[docid].user[userid]) {
  1944. us.mindNetwork[docid].user[userid] = [pageid];
  1945. } else {
  1946. us.mindNetwork[docid].user[userid].push(pageid);
  1947. }
  1948. try {
  1949. us.offLineMessage[pageid].mindNetwork.indexOf(docid) == -1 && us.offLineMessage[pageid].mindNetwork.push(docid); //添加到用户离线消息的连接wrod记录中
  1950. }
  1951. catch (e) {
  1952. }
  1953. //console.log(us.mindNetwork[docid]);
  1954. //如果不存在则去数据库查找
  1955. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', docid],
  1956. function (ret) {
  1957. if (ret) {
  1958. ret[0][0].data = us.mindNetwork[docid].content; //把思维网格的内容转化成数组
  1959. response.end(JSON.stringify(ret)); //返回文档内容
  1960. }
  1961. else {
  1962. response.end(''); //返回文档内容
  1963. }
  1964. });
  1965. }
  1966. else {
  1967. us.mindNetwork[docid] = {
  1968. user: {},
  1969. history: []
  1970. };
  1971. us.mindNetwork[docid].user[userid] = [pageid];
  1972. if (us.offLineMessage[pageid]) {
  1973. us.offLineMessage[pageid].mindNetwork.indexOf(docid) == -1 && us.offLineMessage[pageid].mindNetwork.push(docid); //添加到用户离线消息的连接wrod记录中
  1974. }
  1975. //如果不存在则去数据库查找
  1976. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', docid],
  1977. function (ret) {
  1978. if (ret) {
  1979. us.mindNetwork[docid].content = JSON.parse(ret[0][0].data); //把思维网格的内容转化成数组
  1980. response.end(JSON.stringify(ret)); //返回文档内容
  1981. }
  1982. else {
  1983. us.mindNetwork[docid].content = []; //创建一个空数组
  1984. response.end(''); //返回文档内容
  1985. }
  1986. });
  1987. }
  1988. }
  1989. /**
  1990. * 获取实时课堂据,转成成数组
  1991. *
  1992. */
  1993. us.getRealTimeClass = function (response, docid, pageid, userid) {
  1994. //判断文档是否已在内层中存在
  1995. if (us.realTimeClass[docid]) {
  1996. //如果存在则直接返回内层的文档
  1997. if (!us.realTimeClass[docid].user[userid]) {
  1998. us.realTimeClass[docid].user[userid] = [pageid];
  1999. } else {
  2000. us.realTimeClass[docid].user[userid].push(pageid);
  2001. }
  2002. try {
  2003. us.offLineMessage[pageid].realTimeClass.indexOf(docid) == -1 && us.offLineMessage[pageid].realTimeClass.push(docid); //添加到用户离线消息的连接wrod记录中
  2004. }
  2005. catch (e) {
  2006. }
  2007. //console.log(us.realTimeClass[docid]);
  2008. //如果不存在则去数据库查找
  2009. us.mysql.usselect(['172.16.12.5', 'pbl', 'selectPptPage', docid],
  2010. function (ret) {
  2011. if (ret) {
  2012. ret[0][0].page = us.realTimeClass[docid].content; //把思维网格的内容转化成数组
  2013. response.end(JSON.stringify(ret)); //返回文档内容
  2014. }
  2015. else {
  2016. response.end(''); //返回文档内容
  2017. }
  2018. });
  2019. }
  2020. else {
  2021. us.realTimeClass[docid] = {
  2022. user: {},
  2023. history: []
  2024. };
  2025. us.realTimeClass[docid].user[userid] = [pageid];
  2026. if (us.offLineMessage[pageid]) {
  2027. us.offLineMessage[pageid].realTimeClass.indexOf(docid) == -1 && us.offLineMessage[pageid].realTimeClass.push(docid); //添加到用户离线消息的连接wrod记录中
  2028. }
  2029. //如果不存在则去数据库查找
  2030. us.mysql.usselect(['172.16.12.5', 'pbl', 'selectPptPage', docid],
  2031. function (ret) {
  2032. if (ret) {
  2033. us.realTimeClass[docid].content = JSON.parse(ret[0][0].page); //把思维网格的内容转化成数组
  2034. response.end(JSON.stringify(ret)); //返回文档内容
  2035. }
  2036. else {
  2037. us.realTimeClass[docid].content = []; //创建一个空数组
  2038. response.end(''); //返回文档内容
  2039. }
  2040. });
  2041. }
  2042. }
  2043. /**
  2044. * 获取文档,并生成DOM
  2045. *
  2046. * @param {object} response 用户相应对象
  2047. * @param {string} docid 文档ID
  2048. */
  2049. us.getWord = function (response, docid, pageid, userid) {
  2050. // //判断文档是否已在内层中存在
  2051. // if (us.word[docid]) {
  2052. // //如果存在则直接返回内层的文档
  2053. // if (!us.word[docid].user[userid]) {
  2054. // us.word[docid].user[userid] = [pageid];
  2055. // } else {
  2056. // us.word[docid].user[userid].push(pageid);
  2057. // }
  2058. // us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2059. // response.end(us.word[docid].content('body').html());
  2060. // }
  2061. // else {
  2062. // us.word[docid] = {
  2063. // user: {},
  2064. // history: []
  2065. // };
  2066. // us.word[docid].user[userid] = [pageid];
  2067. // if (us.offLineMessage[pageid]) {
  2068. // us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2069. // }
  2070. // //如果不存在则去数据库查找
  2071. // us.mysql.usselect(['172.16.12.5', 'pbl', 'select_file', docid],
  2072. // function (ret) {
  2073. // if (ret) {
  2074. // var _office = JSON.parse(ret)[0][0].data ? JSON.parse(ret)[0][0].data.replace(/\\'/ig, '\'').replace(/\\"/ig, "\"") : ""; //记录查找内容
  2075. // us.word[docid].content = us.cheerio.load(_office); //将文档添加到内层中
  2076. // response.end(_office); //返回文档内容
  2077. // } else {
  2078. // us.word[docid].content = us.cheerio.load(''); //将文档添加到内层中
  2079. // response.end(''); //返回文档内容
  2080. // }
  2081. // });
  2082. // }
  2083. //判断文档是否已在内层中存在
  2084. if (us.word[docid]) {
  2085. //如果存在则直接返回内层的文档
  2086. if (!us.word[docid].user[userid]) {
  2087. us.word[docid].user[userid] = [pageid];
  2088. } else {
  2089. us.word[docid].user[userid].push(pageid);
  2090. }
  2091. // console.log(us.offLineMessage[pageid]);
  2092. // console.log(pageid);
  2093. try {
  2094. us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2095. }
  2096. catch (e) {
  2097. }
  2098. //如果不存在则去数据库查找
  2099. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_file', docid],
  2100. function (ret) {
  2101. if (ret) {
  2102. ret[0][0].data = us.word[docid].content('body').html();
  2103. response.end(JSON.stringify(ret)); //返回文档内容
  2104. } else {
  2105. us.word[docid].content = us.cheerio.load(''); //将文档添加到内层中
  2106. response.end(''); //返回文档内容
  2107. }
  2108. });
  2109. }
  2110. else {
  2111. us.word[docid] = {
  2112. user: {},
  2113. history: []
  2114. };
  2115. us.word[docid].user[userid] = [pageid];
  2116. if (us.offLineMessage[pageid]) {
  2117. us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2118. }
  2119. //如果不存在则去数据库查找
  2120. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_file', docid],
  2121. function (ret) {
  2122. if (ret) {
  2123. var _office = ret[0][0].data ? ret[0][0].data.replace(/\\'/ig, '\'').replace(/\\"/ig, "\"") : ""; //记录查找内容
  2124. us.word[docid].content = us.cheerio.load(_office); //将文档添加到内层中
  2125. response.end(_office); //返回文档内容
  2126. } else {
  2127. us.word[docid].content = us.cheerio.load(''); //将文档添加到内层中
  2128. response.end(''); //返回文档内容
  2129. }
  2130. });
  2131. }
  2132. }
  2133. us.getExcel = function (response, docid, pageid, userid) {
  2134. //判断文档是否已在内层中存在
  2135. if (us.excel[docid]) {
  2136. //如果存在则直接返回内层的文档
  2137. if (!us.excel[docid].user[userid]) {
  2138. us.excel[docid].user[userid] = [pageid];
  2139. } else {
  2140. us.excel[docid].user[userid].push(pageid);
  2141. }
  2142. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
  2143. var _office = us.excel[docid].content;
  2144. response.end(JSON.stringify(_office));
  2145. } else {
  2146. us.excel[docid] = {
  2147. user: {},
  2148. history: []
  2149. };
  2150. us.excel[docid].user[userid] = [pageid];
  2151. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
  2152. //如果不存在则去数据库查找
  2153. us.mysql.usselect([
  2154. 'sqlserver.1473.cn',
  2155. 'UseStudio_Disk',
  2156. 'GetFileContent',
  2157. docid
  2158. ], function (ret) {
  2159. if (ret) {
  2160. var _office = JSON.parse(ret)[0][0].UsOffice;
  2161. us.excel[docid].content = JSON.parse(_office); //将文档添加到内层中
  2162. response.end(_office); //返回文档内容
  2163. } else {
  2164. us.excel[docid].content = ''; //将文档添加到内层中
  2165. response.end(''); //返回文档内容
  2166. }
  2167. });
  2168. }
  2169. }
  2170. /**
  2171. * 新建文档保存内容并加入协同
  2172. * @param {object} response 用户相应对象
  2173. * @param {guid} docid 文档ID
  2174. * @param {string} content 文档内容
  2175. * @param {string} name 文档名
  2176. * @param {guid} userid 用户ID
  2177. * @param {guid} pageid 页面唯一识别ID
  2178. */
  2179. us.newExcelSave = function (response, docid, content, name, userid, pageid) {
  2180. us.excel[docid] = {
  2181. user: {},
  2182. history: []
  2183. }; //创建excel类
  2184. us.excel[docid].user[userid] = [pageid]; //将用户加入协同记录数组
  2185. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2186. //发送保存请求
  2187. us.mysql.usselect([
  2188. 'sqlserver.1473.cn',
  2189. 'UseStudio_Disk',
  2190. 'SaveFileContent',
  2191. docid,
  2192. content,
  2193. name
  2194. ], function (ret) {
  2195. if (ret) {
  2196. //设置内容
  2197. us.excel[docid].content = JSON.parse(content); //将文档添加到内层中
  2198. response.end('saveOk'); //返回保存成功
  2199. } else {
  2200. response.end('fail'); //返回文档内容
  2201. }
  2202. });
  2203. }
  2204. /**
  2205. * 生成Guid
  2206. *
  2207. **/
  2208. us.createGuid = function () {
  2209. //返回guid的处理
  2210. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  2211. var r = Math.random() * 16 | 0,
  2212. v = c == 'x' ? r : (r & 0x3 | 0x8);
  2213. return v.toString(16);
  2214. });
  2215. };
  2216. /**
  2217. * 监听1473端口的处理
  2218. *
  2219. **/
  2220. us.server.listen('1473', '', function () {
  2221. //在控制台输出监听提示
  2222. console.log("开始监听" + us.server.address().port + "......");
  2223. });
  2224. // 同意处理错误
  2225. //process.on('uncaughtException', function (e) {
  2226. // console.log("错误:" + e);
  2227. //});