/**
* 合并单元格
* @param list 表格的原始数据
* @returns {*} 处理过的数据
*/
let combineCell = list => {
for (let field in list[0]) {
let k = 0;
while (k < list.length) {
list[k][field + 'span'] = 1;
list[k][field + 'dis'] = false;
for (var i = k + 1; i <= list.length - 1; i++) {
if (list[k][field] == list[i][field] && list[k][field] != '') {
list[k][field + 'span']++;
list[k][field + 'dis'] = false;
list[i][field + 'span'] = 1;
list[i][field + 'dis'] = true;
} else {
break;
}
}
k = i;
}
}
return list;
}
/**
*
* @param list 数组
* @param item 要截取的键值
* @returns {Array}
*/
let listHandle = (list, item) => {
let arr = []
list.forEach(ele => {
if (isNaN(ele[item])) {
arr.push(ele[item].replace(/[^0-9]/ig, ""))
} else {
arr.push(ele[item])
}
})
return arr
}
/**
* 判断对象在数组里面的下标位置
* @param item 对象
* @param arr 数组
* @returns {boolean} 对象在数组里面的下标
*/
let findIndJsonArr = (item, arr) => {
let index = arr.findIndex(ele => {
return ele.menuName == item.menuName
})
return index;
};
/**
* dom拖拽方法
* @param dom 需要拖拽的dom对象
* @param vm 所调用页面的当前vue实例
*/
let dragDiv = (dom,vm) => {
dom.onmousedown = function (ev) {
let oevent = ev || event;
let distanceX = oevent.clientX - dom.offsetLeft;
let distanceY = oevent.clientY - dom.offsetTop;
vm.isDrag = false; // 用于判断是点击还是拖拽事件 isDrag来源于调用页面注册的变量
document.onmousemove = function (ev) {
let oevent = ev || event;
dom.style.left = oevent.clientX - distanceX + 'px';
dom.style.top = oevent.clientY - distanceY + 'px';
vm.isDrag = true
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
// vm.isDrag = false
if(!vm.isDrag){
vm.isShow=!vm.isShow
}
};
};
}
export {combineCell, listHandle, findIndJsonArr, dragDiv}
this.dragDiv(document.getElementById('drag-flowAnalysis'),this) // 拖拽