message.js 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373
  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. console.log("------------s------------");
  697. if (us.cscl[classId]) {
  698. var i, j, _is;
  699. var _obj = us.cscl[classId].content;
  700. _obj.backgroundUrl = messageInfo.backgroundUrl;
  701. _obj.edges = _obj.edges || [];
  702. _obj.nodes = _obj.nodes || [];
  703. for (j = 0; j < messageInfo.edges.length; j++) {
  704. _is = true;
  705. for (i = 0; i < _obj.edges.length; i++) {
  706. if (_obj.edges[i].id == messageInfo.edges[j].id) {
  707. if (ty == "update") {
  708. _obj.edges[i] = messageInfo.edges[j];
  709. }
  710. else {
  711. _obj.edges.splice(i, 1);
  712. }
  713. _is = false;
  714. break;
  715. }
  716. }
  717. if (_is && ty == "update") {
  718. _obj.edges.push(messageInfo.edges[j])
  719. }
  720. }
  721. console.log("------------s------------");
  722. console.log(messageInfo.nodes);
  723. console.log(_obj.nodes);
  724. console.log(ty);
  725. for (j = 0; j < messageInfo.nodes.length; j++) {
  726. _is = true;
  727. for (i = 0; i < _obj.nodes.length; i++) {
  728. if (_obj.nodes[i].id == messageInfo.nodes[j].id) {
  729. if (ty == "update") {
  730. _obj.nodes[i] = messageInfo.nodes[j];
  731. }
  732. else {
  733. _obj.nodes.splice(i, 1);
  734. }
  735. _is = false;
  736. break;
  737. }
  738. }
  739. if (_is && ty == "update") {
  740. _obj.nodes.push(messageInfo.nodes[j])
  741. }
  742. }
  743. console.log(_obj);
  744. //如果不存在则去数据库查找
  745. us.mysql.usselect(['172.16.12.5', 'pbl', 'updateRoomData', JSON.stringify(_obj), classId],
  746. function (ret) {
  747. });
  748. //"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}],
  749. //"edges":[],
  750. //"backgroundUrl":"img/bg.ccee1c62.png"
  751. // if (_obj) {
  752. // _obj[messageInfo.id] = messageInfo.content;
  753. // }
  754. }
  755. }
  756. /**
  757. * 更新后台实施课堂内容
  758. * @param {object} message 消息信息
  759. */
  760. us.updaterealTimeClass = function (messageInfo) {
  761. if (us.realTimeClass[messageInfo.docId]) {
  762. var $ = us.realTimeClass[messageInfo.docId].content;
  763. // console.log("---------------------------------------start")
  764. // console.log($);
  765. // console.log("---------------------------------------end")
  766. // console.log("---------------------------------------infostart")
  767. // console.log(messageInfo);
  768. // console.log("---------------------------------------infoend")
  769. if ($) {
  770. us.realTimeClass[messageInfo.docId].content[messageInfo.id] = messageInfo.content;
  771. }
  772. }
  773. }
  774. /**
  775. * 更新后台Word内容
  776. * @param {object} message 消息信息
  777. */
  778. us.updateWord = function (messageInfo) {
  779. if (us.word[messageInfo.docId]) {
  780. var $ = us.word[messageInfo.docId].content;
  781. if ($) {
  782. switch (messageInfo.type) { // 判断消息种类
  783. case 'update':
  784. us.updateEditorLine(messageInfo, $); //修改
  785. break;
  786. case 'add':
  787. us.addEditorLine(messageInfo, $); //添加
  788. break;
  789. case 'delete':
  790. us.deleteEditorLine(messageInfo, $); //删除
  791. break;
  792. }
  793. }
  794. }
  795. }
  796. /**
  797. * 更新后台Nav内容
  798. * @param {object} messageInfo 消息信息
  799. */
  800. us.updateNav = function (messageInfo) {
  801. var _fileinfo = us.nav[messageInfo.docId];
  802. if (_fileinfo) {
  803. switch (messageInfo.type) { // 判断消息种类
  804. case 'update': //修改行
  805. us.updateEditorLine(messageInfo, _fileinfo.page[messageInfo.navId]); //修改
  806. break;
  807. case 'add': //添加行
  808. us.addEditorLine(messageInfo, _fileinfo.page[messageInfo.navId]); //添加
  809. break;
  810. case 'delete': //删除行
  811. us.deleteEditorLine(messageInfo, _fileinfo.page[messageInfo.navId]); //删除
  812. break;
  813. case 'addNav': //添加导航
  814. us.updateNav.addNav(_fileinfo, messageInfo.parentId, messageInfo.index, messageInfo.addNav, messageInfo.content);
  815. break;
  816. case 'updateNav': //修改导航
  817. us.updateNav.updateNav(_fileinfo.navInfo.nav, messageInfo.navId, messageInfo.name);
  818. break;
  819. case 'deleteNav': //删除导航
  820. us.updateNav.deleteNav(_fileinfo, messageInfo.navId, messageInfo.parentId);
  821. break;
  822. case 'updateLogo': //修改logo
  823. _navinfo.logo = messageInfo.logo;
  824. break;
  825. }
  826. }
  827. }
  828. /**
  829. * 根据NavId查找对应的导航信息
  830. */
  831. us.selectByNavId = function (nowinfo, navid) {
  832. var i = 0;
  833. for (i = 0; i < nowinfo.length; i++) {
  834. object = nowinfo[i];
  835. if (object.pageId == navid) {
  836. return object;
  837. } else if (object.child) {
  838. return us.selectNav(object.child, navid);
  839. }
  840. }
  841. }
  842. /**
  843. * 添加Nav
  844. * @param {object} fileinfo 文件信息
  845. * @param {object} parentid 父级ID
  846. * @param {object} addnav 添加导航信息
  847. * @param {number} index 添加位置
  848. */
  849. us.updateNav.addNav = function (fileinfo, parentid, index, addnav, content) {
  850. var _nav = fileinfo.navInfo.nav;
  851. var _parent;
  852. if (parentid) {
  853. // 寻找父级
  854. _parent = us.selectByNavId(_nav, parentid);
  855. // 如果已存在子级处理
  856. if (_parent.child) {
  857. //插入指定位置
  858. _parent.child.splice(index, 0, addnav);
  859. } else {
  860. // 为存在子级则新建子级
  861. _parent.child = [addnav];
  862. }
  863. } else {
  864. _parent = _nav;
  865. _parent.splice(index, 0, addnav);
  866. }
  867. //添加内容
  868. fileinfo.page[addnav.pageId] = us.cheerio.load(content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""));
  869. }
  870. /**
  871. * 修改Nav
  872. * @param {object} nav 导航信息
  873. * @param {object} navid ID
  874. * @param {object} name 名字
  875. */
  876. us.updateNav.updateNav = function (nav, navid, name) {
  877. // 寻找需要修改导航信息
  878. var _nav = us.selectByNavId(nav, navid);
  879. if (_nav) { //存在导航
  880. _nav.name = name; //替换名字
  881. }
  882. }
  883. /**
  884. * 删除Nav
  885. * @param {object} fielinfo 文件信息
  886. * @param {object} navid ID
  887. * @param {object} name 名字
  888. */
  889. us.updateNav.deleteNav = function (fielinfo, deletenavid, parentid) {
  890. var _nav = fielinfo.navInfo.nav;
  891. var _parent;
  892. if (parentid) {
  893. // 寻找父级
  894. _parent = us.selectByNavId(_nav, parentid);
  895. } else {
  896. _parent = _nav;
  897. }
  898. if (_parent) {
  899. var _child = parentid ? _parent.child : _parent;
  900. _child.find(function (object, index) {
  901. if (object.pageId == deletenavid) {
  902. if (!object.child) {
  903. _child.splice(index, 1); //删除数据
  904. us.mysql.usselect([ //删除页面
  905. 'sqlserver.1473.cn',
  906. 'UseStudio_Office',
  907. 'DeletePage',
  908. deletenavid
  909. ], function (ret) {
  910. if (ret) {
  911. delete fielinfo.page[deletenavid]; //删除内容
  912. }
  913. });
  914. }
  915. return true;
  916. }
  917. });
  918. }
  919. }
  920. /**
  921. * 修改操作
  922. * @param {object} opera 操作信息对象
  923. * @param {element} $ 后台word元素形式
  924. */
  925. us.updateEditorLine = function (opera, $) {
  926. // $('#' + opera.id).prop('outerHTML', opera.content); //修改行
  927. $('#' + opera.id).replaceWith(opera.content);
  928. }
  929. /**
  930. * 删除操作
  931. * @param {object} opera 操作信息对象
  932. * @param {element} $ 后台word元素形式
  933. */
  934. us.deleteEditorLine = function (opera, $) {
  935. $('#' + opera.id).remove(); //删除行
  936. }
  937. /**
  938. * 添加操作
  939. * @param {object} opera 操作信息对象
  940. * @param {element} $ 后台word元素形式
  941. */
  942. us.addEditorLine = function (opera, $) {
  943. var _next; //创建记录变量
  944. if (opera.nextId && (_next = $('#' + opera.nextId))[0]) { //判断有没有nextid,nextid是否存在
  945. //如果存在则插入在nexid 元素前
  946. _next.before(opera.content);
  947. } else {
  948. $('body').append(opera.content); //没有就在最后插入
  949. }
  950. }
  951. /**
  952. * 更新后台Word内容
  953. * @param {object} message 消息信息
  954. */
  955. us.updateExcel = function (messageInfo) {
  956. var $ = us.excel[messageInfo.docId].content;
  957. if ($) {
  958. switch (messageInfo.type) { // 判断消息种类
  959. case 'blur':
  960. us.updateExcel.Blur(messageInfo, $); //失焦
  961. break;
  962. case "addLine":
  963. us.updateExcel.addLine(messageInfo, $); //添加行
  964. break;
  965. case "delLine":
  966. us.updateExcel.delLine(messageInfo, $); //刪除行
  967. break;
  968. case "addCol":
  969. us.updateExcel.addCol(messageInfo, $); //添加列
  970. break;
  971. case "delCol":
  972. us.updateExcel.delCol(messageInfo, $); //刪除列
  973. break;
  974. case "merge":
  975. us.updateExcel.merge(messageInfo, $); //合并单元格
  976. break;
  977. case "splitCells":
  978. us.updateExcel.splitCells(messageInfo, $); //拆分单元格
  979. break;
  980. case "rowExpanding":
  981. us.updateExcel.rowExpanding(messageInfo, $); //行板拉伸
  982. break;
  983. case "colExpanding":
  984. us.updateExcel.colExpanding(messageInfo, $); //列板拉伸
  985. break;
  986. case "addTask":
  987. us.updateExcel.addTask(messageInfo, $); //添加工作表
  988. break;
  989. case "deleteTask":
  990. us.updateExcel.deleteTask(messageInfo, $); //刪除工作表
  991. break;
  992. case "reNameTask":
  993. us.updateExcel.reNameTask(messageInfo, $); //刪除工作表
  994. break;
  995. case "img":
  996. us.updateExcel.img(messageInfo, $); //插入图片
  997. break;
  998. }
  999. }
  1000. // console.log($);
  1001. }
  1002. /**
  1003. * 失焦處理
  1004. */
  1005. us.updateExcel.Blur = function (messageInfo, $) {
  1006. var _taskId = messageInfo.worksheetId, //如果有taskId传过来 则修改 data数据里 taskId里的数据 否则则修改当前工作表id里的数据
  1007. _excelData = $[_taskId], //获取taskId工作表的数据
  1008. _cellData = _excelData.cell, //获取该数据里的单元格数据
  1009. _content = messageInfo.content; //获取需要保存的json数据
  1010. _content.forEach(function (data) {
  1011. var _text = data.innerText.replace(/\s+/g, ""), //去掉空格 给下面做判断 如果内容为空 则删除该数据
  1012. _cellColList = _cellData[data.col], //获取该数据里的所有列
  1013. _cell = null;
  1014. if (!_cellColList) { //如果列不存在 则创建一个列
  1015. _cellColList = _cellData[data.col] = {};
  1016. }
  1017. if (!_cellColList[data.row]) { //如果该行_列 不存在单元格数据 则创建个json 给单元格添加数据
  1018. _cellColList[data.row] = {};
  1019. _cellColList[data.row].cssStyle = {}; //css样式
  1020. }
  1021. _cell = _cellColList[data.row]; //获取该单元格的数据 (json)
  1022. data.content ? _cell.innerHTML = data.content : ""; //修改该单元格的innerHTML
  1023. if (data.attr) { //如果存在样式
  1024. _cell.cssStyle[data.attr] = data.value;
  1025. if (!data.value) {
  1026. delete _cell.cssStyle[data.attr]
  1027. }
  1028. }
  1029. if (data.clearStyle) { //如果需要清除所有样式的话
  1030. data.cssStyle = {}
  1031. }
  1032. if (((!(_text) || _text === ("\u200D")) && !(_cell.endRow)) && !(us.jsonLen(_cell.cssStyle))) { //如果innerHTML为空格 或 不存在 并且 不是合并单元格元素 并且没有样式 则删除掉
  1033. delete (_cellColList[data.row]);
  1034. }
  1035. });
  1036. }
  1037. /*
  1038. 获取json的数量
  1039. */
  1040. us.jsonLen = function (json) {
  1041. var _json = json,
  1042. _len = 0;
  1043. for (var i in json) {
  1044. _len++;
  1045. }
  1046. return _len;
  1047. }
  1048. us.updateExcel.addLine = function (messageInfo, $) {
  1049. var _taskId = messageInfo.worksheetId, //单元格id
  1050. _content = messageInfo.content,
  1051. _excelData = $[_taskId],
  1052. _rowData = _excelData.row,
  1053. _cellData = _excelData.cell,
  1054. _start = _content.start, //开始行
  1055. _lineNum = _content.lineNum, //添加行的数量
  1056. _sizeChange = _content.sizeChange, //添加的行的高度
  1057. _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
  1058. _cellCol = null;
  1059. if (_mergeArr.length) {
  1060. _mergeArr.forEach(function (info) {
  1061. _cellData[info.col][info.row].endRow = _cellData[info.col][info.row].endRow + _lineNum;
  1062. });
  1063. }
  1064. for (var k in _cellData) {
  1065. _cellCol = _cellData[k]; //该列下的所有行
  1066. var temp = {};
  1067. for (var row in _cellCol) {
  1068. if (row > _start) {
  1069. temp[(+row) + _lineNum] = _cellCol[row];
  1070. temp[(+row) + _lineNum].endRow ? temp[(+row) + _lineNum].endRow = temp[(+row) + _lineNum].endRow + _lineNum : ""; //如果是合并单元格的元素 则将endRow + _lineNum;
  1071. } else {
  1072. temp[row] = _cellCol[row];
  1073. }
  1074. }
  1075. _cellData[k] = temp;
  1076. } /* 该处for循环是修改数据中单元格的行数 */
  1077. var _rowDataChange = _rowData.change, //获取数据表中 所有被改变高度的 行版信息
  1078. _temp = {},
  1079. _rowChange = null;
  1080. for (var k in _rowDataChange) {
  1081. _rowChange = _rowDataChange[k]; //该行板的所有被改动的行数据
  1082. if (k > _start) {
  1083. _temp[(+k) + _lineNum] = _rowChange;
  1084. } else {
  1085. _temp[k] = _rowChange;
  1086. }
  1087. } /* 该处for循环是修改数据中行版的行数 */
  1088. _rowData.change = _temp;
  1089. if (_sizeChange) {
  1090. for (var i = 1; i <= _lineNum; i++) {
  1091. _rowData.change[_start + i] = _sizeChange;
  1092. }
  1093. }
  1094. _rowData.num = _rowData.num + _lineNum; //行板数量 = 行板数量 + 添加行的数量
  1095. };
  1096. us.updateExcel.delLine = function (messageInfo, $) {
  1097. var _taskId = messageInfo.worksheetId, //单元格id
  1098. _excelData = $[_taskId],
  1099. _content = messageInfo.content,
  1100. _rowData = _excelData.row,
  1101. _cellData = _excelData.cell,
  1102. _start = _content.start, //被选中的第一行
  1103. _end = _content.end, //被选中的最后一行
  1104. _lineNum = _content.lineNum, //所删除的行数
  1105. _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
  1106. _cellCol = null;
  1107. for (var k in _cellData) {
  1108. _cellCol = _cellData[k];
  1109. var temp = {};
  1110. for (var row in _cellCol) {
  1111. if (row > _end) {
  1112. temp[(+row) - _lineNum] = _cellCol[row];
  1113. temp[(+row) - _lineNum].endRow ? temp[(+row) - _lineNum].endRow = temp[(+row) - _lineNum].endRow - _lineNum : ""; //如果是合并单元格的元素 则将endRow - _lineNum;
  1114. } else if (row < _start) {
  1115. temp[row] = _cellCol[row];
  1116. }
  1117. }
  1118. _cellData[k] = temp;
  1119. }
  1120. if (_mergeArr.length) {
  1121. var _cloneMessage = null;
  1122. _mergeArr.forEach(function (info) {
  1123. _cloneMessage = JSON.parse(JSON.stringify(messageInfo));
  1124. _cloneMessage.content = info;
  1125. us.updateExcel.merge(_cloneMessage, $);
  1126. });
  1127. }
  1128. var _rowDataChange = _rowData.change, //获取数据表中 所有被改变高度的 行版信息
  1129. _temp = {},
  1130. _rowChange = null;
  1131. for (var k in _rowDataChange) {
  1132. _rowChange = _rowDataChange[k]; //该行板的所有被改动的行数据
  1133. if (k < _start) { //如果大于结束行 则将该行下面的所有的数字信息 - 被删除的行
  1134. _temp[k] = _rowChange;
  1135. } else if (k > _end) {
  1136. _temp[(+k) - _lineNum] = _rowChange;
  1137. }
  1138. } /* 该处for循环是修改数据中行版的行数 */
  1139. _rowData.change = _temp;
  1140. _rowData.num = _rowData.num - _lineNum; //行板数量 = 行板数量 - 删除行的数量
  1141. };
  1142. us.updateExcel.addCol = function (messageInfo, $) {
  1143. var _taskId = messageInfo.worksheetId, //单元格id
  1144. _excelData = $[_taskId],
  1145. _content = messageInfo.content,
  1146. _colData = _excelData.column,
  1147. _cellData = _excelData.cell,
  1148. _start = _content.start, //被选中的第一列
  1149. _sizeChange = _content.sizeChange, //添加的列的宽度
  1150. _colNums = _content.colNums, //所添加的列数
  1151. _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
  1152. _cellCol = null,
  1153. _temp = {};
  1154. if (_mergeArr.length) {
  1155. _mergeArr.forEach(function (info) {
  1156. _cellData[info.col][info.row].endCol = _cellData[info.col][info.row].endCol + _colNums;
  1157. });
  1158. }
  1159. for (var k in _cellData) {
  1160. _cellCol = _cellData[k];
  1161. if (k > _start) {
  1162. _temp[+(k) + _colNums] = _cellCol;
  1163. var _temp2 = _temp[(+k) + _colNums];
  1164. for (var i in _temp2) {
  1165. _temp2[i].endCol ? _temp2[i].endCol = _temp2[i].endCol + _colNums : ""; //如果是合并单元格的元素 则将endCol + _colNums;
  1166. }
  1167. } else {
  1168. _temp[k] = _cellCol;
  1169. }
  1170. }
  1171. _excelData.cell = _temp;
  1172. var _colDataChange = _colData.change, //获取数据表中 所有被改变宽度的 列版信息
  1173. _temp = {},
  1174. _colChange = null;
  1175. for (var k in _colDataChange) {
  1176. _colChange = _colDataChange[k]; //该列板的所有被改动的列数据
  1177. if (k > _start) {
  1178. _temp[(+k) + _colNums] = _colChange;
  1179. } else {
  1180. _temp[k] = _colChange;
  1181. }
  1182. } /* 该处for循环是修改数据中行版的行数 */
  1183. _colData.change = _temp;
  1184. if (_sizeChange) {
  1185. for (var i = 1; i <= _colNums; i++) {
  1186. _colData.change[_start + i] = _sizeChange;
  1187. }
  1188. }
  1189. _colData.num = _colData.num + _colNums; //列板数量 = 列板数量 + 添加列的数量
  1190. };
  1191. us.updateExcel.delCol = function (messageInfo, $) {
  1192. var _taskId = messageInfo.worksheetId, //单元格id
  1193. _excelData = $[_taskId],
  1194. _content = messageInfo.content,
  1195. _colData = _excelData.column,
  1196. _cellData = _excelData.cell,
  1197. _start = _content.start, //被选中的第一行
  1198. _end = _content.end, //被选中的最后一行
  1199. _colNums = _content.colNums, //所删除的列数
  1200. _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
  1201. _cellCol = null,
  1202. _temp = {};
  1203. for (var k in _cellData) {
  1204. _cellCol = _cellData[k];
  1205. if (k > _end) {
  1206. _temp[+(k) - _colNums] = _cellCol;
  1207. var _temp2 = _temp[(+k) - _colNums];
  1208. for (var i in _temp2) {
  1209. _temp2[i].endCol ? _temp2[i].endCol = _temp2[i].endCol - _colNums : ""; //如果是合并单元格的元素 则将endCol - _colNums;
  1210. }
  1211. } else if (k < _start) {
  1212. _temp[k] = _cellCol;
  1213. }
  1214. }
  1215. _excelData.cell = _temp;
  1216. if (_mergeArr.length) {
  1217. var _cloneMessage = null;
  1218. _mergeArr.forEach(function (info) {
  1219. _cloneMessage = JSON.parse(JSON.stringify(messageInfo));
  1220. _cloneMessage.content = info;
  1221. us.updateExcel.merge(_cloneMessage, $);
  1222. });
  1223. }
  1224. var _colDataChange = _colData.change, //获取数据表中 所有被改变宽度的 列版信息
  1225. _temp = {},
  1226. _colChange;
  1227. for (var k in _colDataChange) {
  1228. _colChange = _colDataChange[k]; //该列板的所有被改动的列数据
  1229. if (k < _start) { //如果大于结束列 则将该列下面的所有的数字信息 - 被删除的列
  1230. _temp[k] = _colChange;
  1231. } else if (k > _end) {
  1232. _temp[(+k) - _colNums] = _colChange;
  1233. }
  1234. } /* 该处for循环是修改数据中行版的行数 */
  1235. _colData.change = _temp;
  1236. _colData.num = _colData.num - _colNums; //列板数量 = 列板数量 - 删除列的数量
  1237. };
  1238. us.updateExcel.merge = function (messageInfo, $) {
  1239. var _taskId = messageInfo.worksheetId, //单元格id
  1240. _excelData = $[_taskId],
  1241. _content = messageInfo.content,
  1242. _cellData = _excelData.cell,
  1243. _cellColList = _cellData[_content.col];
  1244. if (_content.row === _content.endRow && _content.col === _content.endCol) {
  1245. _cellData[_content.col][_content.row].endRow = "";
  1246. _cellData[_content.col][_content.row].endCol = ""
  1247. return;
  1248. }
  1249. if (!_cellColList) {
  1250. _cellColList = _cellData[_content.col] = {};
  1251. }
  1252. if (!_cellColList[_content.row]) {
  1253. _cellColList[_content.row] = {};
  1254. }
  1255. _cellColList[_content.row].innerHTML = _content.content;
  1256. _cellColList[_content.row].endRow = _content.endRow;
  1257. _cellColList[_content.row].endCol = _content.endCol;
  1258. };
  1259. us.updateExcel.splitCells = function (messageInfo, $) {
  1260. var _taskId = messageInfo.worksheetId, //单元格id
  1261. _excelData = $[_taskId],
  1262. _content = messageInfo.content,
  1263. _cellData = _excelData.cell,
  1264. _cell = _cellData[_content.col][_content.row]; //需要拆分的单元格
  1265. _cell.endRow = "";
  1266. _cell.endCol = "";
  1267. };
  1268. us.updateExcel.rowExpanding = function (messageInfo, $) {
  1269. var _taskId = messageInfo.worksheetId, //单元格id
  1270. _excelData = $[_taskId],
  1271. _content = messageInfo.content,
  1272. _rowData = _excelData.row;
  1273. _content.forEach(function (data) {
  1274. var _rowNum = data.rowName, //拉伸行的位置 (数字)
  1275. _rowHeight = data.height; //被拉伸后的高度
  1276. _rowData.change[_rowNum] = _rowHeight;
  1277. });
  1278. };
  1279. us.updateExcel.colExpanding = function (messageInfo, $) {
  1280. var _taskId = messageInfo.worksheetId, //单元格id
  1281. _excelData = $[_taskId],
  1282. _content = messageInfo.content,
  1283. _colData = _excelData.column; //该列的数据
  1284. _content.forEach(function (data) {
  1285. var _colNum = data.colName, //拉伸行的位置 (数字)
  1286. _colWidth = data.width; //被拉伸后的宽度
  1287. _colData.change[_colNum] = _colWidth;
  1288. });
  1289. };
  1290. /*添加工作表*/
  1291. us.updateExcel.addTask = function (messageInfo, $) {
  1292. var _content = messageInfo.content,
  1293. _taskId = _content.id;
  1294. $[_taskId] = _content.data;
  1295. };
  1296. /*刪除工作表*/
  1297. us.updateExcel.deleteTask = function (messageInfo, $) {
  1298. var _content = messageInfo.content,
  1299. _taskId = _content.id;
  1300. delete ($[_taskId]);
  1301. };
  1302. /*命名工作表*/
  1303. us.updateExcel.reNameTask = function (messageInfo, $) {
  1304. var _content = messageInfo.content,
  1305. _taskId = _content.id;
  1306. $[_taskId].taskName = _content.name;
  1307. };
  1308. us.updateExcel.img = function (messageInfo, $) { //此处修改
  1309. var _content = messageInfo.content,
  1310. _taskId = messageInfo.worksheetId,
  1311. _excelData = $[_taskId],
  1312. _imgData = _excelData.img;
  1313. _imgData.push(_content);
  1314. };
  1315. /**
  1316. * 用户群发处理
  1317. *
  1318. * @param {string} 接收信息的用户id
  1319. * @param {string} 发送的用户信息
  1320. **/
  1321. us.setword = function (messageinfo) {
  1322. // us.userConnect[userid].response.end(messageinfo);
  1323. }
  1324. /**
  1325. * 用户群发处理
  1326. *
  1327. * @param {string} userid 接收信息的用户id
  1328. * @param {string} messageinfo 发送的用户信息
  1329. **/
  1330. us.senduser = function (userid, messageinfo) {
  1331. us.userConnect[userid].response.end(messageinfo); //发送消息
  1332. }
  1333. /**
  1334. * 用户群发处理
  1335. *
  1336. * @param {object} messageinfo 发送消息的内容
  1337. * @param {guid} pageid 页面id
  1338. * @param {string} type 类型
  1339. **/
  1340. us.broadcast = function (messageinfo, pageid, type) {
  1341. var i, j, o, //循环变量
  1342. _messageinfo, //消息信息
  1343. _users, //用户ID集合
  1344. _pageids, //用户页面唯一识别集合
  1345. _recievedpageid, //接收用户的页面唯一识别ID
  1346. _issend, // 是否发送
  1347. _userconnect = us.connect; //用户连接池
  1348. for (i in messageinfo) {
  1349. _messageinfo = messageinfo[i]; //记录消息消息
  1350. _users = us[type][i] ? us[type][i].user : {}; //记录用户集合
  1351. // console.log("=================a=============");
  1352. // console.log(_users);
  1353. for (j in _users) { //循环处理每个用户处理 给每个用户集合下的用户发送消息
  1354. _pageids = _users[j]; //记录当前用户在每个端登录的页面唯一识别ID
  1355. // console.log("=================g=============");
  1356. // console.log(_pageids);
  1357. for (o = 0; o < _pageids.length; o++) { //循环发送给当前用户在每个端登录的用户
  1358. _recievedpageid = _pageids[o]; //记录接受者页面唯一识别ID 用于区分是否是发送用户
  1359. if (_recievedpageid != pageid) { //如果接受用户不等于发送用户则发送消息
  1360. try {
  1361. // console.log("=================b=============");
  1362. // console.log(_userconnect[j]);
  1363. if (_userconnect[j] && _userconnect[j][_recievedpageid]) {
  1364. _issend = _userconnect[j][_recievedpageid].response.end(JSON.stringify(_messageinfo)); //发送消息
  1365. if (!_issend) { //如果用户下线了,那么发送消息就会失败
  1366. us.offLineMessage[_recievedpageid].message.push(_messageinfo); //将消息加入用户离线消息中
  1367. }
  1368. }
  1369. }
  1370. catch (e) {
  1371. console.log(e)
  1372. }
  1373. }
  1374. }
  1375. }
  1376. }
  1377. }
  1378. /**
  1379. * 加入文档编辑
  1380. *
  1381. * @param {object} response 用户相应对象
  1382. * @param {string} wordinfo 文档信息 形如: {docId : 'guid,guid,guid', userId : guid, pageId : guid}
  1383. **/
  1384. us.addWord = function (response, wordinfo) {
  1385. //获取用户参数
  1386. wordinfo = JSON.parse(wordinfo);
  1387. var _docidarray = wordinfo.docId.split(','), //根据','号分割多个文档ID
  1388. _userid = wordinfo.userId, //用户ID
  1389. _pageid = wordinfo.pageId, //页面唯一识别ID
  1390. i, //定义循环变量
  1391. _docid, //记录文档ID变量
  1392. _docinfo; //记录文档信息变量
  1393. for (i = 0; i < _docidarray.length; i++) { //循环处理每一份问的加入请求
  1394. _docid = _docidarray[i]; //记录文档ID变量
  1395. _docinfo = us.word[_docid]; //记录文档信息变量
  1396. if (!_docinfo) { //判断群列表是否已存在不存在则创建
  1397. us.word[_docid] = {
  1398. user: {},
  1399. history: []
  1400. }; //创建word文档信息
  1401. us.word[_docid].user[_userid] = [_pageid]; //加入用户
  1402. } else if (!_docinfo.user[_userid]) { //判断文档的用户是否已登陆
  1403. _docinfo.user[_userid] = [_pageid];
  1404. } else if (_docinfo.user[_userid].indexOf(_pageid) == -1) { //将用户添加到群列表中
  1405. _docinfo.user[_userid].push(_pageid);
  1406. }
  1407. us.offLineMessage[_pageid].word.push(_docid); //添加到用户离线消息的连接wrod记录中
  1408. }
  1409. response.end('addword'); //即时相应请求成功
  1410. }
  1411. /**
  1412. * 退出文档编辑
  1413. *
  1414. * @param {object} response 用户相应对象
  1415. * @param {string} wordinfo 文档信息
  1416. **/
  1417. us.quitOffice = function (response, wordinfo) {
  1418. //获取用户参数
  1419. wordinfo = JSON.parse(wordinfo);
  1420. var _docid = wordinfo.docId,
  1421. _userid = wordinfo.userId,
  1422. _pageid = wordinfo.pageId,
  1423. _type = wordinfo.type,
  1424. _messagetype = 'us.' + _type;
  1425. var _docinfo = us[_type][_docid]; //获取文档信息
  1426. //判断是否存在文档信息
  1427. if (_docinfo) {
  1428. us.quitUserList(_docinfo, _userid, _pageid); //将用户在协同列表中删除
  1429. var _j, //创建循环变量
  1430. _message = us.offLineMessage[_pageid] ? us.offLineMessage[_pageid].message : []; //获取该用户的离线消息
  1431. for (_j = _message.length - 1; _j > -1; _j--) { //循环移除该文档的离线消息
  1432. if (_message[_j].type == _messagetype && _message[_j].messageInfo.docId == _docid) { //判断是否为word文档
  1433. _message.splice(_j, 1); //删除记录
  1434. }
  1435. }
  1436. us.insertHistory(_docinfo, _docid, _type);
  1437. }
  1438. response.end('quitOffice'); //响应退出请求
  1439. }
  1440. /**
  1441. * 将用户在协同列表中删除
  1442. *
  1443. * @param {object} docinfo 文档信息
  1444. * @param {string} userid 用户ID
  1445. * @param {string} pageid 用户页面唯一识别ID
  1446. */
  1447. us.quitUserList = function (docinfo, userid, pageid) {
  1448. var _users = docinfo.user[userid]; //记录文档的用户列表
  1449. //获取用户在文档用户列表的位置
  1450. if (_users) {
  1451. var _index = _users.indexOf(pageid);
  1452. // 如果存在则将该用户删除 表示退出协同
  1453. if (_index != -1) {
  1454. _users.splice(_index, 1); //删除该用户
  1455. //如果该用户的全部端用户已退出则删除用户的记录
  1456. if (_users.length == 0) {
  1457. delete docinfo.user[userid];
  1458. }
  1459. }
  1460. }
  1461. }
  1462. /**
  1463. * 插入文档操作历史到数据库
  1464. *
  1465. * @param {object} docinfo 文档信息
  1466. */
  1467. us.insertHistory = function (docinfo, docid, type) {
  1468. var i,
  1469. _info, //操作信息记录
  1470. _isuser = false;
  1471. for (i in docinfo.user) {
  1472. _isuser = true;
  1473. break;
  1474. }
  1475. //如果该文档没有协同用户
  1476. if (!_isuser) {
  1477. switch (type) {
  1478. case 'word':
  1479. var _content = docinfo.content ? docinfo.content('body').html().replace(/'/ig, '\\\'').replace(/"/ig, "\\\"") : "";
  1480. us.mysql.usselect(['sqlserver.1473.cn', 'UseStudio_Disk', 'SaveFileContent', docid, _content, ''],
  1481. function (ret) { });
  1482. break;
  1483. case 'nav':
  1484. us.mysql.usselect(['sqlserver.1473.cn', 'UseStudio_Disk', 'SaveFileContent', docid, JSON.stringify(docinfo.navInfo), ''],
  1485. function (ret) {
  1486. var _key;
  1487. for (_key in docinfo.page) {
  1488. //发送保存内容请求
  1489. var _content = docinfo.page[_key] ? docinfo.page[_key]('body').html().replace(/'/ig, '\\\'').replace(/"/ig, "\\\"") : "";
  1490. us.mysql.usselect(['sqlserver.1473.cn', 'UseStudio_Office', 'SaveNavPageContent', _key, _content], function (ret) { });
  1491. }
  1492. });
  1493. break;
  1494. }
  1495. }
  1496. }
  1497. /**
  1498. * 下线操作
  1499. * @param {object} response 响应对象
  1500. * @param {string} userid 用户ID
  1501. * @param {string} pageid 用户页面唯一识别ID
  1502. */
  1503. us.logout = function (response, userid, pageid) {
  1504. var i, j, _docinfo,
  1505. _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
  1506. _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
  1507. us.connect[userid][pageid].offLineTime = new Date();
  1508. for (i = 0; i < _wordids.length; i++) { //循环处理每一个文档
  1509. _docinfo = us.word[_wordids[i]]; //记录文档信息
  1510. if (_docinfo) { //如果存在文档信息
  1511. us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
  1512. delete us.offLineMessage[pageid]; //删除用户离线消息记录
  1513. us.insertHistory(_docinfo, 'word'); //插入历史
  1514. }
  1515. }
  1516. for (j = 0; i < _excelids.length; j++) {
  1517. _docinfo = us.excel[_excelids[j]]; //记录文档信息
  1518. if (_docinfo) { //如果存在文档信息
  1519. us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
  1520. delete us.offLineMessage[pageid]; //删除用户离线消息记录
  1521. us.insertHistory(_docinfo, 'excel'); //插入历史
  1522. }
  1523. }
  1524. response.end('logout'); //响应退出请求
  1525. }
  1526. /**
  1527. * 获取Excel,并生成后端数据
  1528. *
  1529. * @param {object} response 用户相应对象
  1530. * @param {string} docid 文档ID
  1531. * @param {guid} pageid 页面ID
  1532. * @param {guid} userid 用户ID
  1533. */
  1534. us.getExcel = function (response, docid, pageid, userid) {
  1535. //判断文档是否已在内层中存在
  1536. if (us.excel[docid]) {
  1537. //如果存在则直接返回内层的文档
  1538. if (!us.excel[docid].user[userid]) {
  1539. us.excel[docid].user[userid] = [pageid];
  1540. } else {
  1541. us.excel[docid].user[userid].push(pageid);
  1542. }
  1543. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
  1544. var _office = us.excel[docid].content;
  1545. response.end(JSON.stringify(_office));
  1546. } else {
  1547. us.excel[docid] = {
  1548. user: {},
  1549. history: []
  1550. };
  1551. us.excel[docid].user[userid] = [pageid];
  1552. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
  1553. //如果不存在则去数据库查找
  1554. us.mysql.usselect([
  1555. 'sqlserver.1473.cn',
  1556. 'UseStudio_Disk',
  1557. 'GetFileContent',
  1558. docid
  1559. ], function (ret) {
  1560. if (ret) {
  1561. var _office = JSON.parse(ret)[0][0].UsOffice;
  1562. us.excel[docid].content = JSON.parse(_office); //将文档添加到内层中
  1563. response.end(_office); //返回文档内容
  1564. } else {
  1565. us.excel[docid].content = ''; //将文档添加到内层中
  1566. response.end(''); //返回文档内容
  1567. }
  1568. });
  1569. }
  1570. }
  1571. /**
  1572. * 获取文档,并生成DOM
  1573. *
  1574. * @param {object} response 用户相应对象
  1575. * @param {string} fileid 导航文件ID
  1576. * @param {guid} pageid 页面ID
  1577. * @param {guid} userid 用户ID
  1578. */
  1579. us.getNav = function (response, fileid, pageid, userid) {
  1580. //判断文档是否已在内层中存在
  1581. if (us.nav[fileid]) {
  1582. //如果存在则直接返回内层的文档
  1583. if (!us.nav[fileid].user[userid]) {
  1584. us.nav[fileid].user[userid] = [pageid];
  1585. } else {
  1586. us.nav[fileid].user[userid].push(pageid);
  1587. }
  1588. us.offLineMessage[pageid].nav.indexOf(fileid) == -1 && us.offLineMessage[pageid].nav.push(fileid); //添加到用户离线消息的连接wrod记录中
  1589. response.end(JSON.stringify(us.nav[fileid].navInfo));
  1590. } else {
  1591. //如果不存在则去数据库查找
  1592. us.mysql.usselect([
  1593. 'sqlserver.1473.cn',
  1594. 'UseStudio_Disk',
  1595. 'GetFileContent',
  1596. fileid
  1597. ], function (ret) {
  1598. if (ret) {
  1599. var _navinfo = JSON.parse(ret)[0][0].UsOffice;
  1600. if (_navinfo) {
  1601. var _navdata = us.nav[fileid] = { //生成数据结构
  1602. user: {},
  1603. navInfo: JSON.parse(_navinfo),
  1604. page: {},
  1605. history: []
  1606. };
  1607. _navdata.user[userid] = [pageid]; //记录用户
  1608. us.offLineMessage[pageid].nav.indexOf(fileid) == -1 && us.offLineMessage[pageid].nav.push(fileid); //添加到用户离线消息的连接wrod记录中
  1609. response.end(JSON.stringify(_navinfo)); //返回文档内容
  1610. } else {
  1611. response.end(''); //查询不到文档
  1612. }
  1613. } else {
  1614. response.end(''); //返回文档内容
  1615. }
  1616. });
  1617. }
  1618. }
  1619. /**
  1620. * 获取导航页面内容
  1621. * @param {object} response 用户相应对象
  1622. * @param {guid} fileid 文档ID
  1623. * @param {string} navid 文档内容
  1624. * @param {string} name 文档名
  1625. */
  1626. us.getNavPageContent = function (response, fileid, navid) {
  1627. if (us.nav[fileid] && us.nav[fileid].page[navid]) {
  1628. response.end(us.nav[fileid].page[navid]('body').html()); //后台直接返回
  1629. } else {
  1630. //如果不存在则去数据库查找
  1631. us.mysql.usselect([
  1632. 'sqlserver.1473.cn',
  1633. 'UseStudio_Office',
  1634. 'GetNavPageContent',
  1635. navid
  1636. ], function (ret) {
  1637. if (ret && JSON.parse(ret)[0][0]) {
  1638. var _content = JSON.parse(ret)[0][0].content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""); //记录查找内容
  1639. us.nav[fileid] && (us.nav[fileid].page[navid] = us.cheerio.load(_content)); //将文档添加到内层中
  1640. response.end(_content); //查询不到文档
  1641. } else {
  1642. response.end(''); //返回文档内容
  1643. }
  1644. });
  1645. }
  1646. }
  1647. /**
  1648. * 新建文档保存内容并加入协同
  1649. * @param {object} response 用户相应对象
  1650. * @param {guid} docid 文档ID
  1651. * @param {string} content 文档内容
  1652. * @param {string} name 文档名
  1653. * @param {guid} userid 用户ID
  1654. * @param {guid} pageid 页面唯一识别ID
  1655. */
  1656. us.newWordSave = function (response, docid, content, name, userid, pageid) {
  1657. us.word[docid] = {
  1658. user: {},
  1659. history: []
  1660. }; //创建Word类
  1661. us.word[docid].user[userid] = [pageid]; //将用户加入协同记录数组
  1662. us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  1663. //发送保存请求
  1664. us.mysql.usselect([
  1665. 'sqlserver.1473.cn',
  1666. 'UseStudio_Disk',
  1667. 'SaveFileContent',
  1668. docid,
  1669. content,
  1670. name
  1671. ], function (ret) {
  1672. if (ret) {
  1673. //设置内容
  1674. us.word[docid].content = us.cheerio.load(content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\"")); //将文档添加到内层中
  1675. response.end('save'); //返回保存成功
  1676. } else {
  1677. response.end('fail'); //返回文档内容
  1678. }
  1679. });
  1680. }
  1681. /**
  1682. * 新建文档保存内容并加入协同
  1683. * @param {object} response 用户相应对象
  1684. * @param {guid} docid 文档ID
  1685. * @param {string} content 文档内容
  1686. * @param {string} name 文档名
  1687. * @param {guid} userid 用户ID
  1688. * @param {guid} pageid 页面唯一识别ID
  1689. */
  1690. us.newExcelSave = function (response, docid, content, name, userid, pageid) {
  1691. us.excel[docid] = {
  1692. user: {},
  1693. history: []
  1694. }; //创建excel类
  1695. us.excel[docid].user[userid] = [pageid]; //将用户加入协同记录数组
  1696. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  1697. //发送保存请求
  1698. us.mysql.usselect([
  1699. 'sqlserver.1473.cn',
  1700. 'UseStudio_Disk',
  1701. 'SaveFileContent',
  1702. docid,
  1703. content,
  1704. name
  1705. ], function (ret) {
  1706. if (ret) {
  1707. //设置内容
  1708. us.excel[docid].content = JSON.parse(content); //将文档添加到内层中
  1709. response.end('saveOk'); //返回保存成功
  1710. } else {
  1711. response.end('fail'); //返回文档内容
  1712. }
  1713. });
  1714. }
  1715. /**
  1716. * 新建导航文件保存
  1717. * @param {object} response 用户相应对象
  1718. * @param {guid} fileid 文档ID
  1719. * @param {string} navinfo 导航信息
  1720. * @param {string} nowpageid 当前页面ID
  1721. * @param {string} nowpagecontent 当前页面内容
  1722. * @param {string} name 文档名
  1723. * @param {guid} userid 用户ID
  1724. * @param {guid} pageid 页面唯一识别ID
  1725. */
  1726. us.newNavSave = function (response, fileid, navinfo, name, nowpageid, nowpagecontent, userid, pageid) {
  1727. //发送保存文件请求
  1728. us.mysql.usselect([
  1729. 'sqlserver.1473.cn',
  1730. 'UseStudio_Disk',
  1731. 'SaveFileContent',
  1732. fileid,
  1733. navinfo,
  1734. name
  1735. ], function (ret) {
  1736. if (ret) {
  1737. var _navinfo = JSON.parse(navinfo);
  1738. if (!us.nav[fileid]) {
  1739. us.nav[fileid] = {
  1740. user: {},
  1741. navInfo: _navinfo,
  1742. page: {},
  1743. history: []
  1744. };
  1745. } else {
  1746. us.nav[fileid].navInfo = _navinfo;
  1747. }
  1748. var _navdata = us.nav[fileid];
  1749. _navdata.user[userid] = [pageid]; //将用户加入协同记录数组
  1750. us.offLineMessage[pageid].nav.indexOf(fileid) == -1 && us.offLineMessage[pageid].nav.push(fileid); //添加到用户离线消息的连接wrod记录中
  1751. if (nowpageid) {
  1752. us.SaveNavPageContent(response, fileid, nowpageid, nowpagecontent);
  1753. } else {
  1754. response.end('saveContentSuccess'); //返回文档内容
  1755. }
  1756. } else {
  1757. response.end('saveNavFail'); //返回文档内容
  1758. }
  1759. });
  1760. }
  1761. us.SaveNavPageContent = function (response, fileid, nowpageid, nowpagecontent) {
  1762. var _navdata = us.nav[fileid];
  1763. //发送保存内容请求
  1764. us.mysql.usselect([
  1765. 'sqlserver.1473.cn',
  1766. 'UseStudio_Office',
  1767. 'SaveNavPageContent',
  1768. nowpageid,
  1769. nowpagecontent
  1770. ], function (ret) {
  1771. if (ret) {
  1772. _navdata.page[nowpageid] = us.cheerio.load(nowpagecontent.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""));
  1773. response.end('saveContentSuccess'); //返回文档内容
  1774. } else {
  1775. response.end('saveContentFail'); //返回文档内容
  1776. }
  1777. });
  1778. }
  1779. /**
  1780. * 新建导航页面
  1781. * @param {object} response 用户相应对象
  1782. * @param {string} nowpageid 当前页面ID
  1783. * @param {string} nowpagecontent 当前页面内容
  1784. */
  1785. us.copyPageContent = function (response, fileid, nowpageid, nowpagecontent, copypageid) {
  1786. if (!us.nav[fileid]) {
  1787. us.nav[fileid] = {
  1788. user: {},
  1789. navInfo: "",
  1790. page: {},
  1791. history: []
  1792. };
  1793. }
  1794. var _navdata = us.nav[fileid];
  1795. //发送保存内容请求
  1796. us.mysql.usselect([
  1797. 'sqlserver.1473.cn',
  1798. 'UseStudio_Office',
  1799. 'CopyPageContent',
  1800. nowpageid,
  1801. nowpagecontent,
  1802. copypageid
  1803. ], function (ret) {
  1804. if (ret) {
  1805. nowpagecontent == "" && (nowpagecontent = JSON.parse(ret)[0][0].content);
  1806. _navdata.page[nowpageid] = us.cheerio.load(nowpagecontent.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""));
  1807. response.end('saveContentSuccess'); //返回文档内容
  1808. } else {
  1809. response.end('saveContentFail'); //返回文档内容
  1810. }
  1811. });
  1812. }
  1813. /**
  1814. * 加入文档编辑 该函数暂无使用
  1815. *
  1816. * @param {object} response 用户相应对象
  1817. * @param {string} wordinfo 文档信息 形如: {docId : 'guid,guid,guid', userId : guid, pageId : guid}
  1818. **/
  1819. us.addWord = function (response, wordinfo) {
  1820. //获取用户参数
  1821. wordinfo = JSON.parse(wordinfo);
  1822. var _docidarray = wordinfo.docId.split(','), //根据','号分割多个文档ID
  1823. _userid = wordinfo.userId, //用户ID
  1824. _pageid = wordinfo.pageId, //页面唯一识别ID
  1825. i, //定义循环变量
  1826. _docid, //记录文档ID变量
  1827. _docinfo; //记录文档信息变量
  1828. for (i = 0; i < _docidarray.length; i++) { //循环处理每一份问的加入请求
  1829. _docid = _docidarray[i]; //记录文档ID变量
  1830. _docinfo = us.word[_docid]; //记录文档信息变量
  1831. if (!_docinfo) { //判断群列表是否已存在不存在则创建
  1832. us.word[_docid] = {
  1833. user: {},
  1834. history: []
  1835. }; //创建word文档信息
  1836. us.word[_docid].user[_userid] = [_pageid]; //加入用户
  1837. } else if (!_docinfo.user[_userid]) { //判断文档的用户是否已登陆
  1838. _docinfo.user[_userid] = [_pageid];
  1839. } else if (_docinfo.user[_userid].indexOf(_pageid) == -1) { //将用户添加到群列表中
  1840. _docinfo.user[_userid].push(_pageid);
  1841. }
  1842. us.offLineMessage[_pageid].word.push(_docid); //添加到用户离线消息的连接wrod记录中
  1843. }
  1844. response.end('addword'); //即时相应请求成功
  1845. }
  1846. /**
  1847. * 加入Excel编辑
  1848. *
  1849. * @param {object} response 用户相应对象
  1850. * @param {string} excelinfo 表格信息
  1851. **/
  1852. us.addExcel = function (response, excelinfo) {
  1853. //获取用户id
  1854. //获取用户id
  1855. excelinfo = JSON.parse(excelinfo);
  1856. var _excelinfo = us.excel[excelinfo.docId],
  1857. _userid = excelinfo.userId,
  1858. _pageid = excelinfo.pageId,
  1859. _docid = excelinfo.docId;
  1860. if (!_excelinfo) { //判断群列表是否已存在不存在则创建
  1861. us.excel[_docid] = {
  1862. user: {},
  1863. history: []
  1864. };
  1865. us.excel[_docid].user[_userid] = [_pageid];
  1866. } else if (!_excelinfo.user[_userid]) { //判断文档的用户是否已登陆 如果只有1个页面 则直接添加
  1867. _excelinfo.user[_userid] = [_pageid];
  1868. } else if (_excelinfo.user[_userid].indexOf(_pageid) == -1) { //将用户添加到群列表中 假如是一个用户多个页面 这里 则就是将每个页面添加到该用户下
  1869. _excelinfo.user[_userid].push(_pageid);
  1870. }
  1871. us.offLineMessage[_pageid].excel.push(_docid); //添加到用户离线消息的连接excel记录中
  1872. response.end('OK'); //返回到前台
  1873. }
  1874. /**
  1875. * 初始化获取未来课堂数据
  1876. *
  1877. */
  1878. us.getcscl = function (response, calssid, pageid, userid) {
  1879. //判断文档是否已在内层中存在
  1880. if (us.cscl[calssid]) {
  1881. // console.log("------------------------ssss----------")
  1882. // console.log(userid)
  1883. // console.log(us.cscl[calssid].user[userid])
  1884. //如果存在则直接返回内层的文档
  1885. if (!us.cscl[calssid].user[userid]) {
  1886. us.cscl[calssid].user[userid] = [pageid];
  1887. }
  1888. else if (us.cscl[calssid].user[userid].indexOf(pageid) == -1) {
  1889. us.cscl[calssid].user[userid].push(pageid);
  1890. }
  1891. try {
  1892. us.offLineMessage[pageid].cscl.indexOf(calssid) == -1 && us.offLineMessage[pageid].cscl.push(calssid); //添加到用户离线消息的连接wrod记录中
  1893. }
  1894. catch (e) {
  1895. }
  1896. console.log(us.cscl[calssid])
  1897. //如果不存在则去数据库查找
  1898. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', calssid],
  1899. function (ret) {
  1900. if (ret) {
  1901. console.log(ret[0][0].data)
  1902. ret[0][0].data = us.cscl[calssid].content; //把思维网格的内容转化成数组
  1903. response.end(JSON.stringify(ret)); //返回文档内容
  1904. }
  1905. else {
  1906. response.end(''); //返回文档内容
  1907. }
  1908. });
  1909. }
  1910. else {
  1911. us.cscl[calssid] = {
  1912. user: {},
  1913. history: []
  1914. };
  1915. us.cscl[calssid].user[userid] = [pageid];
  1916. if (us.offLineMessage[pageid]) {
  1917. us.offLineMessage[pageid].cscl.indexOf(calssid) == -1 && us.offLineMessage[pageid].cscl.push(calssid); //添加到用户离线消息的连接wrod记录中
  1918. }
  1919. // console.log("------------------------ggggg----------");
  1920. // console.log(us.cscl[calssid])
  1921. //如果不存在则去数据库查找
  1922. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', calssid],
  1923. function (ret) {
  1924. if (ret) {
  1925. console.log(ret[0][0].data)
  1926. us.cscl[calssid].content = JSON.parse(ret[0][0].data); //把思维网格的内容转化成数组
  1927. response.end(JSON.stringify(ret)); //返回文档内容
  1928. }
  1929. else {
  1930. us.cscl[calssid].content = {}; //创建一个空数组
  1931. response.end(''); //返回文档内容
  1932. }
  1933. });
  1934. }
  1935. }
  1936. /**
  1937. * 获取思维网格数据,转成成数组
  1938. *
  1939. */
  1940. us.getMindNetwork = function (response, docid, pageid, userid) {
  1941. //判断文档是否已在内层中存在
  1942. if (us.mindNetwork[docid]) {
  1943. //如果存在则直接返回内层的文档
  1944. if (!us.mindNetwork[docid].user[userid]) {
  1945. us.mindNetwork[docid].user[userid] = [pageid];
  1946. } else {
  1947. us.mindNetwork[docid].user[userid].push(pageid);
  1948. }
  1949. try {
  1950. us.offLineMessage[pageid].mindNetwork.indexOf(docid) == -1 && us.offLineMessage[pageid].mindNetwork.push(docid); //添加到用户离线消息的连接wrod记录中
  1951. }
  1952. catch (e) {
  1953. }
  1954. //console.log(us.mindNetwork[docid]);
  1955. //如果不存在则去数据库查找
  1956. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', docid],
  1957. function (ret) {
  1958. if (ret) {
  1959. ret[0][0].data = us.mindNetwork[docid].content; //把思维网格的内容转化成数组
  1960. response.end(JSON.stringify(ret)); //返回文档内容
  1961. }
  1962. else {
  1963. response.end(''); //返回文档内容
  1964. }
  1965. });
  1966. }
  1967. else {
  1968. us.mindNetwork[docid] = {
  1969. user: {},
  1970. history: []
  1971. };
  1972. us.mindNetwork[docid].user[userid] = [pageid];
  1973. if (us.offLineMessage[pageid]) {
  1974. us.offLineMessage[pageid].mindNetwork.indexOf(docid) == -1 && us.offLineMessage[pageid].mindNetwork.push(docid); //添加到用户离线消息的连接wrod记录中
  1975. }
  1976. //如果不存在则去数据库查找
  1977. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', docid],
  1978. function (ret) {
  1979. if (ret) {
  1980. us.mindNetwork[docid].content = JSON.parse(ret[0][0].data); //把思维网格的内容转化成数组
  1981. response.end(JSON.stringify(ret)); //返回文档内容
  1982. }
  1983. else {
  1984. us.mindNetwork[docid].content = []; //创建一个空数组
  1985. response.end(''); //返回文档内容
  1986. }
  1987. });
  1988. }
  1989. }
  1990. /**
  1991. * 获取实时课堂据,转成成数组
  1992. *
  1993. */
  1994. us.getRealTimeClass = function (response, docid, pageid, userid) {
  1995. //判断文档是否已在内层中存在
  1996. if (us.realTimeClass[docid]) {
  1997. //如果存在则直接返回内层的文档
  1998. if (!us.realTimeClass[docid].user[userid]) {
  1999. us.realTimeClass[docid].user[userid] = [pageid];
  2000. } else {
  2001. us.realTimeClass[docid].user[userid].push(pageid);
  2002. }
  2003. try {
  2004. us.offLineMessage[pageid].realTimeClass.indexOf(docid) == -1 && us.offLineMessage[pageid].realTimeClass.push(docid); //添加到用户离线消息的连接wrod记录中
  2005. }
  2006. catch (e) {
  2007. }
  2008. //console.log(us.realTimeClass[docid]);
  2009. //如果不存在则去数据库查找
  2010. us.mysql.usselect(['172.16.12.5', 'pbl', 'selectPptPage', docid],
  2011. function (ret) {
  2012. if (ret) {
  2013. ret[0][0].page = us.realTimeClass[docid].content; //把思维网格的内容转化成数组
  2014. response.end(JSON.stringify(ret)); //返回文档内容
  2015. }
  2016. else {
  2017. response.end(''); //返回文档内容
  2018. }
  2019. });
  2020. }
  2021. else {
  2022. us.realTimeClass[docid] = {
  2023. user: {},
  2024. history: []
  2025. };
  2026. us.realTimeClass[docid].user[userid] = [pageid];
  2027. if (us.offLineMessage[pageid]) {
  2028. us.offLineMessage[pageid].realTimeClass.indexOf(docid) == -1 && us.offLineMessage[pageid].realTimeClass.push(docid); //添加到用户离线消息的连接wrod记录中
  2029. }
  2030. //如果不存在则去数据库查找
  2031. us.mysql.usselect(['172.16.12.5', 'pbl', 'selectPptPage', docid],
  2032. function (ret) {
  2033. if (ret) {
  2034. us.realTimeClass[docid].content = JSON.parse(ret[0][0].page); //把思维网格的内容转化成数组
  2035. response.end(JSON.stringify(ret)); //返回文档内容
  2036. }
  2037. else {
  2038. us.realTimeClass[docid].content = []; //创建一个空数组
  2039. response.end(''); //返回文档内容
  2040. }
  2041. });
  2042. }
  2043. }
  2044. /**
  2045. * 获取文档,并生成DOM
  2046. *
  2047. * @param {object} response 用户相应对象
  2048. * @param {string} docid 文档ID
  2049. */
  2050. us.getWord = function (response, docid, pageid, userid) {
  2051. // //判断文档是否已在内层中存在
  2052. // if (us.word[docid]) {
  2053. // //如果存在则直接返回内层的文档
  2054. // if (!us.word[docid].user[userid]) {
  2055. // us.word[docid].user[userid] = [pageid];
  2056. // } else {
  2057. // us.word[docid].user[userid].push(pageid);
  2058. // }
  2059. // us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2060. // response.end(us.word[docid].content('body').html());
  2061. // }
  2062. // else {
  2063. // us.word[docid] = {
  2064. // user: {},
  2065. // history: []
  2066. // };
  2067. // us.word[docid].user[userid] = [pageid];
  2068. // if (us.offLineMessage[pageid]) {
  2069. // us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2070. // }
  2071. // //如果不存在则去数据库查找
  2072. // us.mysql.usselect(['172.16.12.5', 'pbl', 'select_file', docid],
  2073. // function (ret) {
  2074. // if (ret) {
  2075. // var _office = JSON.parse(ret)[0][0].data ? JSON.parse(ret)[0][0].data.replace(/\\'/ig, '\'').replace(/\\"/ig, "\"") : ""; //记录查找内容
  2076. // us.word[docid].content = us.cheerio.load(_office); //将文档添加到内层中
  2077. // response.end(_office); //返回文档内容
  2078. // } else {
  2079. // us.word[docid].content = us.cheerio.load(''); //将文档添加到内层中
  2080. // response.end(''); //返回文档内容
  2081. // }
  2082. // });
  2083. // }
  2084. //判断文档是否已在内层中存在
  2085. if (us.word[docid]) {
  2086. //如果存在则直接返回内层的文档
  2087. if (!us.word[docid].user[userid]) {
  2088. us.word[docid].user[userid] = [pageid];
  2089. } else {
  2090. us.word[docid].user[userid].push(pageid);
  2091. }
  2092. // console.log(us.offLineMessage[pageid]);
  2093. // console.log(pageid);
  2094. try {
  2095. us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2096. }
  2097. catch (e) {
  2098. }
  2099. //如果不存在则去数据库查找
  2100. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_file', docid],
  2101. function (ret) {
  2102. if (ret) {
  2103. ret[0][0].data = us.word[docid].content('body').html();
  2104. response.end(JSON.stringify(ret)); //返回文档内容
  2105. } else {
  2106. us.word[docid].content = us.cheerio.load(''); //将文档添加到内层中
  2107. response.end(''); //返回文档内容
  2108. }
  2109. });
  2110. }
  2111. else {
  2112. us.word[docid] = {
  2113. user: {},
  2114. history: []
  2115. };
  2116. us.word[docid].user[userid] = [pageid];
  2117. if (us.offLineMessage[pageid]) {
  2118. us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2119. }
  2120. //如果不存在则去数据库查找
  2121. us.mysql.usselect(['172.16.12.5', 'pbl', 'select_file', docid],
  2122. function (ret) {
  2123. if (ret) {
  2124. var _office = ret[0][0].data ? ret[0][0].data.replace(/\\'/ig, '\'').replace(/\\"/ig, "\"") : ""; //记录查找内容
  2125. us.word[docid].content = us.cheerio.load(_office); //将文档添加到内层中
  2126. response.end(_office); //返回文档内容
  2127. } else {
  2128. us.word[docid].content = us.cheerio.load(''); //将文档添加到内层中
  2129. response.end(''); //返回文档内容
  2130. }
  2131. });
  2132. }
  2133. }
  2134. us.getExcel = function (response, docid, pageid, userid) {
  2135. //判断文档是否已在内层中存在
  2136. if (us.excel[docid]) {
  2137. //如果存在则直接返回内层的文档
  2138. if (!us.excel[docid].user[userid]) {
  2139. us.excel[docid].user[userid] = [pageid];
  2140. } else {
  2141. us.excel[docid].user[userid].push(pageid);
  2142. }
  2143. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
  2144. var _office = us.excel[docid].content;
  2145. response.end(JSON.stringify(_office));
  2146. } else {
  2147. us.excel[docid] = {
  2148. user: {},
  2149. history: []
  2150. };
  2151. us.excel[docid].user[userid] = [pageid];
  2152. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
  2153. //如果不存在则去数据库查找
  2154. us.mysql.usselect([
  2155. 'sqlserver.1473.cn',
  2156. 'UseStudio_Disk',
  2157. 'GetFileContent',
  2158. docid
  2159. ], function (ret) {
  2160. if (ret) {
  2161. var _office = JSON.parse(ret)[0][0].UsOffice;
  2162. us.excel[docid].content = JSON.parse(_office); //将文档添加到内层中
  2163. response.end(_office); //返回文档内容
  2164. } else {
  2165. us.excel[docid].content = ''; //将文档添加到内层中
  2166. response.end(''); //返回文档内容
  2167. }
  2168. });
  2169. }
  2170. }
  2171. /**
  2172. * 新建文档保存内容并加入协同
  2173. * @param {object} response 用户相应对象
  2174. * @param {guid} docid 文档ID
  2175. * @param {string} content 文档内容
  2176. * @param {string} name 文档名
  2177. * @param {guid} userid 用户ID
  2178. * @param {guid} pageid 页面唯一识别ID
  2179. */
  2180. us.newExcelSave = function (response, docid, content, name, userid, pageid) {
  2181. us.excel[docid] = {
  2182. user: {},
  2183. history: []
  2184. }; //创建excel类
  2185. us.excel[docid].user[userid] = [pageid]; //将用户加入协同记录数组
  2186. us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
  2187. //发送保存请求
  2188. us.mysql.usselect([
  2189. 'sqlserver.1473.cn',
  2190. 'UseStudio_Disk',
  2191. 'SaveFileContent',
  2192. docid,
  2193. content,
  2194. name
  2195. ], function (ret) {
  2196. if (ret) {
  2197. //设置内容
  2198. us.excel[docid].content = JSON.parse(content); //将文档添加到内层中
  2199. response.end('saveOk'); //返回保存成功
  2200. } else {
  2201. response.end('fail'); //返回文档内容
  2202. }
  2203. });
  2204. }
  2205. /**
  2206. * 生成Guid
  2207. *
  2208. **/
  2209. us.createGuid = function () {
  2210. //返回guid的处理
  2211. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  2212. var r = Math.random() * 16 | 0,
  2213. v = c == 'x' ? r : (r & 0x3 | 0x8);
  2214. return v.toString(16);
  2215. });
  2216. };
  2217. /**
  2218. * 监听1473端口的处理
  2219. *
  2220. **/
  2221. us.server.listen('1473', '', function () {
  2222. //在控制台输出监听提示
  2223. console.log("开始监听" + us.server.address().port + "......");
  2224. });
  2225. // 同意处理错误
  2226. //process.on('uncaughtException', function (e) {
  2227. // console.log("错误:" + e);
  2228. //});