drawio.io二次开发采坑记录

本文详细记录了drawio.io的二次开发过程,包括如何修改菜单、实现默认弹出SQL转ER框、添加问题反馈功能、修改File和Help菜单以及部署上线等步骤,同时分享了遇到的问题及解决方案。
摘要由CSDN通过智能技术生成

drawio.io二次开发教程

二次开发

基础资料

导入ide

增加本地和oss存储
纯前端功能
各种修改位置介绍

修改代码

准备环境

git clone  https://github.com/jgraph/drawio.git
cd drawid-dev\src\main\webapp  
python -m http.server 8081  

项目默认是使用打包好的 app.min.js,如果需要修改代码,则需要在请求参数增加 dev=1

同时需要修改 index.html line:245 注释掉远程地址 ,否则测试环境下不会请求本地修改后的js

if (urlParams['dev'] == '1')
{
	// Used to request grapheditor/mxgraph sources in dev mode
	var mxDevUrl = document.location.protocol ; //+ '//devhost.jgraph.com/drawio/src/main';
	
	// Used to request draw.io sources in dev mode
	var drawDevUrl = document.location.protocol ; //+ '//devhost.jgraph.com/drawio/src/main/webapp/';

一切就绪…

修改菜单

菜单相关设置在 js/diagramly/Menus.js
如要删除File --> share…功能

在js/diagramly/Menus.js 搜索 share… 如下,注释掉代码即可

/*
	this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
	{
		try
		{
			var file = editorUi.getCurrentFile();
			
			if (file != null)
			{
				file.share();
			}
		}
		catch (e)
		{
			editorUi.handleError(e);
		}
	}));
*/

修改功能代码也是一样,如将share… 按钮,修改为打开百度,对应代码如下即可

this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
{
	editorUi.openLink('https://www.baidu.com/',"_blank")

}));

可以在浏览器控制台查看各种变量信息 如

console.log(mxResources.get('url'))
修改生效

不能每次都使用dev模式执行,因此需要对 修改后的文件进行 打包

cd drawio/etc/build
ant 

具体功能实现

默认弹出SQL转ER框

发现 菜单的

调整图形 -> 插入 -> 高级 -> SQL... 

这个功能很有意思,可以直接将SQL语句转成ER图

但是这个路径太长了,需要选择好几级菜单才可以找到这个功能

怎样打开页面默认弹出这个编辑框?

  • 首先找到原始功能
调整图形 -> 插入 -> 高级 -> SQL... 

的具体实现在 \src\main\webapp\js\diagramly\Menus.js
功能代码

if (method == 'fromText' || method == 'formatSql' ||
						method == 'plantUml' || method == 'mermaid')
{
	var dlg = new ParseDialog(editorUi, title, method);
	editorUi.showDialog(dlg.container, 620, 420, true, false);
	editorUi.dialog.container.style.overflow = 'auto';
	dlg.init();
}

ParseDialog 具体实现在 \src\main\webapp\js\diagramly\Dialogs.js 中

  • splash对话框分析

默认有个splash对话框,查看这个实现 是在 \src\main\webapp\js\diagramly\App.js

App.prototype.showSplash = function(force)
{
	
	console.log('show Splash is here');
	//Splash dialog shouldn't be shownn when running without a file menu
	if (urlParams['noFileMenu'] == '1')
	{
		return;	
	}
	
	var serviceCount = this.getServiceCount(true);
	
	var showSecondDialog = mxUtils.bind(this, function()
	{
		var dlg = new SplashDialog(this);  //对话框实现在  \src\main\webapp\js\diagramly\Dialogs.js 
		

var SplashDialog = function(editorUi)  //可以看到 app.js中的this 等价与Dialogs.js 的editorUi 
{
	console.log('dialogs SplashDialog');
	var div = document.createElement('div');
	div.style.textAlign = 'center';

是一个原型定义,具体调用代码

this.showSplash();
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值