root 2 years ago
parent
commit
2b7b630987
6 changed files with 2141 additions and 53 deletions
  1. 0 1
      Office/U.OU.Excel.ascx
  2. 0 52
      Office/Word/Word.ascx
  3. 1880 0
      node/message.js
  4. 1 0
      node/node_modules/.package_versions.json
  5. 162 0
      node/package-lock.json
  6. 98 0
      node/sqlserver.js

+ 0 - 1
Office/U.OU.Excel.ascx

@@ -1 +0,0 @@
-<%@ Control Language="C#" %>

+ 0 - 52
Office/Word/Word.ascx

@@ -1,52 +0,0 @@
-<%@ Control Language="C#" %>
-<div id="UD_Word" class="U_MD_O_E">
-    <%-- 菜单栏 --%>
-    <div class="U_MD_O_E_S">
-        <div class='U_MD_O_H_head_logo'>
-            <img src="http://www.1473.cn/BoomYun/img/pc/logo.png" alt="" />
-            <input class="U_MD_O_H_head_navigation_Title" type="text" value="未命名文档(点击编辑)..."
-                onclick="U.UF.EV.stopBubble()" onmousedown="U.UF.EV.stopBubble()" onmouseup="U.UF.EV.stopBubble()"
-                onmouse="U.UF.EV.stopBubble()" onfocus="U.UF.MR.inputPlaceholder(this,'未命名文档(点击编辑)...',{color: '#fff', value : ''});"
-                onblur="U.UF.MR.inputPlaceholder(this,{color: '#fff', value : ''},'未命名文档(点击编辑)...'); " unselectable="on">
-        </div>
-        <div class="U_MD_O_H_head_navigation_one" onmousedown="U.UF.EV.stopBubble();" style='display: none'>
-            <div style="display: none" onclick="U.Word.Tools.ModeSwitch(this, 0); U.Word.Tools.XTemp(0);">
-                首页</div>
-            <div onclick="U.Word.Tools.ModeSwitch(this, 1); U.Word.Tools.XTemp(1);" class="U_MD_O_H_head_navigation_color_789CD5">
-                互联办公</div>
-            <div onclick="U.Word.Tools.ModeSwitch(this, 2); U.Word.Tools.XTemp(2);">
-                云企建站</div>
-            <div onclick="U.Word.Tools.ModeSwitch(this, 3); U.Word.Tools.XTemp(4);">
-                会议录</div>
-            <div onclick="U.Word.Tools.ModeSwitch(this, 4); U.Word.Tools.XTemp(5);">
-                目录模式</div>
-        </div>
-        <div class="U_MD_O_H_head_navigation_two" onmousedown="U.UF.EV.stopBubble();">
-            <div class="U_MD_O_H_head_navigation_two_l" title="导航建站" onclick="U.MD.D.I.openApplication('word', { UserDirectoryExtendType : 'un'});">
-                <div class="U_MD_O_H_img U_MD_O_H_head_navigation_two_i U_MD_O_H_head_navigation_two_io">
-                </div>
-                <span>导航建站</span>
-            </div>
-            <div style="display: none;" class="U_MD_O_H_head_navigation_two_l" title="视图切换" onclick="U.MD.O.W.T.ViewDisplay(this)">
-                <div class="U_MD_O_H_img U_MD_O_H_head_navigation_two_i U_MD_O_H_head_navigation_two_io">
-                </div>
-                <span>视图</span>
-            </div>
-            <div class="U_MD_O_H_head_navigation_two_l" title="建立团队协作" onclick='$("iframe")[$("iframe").length - 1].contentWindow.U.MD.O.W.Panel.displayInsertUser()'>
-                <div class="U_MD_O_H_img U_MD_O_H_head_navigation_two_i U_MD_O_H_head_navigation_two_it">
-                </div>
-                <span>建立团队协作</span>
-            </div>
-            <div class="U_MD_O_H_head_navigation_two_l" title="我的云盘" onclick='top.U.MD.D.I.openApplication("disk", { "userid": US.disk.UserDisk.userInfo.UserId, "directoryid": US.disk.UserDisk.directoryid ? US.disk.UserDisk.directoryid : US.MYFOLDERID })'>
-                <div class="U_MD_O_H_img U_MD_O_H_head_navigation_two_i U_MD_O_H_head_navigation_two_is">
-                </div>
-                <span>我的云盘</span>
-            </div>
-            <div class="U_MD_O_H_head_navigation_two_r">
-            </div>
-        </div>
-    </div>
-    <%-- Word编辑区 --%>
-    <div class="U_MD_O">
-    </div>
-</div>

