1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047 |
- var us = {}; //全局的命名空间
- us.cheerio = require("cheerio"); //dom处理类
- us.qs = require("querystring"); //引用文件解析包
- us.http = require("http"); //引用http server服务
- us.mysql = require("./mysql.js"); //引用执行存储过程包
- /**
- * 用户的链接池集合,以用户id作为搜索键
- **/
- us.connect = {
- //userguid:{pageid : us.userConnect, pageid : us.userConnect}
- }
- /**
- * 用户的数据集合集合,以用户id作为搜索键
- **/
- us.user = {
- //userId : userInfo //用户连接(请求), 这里可以是http短连接可以使socket长连接
- }
- /**
- * 用户的消息集合,以用户的页面id(登录唯一识别ID)作为搜索键
- **/
- us.offLineMessage = {
- //pageId : us.userOffLineMessage
- }
- us.mindNetwork = {
- // mindid: {
- // }
- }
- //文档列表
- us.word = {
- //docId : {
- // user : {userId : [pageId, pageId],
- // userId : [pageId, pageId]},
- // content : docel,
- // history : [operand(操作信息对象), operand(操作信息对象)]
- // } //群信息结构
- //docId : {user : {userId : [pageId, pageId], userId : [pageId, pageId]}, content : docel, history : [operand(操作信息对象), operand(操作信息对象)] } //文档信息结构
- }
- //excel列表
- us.excel = {
- //excelId : {user : {userId : [pageId, pageId], userId : [pageId, pageId]}, content : docel, history : [operand(操作信息对象), operand(操作信息对象)], name : 文件名 } //群信息结构
- //excelId : {user : {userId : [pageId, pageId], userId : [pageId, pageId]}, content : docel, history : [operand(操作信息对象), operand(操作信息对象)], name : 文件名 } //群信息结构
- }
- //导航文件列表
- us.nav = {
- //fileId : {
- // user : {userId : [pageId, pageId], userId : [pageId, pageId]},
- // navInfo : {
- // logo : '',
- // nav : [ {pageId: '', name : ''}, {pageId: '', name : '', child :[ {pageId: '', name : ''} ]} ]
- // },
- // page : {pageId : pageContent, pageId : pageContent},
- // history : [operand(操作信息对象), operand(操作信息对象)]
- //} //导航文档数据结构
- }
- /**
- * 用户链接类
- *
- * @param {string} pageId 页面ID(用户登录唯一识别ID)
- * @param {object} response 对象
- **/
- us.userConnect = function (pageId, response) {
- return {
- "pageId": pageId, //登录用户唯一识别id
- "response": response, //这里可以是http短连接以后可以换成socket长连接
- "loginTime": new Date(), //用户登录时间
- "offLineTime": null //用户下线时间
- }
- }
- /**
- * 用户数据类
- *
- * @param {string} requset对象
- * @param {object} response对象
- **/
- us.userInfo = function (userid, username) {
- return {
- "userId": userid, //用户id
- "userName": username //用户名
- }
- }
- /**
- * 用户连接信息类
- * @param {string} type 用户登录类型
- */
- us.userOffLineMessage = function (type) {
- return {
- "message": [], //用户的消息数组
- "type": type, //链接的端 pc或者pho
- "word": [], //word数据
- "excel": [], //excel数据
- "mindNetwork": [], //思维网格数据
- "nav": [] //导航模式数据
- }
- }
- /**
- * 用户的离线消息结构
- *
- * @param {string} sendid 发送者id
- * @param {string} type 发送的类型, 俱乐部使用时用us开头,后面带用途。例如us.disk或者us.friend us.word
- * @param {string} messageinfo 的处理
- **/
- us.message = function (sendid, type, messageinfo) {
- return {
- id: us.createGuid(), //新生成的guid
- sendId: sendid, //发送消息人的id.
- time: new Date(), //发送时间
- type: type, //类型 俱乐部使用时用us开头,后面带用途。例如us.disk或者us.friend us.word
- messageInfo: messageinfo //{消息结构} 此处为object 如类型为'us.word' 则消息结构为us.word
- }
- }
- /*
- messageinfo 消息结构的处理
- {
- id: string, //行id 多行时用逗号隔开的形式 guid,guid,guid,guid
- type: string, // 处理的类型 如:"add"||"delete"||"update"
- docId: string, // "guid" 文档id
- pageId: pageid, //页面唯一识别ID
- content: string // 变化的内容 add的时候为添加到添加行的下一行
- nextId : string //下一行id
- }
- */
- /**
- * 创建服务
- *
- * @param {object} requset 请求对象
- * @param {object} response 响应对象
- **/
- us.server = us.http.createServer(function (requset, response) {
- //设置跨域
- response.writeHead(200, {
- "Content-Type": "text/html;application/json;charset=utf-8",
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Headers': 'Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With'
- });
- //设置参数,并执行回调
- us.unifyDispose(requset, response, function (param) {
- console.log(param)
- if (param && param[0]) {
- //参数解码 us.parm为全局变量 记录所有参数
- var _userinfo,
- _funname = param[0],
- //参数解码 中文处理
- _param = param.splice(1);
- //执行回调函数
- switch (_funname) {
- //执行登录函数
- case 'login':
- _userinfo = JSON.parse(_param[0]); //登录用户的信息
- us.login(response, _userinfo.userId, _userinfo.pageId, _userinfo.userName, _userinfo.type);
- break;
- case 'logout':
- us.logout(response, _param[0], _param[1]);
- break;
- //执行轮询函数
- case 'polling':
- us.polling(response, _param[0], _param[1], _param[2], _param[3]);
- break;
- //获取文档信息
- case 'getWord':
- us.getWord(response, _param[0], _param[1], _param[2]);
- break;
- //获取Excel信息
- case 'getExcel':
- us.getExcel(response, _param[0], _param[1], _param[2]);
- break;
- //获取导航文件信息
- case 'getNav':
- us.getNav(response, _param[0], _param[1], _param[2]);
- break;
- //获取文档信息
- case 'getMindNetwork':
- us.getMindNetwork(response, _param[0], _param[1], _param[2]);
- break;
- case 'getNavPageContent':
- us.getNavPageContent(response, _param[0], _param[1]);
- break;
- //执行发送函数
- case 'send':
- us.send(response, _param[0]);
- break;
- case 'quitOffice':
- us.quitOffice(response, _param[0]);
- break;
- case 'newWordSave':
- us.newWordSave(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
- break;
- case 'newExcelSave':
- us.newExcelSave(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
- break;
- //新建导航文件保存
- case 'newNavSave':
- //, _param[5], _param[6], _param[7]
- us.newNavSave(response, _param[0], _param[1], _param[2], _param[3], _param[4], _param[5], _param[6]);
- break;
- //加入文档编辑
- case 'addWord':
- //us.addWord(response, _param[0]);
- break;
- //加入Excel表格编辑
- case 'addExcel':
- us.addExcel(response, _param[0]);
- break;
- //加入导航文件
- case 'addNav':
- break;
- case 'copyPageContent':
- us.copyPageContent(response, _param[0], _param[1], _param[2], _param[3]);
- break;
- case 'updateName':
- us.updateName(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
- break;
- case 'insertModifyRecord':
- us.insertModifyRecord(response, _param[0], _param[1], _param[2], _param[3], _param[4], _param[4]);
- break;
- case 'addUser':
- us.addUser(response, _param[0], _param[1], _param[2], _param[3], _param[4]);
- break;
- //其余执行
- default:
- response.end(0);
- }
- }
- else {
- response.end("");
- }
- });
- });
- /**
- * 协同历史(带保存功能,修改了存储过程 既添加历史也保存内容)
- *
- * @param {object} request 请求对象
- * @param {string} type 类型
- * @param {guid} fileid 文件id
- * @param {string} filename 文件名
- * @param {string} html 内容
- * @param {guid} userid 用户ID
- * @param {guid} pageid 页面ID
- **/
- us.insertModifyRecord = function (response, type, fileid, filename, html, userid, pageid) {
- var _html;
- if (us[type][fileid] && us[type][fileid].content) {
- _html = us[type][fileid].content('body').html().replace(/'/ig, "''").replace(/"/ig, "\\\"");
- } else {
- _html = html;
- }
- //发送保存文件请求
- us.mysql.usselect([
- '127.0.0.1',
- 'UseStudio_Office',
- 'InsertDocumentModifyRecord',
- userid,
- fileid,
- _html,
- filename
- ], function (ret) {
- if (ret) {
- var _historyid = JSON.parse(ret)[0][0].historyid;
- var _message = {};
- var _messageinfo = us.message(userid, 'us.' + type, {
- id: us.createGuid(),
- type: "insertModifyRecord",
- historyid: _historyid,
- docId: fileid
- });
- _message[fileid] = [_messageinfo];
- us.broadcast(_message, pageid, type);
- response.end(_historyid); //返回文档内容
- } else {
- response.end(ret); //返回文档内容
- }
- });
- }
- /**
- * 更新文件名
- *
- * @param {object} request 请求对象
- * @param {string} type 类型
- * @param {guid} fileid 文件id
- * @param {string} filename 文件名
- * @param {guid} userid 用户ID
- * @param {guid} pageid 页面ID
- **/
- us.updateName = function (response, type, fileid, filename, userid, pageid) {
- //发送保存文件请求
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Disk',
- 'UpdateFileInfo',
- fileid,
- filename
- ], function (ret) {
- if (ret) {
- var _message = {};
- var _messageinfo = us.message(userid, 'us.' + type, {
- id: us.createGuid(),
- type: "updateName",
- name: filename,
- docId: fileid
- });
- _message[fileid] = [_messageinfo];
- us.broadcast(_message, pageid, type);
- response.end('updateNameSuccess'); //返回文档内容
- } else {
- response.end('updateNameFail'); //返回文档内容
- }
- });
- }
- /**
- * 添加用户
- *
- * @param {object} request 请求对象
- * @param {string} type 类型
- * @param {guid} fileid 文件id
- * @param {string} userids 用户id(多个用逗号隔开)
- * @param {guid} userid 用户ID
- * @param {guid} pageid 页面ID
- **/
- us.addUser = function (response, type, fileid, userids, userid, pageid) {
- var _message = {};
- var _messageinfo = us.message(userid, 'us.' + type, {
- id: us.createGuid(),
- type: "addUser",
- userIds: userids,
- docId: fileid
- });
- _message[fileid] = [_messageinfo];
- us.broadcast(_message, pageid, type);
- response.end('addUserSuccess'); //返回文档内容
- }
- /**
- * 获取用户传参异步
- *
- * @param {object} request 请求对象
- * @param {function} cb 回调函数
- **/
- us.unifyDispose = function (req, res, cb) {
- var i, _param = "";
- //接收参数
- req.on("data", function (chunk) {
- _param += chunk;
- });
- //接收完毕
- req.on("end", function () {
- console.log(_param)
- //前端传入的字符串转化成对象
- if (_param) {
- _param = us.qs.parse(_param);
- }
- console.log(_param)
- //拆分参数
- try {
- _param = _param.mode.split(",")
- } catch (e) {
- _param = req.query;
- }
- if (_param) {
- //循环解析,由于前端发送过来的信息是经过url加密的,这里是解密
- for (i = 0; i < _param.length; i++) {
- _param[i] = decodeURIComponent(_param[i]); //解析
- }
- } else {
- _param = [];
- }
- //回调到指定处理
- cb(_param);
- });
- //请求超时处理
- res.on('timeout', function (e) {
- console.log('请求超时'); //错误消息的输出
- if (req.res) {
- req.res("abort");
- }
- res.end("false"); //返回值
- });
- //设置30秒后超时
- res.setTimeout(30000, function () {
- console.log("响应超时.");
- res.end("false"); //返回值
- });
- //错误处理
- req.on("error", function (e) {
- console.log('程序报错');
- res.end("false");
- });
- }
- /**
- * 获取用户传参异步
- *
- * @param {object} response 响应对象
- * @param {array} userid 用户ID
- * @param {string} pageid 页面ID(登录唯一识别ID)
- * @param {string} username 用户名
- * @param {type} username 用户登录类型
- **/
- us.login = function (response, userid, pageid, username, type) {
- //用户登录信息表,以后移入redis
- //如果用户信息不存在则新建一个用户信息存入
- if (!us.user[userid]) {
- var _userinfo = us.userInfo(userid, username); //初始化用户信息
- us.user[userid] = _userinfo;
- }
- //添加用户轮询列表
- us.polling(response, userid, pageid, type);
- }
- /**
- * 用户下线
- * @param {object} response 响应对象
- * @param {string} userid 用户ID
- * @param {string} pageid 页面ID(唯一识别ID)
- */
- us.offLine = function (response, userid, pageid) {
- //更新用户登出时间
- us.user[userid].offineTime = new Date();
- //获取用户连接的文档消息
- var _joinword = us.offLineMessage[pageid].word;
- var _joinexcel = us.offLineMessage[pageid].excel;
- var _docuser, _now; //记录用户在数组的位置
- var i, j, o; //定义循环变量
- //退出协同word
- for (i = 0; i < _joinword.length; i++) {
- _docuser = us.word[_joinword[i]].user[userid];
- _now = _docuser.indexOf(pageid);
- _now != -1 && us.word[_joinword[i]].user.splice(_now, 1);
- }
- //退出协同Excel
- for (j = 0; j < _joinexcel.length; j++) {
- _docuser = us.excel[_joinexcel[j]].user[userid];
- _now = _docuser.indexOf(pageid);
- _now != -1 && us.excel[_joinexcel[j]].user.splice(_now, 1);
- }
- //删除用户连接
- delete us.connect[userid][pageid];
- //删除用户离校消息记录
- delete us.offLineMessage[pageid];
- //相应退出
- response.end('offLine');
- }
- /**
- * 获取用户传参异步
- *
- * @param {object} response 响应对象
- * @param {string} userid 用户ID
- * @param {string} pageid 页面ID(用户登录唯一识别ID)
- **/
- us.polling = function (response, userid, pageid, type) {
- //判断轮询的用户是否在连接池中
- if (us.connect[userid]) {
- var _userarray = us.connect[userid], //用户连接池,获取制定用户连接的数量,
- _messagearray = us.offLineMessage[pageid] //用户离校消息
- ;
- //获取当前连接的用户,如果获取成功那么直接修改用户的连接
- if (_userarray[pageid]) {
- _userarray[pageid].response = response;
- console.log(pageid);
- if (_messagearray && _messagearray.message.length > 0) {
- response.end(JSON.stringify(_messagearray.message));
- _messagearray.message = [];
- } else {
- us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
- }
- return;
- }
- //如果用户连接不存在
- _userarray[pageid] = us.userConnect(pageid, response); //那么直接添加用户连接 添加到用户连接数组里
- us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
- } else {
- var _userconect = us.userConnect(pageid, response); //创建用户连接对象
- us.connect[userid] = {}; //添加用户连接对象
- us.connect[userid][pageid] = _userconect;
- us.offLineMessage[pageid] = us.userOffLineMessage(type); //初始化用户离线消息记录
- }
- }
- /**
- * 发送消息
- *
- * @param {object} response 响应对象
- * @param {array} messageinfo 参数数组
- **/
- us.send = function (response, messageinfo) {
- console.log(messageinfo);
- var i, j,
- _message,
- _messagelist = {},
- _messageobj = JSON.parse(messageinfo) //获取传入的json对象
- ;
- //循环用户的信息处理
- for (i in _messageobj) {
- switch (i) {
- //word信息交互
- case "us.mindNetwork":
- _messagearr = _messageobj[i]; //获取word消息
- //得到word所有的用户
- for (j = 0; j < _messagearr.length; j++) {
- //生成发送的消息结构体
- _message = us.message(_messagearr[j].sendId, "us.mindNetwork", _messagearr[j].messageInfo);
- //添加消息列表
- if (_messagelist[_messagearr[j].receiveId]) {
- _messagelist[_messagearr[j].receiveId].push(_message);
- } else {
- _messagelist[_messagearr[j].receiveId] = [_message];
- }
- us.mindNetwork[_message.messageInfo.docId] && us.mindNetwork[_message.messageInfo.docId].history.push(_message);
- us.updatemindNetwork(_message.messageInfo);
- }
- //调用群发函数
- _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'mindNetwork');
- break;
- //word信息交互
- case "us.word":
- _messagearr = _messageobj[i]; //获取word消息
- //得到word所有的用户
- for (j = 0; j < _messagearr.length; j++) {
- //生成发送的消息结构体
- _message = us.message(_messagearr[j].sendId, "us.word", _messagearr[j].messageInfo);
- //添加消息列表
- if (_messagelist[_messagearr[j].receiveId]) {
- _messagelist[_messagearr[j].receiveId].push(_message);
- } else {
- _messagelist[_messagearr[j].receiveId] = [_message];
- }
- us.word[_message.messageInfo.docId] && us.word[_message.messageInfo.docId].history.push(_message);
- us.updateWord(_message.messageInfo);
- }
- //由于不能同时操控多个word发送资料,所有信息只同步一个
- //_users = us.word[_messagearr[0].receiveId].user;
- //调用群发函数
- _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'word');
- break;
- //用户信息的交互
- case "us.excel":
- _messagearr = _messageobj[i]; //获取excel消息
- //得到excel所有的用户
- for (j = 0; j < _messagearr.length; j++) {
- //生成发送的消息结构体
- _message = us.message(_messagearr[j].sendId, _messagearr[j].type, _messagearr[j].messageInfo);
- //添加消息列表
- if (_messagelist[_messagearr[j].receiveId]) {
- _messagelist[_messagearr[j].receiveId].push(_message);
- } else {
- _messagelist[_messagearr[j].receiveId] = [_message];
- }
- us.excel[_message.messageInfo.docId] && us.excel[_message.messageInfo.docId].history.push(_message);
- us.updateExcel(_message.messageInfo);
- }
- //由于不能同时操控多个excel发送资料,所有信息只同步一个
- //_users = us.excel[_messagearr[0].receiveId].user;
- //调用群发函数
- us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'excel');
- break;
- case "us.nav":
- _messagearr = _messageobj[i]; //获取excel消息
- //得到excel所有的用户
- for (j = 0; j < _messagearr.length; j++) {
- //生成发送的消息结构体
- _message = us.message(_messagearr[j].sendId, "us.nav", _messagearr[j].messageInfo);
- //添加消息列表
- if (_messagelist[_messagearr[j].receiveId]) {
- _messagelist[_messagearr[j].receiveId].push(_message);
- } else {
- _messagelist[_messagearr[j].receiveId] = [_message];
- }
- us.nav[_message.messageInfo.docId] && us.nav[_message.messageInfo.docId].history.push(_message);
- us.updateNav(_message.messageInfo);
- }
- //调用群发函数
- us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'nav');
- break;
- }
- }
- response.end('send');
- }
- /**
- * 更新后台Word内容
- * @param {object} message 消息信息
- */
- us.updatemindNetwork = function (messageInfo) {
- if (us.mindNetwork[messageInfo.docId]) {
- var $ = us.mindNetwork[messageInfo.docId].content;
- console.log("---------------------------------------start")
- console.log($);
- console.log("---------------------------------------end")
- console.log("---------------------------------------infostart")
- console.log(messageInfo);
- console.log("---------------------------------------infoend")
- if ($) {
- us.mindNetwork[messageInfo.docId].content[messageInfo.id] = messageInfo.content;
- }
- }
- }
- /**
- * 更新后台Word内容
- * @param {object} message 消息信息
- */
- us.updateWord = function (messageInfo) {
- if (us.word[messageInfo.docId]) {
- var $ = us.word[messageInfo.docId].content;
- if ($) {
- switch (messageInfo.type) { // 判断消息种类
- case 'update':
- us.updateEditorLine(messageInfo, $); //修改
- break;
- case 'add':
- us.addEditorLine(messageInfo, $); //添加
- break;
- case 'delete':
- us.deleteEditorLine(messageInfo, $); //删除
- break;
- }
- }
- }
- }
- /**
- * 更新后台Nav内容
- * @param {object} messageInfo 消息信息
- */
- us.updateNav = function (messageInfo) {
- var _fileinfo = us.nav[messageInfo.docId];
- if (_fileinfo) {
- switch (messageInfo.type) { // 判断消息种类
- case 'update': //修改行
- us.updateEditorLine(messageInfo, _fileinfo.page[messageInfo.navId]); //修改
- break;
- case 'add': //添加行
- us.addEditorLine(messageInfo, _fileinfo.page[messageInfo.navId]); //添加
- break;
- case 'delete': //删除行
- us.deleteEditorLine(messageInfo, _fileinfo.page[messageInfo.navId]); //删除
- break;
- case 'addNav': //添加导航
- us.updateNav.addNav(_fileinfo, messageInfo.parentId, messageInfo.index, messageInfo.addNav, messageInfo.content);
- break;
- case 'updateNav': //修改导航
- us.updateNav.updateNav(_fileinfo.navInfo.nav, messageInfo.navId, messageInfo.name);
- break;
- case 'deleteNav': //删除导航
- us.updateNav.deleteNav(_fileinfo, messageInfo.navId, messageInfo.parentId);
- break;
- case 'updateLogo': //修改logo
- _navinfo.logo = messageInfo.logo;
- break;
- }
- }
- }
- /**
- * 根据NavId查找对应的导航信息
- */
- us.selectByNavId = function (nowinfo, navid) {
- var i = 0;
- for (i = 0; i < nowinfo.length; i++) {
- object = nowinfo[i];
- if (object.pageId == navid) {
- return object;
- } else if (object.child) {
- return us.selectNav(object.child, navid);
- }
- }
- }
- /**
- * 添加Nav
- * @param {object} fileinfo 文件信息
- * @param {object} parentid 父级ID
- * @param {object} addnav 添加导航信息
- * @param {number} index 添加位置
- */
- us.updateNav.addNav = function (fileinfo, parentid, index, addnav, content) {
- var _nav = fileinfo.navInfo.nav;
- var _parent;
- if (parentid) {
- // 寻找父级
- _parent = us.selectByNavId(_nav, parentid);
- // 如果已存在子级处理
- if (_parent.child) {
- //插入指定位置
- _parent.child.splice(index, 0, addnav);
- } else {
- // 为存在子级则新建子级
- _parent.child = [addnav];
- }
- } else {
- _parent = _nav;
- _parent.splice(index, 0, addnav);
- }
- //添加内容
- fileinfo.page[addnav.pageId] = us.cheerio.load(content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""));
- }
- /**
- * 修改Nav
- * @param {object} nav 导航信息
- * @param {object} navid ID
- * @param {object} name 名字
- */
- us.updateNav.updateNav = function (nav, navid, name) {
- // 寻找需要修改导航信息
- var _nav = us.selectByNavId(nav, navid);
- if (_nav) { //存在导航
- _nav.name = name; //替换名字
- }
- }
- /**
- * 删除Nav
- * @param {object} fielinfo 文件信息
- * @param {object} navid ID
- * @param {object} name 名字
- */
- us.updateNav.deleteNav = function (fielinfo, deletenavid, parentid) {
- var _nav = fielinfo.navInfo.nav;
- var _parent;
- if (parentid) {
- // 寻找父级
- _parent = us.selectByNavId(_nav, parentid);
- } else {
- _parent = _nav;
- }
- if (_parent) {
- var _child = parentid ? _parent.child : _parent;
- _child.find(function (object, index) {
- if (object.pageId == deletenavid) {
- if (!object.child) {
- _child.splice(index, 1); //删除数据
- us.mysql.usselect([ //删除页面
- 'sqlserver.1473.cn',
- 'UseStudio_Office',
- 'DeletePage',
- deletenavid
- ], function (ret) {
- if (ret) {
- delete fielinfo.page[deletenavid]; //删除内容
- }
- });
- }
- return true;
- }
- });
- }
- }
- /**
- * 修改操作
- * @param {object} opera 操作信息对象
- * @param {element} $ 后台word元素形式
- */
- us.updateEditorLine = function (opera, $) {
- // $('#' + opera.id).prop('outerHTML', opera.content); //修改行
- $('#' + opera.id).replaceWith(opera.content);
- }
- /**
- * 删除操作
- * @param {object} opera 操作信息对象
- * @param {element} $ 后台word元素形式
- */
- us.deleteEditorLine = function (opera, $) {
- $('#' + opera.id).remove(); //删除行
- }
- /**
- * 添加操作
- * @param {object} opera 操作信息对象
- * @param {element} $ 后台word元素形式
- */
- us.addEditorLine = function (opera, $) {
- var _next; //创建记录变量
- if (opera.nextId && (_next = $('#' + opera.nextId))[0]) { //判断有没有nextid,nextid是否存在
- //如果存在则插入在nexid 元素前
- _next.before(opera.content);
- } else {
- $('body').append(opera.content); //没有就在最后插入
- }
- }
- /**
- * 更新后台Word内容
- * @param {object} message 消息信息
- */
- us.updateExcel = function (messageInfo) {
- var $ = us.excel[messageInfo.docId].content;
- if ($) {
- switch (messageInfo.type) { // 判断消息种类
- case 'blur':
- us.updateExcel.Blur(messageInfo, $); //失焦
- break;
- case "addLine":
- us.updateExcel.addLine(messageInfo, $); //添加行
- break;
- case "delLine":
- us.updateExcel.delLine(messageInfo, $); //刪除行
- break;
- case "addCol":
- us.updateExcel.addCol(messageInfo, $); //添加列
- break;
- case "delCol":
- us.updateExcel.delCol(messageInfo, $); //刪除列
- break;
- case "merge":
- us.updateExcel.merge(messageInfo, $); //合并单元格
- break;
- case "splitCells":
- us.updateExcel.splitCells(messageInfo, $); //拆分单元格
- break;
- case "rowExpanding":
- us.updateExcel.rowExpanding(messageInfo, $); //行板拉伸
- break;
- case "colExpanding":
- us.updateExcel.colExpanding(messageInfo, $); //列板拉伸
- break;
- case "addTask":
- us.updateExcel.addTask(messageInfo, $); //添加工作表
- break;
- case "deleteTask":
- us.updateExcel.deleteTask(messageInfo, $); //刪除工作表
- break;
- case "reNameTask":
- us.updateExcel.reNameTask(messageInfo, $); //刪除工作表
- break;
- case "img":
- us.updateExcel.img(messageInfo, $); //插入图片
- break;
- }
- }
- // console.log($);
- }
- /**
- * 失焦處理
- */
- us.updateExcel.Blur = function (messageInfo, $) {
- var _taskId = messageInfo.worksheetId, //如果有taskId传过来 则修改 data数据里 taskId里的数据 否则则修改当前工作表id里的数据
- _excelData = $[_taskId], //获取taskId工作表的数据
- _cellData = _excelData.cell, //获取该数据里的单元格数据
- _content = messageInfo.content; //获取需要保存的json数据
- _content.forEach(function (data) {
- var _text = data.innerText.replace(/\s+/g, ""), //去掉空格 给下面做判断 如果内容为空 则删除该数据
- _cellColList = _cellData[data.col], //获取该数据里的所有列
- _cell = null;
- if (!_cellColList) { //如果列不存在 则创建一个列
- _cellColList = _cellData[data.col] = {};
- }
- if (!_cellColList[data.row]) { //如果该行_列 不存在单元格数据 则创建个json 给单元格添加数据
- _cellColList[data.row] = {};
- _cellColList[data.row].cssStyle = {}; //css样式
- }
- _cell = _cellColList[data.row]; //获取该单元格的数据 (json)
- data.content ? _cell.innerHTML = data.content : ""; //修改该单元格的innerHTML
- if (data.attr) { //如果存在样式
- _cell.cssStyle[data.attr] = data.value;
- if (!data.value) {
- delete _cell.cssStyle[data.attr]
- }
- }
- if (data.clearStyle) { //如果需要清除所有样式的话
- data.cssStyle = {}
- }
- if (((!(_text) || _text === ("\u200D")) && !(_cell.endRow)) && !(us.jsonLen(_cell.cssStyle))) { //如果innerHTML为空格 或 不存在 并且 不是合并单元格元素 并且没有样式 则删除掉
- delete (_cellColList[data.row]);
- }
- });
- }
- /*
- 获取json的数量
- */
- us.jsonLen = function (json) {
- var _json = json,
- _len = 0;
- for (var i in json) {
- _len++;
- }
- return _len;
- }
- us.updateExcel.addLine = function (messageInfo, $) {
- var _taskId = messageInfo.worksheetId, //单元格id
- _content = messageInfo.content,
- _excelData = $[_taskId],
- _rowData = _excelData.row,
- _cellData = _excelData.cell,
- _start = _content.start, //开始行
- _lineNum = _content.lineNum, //添加行的数量
- _sizeChange = _content.sizeChange, //添加的行的高度
- _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
- _cellCol = null;
- if (_mergeArr.length) {
- _mergeArr.forEach(function (info) {
- _cellData[info.col][info.row].endRow = _cellData[info.col][info.row].endRow + _lineNum;
- });
- }
- for (var k in _cellData) {
- _cellCol = _cellData[k]; //该列下的所有行
- var temp = {};
- for (var row in _cellCol) {
- if (row > _start) {
- temp[(+row) + _lineNum] = _cellCol[row];
- temp[(+row) + _lineNum].endRow ? temp[(+row) + _lineNum].endRow = temp[(+row) + _lineNum].endRow + _lineNum : ""; //如果是合并单元格的元素 则将endRow + _lineNum;
- } else {
- temp[row] = _cellCol[row];
- }
- }
- _cellData[k] = temp;
- } /* 该处for循环是修改数据中单元格的行数 */
- var _rowDataChange = _rowData.change, //获取数据表中 所有被改变高度的 行版信息
- _temp = {},
- _rowChange = null;
- for (var k in _rowDataChange) {
- _rowChange = _rowDataChange[k]; //该行板的所有被改动的行数据
- if (k > _start) {
- _temp[(+k) + _lineNum] = _rowChange;
- } else {
- _temp[k] = _rowChange;
- }
- } /* 该处for循环是修改数据中行版的行数 */
- _rowData.change = _temp;
- if (_sizeChange) {
- for (var i = 1; i <= _lineNum; i++) {
- _rowData.change[_start + i] = _sizeChange;
- }
- }
- _rowData.num = _rowData.num + _lineNum; //行板数量 = 行板数量 + 添加行的数量
- };
- us.updateExcel.delLine = function (messageInfo, $) {
- var _taskId = messageInfo.worksheetId, //单元格id
- _excelData = $[_taskId],
- _content = messageInfo.content,
- _rowData = _excelData.row,
- _cellData = _excelData.cell,
- _start = _content.start, //被选中的第一行
- _end = _content.end, //被选中的最后一行
- _lineNum = _content.lineNum, //所删除的行数
- _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
- _cellCol = null;
- for (var k in _cellData) {
- _cellCol = _cellData[k];
- var temp = {};
- for (var row in _cellCol) {
- if (row > _end) {
- temp[(+row) - _lineNum] = _cellCol[row];
- temp[(+row) - _lineNum].endRow ? temp[(+row) - _lineNum].endRow = temp[(+row) - _lineNum].endRow - _lineNum : ""; //如果是合并单元格的元素 则将endRow - _lineNum;
- } else if (row < _start) {
- temp[row] = _cellCol[row];
- }
- }
- _cellData[k] = temp;
- }
- if (_mergeArr.length) {
- var _cloneMessage = null;
- _mergeArr.forEach(function (info) {
- _cloneMessage = JSON.parse(JSON.stringify(messageInfo));
- _cloneMessage.content = info;
- us.updateExcel.merge(_cloneMessage, $);
- });
- }
- var _rowDataChange = _rowData.change, //获取数据表中 所有被改变高度的 行版信息
- _temp = {},
- _rowChange = null;
- for (var k in _rowDataChange) {
- _rowChange = _rowDataChange[k]; //该行板的所有被改动的行数据
- if (k < _start) { //如果大于结束行 则将该行下面的所有的数字信息 - 被删除的行
- _temp[k] = _rowChange;
- } else if (k > _end) {
- _temp[(+k) - _lineNum] = _rowChange;
- }
- } /* 该处for循环是修改数据中行版的行数 */
- _rowData.change = _temp;
- _rowData.num = _rowData.num - _lineNum; //行板数量 = 行板数量 - 删除行的数量
- };
- us.updateExcel.addCol = function (messageInfo, $) {
- var _taskId = messageInfo.worksheetId, //单元格id
- _excelData = $[_taskId],
- _content = messageInfo.content,
- _colData = _excelData.column,
- _cellData = _excelData.cell,
- _start = _content.start, //被选中的第一列
- _sizeChange = _content.sizeChange, //添加的列的宽度
- _colNums = _content.colNums, //所添加的列数
- _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
- _cellCol = null,
- _temp = {};
- if (_mergeArr.length) {
- _mergeArr.forEach(function (info) {
- _cellData[info.col][info.row].endCol = _cellData[info.col][info.row].endCol + _colNums;
- });
- }
- for (var k in _cellData) {
- _cellCol = _cellData[k];
- if (k > _start) {
- _temp[+(k) + _colNums] = _cellCol;
- var _temp2 = _temp[(+k) + _colNums];
- for (var i in _temp2) {
- _temp2[i].endCol ? _temp2[i].endCol = _temp2[i].endCol + _colNums : ""; //如果是合并单元格的元素 则将endCol + _colNums;
- }
- } else {
- _temp[k] = _cellCol;
- }
- }
- _excelData.cell = _temp;
- var _colDataChange = _colData.change, //获取数据表中 所有被改变宽度的 列版信息
- _temp = {},
- _colChange = null;
- for (var k in _colDataChange) {
- _colChange = _colDataChange[k]; //该列板的所有被改动的列数据
- if (k > _start) {
- _temp[(+k) + _colNums] = _colChange;
- } else {
- _temp[k] = _colChange;
- }
- } /* 该处for循环是修改数据中行版的行数 */
- _colData.change = _temp;
- if (_sizeChange) {
- for (var i = 1; i <= _colNums; i++) {
- _colData.change[_start + i] = _sizeChange;
- }
- }
- _colData.num = _colData.num + _colNums; //列板数量 = 列板数量 + 添加列的数量
- };
- us.updateExcel.delCol = function (messageInfo, $) {
- var _taskId = messageInfo.worksheetId, //单元格id
- _excelData = $[_taskId],
- _content = messageInfo.content,
- _colData = _excelData.column,
- _cellData = _excelData.cell,
- _start = _content.start, //被选中的第一行
- _end = _content.end, //被选中的最后一行
- _colNums = _content.colNums, //所删除的列数
- _mergeArr = _content.mergeArr, //合并单元格 元素 数组集合
- _cellCol = null,
- _temp = {};
- for (var k in _cellData) {
- _cellCol = _cellData[k];
- if (k > _end) {
- _temp[+(k) - _colNums] = _cellCol;
- var _temp2 = _temp[(+k) - _colNums];
- for (var i in _temp2) {
- _temp2[i].endCol ? _temp2[i].endCol = _temp2[i].endCol - _colNums : ""; //如果是合并单元格的元素 则将endCol - _colNums;
- }
- } else if (k < _start) {
- _temp[k] = _cellCol;
- }
- }
- _excelData.cell = _temp;
- if (_mergeArr.length) {
- var _cloneMessage = null;
- _mergeArr.forEach(function (info) {
- _cloneMessage = JSON.parse(JSON.stringify(messageInfo));
- _cloneMessage.content = info;
- us.updateExcel.merge(_cloneMessage, $);
- });
- }
- var _colDataChange = _colData.change, //获取数据表中 所有被改变宽度的 列版信息
- _temp = {},
- _colChange;
- for (var k in _colDataChange) {
- _colChange = _colDataChange[k]; //该列板的所有被改动的列数据
- if (k < _start) { //如果大于结束列 则将该列下面的所有的数字信息 - 被删除的列
- _temp[k] = _colChange;
- } else if (k > _end) {
- _temp[(+k) - _colNums] = _colChange;
- }
- } /* 该处for循环是修改数据中行版的行数 */
- _colData.change = _temp;
- _colData.num = _colData.num - _colNums; //列板数量 = 列板数量 - 删除列的数量
- };
- us.updateExcel.merge = function (messageInfo, $) {
- var _taskId = messageInfo.worksheetId, //单元格id
- _excelData = $[_taskId],
- _content = messageInfo.content,
- _cellData = _excelData.cell,
- _cellColList = _cellData[_content.col];
- if (_content.row === _content.endRow && _content.col === _content.endCol) {
- _cellData[_content.col][_content.row].endRow = "";
- _cellData[_content.col][_content.row].endCol = ""
- return;
- }
- if (!_cellColList) {
- _cellColList = _cellData[_content.col] = {};
- }
- if (!_cellColList[_content.row]) {
- _cellColList[_content.row] = {};
- }
- _cellColList[_content.row].innerHTML = _content.content;
- _cellColList[_content.row].endRow = _content.endRow;
- _cellColList[_content.row].endCol = _content.endCol;
- };
- us.updateExcel.splitCells = function (messageInfo, $) {
- var _taskId = messageInfo.worksheetId, //单元格id
- _excelData = $[_taskId],
- _content = messageInfo.content,
- _cellData = _excelData.cell,
- _cell = _cellData[_content.col][_content.row]; //需要拆分的单元格
- _cell.endRow = "";
- _cell.endCol = "";
- };
- us.updateExcel.rowExpanding = function (messageInfo, $) {
- var _taskId = messageInfo.worksheetId, //单元格id
- _excelData = $[_taskId],
- _content = messageInfo.content,
- _rowData = _excelData.row;
- _content.forEach(function (data) {
- var _rowNum = data.rowName, //拉伸行的位置 (数字)
- _rowHeight = data.height; //被拉伸后的高度
- _rowData.change[_rowNum] = _rowHeight;
- });
- };
- us.updateExcel.colExpanding = function (messageInfo, $) {
- var _taskId = messageInfo.worksheetId, //单元格id
- _excelData = $[_taskId],
- _content = messageInfo.content,
- _colData = _excelData.column; //该列的数据
- _content.forEach(function (data) {
- var _colNum = data.colName, //拉伸行的位置 (数字)
- _colWidth = data.width; //被拉伸后的宽度
- _colData.change[_colNum] = _colWidth;
- });
- };
- /*添加工作表*/
- us.updateExcel.addTask = function (messageInfo, $) {
- var _content = messageInfo.content,
- _taskId = _content.id;
- $[_taskId] = _content.data;
- };
- /*刪除工作表*/
- us.updateExcel.deleteTask = function (messageInfo, $) {
- var _content = messageInfo.content,
- _taskId = _content.id;
- delete ($[_taskId]);
- };
- /*命名工作表*/
- us.updateExcel.reNameTask = function (messageInfo, $) {
- var _content = messageInfo.content,
- _taskId = _content.id;
- $[_taskId].taskName = _content.name;
- };
- us.updateExcel.img = function (messageInfo, $) { //此处修改
- var _content = messageInfo.content,
- _taskId = messageInfo.worksheetId,
- _excelData = $[_taskId],
- _imgData = _excelData.img;
- _imgData.push(_content);
- };
- /**
- * 用户群发处理
- *
- * @param {string} 接收信息的用户id
- * @param {string} 发送的用户信息
- **/
- us.setword = function (messageinfo) {
- // us.userConnect[userid].response.end(messageinfo);
- }
- /**
- * 用户群发处理
- *
- * @param {string} userid 接收信息的用户id
- * @param {string} messageinfo 发送的用户信息
- **/
- us.senduser = function (userid, messageinfo) {
- us.userConnect[userid].response.end(messageinfo); //发送消息
- }
- /**
- * 用户群发处理
- *
- * @param {object} messageinfo 发送消息的内容
- * @param {guid} pageid 页面id
- * @param {string} type 类型
- **/
- us.broadcast = function (messageinfo, pageid, type) {
- var i, j, o, //循环变量
- _messageinfo, //消息信息
- _users, //用户ID集合
- _pageids, //用户页面唯一识别集合
- _recievedpageid, //接收用户的页面唯一识别ID
- _issend, // 是否发送
- _userconnect = us.connect; //用户连接池
- console.log("1")
- console.log(messageinfo)
- for (i in messageinfo) {
- _messageinfo = messageinfo[i]; //记录消息消息
- _users = us[type][i] ? us[type][i].user : {}; //记录用户集合
- console.log(_users)
- for (j in _users) { //循环处理每个用户处理 给每个用户集合下的用户发送消息
- _pageids = _users[j]; //记录当前用户在每个端登录的页面唯一识别ID
- for (o = 0; o < _pageids.length; o++) { //循环发送给当前用户在每个端登录的用户
- _recievedpageid = _pageids[o]; //记录接受者页面唯一识别ID 用于区分是否是发送用户
- if (_recievedpageid != pageid) { //如果接受用户不等于发送用户则发送消息
- console.log("2")
- console.log(_users[j])
- //console.log(_messageinfo);
- _issend = _userconnect[j][_recievedpageid].response.end(JSON.stringify(_messageinfo)); //发送消息
- if (!_issend) { //如果用户下线了,那么发送消息就会失败
- console.log("3")
- us.offLineMessage[_recievedpageid].message.push(_messageinfo); //将消息加入用户离线消息中
- }
- }
- }
- }
- }
- }
- /**
- * 加入文档编辑
- *
- * @param {object} response 用户相应对象
- * @param {string} wordinfo 文档信息 形如: {docId : 'guid,guid,guid', userId : guid, pageId : guid}
- **/
- us.addWord = function (response, wordinfo) {
- //获取用户参数
- wordinfo = JSON.parse(wordinfo);
- var _docidarray = wordinfo.docId.split(','), //根据','号分割多个文档ID
- _userid = wordinfo.userId, //用户ID
- _pageid = wordinfo.pageId, //页面唯一识别ID
- i, //定义循环变量
- _docid, //记录文档ID变量
- _docinfo; //记录文档信息变量
- for (i = 0; i < _docidarray.length; i++) { //循环处理每一份问的加入请求
- _docid = _docidarray[i]; //记录文档ID变量
- _docinfo = us.word[_docid]; //记录文档信息变量
- if (!_docinfo) { //判断群列表是否已存在不存在则创建
- us.word[_docid] = {
- user: {},
- history: []
- }; //创建word文档信息
- us.word[_docid].user[_userid] = [_pageid]; //加入用户
- } else if (!_docinfo.user[_userid]) { //判断文档的用户是否已登陆
- _docinfo.user[_userid] = [_pageid];
- } else if (_docinfo.user[_userid].indexOf(_pageid) == -1) { //将用户添加到群列表中
- _docinfo.user[_userid].push(_pageid);
- }
- us.offLineMessage[_pageid].word.push(_docid); //添加到用户离线消息的连接wrod记录中
- }
- response.end('addword'); //即时相应请求成功
- }
- /**
- * 退出文档编辑
- *
- * @param {object} response 用户相应对象
- * @param {string} wordinfo 文档信息
- **/
- us.quitOffice = function (response, wordinfo) {
- //获取用户参数
- wordinfo = JSON.parse(wordinfo);
- var _docid = wordinfo.docId,
- _userid = wordinfo.userId,
- _pageid = wordinfo.pageId,
- _type = wordinfo.type,
- _messagetype = 'us.' + _type;
- var _docinfo = us[_type][_docid]; //获取文档信息
- //判断是否存在文档信息
- if (_docinfo) {
- us.quitUserList(_docinfo, _userid, _pageid); //将用户在协同列表中删除
- var _j, //创建循环变量
- _message = us.offLineMessage[_pageid] ? us.offLineMessage[_pageid].message : []; //获取该用户的离线消息
- for (_j = _message.length - 1; _j > -1; _j--) { //循环移除该文档的离线消息
- if (_message[_j].type == _messagetype && _message[_j].messageInfo.docId == _docid) { //判断是否为word文档
- _message.splice(_j, 1); //删除记录
- }
- }
- us.insertHistory(_docinfo, _docid, _type);
- }
- response.end('quitOffice'); //响应退出请求
- }
- /**
- * 将用户在协同列表中删除
- *
- * @param {object} docinfo 文档信息
- * @param {string} userid 用户ID
- * @param {string} pageid 用户页面唯一识别ID
- */
- us.quitUserList = function (docinfo, userid, pageid) {
- var _users = docinfo.user[userid]; //记录文档的用户列表
- //获取用户在文档用户列表的位置
- if (_users) {
- var _index = _users.indexOf(pageid);
- // 如果存在则将该用户删除 表示退出协同
- if (_index != -1) {
- _users.splice(_index, 1); //删除该用户
- //如果该用户的全部端用户已退出则删除用户的记录
- if (_users.length == 0) {
- delete docinfo.user[userid];
- }
- }
- }
- }
- /**
- * 插入文档操作历史到数据库
- *
- * @param {object} docinfo 文档信息
- */
- us.insertHistory = function (docinfo, docid, type) {
- var i,
- _info, //操作信息记录
- _isuser = false;
- for (i in docinfo.user) {
- _isuser = true;
- break;
- }
- //如果该文档没有协同用户
- if (!_isuser) {
- switch (type) {
- case 'word':
- var _content = docinfo.content ? docinfo.content('body').html().replace(/'/ig, '\\\'').replace(/"/ig, "\\\"") : "";
- us.mysql.usselect(['sqlserver.1473.cn', 'UseStudio_Disk', 'SaveFileContent', docid, _content, ''],
- function (ret) { });
- break;
- case 'nav':
- us.mysql.usselect(['sqlserver.1473.cn', 'UseStudio_Disk', 'SaveFileContent', docid, JSON.stringify(docinfo.navInfo), ''],
- function (ret) {
- var _key;
- for (_key in docinfo.page) {
- //发送保存内容请求
- var _content = docinfo.page[_key] ? docinfo.page[_key]('body').html().replace(/'/ig, '\\\'').replace(/"/ig, "\\\"") : "";
- us.mysql.usselect(['sqlserver.1473.cn', 'UseStudio_Office', 'SaveNavPageContent', _key, _content], function (ret) { });
- }
- });
- break;
- }
- }
- }
- /**
- * 下线操作
- * @param {object} response 响应对象
- * @param {string} userid 用户ID
- * @param {string} pageid 用户页面唯一识别ID
- */
- us.logout = function (response, userid, pageid) {
- var i, j, _docinfo,
- _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
- _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
- us.connect[userid][pageid].offLineTime = new Date();
- for (i = 0; i < _wordids.length; i++) { //循环处理每一个文档
- _docinfo = us.word[_wordids[i]]; //记录文档信息
- if (_docinfo) { //如果存在文档信息
- us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
- delete us.offLineMessage[pageid]; //删除用户离线消息记录
- us.insertHistory(_docinfo, 'word'); //插入历史
- }
- }
- for (j = 0; i < _excelids.length; j++) {
- _docinfo = us.excel[_excelids[j]]; //记录文档信息
- if (_docinfo) { //如果存在文档信息
- us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
- delete us.offLineMessage[pageid]; //删除用户离线消息记录
- us.insertHistory(_docinfo, 'excel'); //插入历史
- }
- }
- response.end('logout'); //响应退出请求
- }
- /**
- * 获取Excel,并生成后端数据
- *
- * @param {object} response 用户相应对象
- * @param {string} docid 文档ID
- * @param {guid} pageid 页面ID
- * @param {guid} userid 用户ID
- */
- us.getExcel = function (response, docid, pageid, userid) {
- //判断文档是否已在内层中存在
- if (us.excel[docid]) {
- //如果存在则直接返回内层的文档
- if (!us.excel[docid].user[userid]) {
- us.excel[docid].user[userid] = [pageid];
- } else {
- us.excel[docid].user[userid].push(pageid);
- }
- us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
- var _office = us.excel[docid].content;
- response.end(JSON.stringify(_office));
- } else {
- us.excel[docid] = {
- user: {},
- history: []
- };
- us.excel[docid].user[userid] = [pageid];
- us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
- //如果不存在则去数据库查找
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Disk',
- 'GetFileContent',
- docid
- ], function (ret) {
- if (ret) {
- var _office = JSON.parse(ret)[0][0].UsOffice;
- us.excel[docid].content = JSON.parse(_office); //将文档添加到内层中
- response.end(_office); //返回文档内容
- } else {
- us.excel[docid].content = ''; //将文档添加到内层中
- response.end(''); //返回文档内容
- }
- });
- }
- }
- /**
- * 获取文档,并生成DOM
- *
- * @param {object} response 用户相应对象
- * @param {string} fileid 导航文件ID
- * @param {guid} pageid 页面ID
- * @param {guid} userid 用户ID
- */
- us.getNav = function (response, fileid, pageid, userid) {
- //判断文档是否已在内层中存在
- if (us.nav[fileid]) {
- //如果存在则直接返回内层的文档
- if (!us.nav[fileid].user[userid]) {
- us.nav[fileid].user[userid] = [pageid];
- } else {
- us.nav[fileid].user[userid].push(pageid);
- }
- us.offLineMessage[pageid].nav.indexOf(fileid) == -1 && us.offLineMessage[pageid].nav.push(fileid); //添加到用户离线消息的连接wrod记录中
- response.end(JSON.stringify(us.nav[fileid].navInfo));
- } else {
- //如果不存在则去数据库查找
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Disk',
- 'GetFileContent',
- fileid
- ], function (ret) {
- if (ret) {
- var _navinfo = JSON.parse(ret)[0][0].UsOffice;
- if (_navinfo) {
- var _navdata = us.nav[fileid] = { //生成数据结构
- user: {},
- navInfo: JSON.parse(_navinfo),
- page: {},
- history: []
- };
- _navdata.user[userid] = [pageid]; //记录用户
- us.offLineMessage[pageid].nav.indexOf(fileid) == -1 && us.offLineMessage[pageid].nav.push(fileid); //添加到用户离线消息的连接wrod记录中
- response.end(JSON.stringify(_navinfo)); //返回文档内容
- } else {
- response.end(''); //查询不到文档
- }
- } else {
- response.end(''); //返回文档内容
- }
- });
- }
- }
- /**
- * 获取导航页面内容
- * @param {object} response 用户相应对象
- * @param {guid} fileid 文档ID
- * @param {string} navid 文档内容
- * @param {string} name 文档名
- */
- us.getNavPageContent = function (response, fileid, navid) {
- if (us.nav[fileid] && us.nav[fileid].page[navid]) {
- response.end(us.nav[fileid].page[navid]('body').html()); //后台直接返回
- } else {
- //如果不存在则去数据库查找
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Office',
- 'GetNavPageContent',
- navid
- ], function (ret) {
- if (ret && JSON.parse(ret)[0][0]) {
- var _content = JSON.parse(ret)[0][0].content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""); //记录查找内容
- us.nav[fileid] && (us.nav[fileid].page[navid] = us.cheerio.load(_content)); //将文档添加到内层中
- response.end(_content); //查询不到文档
- } else {
- response.end(''); //返回文档内容
- }
- });
- }
- }
- /**
- * 新建文档保存内容并加入协同
- * @param {object} response 用户相应对象
- * @param {guid} docid 文档ID
- * @param {string} content 文档内容
- * @param {string} name 文档名
- * @param {guid} userid 用户ID
- * @param {guid} pageid 页面唯一识别ID
- */
- us.newWordSave = function (response, docid, content, name, userid, pageid) {
- us.word[docid] = {
- user: {},
- history: []
- }; //创建Word类
- us.word[docid].user[userid] = [pageid]; //将用户加入协同记录数组
- us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
- //发送保存请求
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Disk',
- 'SaveFileContent',
- docid,
- content,
- name
- ], function (ret) {
- if (ret) {
- //设置内容
- us.word[docid].content = us.cheerio.load(content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\"")); //将文档添加到内层中
- response.end('save'); //返回保存成功
- } else {
- response.end('fail'); //返回文档内容
- }
- });
- }
- /**
- * 新建文档保存内容并加入协同
- * @param {object} response 用户相应对象
- * @param {guid} docid 文档ID
- * @param {string} content 文档内容
- * @param {string} name 文档名
- * @param {guid} userid 用户ID
- * @param {guid} pageid 页面唯一识别ID
- */
- us.newExcelSave = function (response, docid, content, name, userid, pageid) {
- us.excel[docid] = {
- user: {},
- history: []
- }; //创建excel类
- us.excel[docid].user[userid] = [pageid]; //将用户加入协同记录数组
- us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
- //发送保存请求
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Disk',
- 'SaveFileContent',
- docid,
- content,
- name
- ], function (ret) {
- if (ret) {
- //设置内容
- us.excel[docid].content = JSON.parse(content); //将文档添加到内层中
- response.end('saveOk'); //返回保存成功
- } else {
- response.end('fail'); //返回文档内容
- }
- });
- }
- /**
- * 新建导航文件保存
- * @param {object} response 用户相应对象
- * @param {guid} fileid 文档ID
- * @param {string} navinfo 导航信息
- * @param {string} nowpageid 当前页面ID
- * @param {string} nowpagecontent 当前页面内容
- * @param {string} name 文档名
- * @param {guid} userid 用户ID
- * @param {guid} pageid 页面唯一识别ID
- */
- us.newNavSave = function (response, fileid, navinfo, name, nowpageid, nowpagecontent, userid, pageid) {
- //发送保存文件请求
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Disk',
- 'SaveFileContent',
- fileid,
- navinfo,
- name
- ], function (ret) {
- if (ret) {
- var _navinfo = JSON.parse(navinfo);
- if (!us.nav[fileid]) {
- us.nav[fileid] = {
- user: {},
- navInfo: _navinfo,
- page: {},
- history: []
- };
- } else {
- us.nav[fileid].navInfo = _navinfo;
- }
- var _navdata = us.nav[fileid];
- _navdata.user[userid] = [pageid]; //将用户加入协同记录数组
- us.offLineMessage[pageid].nav.indexOf(fileid) == -1 && us.offLineMessage[pageid].nav.push(fileid); //添加到用户离线消息的连接wrod记录中
- if (nowpageid) {
- us.SaveNavPageContent(response, fileid, nowpageid, nowpagecontent);
- } else {
- response.end('saveContentSuccess'); //返回文档内容
- }
- } else {
- response.end('saveNavFail'); //返回文档内容
- }
- });
- }
- us.SaveNavPageContent = function (response, fileid, nowpageid, nowpagecontent) {
- var _navdata = us.nav[fileid];
- //发送保存内容请求
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Office',
- 'SaveNavPageContent',
- nowpageid,
- nowpagecontent
- ], function (ret) {
- if (ret) {
- _navdata.page[nowpageid] = us.cheerio.load(nowpagecontent.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""));
- response.end('saveContentSuccess'); //返回文档内容
- } else {
- response.end('saveContentFail'); //返回文档内容
- }
- });
- }
- /**
- * 新建导航页面
- * @param {object} response 用户相应对象
- * @param {string} nowpageid 当前页面ID
- * @param {string} nowpagecontent 当前页面内容
- */
- us.copyPageContent = function (response, fileid, nowpageid, nowpagecontent, copypageid) {
- if (!us.nav[fileid]) {
- us.nav[fileid] = {
- user: {},
- navInfo: "",
- page: {},
- history: []
- };
- }
- var _navdata = us.nav[fileid];
- //发送保存内容请求
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Office',
- 'CopyPageContent',
- nowpageid,
- nowpagecontent,
- copypageid
- ], function (ret) {
- if (ret) {
- nowpagecontent == "" && (nowpagecontent = JSON.parse(ret)[0][0].content);
- _navdata.page[nowpageid] = us.cheerio.load(nowpagecontent.replace(/\\'/ig, '\'').replace(/\\"/ig, "\""));
- response.end('saveContentSuccess'); //返回文档内容
- } else {
- response.end('saveContentFail'); //返回文档内容
- }
- });
- }
- /**
- * 加入文档编辑 该函数暂无使用
- *
- * @param {object} response 用户相应对象
- * @param {string} wordinfo 文档信息 形如: {docId : 'guid,guid,guid', userId : guid, pageId : guid}
- **/
- us.addWord = function (response, wordinfo) {
- //获取用户参数
- wordinfo = JSON.parse(wordinfo);
- var _docidarray = wordinfo.docId.split(','), //根据','号分割多个文档ID
- _userid = wordinfo.userId, //用户ID
- _pageid = wordinfo.pageId, //页面唯一识别ID
- i, //定义循环变量
- _docid, //记录文档ID变量
- _docinfo; //记录文档信息变量
- for (i = 0; i < _docidarray.length; i++) { //循环处理每一份问的加入请求
- _docid = _docidarray[i]; //记录文档ID变量
- _docinfo = us.word[_docid]; //记录文档信息变量
- if (!_docinfo) { //判断群列表是否已存在不存在则创建
- us.word[_docid] = {
- user: {},
- history: []
- }; //创建word文档信息
- us.word[_docid].user[_userid] = [_pageid]; //加入用户
- } else if (!_docinfo.user[_userid]) { //判断文档的用户是否已登陆
- _docinfo.user[_userid] = [_pageid];
- } else if (_docinfo.user[_userid].indexOf(_pageid) == -1) { //将用户添加到群列表中
- _docinfo.user[_userid].push(_pageid);
- }
- us.offLineMessage[_pageid].word.push(_docid); //添加到用户离线消息的连接wrod记录中
- }
- response.end('addword'); //即时相应请求成功
- }
- /**
- * 加入Excel编辑
- *
- * @param {object} response 用户相应对象
- * @param {string} excelinfo 表格信息
- **/
- us.addExcel = function (response, excelinfo) {
- //获取用户id
- //获取用户id
- excelinfo = JSON.parse(excelinfo);
- var _excelinfo = us.excel[excelinfo.docId],
- _userid = excelinfo.userId,
- _pageid = excelinfo.pageId,
- _docid = excelinfo.docId;
- if (!_excelinfo) { //判断群列表是否已存在不存在则创建
- us.excel[_docid] = {
- user: {},
- history: []
- };
- us.excel[_docid].user[_userid] = [_pageid];
- } else if (!_excelinfo.user[_userid]) { //判断文档的用户是否已登陆 如果只有1个页面 则直接添加
- _excelinfo.user[_userid] = [_pageid];
- } else if (_excelinfo.user[_userid].indexOf(_pageid) == -1) { //将用户添加到群列表中 假如是一个用户多个页面 这里 则就是将每个页面添加到该用户下
- _excelinfo.user[_userid].push(_pageid);
- }
- us.offLineMessage[_pageid].excel.push(_docid); //添加到用户离线消息的连接excel记录中
- response.end('OK'); //返回到前台
- }
- /**
- * 获取思维网格数据,转成成数组
- *
- */
- us.getMindNetwork = function (response, docid, pageid, userid) {
- //判断文档是否已在内层中存在
- if (us.mindNetwork[docid]) {
- //如果存在则直接返回内层的文档
- if (!us.mindNetwork[docid].user[userid]) {
- us.mindNetwork[docid].user[userid] = [pageid];
- } else {
- us.mindNetwork[docid].user[userid].push(pageid);
- }
- try {
- us.offLineMessage[pageid].mindNetwork.indexOf(docid) == -1 && us.offLineMessage[pageid].mindNetwork.push(docid); //添加到用户离线消息的连接wrod记录中
- }
- catch (e) {
- }
- console.log(us.mindNetwork[docid]);
- //如果不存在则去数据库查找
- us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', docid],
- function (ret) {
- if (ret) {
- ret[0][0].data = us.mindNetwork[docid].content; //把思维网格的内容转化成数组
- response.end(JSON.stringify(ret)); //返回文档内容
- }
- else {
- response.end(''); //返回文档内容
- }
- });
- }
- else {
- us.mindNetwork[docid] = {
- user: {},
- history: []
- };
- us.mindNetwork[docid].user[userid] = [pageid];
- if (us.offLineMessage[pageid]) {
- us.offLineMessage[pageid].mindNetwork.indexOf(docid) == -1 && us.offLineMessage[pageid].mindNetwork.push(docid); //添加到用户离线消息的连接wrod记录中
- }
- //如果不存在则去数据库查找
- us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', docid],
- function (ret) {
- if (ret) {
- us.mindNetwork[docid].content = JSON.parse(ret[0][0].data); //把思维网格的内容转化成数组
- response.end(JSON.stringify(ret)); //返回文档内容
- }
- else {
- us.mindNetwork[docid].content = []; //创建一个空数组
- response.end(''); //返回文档内容
- }
- });
- }
- }
- /**
- * 获取文档,并生成DOM
- *
- * @param {object} response 用户相应对象
- * @param {string} docid 文档ID
- */
- us.getWord = function (response, docid, pageid, userid) {
- // //判断文档是否已在内层中存在
- // if (us.word[docid]) {
- // //如果存在则直接返回内层的文档
- // if (!us.word[docid].user[userid]) {
- // us.word[docid].user[userid] = [pageid];
- // } else {
- // us.word[docid].user[userid].push(pageid);
- // }
- // us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
- // response.end(us.word[docid].content('body').html());
- // }
- // else {
- // us.word[docid] = {
- // user: {},
- // history: []
- // };
- // us.word[docid].user[userid] = [pageid];
- // if (us.offLineMessage[pageid]) {
- // us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
- // }
- // //如果不存在则去数据库查找
- // us.mysql.usselect(['172.16.12.5', 'pbl', 'select_file', docid],
- // function (ret) {
- // if (ret) {
- // var _office = JSON.parse(ret)[0][0].data ? JSON.parse(ret)[0][0].data.replace(/\\'/ig, '\'').replace(/\\"/ig, "\"") : ""; //记录查找内容
- // us.word[docid].content = us.cheerio.load(_office); //将文档添加到内层中
- // response.end(_office); //返回文档内容
- // } else {
- // us.word[docid].content = us.cheerio.load(''); //将文档添加到内层中
- // response.end(''); //返回文档内容
- // }
- // });
- // }
- //判断文档是否已在内层中存在
- if (us.word[docid]) {
- //如果存在则直接返回内层的文档
- if (!us.word[docid].user[userid]) {
- us.word[docid].user[userid] = [pageid];
- } else {
- us.word[docid].user[userid].push(pageid);
- }
- console.log(us.offLineMessage[pageid]);
- console.log(pageid);
- try {
- us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
- }
- catch (e) {
- }
- //如果不存在则去数据库查找
- us.mysql.usselect(['172.16.12.5', 'pbl', 'select_file', docid],
- function (ret) {
- if (ret) {
- ret[0][0].data = us.word[docid].content; //把思维网格的内容转化成数组
- response.end(JSON.stringify(ret)); //返回文档内容
- }
- else {
- response.end(''); //返回文档内容
- }
- });
- }
- else {
- us.word[docid] = {
- user: {},
- history: []
- };
- us.word[docid].user[userid] = [pageid];
- if (us.offLineMessage[pageid]) {
- us.offLineMessage[pageid].word.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
- }
- //如果不存在则去数据库查找
- us.mysql.usselect(['172.16.12.5', 'pbl', 'select_file', docid],
- function (ret) {
- if (ret) {
- us.word[docid].content = ret[0][0].data; //把思维网格的内容转化成数组
- response.end(JSON.stringify(ret)); //返回文档内容
- }
- else {
- us.word[docid].content = []; //创建一个空数组
- response.end(''); //返回文档内容
- }
- });
- }
- }
- us.getExcel = function (response, docid, pageid, userid) {
- //判断文档是否已在内层中存在
- if (us.excel[docid]) {
- //如果存在则直接返回内层的文档
- if (!us.excel[docid].user[userid]) {
- us.excel[docid].user[userid] = [pageid];
- } else {
- us.excel[docid].user[userid].push(pageid);
- }
- us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
- var _office = us.excel[docid].content;
- response.end(JSON.stringify(_office));
- } else {
- us.excel[docid] = {
- user: {},
- history: []
- };
- us.excel[docid].user[userid] = [pageid];
- us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].excel.push(docid); //添加到用户离线消息的连接wrod记录中
- //如果不存在则去数据库查找
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Disk',
- 'GetFileContent',
- docid
- ], function (ret) {
- if (ret) {
- var _office = JSON.parse(ret)[0][0].UsOffice;
- us.excel[docid].content = JSON.parse(_office); //将文档添加到内层中
- response.end(_office); //返回文档内容
- } else {
- us.excel[docid].content = ''; //将文档添加到内层中
- response.end(''); //返回文档内容
- }
- });
- }
- }
- /**
- * 新建文档保存内容并加入协同
- * @param {object} response 用户相应对象
- * @param {guid} docid 文档ID
- * @param {string} content 文档内容
- * @param {string} name 文档名
- * @param {guid} userid 用户ID
- * @param {guid} pageid 页面唯一识别ID
- */
- us.newExcelSave = function (response, docid, content, name, userid, pageid) {
- us.excel[docid] = {
- user: {},
- history: []
- }; //创建excel类
- us.excel[docid].user[userid] = [pageid]; //将用户加入协同记录数组
- us.offLineMessage[pageid].excel.indexOf(docid) == -1 && us.offLineMessage[pageid].word.push(docid); //添加到用户离线消息的连接wrod记录中
- //发送保存请求
- us.mysql.usselect([
- 'sqlserver.1473.cn',
- 'UseStudio_Disk',
- 'SaveFileContent',
- docid,
- content,
- name
- ], function (ret) {
- if (ret) {
- //设置内容
- us.excel[docid].content = JSON.parse(content); //将文档添加到内层中
- response.end('saveOk'); //返回保存成功
- } else {
- response.end('fail'); //返回文档内容
- }
- });
- }
- /**
- * 生成Guid
- *
- **/
- us.createGuid = function () {
- //返回guid的处理
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
- var r = Math.random() * 16 | 0,
- v = c == 'x' ? r : (r & 0x3 | 0x8);
- return v.toString(16);
- });
- };
- /**
- * 监听1473端口的处理
- *
- **/
- us.server.listen('1473', '', function () {
- //在控制台输出监听提示
- console.log("开始监听" + us.server.address().port + "......");
- });
- // 同意处理错误
- //process.on('uncaughtException', function (e) {
- // console.log("错误:" + e);
- //});
|