This commit is contained in:
aqu415
2022-02-15 20:53:30 +08:00
parent 4074afd250
commit 2782fda765
3 changed files with 44 additions and 47 deletions
+31 -41
View File
@@ -12,7 +12,7 @@
function jsMindCallBackFacade(type, body) {
const coop = $w.coop
if (coop) {
coop.jsMindCallBack_(type, body)
coop.js_mind_callback_(type, body)
} else {
console.error('coop is undefined')
}
@@ -56,18 +56,16 @@
},
_init_properties: function (_jm) {
// 设置属性
this.client_id = Jm.util.uuid.newid()
this.coop_api_url = _jm.options.coop_api_url
this.coop_ws_url = _jm.options.coop_ws_url
this.client_id = Jm.util.uuid.newid()
const coop_mind_id = _jm.options.coop_mind_id
if (this.notNull(coop_mind_id)) {
this.coop_mind_id = coop_mind_id
// this.timerFetch()
}
this.coop_mind_id = _jm.options.coop_mind_id
this.coop_mind_log_id = _jm.options.coop_mind_log_id
this.coop_mind_log_last_id = _jm.options.coop_mind_log_id
},
// 初始化websocket
_init_ws: function () {
if (!this.web_socket) {
if (!this.web_socket && this.coop_mind_id) {
const ws = new WebSocket(this.coop_ws_url + '?_' + this.coop_mind_id)
this.web_socket = ws
//申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
@@ -90,6 +88,8 @@
console.log('error');
this.web_socket = null
}
} else {
console.error('_init_ws failed,this.coop_mind_id is' + this.coop_mind_id)
}
},
// 清理定时任务
@@ -106,16 +106,16 @@
* 是否为空
* @param obj
*/
notNull: function (obj) {
_not_null: function (obj) {
return obj !== null && obj !== undefined
},
isNull: function (obj) {
return !this.notNull(obj)
_is_null: function (obj) {
return !this._not_null(obj)
},
/**
* 构建公共参数
*/
buildCommonParam: function () {
_build_evt_param: function () {
return {'client_id': this.client_id, 'log_uuid': Jm.util.uuid.newid()}
},
/**
@@ -130,36 +130,26 @@
* @param body
* @private
*/
jsMindCallBack_: function (type, body) {
js_mind_callback_: function (type, body) {
const evt = body.evt
const data = body.data
const param = this.buildCommonParam()
param.type = type
if (!!evt) {
const data = body.data
const param = this._build_evt_param()
if (type === 1 || (evt && evt.length > 0)) {
if (type === 1) {
// 新建脑图
param.name = data[0].meta.name
} else if (this.notNull(evt) && evt.length > 0) {
// 脑图编辑
param.evt = evt
param.data = data.join(';')
param.node = body.node
param.coop_mind_id = this.coop_mind_id
}
// ajax
const me = this
/*Jm.util.ajax.post(this.coop_api_url, param, function (resp) {
if (type === 1) {
// 新建
me.coop_mind_id = resp.coop_mind_id
// this.timerFetch()
// this.timerPush()
} else {
// 操作
me.coop_mind_log_id = resp.coop_mind_log_id
}
})*/
param.type = type
// 脑图编辑
param.evt = evt
param.data = data.join(';')
param.node = body.node
param.coop_mind_id = this.coop_mind_id
console.log(param)
}
},
_send_ws_message: function (msg) {
if (this.web_socket) {
this.web_socket.send(msg)
} else {
console.error('web_socket is not ready!')
}
},
/**
@@ -175,7 +165,7 @@
timerPush: function () {
// 把操作日志最大的data 持久化到数据库
const me = this
if (this.isNull(me.timer_push_task)) {
if (this._is_null(me.timer_push_task)) {
me.timer_push_task = setInterval(function () {
const param = {
'data': Jm.util.json.json2string(me._jm.get_data('node_array').data),