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
+3 -1
View File
@@ -21,6 +21,7 @@
const fetch = function () { const fetch = function () {
this.jm = null this.jm = null
this.coop_mind_id = null this.coop_mind_id = null
this.coop_mind_log_id = null
} }
// prototype // prototype
fetch.prototype = { fetch.prototype = {
@@ -37,13 +38,14 @@
loadMind: function () { loadMind: function () {
// 打开已有脑图1、查询数据,组装option 2、实例化jm、show // 打开已有脑图1、查询数据,组装option 2、实例化jm、show
let id = {{ id }}; let id = {{ id }};
this.coop_mind_id = id
const me = this const me = this
$.get('list?id=' + id, function (resp) { $.get('list?id=' + id, function (resp) {
// reset // reset
me.destroy_coop_timer_if_necessary() me.destroy_coop_timer_if_necessary()
// show // show
let data = resp.data.snapshot_data let data = resp.data.snapshot_data
me.coop_mind_id = id
me.coop_mind_log_id = resp.data.snapshot_log_id
me.show_mind(resp.data.coop_mind_name, JSON.parse(data)) me.show_mind(resp.data.coop_mind_name, JSON.parse(data))
}) })
}, },
+23 -33
View File
@@ -12,7 +12,7 @@
function jsMindCallBackFacade(type, body) { function jsMindCallBackFacade(type, body) {
const coop = $w.coop const coop = $w.coop
if (coop) { if (coop) {
coop.jsMindCallBack_(type, body) coop.js_mind_callback_(type, body)
} else { } else {
console.error('coop is undefined') console.error('coop is undefined')
} }
@@ -56,18 +56,16 @@
}, },
_init_properties: function (_jm) { _init_properties: function (_jm) {
// 设置属性 // 设置属性
this.client_id = Jm.util.uuid.newid()
this.coop_api_url = _jm.options.coop_api_url this.coop_api_url = _jm.options.coop_api_url
this.coop_ws_url = _jm.options.coop_ws_url this.coop_ws_url = _jm.options.coop_ws_url
this.client_id = Jm.util.uuid.newid() this.coop_mind_id = _jm.options.coop_mind_id
const coop_mind_id = _jm.options.coop_mind_id this.coop_mind_log_id = _jm.options.coop_mind_log_id
if (this.notNull(coop_mind_id)) { this.coop_mind_log_last_id = _jm.options.coop_mind_log_id
this.coop_mind_id = coop_mind_id
// this.timerFetch()
}
}, },
// 初始化websocket // 初始化websocket
_init_ws: function () { _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) const ws = new WebSocket(this.coop_ws_url + '?_' + this.coop_mind_id)
this.web_socket = ws this.web_socket = ws
//申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头 //申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
@@ -90,6 +88,8 @@
console.log('error'); console.log('error');
this.web_socket = null 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 * @param obj
*/ */
notNull: function (obj) { _not_null: function (obj) {
return obj !== null && obj !== undefined return obj !== null && obj !== undefined
}, },
isNull: function (obj) { _is_null: function (obj) {
return !this.notNull(obj) return !this._not_null(obj)
}, },
/** /**
* 构建公共参数 * 构建公共参数
*/ */
buildCommonParam: function () { _build_evt_param: function () {
return {'client_id': this.client_id, 'log_uuid': Jm.util.uuid.newid()} return {'client_id': this.client_id, 'log_uuid': Jm.util.uuid.newid()}
}, },
/** /**
@@ -130,36 +130,26 @@
* @param body * @param body
* @private * @private
*/ */
jsMindCallBack_: function (type, body) { js_mind_callback_: function (type, body) {
const evt = body.evt const evt = body.evt
if (!!evt) {
const data = body.data const data = body.data
const param = this.buildCommonParam() const param = this._build_evt_param()
param.type = type
if (type === 1 || (evt && evt.length > 0)) { param.type = type
if (type === 1) {
// 新建脑图
param.name = data[0].meta.name
} else if (this.notNull(evt) && evt.length > 0) {
// 脑图编辑 // 脑图编辑
param.evt = evt param.evt = evt
param.data = data.join(';') param.data = data.join(';')
param.node = body.node param.node = body.node
param.coop_mind_id = this.coop_mind_id param.coop_mind_id = this.coop_mind_id
console.log(param)
} }
// ajax },
const me = this _send_ws_message: function (msg) {
/*Jm.util.ajax.post(this.coop_api_url, param, function (resp) { if (this.web_socket) {
if (type === 1) { this.web_socket.send(msg)
// 新建
me.coop_mind_id = resp.coop_mind_id
// this.timerFetch()
// this.timerPush()
} else { } else {
// 操作 console.error('web_socket is not ready!')
me.coop_mind_log_id = resp.coop_mind_log_id
}
})*/
} }
}, },
/** /**
@@ -175,7 +165,7 @@
timerPush: function () { timerPush: function () {
// 把操作日志最大的data 持久化到数据库 // 把操作日志最大的data 持久化到数据库
const me = this const me = this
if (this.isNull(me.timer_push_task)) { if (this._is_null(me.timer_push_task)) {
me.timer_push_task = setInterval(function () { me.timer_push_task = setInterval(function () {
const param = { const param = {
'data': Jm.util.json.json2string(me._jm.get_data('node_array').data), 'data': Jm.util.json.json2string(me._jm.get_data('node_array').data),
+9 -4
View File
@@ -2564,7 +2564,7 @@
} }
d.setAttribute('nodeid', node.id); d.setAttribute('nodeid', node.id);
d.style.visibility = 'hidden'; d.style.visibility = 'hidden';
this._reset_node_custom_style(d, node.data); this._reset_node_custom_style(node, d, node.data);
parent_node.appendChild(d); parent_node.appendChild(d);
view_data.element = d; view_data.element = d;
@@ -2826,10 +2826,10 @@
}, },
reset_node_custom_style: function (node) { reset_node_custom_style: function (node) {
this._reset_node_custom_style(node._data.view.element, node.data); this._reset_node_custom_style(node, node._data.view.element, node.data);
}, },
_reset_node_custom_style: function (node_element, node_data) { _reset_node_custom_style: function (node, node_element, node_data) {
if ('background-color' in node_data) { if ('background-color' in node_data) {
node_element.style.backgroundColor = node_data['background-color']; node_element.style.backgroundColor = node_data['background-color'];
} }
@@ -2842,8 +2842,13 @@
if ('height' in node_data) { if ('height' in node_data) {
node_element.style.height = node_data['height'] + 'px'; node_element.style.height = node_data['height'] + 'px';
} }
if ('font-size' in node_data) { /*if ('font-size' in node_data) {
node_element.style.fontSize = node_data['font-size'] + 'px'; node_element.style.fontSize = node_data['font-size'] + 'px';
}*/
if (node.isroot) {
node_element.style.backgroundColor = '#289f45'
} else {
node_element.style.fontSize = '12px';
} }
if ('font-weight' in node_data) { if ('font-weight' in node_data) {
node_element.style.fontWeight = node_data['font-weight']; node_element.style.fontWeight = node_data['font-weight'];