213 lines
4.5 KiB
JavaScript
213 lines
4.5 KiB
JavaScript
// 公共工具函数模块
|
|
|
|
/**
|
|
* DES加密函数
|
|
*/
|
|
function desEncrypt(str, key = "df6a551ca43181fc485f3043bcdd2fbc") {
|
|
var APIFMS;
|
|
try {
|
|
var keyHex_encrypt = CryptoJS.enc.Utf8.parse(key);
|
|
var encrypted = CryptoJS.DES.encrypt(str, keyHex_encrypt, {
|
|
mode: CryptoJS.mode.ECB,
|
|
padding: CryptoJS.pad.Pkcs7
|
|
});
|
|
APIFMS = CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
|
|
} catch (err) {
|
|
console.log('des 加密 -------------------------');
|
|
console.log(err);
|
|
}
|
|
return APIFMS;
|
|
}
|
|
|
|
/**
|
|
* 获取URL参数
|
|
*/
|
|
function GetFile() {
|
|
const params = new URLSearchParams(window.location.search);
|
|
return params;
|
|
}
|
|
|
|
/**
|
|
* 日期格式化
|
|
*/
|
|
function getDate() {
|
|
let date = new Date();
|
|
return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
|
|
}
|
|
|
|
/**
|
|
* 获取对象的绝对坐标
|
|
*/
|
|
function getAbsoluteXY(_obj) {
|
|
let coord = _obj.get("lineCoords");
|
|
return [_obj.get("left"), _obj.get("top")];
|
|
}
|
|
|
|
/**
|
|
* 计算两点之间的距离
|
|
*/
|
|
function getDisdance(x1, y1, x2, y2) {
|
|
var dx = Math.abs(x2 - x1); // 计算x轴上的距离差,并取绝对值
|
|
var dy = Math.abs(y2 - y1); // 计算y轴上的距离差,并取绝对值
|
|
var distance = Math.sqrt(dx * dx + dy * dy); // 应用勾股定理计算距离
|
|
return distance;
|
|
}
|
|
|
|
/**
|
|
* 计算角度(相对于画布中心)
|
|
*/
|
|
function getDeg(pointer, canvas) {
|
|
// 计算点击位置与画布中心的坐标差
|
|
var centerX = canvas.width / 2;
|
|
var centerY = canvas.height / 2;
|
|
var mouseX = pointer.x;
|
|
var mouseY = pointer.y;
|
|
var dx = mouseX - centerX;
|
|
var dy = mouseY - centerY;
|
|
// 计算旋转角度(弧度)
|
|
var angleRad = Math.atan2(dy, dx);
|
|
// 将角度转换为度数
|
|
var angleDeg = angleRad * (180 / Math.PI);
|
|
if (angleDeg < 0) {
|
|
angleDeg += 360;
|
|
}
|
|
angleDeg += 90;
|
|
return angleDeg;
|
|
}
|
|
|
|
/**
|
|
* 检查字段名是否重复
|
|
*/
|
|
function checkName(name, objs1, objs2) {
|
|
//检查字段名是否重复了
|
|
for (let item of objs1) {
|
|
if (item.name == name) {
|
|
return false;
|
|
}
|
|
}
|
|
for (let item of objs2) {
|
|
if (item.name == name) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 返回不重复的字段名
|
|
*/
|
|
function resName(pre_name, objs1, objs2) {
|
|
//返回的是不重复的字段名
|
|
let num = (objs1.length + objs2.length) - 1;
|
|
do {
|
|
num++;
|
|
}
|
|
while (!checkName(pre_name + num, objs1, objs2));//重复了就再加1
|
|
return pre_name + num;
|
|
}
|
|
|
|
/**
|
|
* 获取对象在画布中的索引
|
|
*/
|
|
function getIndex(target, canvas, _canvas = null) {
|
|
let temp_objs;
|
|
if (_canvas == null) {
|
|
temp_objs = canvas.getObjects();
|
|
} else {
|
|
temp_objs = _canvas.getObjects();
|
|
}
|
|
|
|
let i = 0;
|
|
for (let res of temp_objs) {
|
|
if (target == res) {
|
|
return i;
|
|
}
|
|
i++;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* 获取对象类型
|
|
*/
|
|
function getType(target, canvas, objs) {
|
|
let temp_objs = canvas.getObjects();
|
|
let i = 0;
|
|
for (let res of temp_objs) {
|
|
if (target == res) {
|
|
return objs[i].type;
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取坐标的最小X值
|
|
*/
|
|
function getCoordsMinX(acoords) {
|
|
let x = acoords[0].x;
|
|
for (let item of acoords) {
|
|
if (item.x < x) {
|
|
x = item.x;
|
|
}
|
|
}
|
|
return x;
|
|
}
|
|
|
|
/**
|
|
* 获取坐标的最大X值
|
|
*/
|
|
function getCoordsMaxX(acoords) {
|
|
let x = acoords[0].x;
|
|
for (let item of acoords) {
|
|
if (item.x > x) {
|
|
x = item.x;
|
|
}
|
|
}
|
|
return x;
|
|
}
|
|
|
|
/**
|
|
* 获取坐标的最小Y值
|
|
*/
|
|
function getCoordsMinY(acoords) {
|
|
let y = acoords[0].y;
|
|
for (let item of acoords) {
|
|
if (item.y < y) {
|
|
y = item.y;
|
|
}
|
|
}
|
|
return y;
|
|
}
|
|
|
|
/**
|
|
* 获取坐标的最大Y值
|
|
*/
|
|
function getCoordsMaxY(acoords) {
|
|
let y = acoords[0].y;
|
|
for (let item of acoords) {
|
|
if (item.y > y) {
|
|
y = item.y;
|
|
}
|
|
}
|
|
return y;
|
|
}
|
|
|
|
module.exports = {
|
|
desEncrypt,
|
|
GetFile,
|
|
getDate,
|
|
getAbsoluteXY,
|
|
getDisdance,
|
|
getDeg,
|
|
checkName,
|
|
resName,
|
|
getIndex,
|
|
getType,
|
|
getCoordsMinX,
|
|
getCoordsMaxX,
|
|
getCoordsMinY,
|
|
getCoordsMaxY
|
|
};
|
|
|