/**
* 数据字典绘制方法集
* 作者:刘广文
* 邮箱:liugw@imut.edu.cn
* 版本:20230819
* 功能:基于canvas实现数据字典的绘制
*/
var tool = 1;
var current = -1;
var flag=false;
var mouseX= 0;
var mouseY= 0;
var mouseX1= 0;
var mouseY1= 0;
var aryValue = [];
var aryObject = [];
var drawn = false;
var myText = null, okButton = null, cancelButton = null;
var w = 0, h = 0, x = 0, y = 0, pLeft = 0, pTop = 0;
const aryTitle = ["数据存储名称", "属性名称", "数据类型", "描述"]
//加载工具
function loadTools(target){
target.innerHTML = "
方框
"
+ "
表格
"
+ ""
+ "";
}
//确定添加
function okTool(){
if (tool == 1)
pushTool(tool, x, y, x + w, y + h, myText.value, color.value, bcolor.value, size.value);
if (tool == 2)
{
aryValue = [];
for(var i = 1; i < myText.children[0].children[0].children.length; i ++){
var row = myText.children[0].children[0].children[i];
for(var j = 0; j < aryTitle.length; j ++)
aryValue.push(row.cells[j].children[0].value);
}
pushTool(tool, x, y, x + w, y + h, "", color.value, bcolor.value, size.value);
}
cancelTool();
updateTools(cxt, tool, x, y, x + w, y + h, color.value, bcolor.value, size.value);
}
//取消添加
function cancelTool(){
if (myText != null)
{
myText.hidden = true;
okButton.hidden = true;
cancelButton.hidden = true;
}
drawn = false;
}
//鼠标抬起响应动作
function myMouseUp(e, page){
flag=false;
if (!drawn)
{
//pushTool(tool, mouseX, mouseY, mouseX1, mouseY1, text.value, color.value, bcolor.value, size.value);
drawn = true;
if (tool == 1)
{
if (myText == null)
{
myText = document.getElementById("myText");
okButton = document.getElementById("okButton");
cancelButton = document.getElementById("cancelButton");
}
myText.hidden = false;
okButton.hidden = false;
cancelButton.hidden = false;
x = mouseX;
y = mouseY;
if (mouseX1 < mouseX)
x = mouseX1;
if (mouseY1 < mouseY)
y = mouseY1;
w = Math.abs(mouseX - mouseX1);
h = Math.abs(mouseY - mouseY1);
var rect = canvas.getBoundingClientRect();
pLeft = rect.left;
pTop = rect.top;
myText.style.left = (x + pLeft) + "px";
myText.style.top = (y + pTop) + "px";
myText.style.width = w + "px";
myText.style.height = h + "px";
cancelButton.style.left = (x + pLeft + w - 50) + "px";
cancelButton.style.top = (y + pTop + h + 5) + "px";
okButton.style.left = (x + pLeft + w - 110) + "px";
okButton.style.top = (y + pTop + h + 5) + "px";
textWidth = w;
textHeight = h;
myText.addEventListener("mousemove", function(){
if(myText.clientWidth != w || myText.clientHeight != h){
w = myText.clientWidth;
h = myText.clientHeight;
cancelButton.style.left = (x + pLeft + w - 50) + "px";
cancelButton.style.top = (y + pTop + h + 5) + "px";
okButton.style.left = (x + pLeft + w - 110) + "px";
okButton.style.top = (y + pTop + h + 5) + "px";
}
});
myText.focus();
}
if (tool == 2)
{
if (myText == null)
{
myText = document.getElementById("myTable");
okButton = document.getElementById("okButton");
cancelButton = document.getElementById("cancelButton");
}
myText.hidden = false;
okButton.hidden = false;
cancelButton.hidden = false;
x = mouseX;
y = mouseY;
if (mouseX1 < mouseX)
x = mouseX1;
if (mouseY1 < mouseY)
y = mouseY1;
w = Math.abs(mouseX - mouseX1);
h = Math.abs(mouseY - mouseY1);
var rect = canvas.getBoundingClientRect();
pLeft = rect.left;
pTop = rect.top;
myText.style.left = (x + pLeft) + "px";
myText.style.top = (y + pTop) + "px";
myText.style.width = w + "px";
myText.style.height = h + "px";
cancelButton.style.left = (x + pLeft + w - 50) + "px";
cancelButton.style.top = (y + pTop + h + 5) + "px";
okButton.style.left = (x + pLeft + w - 110) + "px";
okButton.style.top = (y + pTop + h + 5) + "px";
textWidth = w;
textHeight = h;
var rowcount = parseInt(text.value);
if (rowcount > 0){
var ww = w / 4 - 10, hh = 25;
var s = "