Commit 67955fa6 by 施晓雨

up

parent 49a6ae73
......@@ -28,29 +28,30 @@ function table () {
this.xpath = null;//防止反复验证,需要清空XPath
if (this.cells.length < 1) return _isVerified;
let tableXpath = [];
let tableXpathArray = [];
{//获取所有单元格共同的父节点路径
let allCellXpaths = this.cells.map(cell => cell.xpath.split('/'));// 分割每个路径为组成部分
for (let i = 0; i < allCellXpaths[0].length; i++) {
let currentPath = allCellXpaths[0][i];
if (allCellXpaths.every(path => path[i] === currentPath)) { // 检查所有路径是否有这个部分
tableXpath.push(currentPath);
tableXpathArray.push(currentPath);
} else { break; }//如果发现不同的,直接就可以退出了
}
//判断下tableXPathArray不能和某一个元素的路径完全相同,如果相同就应该去掉一级
}
if (tableXpath.length < 1) return _isVerified;//如果没有共同父节点,返回false
if (tableXpathArray.length < 1) return _isVerified;//如果没有共同父节点,返回false
while (tableXpath.length > 0) {
this.cells.forEach(cell => cell.updateRelativePath(tableXpath));//先对所有的Cell更新下相对路径
this.cells.forEach(cell => cell.updateRelativePath(tableXpathArray));//先对所有的Cell更新下相对路径
if (this.cells.every(cell => cell.isExist())) break;//如果每个cell都存在,成功
tableXpath.pop();//向上一级找
tableXpathArray.pop();//向上一级找
}
if (tableXpath.length < 1) return _isVerified;//如果没有共同父节点,返回false
if (tableXpathArray.length < 1) return _isVerified;//如果没有共同父节点,返回false
this.cells.forEach(cell => cell.confirm());//对所有单元格进行确认
_isVerified = true;
this.xpath = tableXpath.join("/");//是否可以转换成SmallXPath
this.xpath = tableXpathArray.join("/");//是否可以转换成SmallXPath
return _isVerified;
}
/**
......@@ -98,17 +99,17 @@ function cell (xpath, name = "", type = "", title = "") {
/**当前XPath的数组结构 */
let _xpathArray = this.xpath.split('/');
/**当前表路径的数组结构 */
this._tableXpathArray = null;
let _tableXpathArray = null;
/**当前单元格的相对路径的数组结构 */
this._relativeXpathArray = null;
let _relativeXpathArray = null;
/**
* 根据父路径更新当前的相对路径
* @param {string[]} parentXpath 父路径
*/
this.updateRelativePath = function (parentXpath) {
this._tableXpathArray = parentXpath;//其实这边严谨的来说要验证一下XPath是否真的有相同的根
this._relativeXpathArray = _xpathArray.slice(this._tableXpathArray.length);
_tableXpathArray = parentXpath;//其实这边严谨的来说要验证一下XPath是否真的有相同的根
_relativeXpathArray = _xpathArray.slice(_tableXpathArray.length);
// this.relativeXpath = this._relativeXpathArray
// this.tableXpath = _tableXpathArray
// console.log(this._relativeXpathArray)
......@@ -117,17 +118,11 @@ function cell (xpath, name = "", type = "", title = "") {
* 单元格是否存在
* @returns {boolean}
*/
this.isExist = function (cell) {
this.isExist = function () {
let existCount = 0;
let _tableXpathArray = [...cell._tableXpathArray] //深拷贝,值修改不影响原数组
let _relativeXpathArray = [...cell._relativeXpathArray]//深拷贝,值修改不影响原数组
// 移除最后一个元素的下标
if (_tableXpathArray.length > 0) {
let lastElement = _tableXpathArray[_tableXpathArray.length - 1];
let lastElementWithoutIndex = lastElement.split('[')[0];
_tableXpathArray[_tableXpathArray.length - 1] = lastElementWithoutIndex;
}
let _tableXpathArray = [..._tableXpathArray] //深拷贝,值修改不影响原数组
let _relativeXpathArray = [..._relativeXpathArray]//深拷贝,值修改不影响原数组
_tableXpathArray = _tableXpathArray.join('/')
_relativeXpathArray = _relativeXpathArray.join('/')
//table[0]+relativeXpath,可以不存在,因为可能是表头,1,2
......@@ -146,8 +141,14 @@ function cell (xpath, name = "", type = "", title = "") {
}
/**当所有单元格验证成功后,由表发起确认动作 */
this.confirm = function () {
this.tableXpath = this._tableXpathArray.join("/");//处理下标的事
this.relativePath = this._relativeXpathArray.join("/");
// 移除最后一个元素的下标
if (_tableXpathArray.length > 0) {
let lastElement = _tableXpathArray[_tableXpathArray.length - 1];
let lastElementWithoutIndex = lastElement.split('[')[0];
_tableXpathArray[_tableXpathArray.length - 1] = lastElementWithoutIndex;
}
this.tableXpath = _tableXpathArray.join("/");//处理下标的事
this.relativePath = _relativeXpathArray.join("/");
}
/**
* 根据索引获取值,返回{name:value}格式
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment