|
|
@@ -1,34 +1,95 @@
|
|
|
-var us = {};
|
|
|
-us.cheerio = require("cheerio");
|
|
|
-us.qs = require("querystring");
|
|
|
-us.http = require("http");
|
|
|
-us.mysql = require("./mysql.js");
|
|
|
-
|
|
|
-// 将 mysql 调用 Promise 化(若原方法为回调风格)
|
|
|
-us.mysql.usselectAsync = (params) => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- us.mysql.usselect(params, (ret) => {
|
|
|
- if (ret === null || ret === undefined) {
|
|
|
- reject(new Error('Database query returned null'));
|
|
|
- } else {
|
|
|
- resolve(ret);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
-};
|
|
|
+var us = {}; //全局的命名空间
|
|
|
+
|
|
|
+us.cheerio = require("cheerio"); //dom处理类
|
|
|
+us.qs = require("querystring"); //引用文件解析包
|
|
|
+us.http = require("http"); //引用http server服务
|
|
|
+us.mysql = require("./mysql.js"); //引用执行存储过程包
|
|
|
|
|
|
+/**
|
|
|
+* 保持知识建构的时间变量
|
|
|
+**/
|
|
|
us.savecscltime = null;
|
|
|
|
|
|
-us.connect = {};
|
|
|
-us.user = {};
|
|
|
-us.cscl = {};
|
|
|
-us.offLineMessage = {};
|
|
|
-us.mindNetwork = {};
|
|
|
-us.realTimeClass = {};
|
|
|
-us.word = {};
|
|
|
-us.excel = {};
|
|
|
-us.nav = {};
|
|
|
+/**
|
|
|
+* 用户的链接池集合,以用户id作为搜索键
|
|
|
+**/
|
|
|
+us.connect = {
|
|
|
+ //userguid:{pageid : us.userConnect, pageid : us.userConnect}
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 用户的数据集合集合,以用户id作为搜索键
|
|
|
+**/
|
|
|
+us.user = {
|
|
|
+ //userId : userInfo //用户连接(请求), 这里可以是http短连接可以使socket长连接
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 未来课堂数据结构
|
|
|
+**/
|
|
|
+us.cscl = {
|
|
|
+ //"nodes":[{"id":"9f6d7459-d376-4c0c-944b-a6b140085903","type":"icon-start","x":625,"y":145,"properties":{},"zIndex":1002,"text":{"x":625,"y":145,"value":"起始"}},{"id":"16e18308-7517-4162-8b32-a877b7cf42a0","type":"icon-card","x":325,"y":445,"properties":{},"zIndex":1002},{"id":"5c492b0d-092d-4d84-bd70-4d5734de9266","type":"icon-select","x":970,"y":510,"properties":{},"zIndex":1002}],
|
|
|
+ //"edges":[],
|
|
|
+ //"backgroundUrl":"img/bg.ccee1c62.png"
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+* 离线数据
|
|
|
+**/
|
|
|
+us.offLineMessage = {
|
|
|
+ //pageId : us.userOffLineMessage
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+* 思维网格
|
|
|
+**/
|
|
|
+us.mindNetwork = {
|
|
|
+ // mindid: {
|
|
|
+ // }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+* 同步课堂
|
|
|
+**/
|
|
|
+us.realTimeClass = {
|
|
|
+ // 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(操作信息对象)]
|
|
|
+ //} //导航文档数据结构
|
|
|
+}
|
|
|
+
|
|
|
+//知识建构的数据结构
|
|
|
us.cscldata = function () {
|
|
|
return {
|
|
|
id: "",
|
|
|
@@ -41,554 +102,2544 @@ us.cscldata = function () {
|
|
|
createuser: "",
|
|
|
smailheadportrait: ""
|
|
|
};
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
+/**
|
|
|
+* 用户链接类
|
|
|
+*
|
|
|
+* @param {string} pageId 页面ID(用户登录唯一识别ID)
|
|
|
+* @param {object} response 对象
|
|
|
+**/
|
|
|
us.userConnect = function (pageId, response) {
|
|
|
return {
|
|
|
- "pageId": pageId,
|
|
|
- "response": response,
|
|
|
- "loginTime": new Date(),
|
|
|
- "offLineTime": null
|
|
|
- };
|
|
|
-};
|
|
|
+ "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,
|
|
|
- "userName": username
|
|
|
- };
|
|
|
-};
|
|
|
+ "userId": userid, //用户id
|
|
|
+ "userName": username //用户名
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+/**
|
|
|
+* 用户离线数据
|
|
|
+* @param {string} type 用户登录类型
|
|
|
+*/
|
|
|
us.userOffLineMessage = function (type) {
|
|
|
return {
|
|
|
- "message": [],
|
|
|
- "type": type,
|
|
|
- "word": [],
|
|
|
- "excel": [],
|
|
|
- "mindNetwork": [],
|
|
|
- "realTimeClass": [],
|
|
|
- "cscl": [],
|
|
|
- "nav": []
|
|
|
- };
|
|
|
-};
|
|
|
+ "message": [], //用户的消息数组
|
|
|
+ "type": type, //链接的端 pc或者pho
|
|
|
+ "word": [], //word数据
|
|
|
+ "excel": [], //excel数据
|
|
|
+ "mindNetwork": [], //思维网格数据
|
|
|
+ "realTimeClass": [], //实施课堂数据
|
|
|
+ "cscl": [], //未来课堂数据
|
|
|
+ "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(),
|
|
|
- "sendId": sendid,
|
|
|
- "time": new Date(),
|
|
|
- "type": type,
|
|
|
- "messageInfo": messageinfo
|
|
|
- };
|
|
|
-};
|
|
|
+ "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
|
|
|
+}
|
|
|
+*/
|
|
|
|
|
|
process.on('uncaughtException', (e) => {
|
|
|
console.error('process error is:', e.message);
|
|
|
});
|
|
|
|
|
|
-us.server = us.http.createServer(async (req, res) => {
|
|
|
- res.writeHead(200, {
|
|
|
+
|
|
|
+/**
|
|
|
+* 创建服务
|
|
|
+*
|
|
|
+* @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'
|
|
|
});
|
|
|
|
|
|
- try {
|
|
|
- const param = await us.unifyDisposeAsync(req, res);
|
|
|
- if (!param || !param[0]) {
|
|
|
- return res.end("");
|
|
|
- }
|
|
|
- const _funname = param[0];
|
|
|
- const _param = param.slice(1);
|
|
|
-
|
|
|
- switch (_funname) {
|
|
|
- case 'login': {
|
|
|
- const _userinfo = JSON.parse(_param[0]);
|
|
|
- us.login(req, res, _userinfo.userId, _userinfo.pageId, _userinfo.userName, _userinfo.type);
|
|
|
- break;
|
|
|
+ //设置参数,并执行回调
|
|
|
+ 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(requset, response, _userinfo.userId, _userinfo.pageId, _userinfo.userName, _userinfo.type);
|
|
|
+ break;
|
|
|
+ case 'logout':
|
|
|
+ us.logout(response, _param[0], _param[1]);
|
|
|
+ break;
|
|
|
+ //执行轮询函数
|
|
|
+ case 'polling':
|
|
|
+ us.polling(requset, 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 'getcscl':
|
|
|
+ us.getcscl(response, _param[0], _param[1], _param[2]);
|
|
|
+ break;
|
|
|
+ //获取未来课堂数据
|
|
|
+ case 'getcscldata':
|
|
|
+ us.getcscldata(response, _param[0], _param[1], _param[2]);
|
|
|
+ break;
|
|
|
+ //获取文档信息
|
|
|
+ case 'getRealTimeClass':
|
|
|
+ us.getRealTimeClass(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 'quitcscl':
|
|
|
+ us.quitcscl(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':
|
|
|
+ us.newNavSave(response, _param[0], _param[1], _param[2], _param[3], _param[4], _param[5], _param[6]);
|
|
|
+ break;
|
|
|
+ //加入文档编辑
|
|
|
+ case 'addWord':
|
|
|
+ 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);
|
|
|
}
|
|
|
- case 'logout':
|
|
|
- us.logout(res, _param[0], _param[1]);
|
|
|
- break;
|
|
|
- case 'polling':
|
|
|
- us.polling(req, res, _param[0], _param[1], _param[2], _param[3]);
|
|
|
- break;
|
|
|
- case 'getWord':
|
|
|
- await us.getWord(res, _param[0], _param[1], _param[2]);
|
|
|
- break;
|
|
|
- case 'getExcel':
|
|
|
- await us.getExcel(res, _param[0], _param[1], _param[2]);
|
|
|
- break;
|
|
|
- case 'getNav':
|
|
|
- await us.getNav(res, _param[0], _param[1], _param[2]);
|
|
|
- break;
|
|
|
- case 'getMindNetwork':
|
|
|
- await us.getMindNetwork(res, _param[0], _param[1], _param[2]);
|
|
|
- break;
|
|
|
- case 'getcscl':
|
|
|
- await us.getcscl(res, _param[0], _param[1], _param[2]);
|
|
|
- break;
|
|
|
- case 'getcscldata':
|
|
|
- await us.getcscldata(res, _param[0], _param[1], _param[2]);
|
|
|
- break;
|
|
|
- case 'getRealTimeClass':
|
|
|
- await us.getRealTimeClass(res, _param[0], _param[1], _param[2]);
|
|
|
- break;
|
|
|
- case 'getNavPageContent':
|
|
|
- await us.getNavPageContent(res, _param[0], _param[1]);
|
|
|
- break;
|
|
|
- case 'send':
|
|
|
- await us.send(res, _param[0]);
|
|
|
- break;
|
|
|
- case 'quitOffice':
|
|
|
- us.quitOffice(res, _param[0]);
|
|
|
- break;
|
|
|
- case 'quitcscl':
|
|
|
- us.quitcscl(res, _param[0]);
|
|
|
- break;
|
|
|
- case 'newWordSave':
|
|
|
- await us.newWordSave(res, _param[0], _param[1], _param[2], _param[3], _param[4]);
|
|
|
- break;
|
|
|
- case 'newExcelSave':
|
|
|
- await us.newExcelSave(res, _param[0], _param[1], _param[2], _param[3], _param[4]);
|
|
|
- break;
|
|
|
- case 'newNavSave':
|
|
|
- await us.newNavSave(res, _param[0], _param[1], _param[2], _param[3], _param[4], _param[5], _param[6]);
|
|
|
- break;
|
|
|
- case 'addExcel':
|
|
|
- us.addExcel(res, _param[0]);
|
|
|
- break;
|
|
|
- case 'copyPageContent':
|
|
|
- await us.copyPageContent(res, _param[0], _param[1], _param[2], _param[3]);
|
|
|
- break;
|
|
|
- case 'updateName':
|
|
|
- await us.updateName(res, _param[0], _param[1], _param[2], _param[3], _param[4]);
|
|
|
- break;
|
|
|
- case 'insertModifyRecord':
|
|
|
- await us.insertModifyRecord(res, _param[0], _param[1], _param[2], _param[3], _param[4], _param[5]);
|
|
|
- break;
|
|
|
- case 'addUser':
|
|
|
- us.addUser(res, _param[0], _param[1], _param[2], _param[3], _param[4]);
|
|
|
- break;
|
|
|
- default:
|
|
|
- res.end("0");
|
|
|
}
|
|
|
- } catch (err) {
|
|
|
- console.error('Request error:', err);
|
|
|
- res.end("");
|
|
|
- }
|
|
|
+ else {
|
|
|
+ response.end("");
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
-// 将原有的 unifyDispose 改为 Promise 版本
|
|
|
-us.unifyDisposeAsync = (req, res) => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- let _param = "";
|
|
|
- req.on("data", chunk => _param += chunk);
|
|
|
- req.on("end", () => {
|
|
|
- try {
|
|
|
- if (_param) {
|
|
|
- _param = us.qs.parse(_param);
|
|
|
- }
|
|
|
- _param = _param.mode ? _param.mode.split(",") : [];
|
|
|
- for (let i = 0; i < _param.length; i++) {
|
|
|
- _param[i] = decodeURIComponent(_param[i]);
|
|
|
- }
|
|
|
- resolve(_param);
|
|
|
- } catch (e) {
|
|
|
- reject(e);
|
|
|
- }
|
|
|
- });
|
|
|
- res.setTimeout(60000, () => {
|
|
|
- try { res.end(""); } catch (e) {}
|
|
|
- });
|
|
|
- req.on("error", (e) => reject(e));
|
|
|
- });
|
|
|
-};
|
|
|
|
|
|
-us.insertModifyRecord = async (response, type, fileid, filename, html, userid, pageid) => {
|
|
|
- let _html = html;
|
|
|
- if (us[type] && us[type][fileid] && us[type][fileid].content) {
|
|
|
+/**
|
|
|
+* 协同历史(带保存功能,修改了存储过程 既添加历史也保存内容)
|
|
|
+*
|
|
|
+* @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;
|
|
|
}
|
|
|
- try {
|
|
|
- const ret = await us.mysql.usselectAsync([
|
|
|
- '127.0.0.1', 'UseStudio_Office', 'InsertDocumentModifyRecord',
|
|
|
- userid, fileid, _html, filename
|
|
|
- ]);
|
|
|
- const _historyid = JSON.parse(ret)[0][0].historyid;
|
|
|
- const _messageinfo = us.message(userid, 'us.' + type, {
|
|
|
- id: us.createGuid(),
|
|
|
- type: "insertModifyRecord",
|
|
|
- historyid: _historyid,
|
|
|
- docId: fileid
|
|
|
- });
|
|
|
- const _message = { [fileid]: [_messageinfo] };
|
|
|
- us.broadcast(_message, pageid, type);
|
|
|
- response.end(_historyid);
|
|
|
- } catch (e) {
|
|
|
- response.end("");
|
|
|
- }
|
|
|
-};
|
|
|
+ //发送保存文件请求
|
|
|
+ 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); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
-us.updateName = async (response, type, fileid, filename, userid, pageid) => {
|
|
|
- try {
|
|
|
- const ret = await us.mysql.usselectAsync([
|
|
|
- 'sqlserver.1473.cn', 'UseStudio_Disk', 'UpdateFileInfo', fileid, filename
|
|
|
- ]);
|
|
|
+
|
|
|
+/**
|
|
|
+* 更新文件名
|
|
|
+*
|
|
|
+* @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) {
|
|
|
- const _messageinfo = us.message(userid, 'us.' + type, {
|
|
|
+ var _message = {};
|
|
|
+ var _messageinfo = us.message(userid, 'us.' + type, {
|
|
|
id: us.createGuid(),
|
|
|
type: "updateName",
|
|
|
name: filename,
|
|
|
docId: fileid
|
|
|
});
|
|
|
- us.broadcast({ [fileid]: [_messageinfo] }, pageid, type);
|
|
|
- response.end('updateNameSuccess');
|
|
|
+ _message[fileid] = [_messageinfo];
|
|
|
+ us.broadcast(_message, pageid, type);
|
|
|
+ response.end('updateNameSuccess'); //返回文档内容
|
|
|
} else {
|
|
|
- response.end('updateNameFail');
|
|
|
+ response.end('updateNameFail'); //返回文档内容
|
|
|
}
|
|
|
- } catch (e) {
|
|
|
- response.end('updateNameFail');
|
|
|
- }
|
|
|
-};
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
-us.addUser = (response, type, fileid, userids, userid, pageid) => {
|
|
|
- const _messageinfo = us.message(userid, 'us.' + type, {
|
|
|
+/**
|
|
|
+* 添加用户
|
|
|
+*
|
|
|
+* @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
|
|
|
});
|
|
|
- us.broadcast({ [fileid]: [_messageinfo] }, pageid, type);
|
|
|
- response.end('addUserSuccess');
|
|
|
-};
|
|
|
+ _message[fileid] = [_messageinfo];
|
|
|
+ us.broadcast(_message, pageid, type);
|
|
|
+ response.end('addUserSuccess'); //返回文档内容
|
|
|
+}
|
|
|
|
|
|
-us.getuserbytype = (userids) => {
|
|
|
- const _userinfo = [];
|
|
|
- for (let i in userids) {
|
|
|
- if (us.user[i]) _userinfo.push(us.user[i]);
|
|
|
+/**
|
|
|
+* 根据用户集合,获取详细的用户信息
|
|
|
+*
|
|
|
+* @param {object} userids 用户id集合
|
|
|
+**/
|
|
|
+us.getuserbytype = function (userids) {
|
|
|
+ var _userinfo = [];
|
|
|
+ //console.log(us.user);
|
|
|
+ for (var i in userids) {
|
|
|
+ if (us.user[i]) {
|
|
|
+ _userinfo.push(us.user[i])
|
|
|
+ }
|
|
|
}
|
|
|
return _userinfo;
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
-us.sendUser = (userinfo, type, pageid, fileid) => {
|
|
|
- const _messageinfo = us.message(userinfo.userid, 'us.' + type, {
|
|
|
+/**
|
|
|
+* 用户加入某个项目后通知所有已经在项目的用户
|
|
|
+*
|
|
|
+* @param {object} userinfo 用户信息
|
|
|
+* @param {string} type 项目类型
|
|
|
+* @param {string} fileid 项目的id
|
|
|
+**/
|
|
|
+us.sendUser = function (userinfo, type, pageid, fileid) {
|
|
|
+ var _message = {};
|
|
|
+ var _messageinfo = us.message(userinfo.userid, 'us.' + type, {
|
|
|
id: us.createGuid(),
|
|
|
type: "addUser",
|
|
|
userinfo: userinfo,
|
|
|
docId: fileid
|
|
|
});
|
|
|
- us.broadcast({ [fileid]: [_messageinfo] }, pageid, type);
|
|
|
-};
|
|
|
+ _message[fileid] = [_messageinfo];
|
|
|
+ // console.log("2222222222")
|
|
|
+ // console.log(_message)
|
|
|
+ us.broadcast(_message, pageid, type);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-us.login = (req, res, userid, pageid, username, type) => {
|
|
|
+/**
|
|
|
+* 获取用户传参异步
|
|
|
+*
|
|
|
+* @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) {
|
|
|
+ try {
|
|
|
+ //console.log('请求超时'); //错误消息的输出
|
|
|
+ //res.end("false"); //返回值
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ console.error('process error is:', e.message);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //设置30秒后超时
|
|
|
+ res.setTimeout(60000, function () {
|
|
|
+ try {
|
|
|
+ //console.log("响应超时.");
|
|
|
+ res.end(""); //返回值
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ console.error('process error is:', e.message);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //错误处理
|
|
|
+ req.on("error", function (e) {
|
|
|
+ try {
|
|
|
+ console.log(e);
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ console.error('process error is:', e.message);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 获取用户传参异步
|
|
|
+*
|
|
|
+* @param {object} response 响应对象
|
|
|
+* @param {array} userid 用户ID
|
|
|
+* @param {string} pageid 页面ID(登录唯一识别ID)
|
|
|
+* @param {string} username 用户名
|
|
|
+* @param {type} username 用户登录类型
|
|
|
+**/
|
|
|
+us.login = function (requset, response, userid, pageid, username, type) {
|
|
|
if (userid && pageid) {
|
|
|
+ //用户登录信息表,以后移入redis
|
|
|
+ //如果用户信息不存在则新建一个用户信息存入
|
|
|
if (!us.user[userid]) {
|
|
|
- us.user[userid] = us.userInfo(userid, username || "");
|
|
|
+ username = username || "";
|
|
|
+ var _userinfo = us.userInfo(userid, username); //初始化用户信息
|
|
|
+ us.user[userid] = _userinfo;
|
|
|
}
|
|
|
- us.polling(req, res, userid, pageid, type);
|
|
|
+ //添加用户轮询列表
|
|
|
+ us.polling(requset, response, userid, pageid, type);
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
-us.deluser = (userid, pageid) => {
|
|
|
+/**
|
|
|
+* 用户下线,清理用户的数据
|
|
|
+*/
|
|
|
+us.deluser = function (userid, pageid) {
|
|
|
if (pageid && us.offLineMessage[pageid]) {
|
|
|
- const _csclids = us.offLineMessage[pageid].cscl;
|
|
|
+ var i, j, z; //定义循环变量
|
|
|
+ var _userid, _fileid, _message, _docinfo, _messageinfo,
|
|
|
+ _csclids = us.offLineMessage[pageid].cscl;
|
|
|
+ //其他应用的数据
|
|
|
+ // _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
|
|
|
+ // _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
|
|
|
+ console.log("1111111111111")
|
|
|
+ console.log(_csclids)
|
|
|
+ console.log(pageid)
|
|
|
+ console.log(us.offLineMessage[pageid])
|
|
|
+ //删除用户离校消息记录
|
|
|
delete us.offLineMessage[pageid];
|
|
|
- for (let i = 0; i < _csclids.length; i++) {
|
|
|
- const _docinfo = us.cscl[_csclids[i]];
|
|
|
- if (_docinfo) {
|
|
|
- const _fileid = _csclids[i];
|
|
|
- const _quitUserId = us.quitUserList(_docinfo, userid, pageid);
|
|
|
- if (_quitUserId) {
|
|
|
- const _messageinfo = us.message(userid, 'us.cscl', {
|
|
|
- id: us.createGuid(),
|
|
|
- type: "delUser",
|
|
|
- userinfo: us.user[_quitUserId],
|
|
|
- docId: _fileid
|
|
|
- });
|
|
|
- us.broadcast({ [_fileid]: [_messageinfo] }, pageid, "cscl");
|
|
|
- }
|
|
|
+ //知识架构的下线的处理
|
|
|
+ for (i = 0; i < _csclids.length; i++) { //循环处理每一个文档
|
|
|
+ _docinfo = us.cscl[_csclids[i]]; //记录文档信息
|
|
|
+ if (_docinfo) { //如果存在文档信息
|
|
|
+ _fileid = _csclids[i];
|
|
|
+ _userid = us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
|
|
|
}
|
|
|
}
|
|
|
+ console.log(_userid)
|
|
|
+ //下线后通知所有的用户
|
|
|
+ if (_userid) {
|
|
|
+ _message = {};
|
|
|
+ var _messageinfo = us.message(userid, 'us.cscl', {
|
|
|
+ id: us.createGuid(),
|
|
|
+ type: "delUser",
|
|
|
+ userinfo: us.user[_userid],
|
|
|
+ docId: _fileid
|
|
|
+ });
|
|
|
+ _message[_fileid] = [_messageinfo];
|
|
|
+ console.log(_message)
|
|
|
+ us.broadcast(_message, pageid, "cscl");
|
|
|
+ }
|
|
|
}
|
|
|
-};
|
|
|
+ //其他应用的处理
|
|
|
+ // //word的下线的处理
|
|
|
+ // for (i = 0; i < _wordids.length; i++) { //循环处理每一个文档
|
|
|
+ // _docinfo = us.word[_wordids[i]]; //记录文档信息
|
|
|
+ // if (_docinfo) { //如果存在文档信息
|
|
|
+ // us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
|
|
|
+ // us.insertHistory(_docinfo, 'word'); //插入历史
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // //excel的下线的处理
|
|
|
+ // for (j = 0; i < _excelids.length; j++) {
|
|
|
+ // _docinfo = us.excel[_excelids[j]]; //记录文档信息
|
|
|
+ // if (_docinfo) { //如果存在文档信息
|
|
|
+ // us.quitUserList(_docinfo, userid, pageid); //将用户在协同列表中删除
|
|
|
+ // us.insertHistory(_docinfo, 'excel'); //插入历史
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+}
|
|
|
|
|
|
-us.offLine = () => {
|
|
|
- const _connect = us.connect;
|
|
|
- for (let i in _connect) {
|
|
|
- const _user = _connect[i];
|
|
|
- for (let j in _user) {
|
|
|
+/**
|
|
|
+* 用户下线,用计时器实时的监控用户是否在线
|
|
|
+*/
|
|
|
+us.offLine = function () {
|
|
|
+ var i, j;
|
|
|
+ var _user, _connect = us.connect;
|
|
|
+ //循环目前所有的连接用户
|
|
|
+ for (i in _connect) {
|
|
|
+ _user = _connect[i];
|
|
|
+ for (j in _user) {
|
|
|
+ console.log("====================offline======================");
|
|
|
+ console.log(i);
|
|
|
+ console.log(j);
|
|
|
+ console.log(_user[j].response.finished);
|
|
|
+ console.log((_user[j].response.connection == null || _user[j].response.connection.destroyed));
|
|
|
+ //判断用户已下线
|
|
|
if (_user[j].response.finished || (_user[j].response.connection == null || _user[j].response.connection.destroyed)) {
|
|
|
+ //if (_user[j].response.connection == null || _user[j].response.connection.destroyed) {
|
|
|
+ //等待五秒后,判断用户是否重连,重连的用户不为下线用户
|
|
|
us.offLineByUser(i, j, _user);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
-us.offLineByUser = (userId, pageId, _user) => {
|
|
|
+/**
|
|
|
+* 用户下线
|
|
|
+*/
|
|
|
+us.offLineByUser = function (i, j, _user) {
|
|
|
setTimeout(() => {
|
|
|
- if (_user[pageId].response.finished || (_user[pageId].response.connection == null || _user[pageId].response.connection.destroyed)) {
|
|
|
- us.deluser(userId, pageId);
|
|
|
- delete _user[pageId];
|
|
|
- if (Object.keys(_user).length === 0) {
|
|
|
- delete us.user[userId];
|
|
|
- delete us.connect[userId];
|
|
|
+ if (_user[j].response.finished || (_user[j].response.connection == null || _user[j].response.connection.destroyed)) {
|
|
|
+ var k, istrue = true;
|
|
|
+ us.deluser(i, j); //删除用户的数据
|
|
|
+ delete _user[j];
|
|
|
+ for (k in _user) { istrue = false; break }
|
|
|
+ //这个用户下所有的连接用户都不在了
|
|
|
+ if (istrue) {
|
|
|
+ //用户登录数据清理,用于已经下线
|
|
|
+ delete us.user[i];
|
|
|
+ delete us.connect[i];
|
|
|
}
|
|
|
}
|
|
|
}, 5000);
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
-us.polling = (req, res, userid, pageid, type) => {
|
|
|
- if (!us.connect[userid]) us.connect[userid] = {};
|
|
|
- const _userarray = us.connect[userid];
|
|
|
- const _messagearray = us.offLineMessage[pageid];
|
|
|
- const chunkSize = 100;
|
|
|
- if (_userarray[pageid]) {
|
|
|
- try { _userarray[pageid].response.end(""); } catch (e) {}
|
|
|
- _userarray[pageid].response = res;
|
|
|
- if (_messagearray && _messagearray.message.length > 0) {
|
|
|
- const _data = JSON.stringify(_messagearray.message);
|
|
|
- for (let i = 0; i < _data.length; i += chunkSize) {
|
|
|
- res.write(_data.slice(i, i + chunkSize));
|
|
|
+/**
|
|
|
+* 获取用户传参异步
|
|
|
+*
|
|
|
+* @param {object} response 响应对象
|
|
|
+* @param {string} userid 用户ID
|
|
|
+* @param {string} pageid 页面ID(用户登录唯一识别ID)
|
|
|
+**/
|
|
|
+us.polling = function (requset, response, userid, pageid, type) {
|
|
|
+ // 监听请求的close事件
|
|
|
+ // requset.on('close', () => {
|
|
|
+ // console.log("--------" + userid + "-------------" + pageid);
|
|
|
+ // //us.offLine(response, userid, pageid)
|
|
|
+ // });
|
|
|
+ //判断轮询的用户是否在连接池中
|
|
|
+ if (us.connect[userid]) {
|
|
|
+ var _data,
|
|
|
+ _userarray = us.connect[userid], //用户连接池,获取制定用户连接的数量,
|
|
|
+ _messagearray = us.offLineMessage[pageid] //用户离线信息
|
|
|
+ ;
|
|
|
+ const chunkSize = 100;
|
|
|
+ //获取当前连接的用户,如果获取成功那么直接修改用户的连接
|
|
|
+ if (_userarray[pageid]) {
|
|
|
+ //防止重复多连
|
|
|
+ try {
|
|
|
+ _userarray[pageid].response.end("");
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ _userarray[pageid].response = response;
|
|
|
+ if (_messagearray && _messagearray.message.length > 0) {
|
|
|
+ _data = JSON.stringify(_messagearray.message);
|
|
|
+ for (let i = 0; i < _data.length; i += chunkSize) {
|
|
|
+ const chunk = _data.slice(i, i + chunkSize);
|
|
|
+ response.write(chunk);
|
|
|
+ }
|
|
|
+ response.write("\r\n");
|
|
|
+ _messagearray.message = [];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ us.offLineMessage[pageid] = us.offLineMessage[pageid] || us.userOffLineMessage(type); //初始化用户离线消息记录
|
|
|
}
|
|
|
- res.write("\r\n");
|
|
|
- _messagearray.message = [];
|
|
|
- } else {
|
|
|
- us.offLineMessage[pageid] = us.offLineMessage[pageid] || us.userOffLineMessage(type);
|
|
|
}
|
|
|
- } else {
|
|
|
- _userarray[pageid] = us.userConnect(pageid, res);
|
|
|
- us.offLineMessage[pageid] = us.userOffLineMessage(type);
|
|
|
+ else {
|
|
|
+ //如果用户连接不存在
|
|
|
+ _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.offLineMessage[pageid] || us.userOffLineMessage(type); //初始化用户离线消息记录
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 发送消息
|
|
|
+*
|
|
|
+* @param {object} response 响应对象
|
|
|
+* @param {array} messageinfo 参数数组
|
|
|
+**/
|
|
|
+us.send = function (response, messageinfo) {
|
|
|
+ var i, j,
|
|
|
+ _message,
|
|
|
+ _messagelist = {},
|
|
|
+ _messageobj = JSON.parse(messageinfo) //获取传入的json对象
|
|
|
+ ;
|
|
|
+
|
|
|
+ //循环用户的信息处理
|
|
|
+ for (i in _messageobj) {
|
|
|
+ //console.log(i);
|
|
|
+ switch (i) {
|
|
|
+ //思维网格交互
|
|
|
+ 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;
|
|
|
+ //未来课堂交互
|
|
|
+ case "us.cscl":
|
|
|
+
|
|
|
+ _messagearr = _messageobj[i]; //获取未来消息
|
|
|
+ //得到未来课堂所有的用户
|
|
|
+ for (j = 0; j < _messagearr.length; j++) {
|
|
|
+ // //如果存在则直接返回内层的文档
|
|
|
+ // if (!us.cscl[calssid].user[userid]) {
|
|
|
+ // us.cscl[calssid].user[userid] = [pageid];
|
|
|
+ // }
|
|
|
+ // else if (us.cscl[calssid].user[userid].indexOf(pageid) == -1) {
|
|
|
+ // us.cscl[calssid].user[userid].push(pageid);
|
|
|
+ // }
|
|
|
+ // try {
|
|
|
+ // us.offLineMessage[pageid].cscl.indexOf(calssid) == -1 && us.offLineMessage[pageid].cscl.push(calssid); //添加到用户离线消息的连接wrod记录中
|
|
|
+ // }
|
|
|
+ // catch (e) {
|
|
|
+
|
|
|
+ // }
|
|
|
+ _messagearr[j].messageInfo.type = _messagearr[j].type;
|
|
|
+ //生成发送的消息结构体
|
|
|
+ _message = us.message(_messagearr[j].sendId, "us.cscl", _messagearr[j].messageInfo);
|
|
|
+ _message.ttype = _messagearr[j].type;
|
|
|
+ //添加消息列表
|
|
|
+ if (_messagelist[_messagearr[j].receiveId]) {
|
|
|
+ _messagelist[_messagearr[j].receiveId].push(_message);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _messagelist[_messagearr[j].receiveId] = [_message];
|
|
|
+ }
|
|
|
+ us.cscl[_messagearr[j].receiveId] && us.cscl[_messagearr[j].receiveId].history.push(_message);
|
|
|
+ us.updatecscl(_message.messageInfo, _messagearr[j].receiveId, _messagearr[j].type);
|
|
|
+ }
|
|
|
+ //调用群发函数
|
|
|
+ _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].pageId, 'cscl');
|
|
|
+ break;
|
|
|
+ //同步课堂
|
|
|
+ case "us.realTimeClass":
|
|
|
+ //console.log("us.realTimeClass");
|
|
|
+ _messagearr = _messageobj[i]; //获取word消息
|
|
|
+ //得到word所有的用户
|
|
|
+ for (j = 0; j < _messagearr.length; j++) {
|
|
|
+ //生成发送的消息结构体
|
|
|
+ _message = us.message(_messagearr[j].sendId, "us.realTimeClass", _messagearr[j].messageInfo);
|
|
|
+ //console.log(_message)
|
|
|
+ // console.log(_messagelist[_messagearr[j].receiveId])
|
|
|
+ //添加消息列表
|
|
|
+ if (_messagelist[_messagearr[j].receiveId]) {
|
|
|
+ _messagelist[_messagearr[j].receiveId].push(_message);
|
|
|
+ } else {
|
|
|
+ _messagelist[_messagearr[j].receiveId] = [_message];
|
|
|
+ }
|
|
|
+ us.realTimeClass[_message.messageInfo.docId] && us.realTimeClass[_message.messageInfo.docId].history.push(_message);
|
|
|
+ us.updaterealTimeClass(_message.messageInfo);
|
|
|
+ }
|
|
|
+ //调用群发函数
|
|
|
+ _messagearr[0] && us.broadcast(_messagelist, _messagearr[0].messageInfo.pageId, 'realTimeClass');
|
|
|
+ break;
|
|
|
+ //word信息交互
|
|
|
+ case "us.word":
|
|
|
+ try {
|
|
|
+ _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');
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ console.log(e)
|
|
|
+ }
|
|
|
+ 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');
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
-us.send = async (response, messageinfo) => {
|
|
|
- const _messageobj = JSON.parse(messageinfo);
|
|
|
- const _messagelist = {};
|
|
|
-
|
|
|
- // 使用 setImmediate 分片处理循环,避免长时间阻塞
|
|
|
- const processMessages = async () => {
|
|
|
- for (let i in _messageobj) {
|
|
|
- const _messagearr = _messageobj[i];
|
|
|
- const type = i.split('.')[1]; // mindNetwork, cscl, realTimeClass, word, excel, nav
|
|
|
- for (let j = 0; j < _messagearr.length; j++) {
|
|
|
- const msg = _messagearr[j];
|
|
|
- const _message = us.message(msg.sendId, i, msg.messageInfo);
|
|
|
- _message.ttype = msg.type;
|
|
|
- if (!_messagelist[msg.receiveId]) _messagelist[msg.receiveId] = [];
|
|
|
- _messagelist[msg.receiveId].push(_message);
|
|
|
-
|
|
|
- // 更新内存数据
|
|
|
- if (us[type] && us[type][msg.receiveId]) {
|
|
|
- us[type][msg.receiveId].history.push(_message);
|
|
|
- }
|
|
|
- if (type === 'mindNetwork') us.updatemindNetwork(msg.messageInfo);
|
|
|
- else if (type === 'cscl') us.updatecscl(msg.messageInfo, msg.receiveId, msg.type);
|
|
|
- else if (type === 'realTimeClass') us.updaterealTimeClass(msg.messageInfo);
|
|
|
- else if (type === 'word') us.updateWord(msg.messageInfo);
|
|
|
- else if (type === 'excel') us.updateExcel(msg.messageInfo);
|
|
|
- else if (type === 'nav') us.updateNav(msg.messageInfo);
|
|
|
-
|
|
|
- // 每处理10条消息让出事件循环
|
|
|
- if (j % 10 === 0) await new Promise(resolve => setImmediate(resolve));
|
|
|
+/**
|
|
|
+* 更新后台思维网格的内容
|
|
|
+* @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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 更新后台未来课堂内容
|
|
|
+* @param {object} message 消息信息
|
|
|
+*/
|
|
|
+us.updatecscl = function (messageInfo, classId, ty) {
|
|
|
+ if (us.cscl[classId]) {
|
|
|
+ var i, j, _is;
|
|
|
+ var _obj = us.cscl[classId].content;
|
|
|
+ if (ty == "clean") {
|
|
|
+ _obj = us.cscl[classId].content = {};
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _obj.backgroundUrl = messageInfo.backgroundUrl;
|
|
|
+ _obj.edges = _obj.edges || [];
|
|
|
+ _obj.nodes = _obj.nodes || [];
|
|
|
+ //循环线的处理
|
|
|
+ for (j = 0; j < messageInfo.edges.length; j++) {
|
|
|
+ _is = true;
|
|
|
+ for (i = 0; i < _obj.edges.length; i++) {
|
|
|
+ if (_obj.edges[i].id == messageInfo.edges[j].id) {
|
|
|
+ //如果是修改线同时先又存在那就直接修改
|
|
|
+ if (ty == "update") {
|
|
|
+ _obj.edges[i] = messageInfo.edges[j];
|
|
|
+ }
|
|
|
+ //如果是删除线的操作
|
|
|
+ else {
|
|
|
+ _obj.edges.splice(i, 1);
|
|
|
+ }
|
|
|
+ _is = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改包含了添加和修改,如果没有修改说明是添加的功能
|
|
|
+ if (_is && ty == "update") {
|
|
|
+ _obj.edges.push(messageInfo.edges[j])
|
|
|
+ }
|
|
|
}
|
|
|
- if (_messagearr.length > 0) {
|
|
|
- us.broadcast(_messagelist, _messagearr[0].messageInfo?.pageId || _messagearr[0].pageId, type);
|
|
|
+ for (j = 0; j < messageInfo.nodes.length; j++) {
|
|
|
+ _is = true;
|
|
|
+ for (i = 0; i < _obj.nodes.length; i++) {
|
|
|
+ if (_obj.nodes[i].id == messageInfo.nodes[j].id) {
|
|
|
+ //如果是修改节点
|
|
|
+ if (ty == "update") {
|
|
|
+ _obj.nodes[i] = messageInfo.nodes[j];
|
|
|
+ }
|
|
|
+ //如果是删除节点
|
|
|
+ else {
|
|
|
+ _obj.nodes.splice(i, 1);
|
|
|
+ }
|
|
|
+ _is = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改包含了添加和修改,如果没有修改说明是添加的功能
|
|
|
+ if (_is && ty == "update") {
|
|
|
+ _obj.nodes.push(messageInfo.nodes[j])
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- };
|
|
|
- await processMessages();
|
|
|
- response.end('send');
|
|
|
-};
|
|
|
+ //如果不存在则去数据库查找
|
|
|
+ try {
|
|
|
+ clearTimeout(us.savecscltime);
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
|
|
|
-us.updatemindNetwork = (messageInfo) => {
|
|
|
- if (us.mindNetwork[messageInfo.docId]?.content) {
|
|
|
- us.mindNetwork[messageInfo.docId].content[messageInfo.id] = messageInfo.content;
|
|
|
+ }
|
|
|
}
|
|
|
-};
|
|
|
+ //每次修改每隔五秒保存一次数据,防止数据操作频繁导致数据库太卡
|
|
|
+ us.savecscltime = setTimeout(function () {
|
|
|
+ us.mysql.usselect(['172.16.12.5', 'pbl', 'updateRoomData', JSON.stringify(_obj), classId], function (ret) { });
|
|
|
+ }, 5000)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 更新后台实施课堂内容
|
|
|
+* @param {object} message 消息信息
|
|
|
+*/
|
|
|
+us.updaterealTimeClass = function (messageInfo) {
|
|
|
+ if (us.realTimeClass[messageInfo.docId]) {
|
|
|
+ var $ = us.realTimeClass[messageInfo.docId].content;
|
|
|
+ // console.log("---------------------------------------start")
|
|
|
+ // console.log($);
|
|
|
+ // console.log("---------------------------------------end")
|
|
|
+ // console.log("---------------------------------------infostart")
|
|
|
+ // console.log(messageInfo);
|
|
|
+ // console.log("---------------------------------------infoend")
|
|
|
+ if ($) {
|
|
|
+ us.realTimeClass[messageInfo.docId].content[messageInfo.id] = messageInfo.content;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-us.updatecscl = (messageInfo, classId, ty) => {
|
|
|
- if (!us.cscl[classId]) return;
|
|
|
- let _obj = us.cscl[classId].content;
|
|
|
- if (ty === "clean") {
|
|
|
- us.cscl[classId].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 {
|
|
|
- _obj.backgroundUrl = messageInfo.backgroundUrl;
|
|
|
- _obj.edges = _obj.edges || [];
|
|
|
- _obj.nodes = _obj.nodes || [];
|
|
|
- // 处理 edges 和 nodes(原逻辑保留)
|
|
|
- for (let j = 0; j < messageInfo.edges.length; j++) {
|
|
|
- const edge = messageInfo.edges[j];
|
|
|
- const idx = _obj.edges.findIndex(e => e.id === edge.id);
|
|
|
- if (ty === "update") {
|
|
|
- if (idx === -1) _obj.edges.push(edge);
|
|
|
- else _obj.edges[idx] = edge;
|
|
|
- } else if (ty === "delete") {
|
|
|
- if (idx !== -1) _obj.edges.splice(idx, 1);
|
|
|
+ _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] = {};
|
|
|
}
|
|
|
- for (let j = 0; j < messageInfo.nodes.length; j++) {
|
|
|
- const node = messageInfo.nodes[j];
|
|
|
- const idx = _obj.nodes.findIndex(n => n.id === node.id);
|
|
|
- if (ty === "update") {
|
|
|
- if (idx === -1) _obj.nodes.push(node);
|
|
|
- else _obj.nodes[idx] = node;
|
|
|
- } else if (ty === "delete") {
|
|
|
- if (idx !== -1) _obj.nodes.splice(idx, 1);
|
|
|
+
|
|
|
+ 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++;
|
|
|
}
|
|
|
- clearTimeout(us.savecscltime);
|
|
|
- us.savecscltime = setTimeout(() => {
|
|
|
- us.mysql.usselectAsync(['172.16.12.5', 'pbl', 'updateRoomData', JSON.stringify(us.cscl[classId].content), classId])
|
|
|
- .catch(e => console.error(e));
|
|
|
- }, 5000);
|
|
|
+ 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.updaterealTimeClass = (messageInfo) => {
|
|
|
- if (us.realTimeClass[messageInfo.docId]?.content) {
|
|
|
- us.realTimeClass[messageInfo.docId].content[messageInfo.id] = messageInfo.content;
|
|
|
+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.updateWord = (messageInfo) => {
|
|
|
- const doc = us.word[messageInfo.docId];
|
|
|
- if (!doc?.content) return;
|
|
|
- const $ = doc.content;
|
|
|
- switch (messageInfo.type) {
|
|
|
- case 'update': $('#' + messageInfo.id).replaceWith(messageInfo.content); break;
|
|
|
- case 'add': messageInfo.nextId ? $('#' + messageInfo.nextId).before(messageInfo.content) : $('body').append(messageInfo.content); break;
|
|
|
- case 'delete': $('#' + messageInfo.id).remove(); break;
|
|
|
+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.updateNav = (messageInfo) => {
|
|
|
- const file = us.nav[messageInfo.docId];
|
|
|
- if (!file) return;
|
|
|
- const pageContent = file.page[messageInfo.navId];
|
|
|
- if (pageContent) {
|
|
|
- switch (messageInfo.type) {
|
|
|
- case 'update': pageContent('#' + messageInfo.id).replaceWith(messageInfo.content); break;
|
|
|
- case 'add': messageInfo.nextId ? pageContent('#' + messageInfo.nextId).before(messageInfo.content) : pageContent('body').append(messageInfo.content); break;
|
|
|
- case 'delete': pageContent('#' + messageInfo.id).remove(); break;
|
|
|
+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] = {};
|
|
|
}
|
|
|
- // 其他 nav 操作(addNav, updateNav, deleteNav)保留原有实现...
|
|
|
+
|
|
|
+ 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 = (messageInfo) => {
|
|
|
- // 保留原有 Excel 更新逻辑,此处省略以节省篇幅,实际使用时需包含原代码中的 us.updateExcel 函数及其子方法
|
|
|
+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.broadcast = (messageinfo, pageid, type) => {
|
|
|
+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, //循环变量
|
|
|
+ _data,
|
|
|
+ _messageinfo, //消息信息
|
|
|
+ _users, //用户ID集合
|
|
|
+ _pageids, //用户页面唯一识别集合
|
|
|
+ _recievedpageid, //接收用户的页面唯一识别ID
|
|
|
+ _issend, // 是否发送
|
|
|
+ _userconnect = us.connect; //用户连接池
|
|
|
const chunkSize = 100;
|
|
|
- const _userconnect = us.connect;
|
|
|
- for (let docId in messageinfo) {
|
|
|
- const _messageinfo = messageinfo[docId];
|
|
|
- const users = us[type]?.[docId]?.user || {};
|
|
|
- for (let userId in users) {
|
|
|
- const pageIds = users[userId];
|
|
|
- for (let pid of pageIds) {
|
|
|
- if (pid === pageid) continue;
|
|
|
- try {
|
|
|
- const conn = _userconnect[userId]?.[pid];
|
|
|
- if (conn) {
|
|
|
- const data = JSON.stringify(_messageinfo);
|
|
|
- const success = conn.response.write("");
|
|
|
- if (!success) {
|
|
|
- us.offLineMessage[pid].message.push(..._messageinfo);
|
|
|
- } else {
|
|
|
- for (let i = 0; i < data.length; i += chunkSize) {
|
|
|
- conn.response.write(data.slice(i, i + chunkSize));
|
|
|
+ for (i in messageinfo) {
|
|
|
+ _messageinfo = messageinfo[i]; //记录消息消息b
|
|
|
+ _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) { //如果接受用户不等于发送用户则发送消息
|
|
|
+ try {
|
|
|
+ if (_userconnect[j] && _userconnect[j][_recievedpageid]) {
|
|
|
+ console.log(_recievedpageid);
|
|
|
+ _data = JSON.stringify(_messageinfo);
|
|
|
+ _issend = _userconnect[j][_recievedpageid].response.write(""); //发送消息
|
|
|
+ //用户在轮询切换的时候的中间,会产生数据无法接受,这里是存储数据
|
|
|
+ if (!_issend) {
|
|
|
+ us.offLineMessage[_recievedpageid].message.push(_messageinfo); //将消息加入用户离线消息中
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ for (let i = 0; i < _data.length; i += chunkSize) {
|
|
|
+ const chunk = _data.slice(i, i + chunkSize);
|
|
|
+ _userconnect[j][_recievedpageid].response.write(chunk);
|
|
|
+ }
|
|
|
+ _userconnect[j][_recievedpageid].response.write("\r\n");
|
|
|
}
|
|
|
- conn.response.write("\r\n");
|
|
|
}
|
|
|
}
|
|
|
- } catch (e) {
|
|
|
- console.error(e);
|
|
|
+ catch (e) {
|
|
|
+ console.log(e)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 加入文档编辑
|
|
|
+*
|
|
|
+* @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'); //响应退出请求
|
|
|
+}
|
|
|
|
|
|
-us.quitUserList = (docinfo, userid, pageid) => {
|
|
|
- const pages = docinfo.user[userid];
|
|
|
- if (pages) {
|
|
|
- const idx = pages.indexOf(pageid);
|
|
|
- if (idx !== -1) {
|
|
|
- pages.splice(idx, 1);
|
|
|
- if (pages.length === 0) {
|
|
|
+/**
|
|
|
+* 退出知识建构
|
|
|
+*
|
|
|
+* @param {object} response 用户相应对象
|
|
|
+* @param {string} wordinfo 文档信息
|
|
|
+**/
|
|
|
+us.quitcscl = function (response, info) {
|
|
|
+ console.log(info)
|
|
|
+ //获取用户参数
|
|
|
+ info = JSON.parse(info);
|
|
|
+ var _docid = info.docId,
|
|
|
+ _userid = info.userId,
|
|
|
+ _pageid = info.pageId,
|
|
|
+ _type = info.type;
|
|
|
+ var _docinfo = us[_type][_docid]; //获取文档信息
|
|
|
+ //判断是否存在文档信息
|
|
|
+ if (_docinfo) {
|
|
|
+ _userid = us.quitUserList(_docinfo, _userid, _pageid); //将用户在协同列表中删除
|
|
|
+ console.log(_userid)
|
|
|
+ //下线后通知所有的用户
|
|
|
+ if (_userid) {
|
|
|
+ _message = {};
|
|
|
+ var _messageinfo = us.message(_userid, 'us.cscl', {
|
|
|
+ id: us.createGuid(),
|
|
|
+ type: "delUser",
|
|
|
+ userinfo: us.user[_userid],
|
|
|
+ docId: _docid
|
|
|
+ });
|
|
|
+ _message[_docid] = [_messageinfo];
|
|
|
+ console.log(_message)
|
|
|
+ us.broadcast(_message, _pageid, "cscl");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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); //删除记录
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ response.end('quitcscl'); //响应退出请求
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 将用户在协同列表中删除
|
|
|
+*
|
|
|
+* @param {object} docinfo 文档信息
|
|
|
+* @param {string} userid 用户ID
|
|
|
+* @param {string} pageid 用户页面唯一识别ID
|
|
|
+*/
|
|
|
+us.quitUserList = function (docinfo, userid, pageid) {
|
|
|
+ var _users = docinfo.user[userid]; //记录文档的用户列表
|
|
|
+ console.log(_users)
|
|
|
+ //获取用户在文档用户列表的位置
|
|
|
+ if (_users) {
|
|
|
+ var _index = _users.indexOf(pageid);
|
|
|
+ // 如果存在则将该用户删除 表示退出协同
|
|
|
+ if (_index != -1) {
|
|
|
+ _users.splice(_index, 1); //删除该用户
|
|
|
+ //如果该用户的全部端用户已退出则删除用户的记录
|
|
|
+ if (_users.length == 0) {
|
|
|
delete docinfo.user[userid];
|
|
|
return userid;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
-us.insertHistory = (docinfo, docid, type) => {
|
|
|
- if (Object.keys(docinfo.user).length === 0) {
|
|
|
+
|
|
|
+/**
|
|
|
+* 插入文档操作历史到数据库
|
|
|
+*
|
|
|
+* @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': {
|
|
|
- const content = docinfo.content ? docinfo.content('body').html().replace(/'/ig, "\\'").replace(/"/ig, '\\"') : "";
|
|
|
- us.mysql.usselectAsync(['sqlserver.1473.cn', 'UseStudio_Disk', 'SaveFileContent', docid, content, ''])
|
|
|
- .catch(e => console.error(e));
|
|
|
+ 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;
|
|
|
- }
|
|
|
- // 其他类型类似...
|
|
|
}
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
-us.logout = (response, userid, pageid) => {
|
|
|
- us.deluser(userid, pageid);
|
|
|
- const _user = us.connect[userid];
|
|
|
+/**
|
|
|
+* 下线操作
|
|
|
+* @param {object} response 响应对象
|
|
|
+* @param {string} userid 用户ID
|
|
|
+* @param {string} pageid 用户页面唯一识别ID
|
|
|
+*/
|
|
|
+us.logout = function (response, userid, pageid) {
|
|
|
+ console.log("234566666666666666")
|
|
|
+ console.log(userid)
|
|
|
+ var j, istrue = true;
|
|
|
+ var _user = us.connect[userid];
|
|
|
+ //循环目前所有的连接用户
|
|
|
+ us.deluser(userid, pageid); //删除用户的数据
|
|
|
if (_user) {
|
|
|
- delete _user[pageid];
|
|
|
- if (Object.keys(_user).length === 0) {
|
|
|
+ delete _user[pageid]
|
|
|
+ for (j in _user) { istrue = false; break }
|
|
|
+ //这个用户下所有的连接用户都不在了
|
|
|
+ if (istrue) {
|
|
|
+ //用户登录数据清理,用于已经下线
|
|
|
delete us.user[userid];
|
|
|
delete us.connect[userid];
|
|
|
}
|
|
|
+ console.log(pageid)
|
|
|
}
|
|
|
- response.end('logout');
|
|
|
-};
|
|
|
+ response.end('logout'); //响应退出请求
|
|
|
+
|
|
|
+ // var i, j, _docinfo,
|
|
|
+ // _wordids = us.offLineMessage[pageid].word, //得到加入的所有word
|
|
|
+ // _excelids = us.offLineMessage[pageid].excel; //得到加入的所有excel
|
|
|
|
|
|
-// 其他函数(getWord, getExcel, getNav, getcscl, newWordSave 等)均改为 async/await 并调用 us.mysql.usselectAsync
|
|
|
-// 限于篇幅,此处仅给出 getWord 示例,其余类似改造。
|
|
|
+ // us.connect[userid][pageid].offLineTime = new Date();
|
|
|
|
|
|
-us.getWord = async (response, docid, pageid, userid) => {
|
|
|
- if (!us.word[docid]) {
|
|
|
- us.word[docid] = { user: {}, history: [] };
|
|
|
- us.offLineMessage[pageid]?.word.push(docid);
|
|
|
+ // 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'); //插入历史
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+* 获取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(''); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- const doc = us.word[docid];
|
|
|
- if (!doc.user[userid]) doc.user[userid] = [pageid];
|
|
|
- else if (!doc.user[userid].includes(pageid)) doc.user[userid].push(pageid);
|
|
|
+}
|
|
|
|
|
|
- try {
|
|
|
- const ret = await us.mysql.usselectAsync(['172.16.12.5', 'pbl', 'select_file', docid]);
|
|
|
+/**
|
|
|
+* 获取导航页面内容
|
|
|
+* @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) {
|
|
|
- const officeData = ret[0][0].data ? ret[0][0].data.replace(/\\'/ig, "'").replace(/\\"/g, '"') : "";
|
|
|
- doc.content = us.cheerio.load(officeData);
|
|
|
- response.end(officeData);
|
|
|
+ //设置内容
|
|
|
+ us.word[docid].content = us.cheerio.load(content.replace(/\\'/ig, '\'').replace(/\\"/ig, "\"")); //将文档添加到内层中
|
|
|
+ response.end('save'); //返回保存成功
|
|
|
} else {
|
|
|
- doc.content = us.cheerio.load('');
|
|
|
- response.end('');
|
|
|
+ response.end('fail'); //返回文档内容
|
|
|
}
|
|
|
- } catch (e) {
|
|
|
- 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'); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 新建导航文件保存
|
|
|
+* @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.getcscl = function (response, calssid, pageid, userid) {
|
|
|
+ //判断文档是否已在内层中存在
|
|
|
+ if (us.cscl[calssid]) {
|
|
|
+ //如果存在则直接返回内层的文档
|
|
|
+ if (!us.cscl[calssid].user[userid]) {
|
|
|
+ us.cscl[calssid].user[userid] = [pageid];
|
|
|
+ }
|
|
|
+ else if (us.cscl[calssid].user[userid].indexOf(pageid) == -1) {
|
|
|
+ us.cscl[calssid].user[userid].push(pageid);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ us.offLineMessage[pageid].cscl.indexOf(calssid) == -1 && us.offLineMessage[pageid].cscl.push(calssid); //添加到用户离线消息的连接wrod记录中
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ //后续优化到redis获取
|
|
|
+ us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', calssid],
|
|
|
+ function (ret) {
|
|
|
+ var _user = us.getuserbytype(us.cscl[calssid].user); //获取当前项目下所有的用户信息
|
|
|
+ var _data = us.cscl[calssid].content; //保存在内存的知识建构数据
|
|
|
+ if (ret) {
|
|
|
+ ret[0][0].user = _user; //这里是项目当前所有用户
|
|
|
+ ret[0][0].data = _data; //把思维网格的内容转化成数组
|
|
|
+ if (userid && us.user[userid]) {
|
|
|
+ us.sendUser(us.user[userid], "cscl", pageid, calssid); //加入知识建构项目后通知所有的用户
|
|
|
+ }
|
|
|
+ response.end(JSON.stringify(ret)); //返回文档内容
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ response.end(''); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ us.cscl[calssid] = {
|
|
|
+ user: {},
|
|
|
+ history: []
|
|
|
+ };
|
|
|
+ us.cscl[calssid].user[userid] = [pageid];
|
|
|
+ if (us.offLineMessage[pageid]) {
|
|
|
+ us.offLineMessage[pageid].cscl.indexOf(calssid) == -1 && us.offLineMessage[pageid].cscl.push(calssid); //添加到用户离线消息的连接wrod记录中
|
|
|
+ }
|
|
|
+ //如果不存在则去数据库查找
|
|
|
+ us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', calssid],
|
|
|
+ function (ret) {
|
|
|
+ var _user = us.getuserbytype(us.cscl[calssid].user);
|
|
|
+ if (ret) {
|
|
|
+ ret[0][0].user = _user; //这里是项目当前所有用户
|
|
|
+ try {
|
|
|
+ us.cscl[calssid].content = JSON.parse(ret[0][0].data) || {}; //把思维网格的内容转化成数组
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ us.cscl[calssid].content = ret[0][0].data || {};
|
|
|
+ }
|
|
|
+ response.end(JSON.stringify(ret)); //返回文档内容
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ us.cscl[calssid].content = {}; //创建一个空数组
|
|
|
+ response.end(''); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+* 初始化获取未来课堂数据
|
|
|
+*
|
|
|
+*/
|
|
|
+us.getcscldata = function (response, calssid, pageid, userid) {
|
|
|
+ //判断文档是否已在内层中存在
|
|
|
+ if (us.cscl[calssid]) {
|
|
|
+ //后续优化到redis获取
|
|
|
+ us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', calssid],
|
|
|
+ function (ret) {
|
|
|
+ var _user = us.getuserbytype(us.cscl[calssid].user); //获取当前项目下所有的用户信息
|
|
|
+ var _data = us.cscl[calssid].content; //保存在内存的知识建构数据
|
|
|
+ if (ret) {
|
|
|
+ ret[0][0].user = _user; //这里是项目当前所有用户
|
|
|
+ ret[0][0].data = _data; //把思维网格的内容转化成数组
|
|
|
+ response.end(JSON.stringify(ret)); //返回文档内容
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ response.end(''); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //如果不存在则去数据库查找
|
|
|
+ us.mysql.usselect(['172.16.12.5', 'pbl', 'select_room', calssid],
|
|
|
+ function (ret) {
|
|
|
+ var _user = [];
|
|
|
+ if (ret) {
|
|
|
+ ret[0][0].user = _user; //这里是项目当前所有用户
|
|
|
+ response.end(JSON.stringify(ret)); //返回文档内容
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ response.end(''); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-us.createGuid = () => {
|
|
|
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
|
- const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
|
+/**
|
|
|
+* 获取思维网格数据,转成成数组
|
|
|
+*
|
|
|
+*/
|
|
|
+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(''); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+* 获取实时课堂据,转成成数组
|
|
|
+*
|
|
|
+*/
|
|
|
+us.getRealTimeClass = function (response, docid, pageid, userid) {
|
|
|
+ //判断文档是否已在内层中存在
|
|
|
+ if (us.realTimeClass[docid]) {
|
|
|
+ //如果存在则直接返回内层的文档
|
|
|
+ if (!us.realTimeClass[docid].user[userid]) {
|
|
|
+ us.realTimeClass[docid].user[userid] = [pageid];
|
|
|
+ } else {
|
|
|
+ us.realTimeClass[docid].user[userid].push(pageid);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ us.offLineMessage[pageid].realTimeClass.indexOf(docid) == -1 && us.offLineMessage[pageid].realTimeClass.push(docid); //添加到用户离线消息的连接wrod记录中
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ //console.log(us.realTimeClass[docid]);
|
|
|
+ //如果不存在则去数据库查找
|
|
|
+ us.mysql.usselect(['172.16.12.5', 'pbl', 'selectPptPage', docid],
|
|
|
+ function (ret) {
|
|
|
+ if (ret) {
|
|
|
+ ret[0][0].page = us.realTimeClass[docid].content; //把思维网格的内容转化成数组
|
|
|
+ response.end(JSON.stringify(ret)); //返回文档内容
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ response.end(''); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ us.realTimeClass[docid] = {
|
|
|
+ user: {},
|
|
|
+ history: []
|
|
|
+ };
|
|
|
+ us.realTimeClass[docid].user[userid] = [pageid];
|
|
|
+ if (us.offLineMessage[pageid]) {
|
|
|
+ us.offLineMessage[pageid].realTimeClass.indexOf(docid) == -1 && us.offLineMessage[pageid].realTimeClass.push(docid); //添加到用户离线消息的连接wrod记录中
|
|
|
+ }
|
|
|
+ //如果不存在则去数据库查找
|
|
|
+ us.mysql.usselect(['172.16.12.5', 'pbl', 'selectPptPage', docid],
|
|
|
+ function (ret) {
|
|
|
+ if (ret) {
|
|
|
+ us.realTimeClass[docid].content = JSON.parse(ret[0][0].page); //把思维网格的内容转化成数组
|
|
|
+ response.end(JSON.stringify(ret)); //返回文档内容
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ us.realTimeClass[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('body').html();
|
|
|
+ response.end(JSON.stringify(ret)); //返回文档内容
|
|
|
+ } else {
|
|
|
+ us.word[docid].content = us.cheerio.load(''); //将文档添加到内层中
|
|
|
+ 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) {
|
|
|
+ var _office = ret[0][0].data ? 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(''); //返回文档内容
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+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);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-us.server.listen('1473', '', () => {
|
|
|
- setInterval(() => us.offLine(), 60000);
|
|
|
+
|
|
|
+/**
|
|
|
+* 监听1473端口的处理
|
|
|
+*
|
|
|
+**/
|
|
|
+us.server.listen('1473', '', function () {
|
|
|
+ //用户下线监控
|
|
|
+ setInterval(function () { us.offLine() }, 60000);
|
|
|
+ //在控制台输出监听提示
|
|
|
console.log("开始监听" + us.server.address().port + "......");
|
|
|
-});
|
|
|
+});
|
|
|
+
|
|
|
+// 同意处理错误
|
|
|
+//process.on('uncaughtException', function (e) {
|
|
|
+// console.log("错误:" + e);
|
|
|
+//});
|