+ 1880 - 0
node/message.js

@@ -0,0 +1,1880 @@
+var us = {}; //全局的命名空间
+
+us.cheerio = require("cheerio"); //dom处理类
+us.qs = require("querystring"); //引用文件解析包
+us.http = require("http"); //引用http server服务
+us.mysql = require("./sqlserver.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.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": [],
+        "excel": [],
+        "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) {
+        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 '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([
+        'sqlserver.1473.cn',
+        '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 () {
+        //前端传入的字符串转化成对象
+        if (_param) {
+            _param = us.qs.parse(_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;
+            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) {
+    var i, j,
+        _message,
+        _messagelist = {},
+    // _messageall = [],
+        _messageobj = JSON.parse(messageinfo) //获取传入的json对象
+    ;
+
+    //循环用户的信息处理
+    for (i in _messageobj) {
+        switch (i) {
+            //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.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; //用户连接池
+    for (i in messageinfo) {
+        _messageinfo = messageinfo[i]; //记录消息消息
+        _users = us[type][i] ? us[type][i].user : {}; //记录用户集合
+        for (j in _users) { //循环处理每个用户处理 给每个用户集合下的用户发送消息
+            _pageids = _users[j]; //记录当前用户在每个端登录的页面唯一识别ID
+            for (o = 0; o < _pageids.length; o++) { //循环发送给当前用户在每个端登录的用户
+                _recievedpageid = _pageids[o]; //记录接受者页面唯一识别ID  用于区分是否是发送用户
+                if (_recievedpageid != pageid) { //如果接受用户不等于发送用户则发送消息
+                    //console.log(_messageinfo);
+                    _issend = _userconnect[j][_recievedpageid].response.end(JSON.stringify(_messageinfo)); //发送消息
+                    if (!_issend) { //如果用户下线了,那么发送消息就会失败
+                        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'); //返回到前台
+}
+
+/**
+* 获取文档,并生成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(['sqlserver.1473.cn', 'UseStudio_Disk', 'GetFileContent', docid],
+        function (ret) {
+            if (ret) {
+                var _office = JSON.parse(ret)[0][0].UsOffice ? JSON.parse(ret)[0][0].UsOffice.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(''); //返回文档内容 
+            }
+        });
+    }
+}
+
+
+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);
+//});

+ 1 - 0
node/node_modules/.package_versions.json

@@ -0,0 +1 @@
+{}

+ 162 - 0
node/package-lock.json

@@ -0,0 +1,162 @@
+{
+  "requires": true,
+  "lockfileVersion": 1,
+  "dependencies": {
+    "babel-runtime": {
+      "version": "6.26.0",
+      "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
+      "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=",
+      "requires": {
+        "core-js": "2.5.7",
+        "regenerator-runtime": "0.11.1"
+      }
+    },
+    "big-number": {
+      "version": "0.3.1",
+      "resolved": "https://registry.npmjs.org/big-number/-/big-number-0.3.1.tgz",
+      "integrity": "sha1-rHMCDApZu3nrF8LOLbd/d9l04BM="
+    },
+    "bl": {
+      "version": "1.2.2",
+      "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz",
+      "integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==",
+      "requires": {
+        "readable-stream": "2.3.6",
+        "safe-buffer": "5.1.2"
+      }
+    },
+    "core-js": {
+      "version": "2.5.7",
+      "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.7.tgz",
+      "integrity": "sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw=="
+    },
+    "core-util-is": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
+      "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
+    },
+    "debug": {
+      "version": "2.6.9",
+      "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
+      "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
+      "requires": {
+        "ms": "2.0.0"
+      }
+    },
+    "depd": {
+      "version": "1.1.2",
+      "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
+      "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
+    },
+    "generic-pool": {
+      "version": "3.4.2",
+      "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.4.2.tgz",
+      "integrity": "sha512-H7cUpwCQSiJmAHM4c/aFu6fUfrhWXW1ncyh8ftxEPMu6AiYkHw9K8br720TGPZJbk5eOH2bynjZD1yPvdDAmag=="
+    },
+    "iconv-lite": {
+      "version": "0.4.23",
+      "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz",
+      "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==",
+      "requires": {
+        "safer-buffer": "2.1.2"
+      }
+    },
+    "inherits": {
+      "version": "2.0.3",
+      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
+      "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
+    },
+    "isarray": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
+      "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
+    },
+    "ms": {
+      "version": "2.0.0",
+      "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+      "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
+    },
+    "mssql": {
+      "version": "4.1.0",
+      "resolved": "https://registry.npmjs.org/mssql/-/mssql-4.1.0.tgz",
+      "integrity": "sha512-ekht0eILEV0P1CbpkwpAxhgO+/5goYizUJrt7pgDm3fP6lGKe0+8V9jhTvQZ8DPHkycSd0wYGUoz/YA7VN7kQQ==",
+      "requires": {
+        "debug": "2.6.9",
+        "generic-pool": "3.4.2",
+        "tedious": "2.6.3"
+      }
+    },
+    "process-nextick-args": {
+      "version": "2.0.0",
+      "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
+      "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
+    },
+    "punycode": {
+      "version": "2.1.1",
+      "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
+      "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
+    },
+    "readable-stream": {
+      "version": "2.3.6",
+      "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
+      "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
+      "requires": {
+        "core-util-is": "1.0.2",
+        "inherits": "2.0.3",
+        "isarray": "1.0.0",
+        "process-nextick-args": "2.0.0",
+        "safe-buffer": "5.1.2",
+        "string_decoder": "1.1.1",
+        "util-deprecate": "1.0.2"
+      }
+    },
+    "regenerator-runtime": {
+      "version": "0.11.1",
+      "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
+      "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg=="
+    },
+    "safe-buffer": {
+      "version": "5.1.2",
+      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
+      "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
+    },
+    "safer-buffer": {
+      "version": "2.1.2",
+      "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
+      "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
+    },
+    "sprintf-js": {
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.1.tgz",
+      "integrity": "sha1-Nr54Mgr+WAH2zqPueLblqrlA6gw="
+    },
+    "string_decoder": {
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+      "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
+      "requires": {
+        "safe-buffer": "5.1.2"
+      }
+    },
+    "tedious": {
+      "version": "2.6.3",
+      "resolved": "https://registry.npmjs.org/tedious/-/tedious-2.6.3.tgz",
+      "integrity": "sha512-pt0FWkDAbZl0e9sjK4wOcZNJ3/xNp1AeqKBAsQpQVnLBpzM6lJCvoiF/blUC1O7biFO3YX9M4fac2ENg1w4PWQ==",
+      "requires": {
+        "babel-runtime": "6.26.0",
+        "big-number": "0.3.1",
+        "bl": "1.2.2",
+        "depd": "1.1.2",
+        "iconv-lite": "0.4.23",
+        "punycode": "2.1.1",
+        "readable-stream": "2.3.6",
+        "sprintf-js": "1.1.1"
+      }
+    },
+    "util-deprecate": {
+      "version": "1.0.2",
+      "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
+      "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
+    }
+  }
+}

+ 98 - 0
node/sqlserver.js

@@ -0,0 +1,98 @@
+var mssql = require('mssql'); //包含mssql模块
+//----------------------------------mssql 连接设置--------------------------------------
+function mssqlconnet(ho, db) {
+    return {
+        user: 'usestudio',
+        password: 'usestudio-1',
+        server: ho,
+        database: db,
+        port: 11302
+    };
+}
+
+//----------------------------------mssql 查询语句--------------------------------------
+exports.usselect = function (paramsarr, callback) {
+    var _params; //截取存储过程参数数组变量
+    var _sql = "EXEC " + paramsarr[2]; //拼接sqlserver语句
+    if (paramsarr[3]) { //判断是否存在参数
+        _params = paramsarr.slice(3); //截取参数
+    }
+    console.log(paramsarr[0]); //输出数据库地址
+    console.log(paramsarr[1]); //输出数据库名称
+
+    var config = mssqlconnet(paramsarr[0], paramsarr[1]); //更新设置
+    var connection = new mssql.ConnectionPool(config, function (err) { //创建连接
+        var _ps = new mssql.PreparedStatement(connection); //调用查询方法
+        var _param = {}; //定义存储过程参数对象
+        if (_params) { //判断是否存在参数
+            _params.forEach((value, key) => { //循环处理参数
+                var _key = `param${key}`; //拼接参数名称
+                _param[_key] = value; //设置的参数对象中
+                if (typeof value == "number") { //数字类型参数处理
+                    _ps.input(index, mssql.Int); //添加整形参数类型
+                } else if (typeof value == "string" && /^[a-fA-F0-9]{8}(-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}$/.test(value)) { //guid参数处理
+                    _ps.input(_key, mssql.UniqueIdentifier); //添加guid参数类型
+                } else if (typeof value == "string") { //字符串参数处理
+                    _ps.input(_key, mssql.NVarChar); //添加字符串参数类型
+                }
+                _sql += ` @${_key},`; //拼接sql语句
+            });
+            _sql = _sql.slice(0, _sql.length - 1); //删除多余“,”号
+        }
+
+        _ps.prepare(_sql, function (err) { //格式化处理预执行sql语句
+            if (err) //存在错误则输出日志
+                console.log(err);
+            _ps.execute(_param, function (err, data) { //传入参数执行sql语句
+                if (err)
+                    console.log(err);
+                else
+                    callback(JSON.stringify(data.recordsets)); //输出结果
+                _ps.unprepare(function (err) { //释放连接
+                    if (err) //存在错误则输出日志
+                        console.log(err);
+                });
+            });
+        });
+    });
+}
+
+// var sql = require('mssql');//包含mssql模块
+// //----------------------------------mssql 连接设置--------------------------------------
+// function mssqlconnet(ho, db) {
+//     return {
+//         user: 'usestudio',
+//         password: 'usestudio-1',
+//         server: ho,
+//         database: db,
+//         port:11302
+//     };
+// }
+
+// exports.usselect = function (pArr, callback) {
+//     var _pro = "", i; //定义循环变量,对字符串解密
+//     //for (i = 0; i < pArr.length; i++) { pArr[i] = decodeURIComponent(pArr[i]); } //解密中文字符串。
+
+//     //如果前台没有传参数过来,则需进这里
+//     if (!pArr[3]) {
+//         _pro = "EXEC " + pArr[2];
+//     } else {  //否则有参数
+//         _pro = "EXEC " + "" + pArr[2] + " '"; //命令拼凑
+//         for (i = 3; i < pArr.length; i++) { _pro += pArr[i]; if (i < pArr.length - 1) _pro += "','"; } //拼凑参数
+//         _pro += "'"; //拼凑结束。
+//     } 
+
+//     console.log(pArr[0]);
+//  console.log(pArr[1]);
+
+
+//     var config = mssqlconnet(pArr[0], pArr[1]);//更新设置
+//     var connection = new sql.ConnectionPool(config, function (err) {//创建连接
+
+// 	var request = new sql.Request(connection);//创建连接
+//         request.query(_pro, function (err, recordsets) {//执行语句
+// 	 callback(JSON.stringify(recordsets)); //返回json数据
+//         });
+
+//     });
+// }