Commit 4dc97673 by 施晓雨

更新逻辑结构,加入table

parent 75a6b6dc
/**
* 定义表格对象
*/
function table() {
/**表格名称,当该表格获取完数据后,应该存储的对象名 */
this.name = "";
/**表格所在的XPath,由验证表格功能具体生成,如果为null,说明验证不成功 */
this.xpath = null;
/**所有的单元格信息*/
this.cells = [];
/**当前table是否通过了验证*/
let _isVerified = false;
/**
* 新生成一个单元格
* @param {any} xpath
*/
this.newCell = function (xpath) {
_isVerified = false;//加入了
let cell = new cell(xpath);
this.cells.push(cell);
}
/**
* 根据传入的cell进行验证,如果验证成功,xpath自动变化
* @returns {boolean} 返回true或false
* */
this.verify = function () {
_isVerified = false;
this.xpath = null;//防止反复验证,需要清空XPath
if (this.cells.length < 1) return _isVerified;
let tableXpath = [];
{//获取所有单元格共同的父节点路径
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);
} else { break; }//如果发现不同的,直接就可以退出了
}
}
if (tableXpath.length < 1) return _isVerified;//如果没有共同父节点,返回false
while (tableXpath.length > 0) {
this.cells.forEach(cell => cell.updateRelativePath(tableXpath));//先对所有的Cell更新下相对路径
if (this.cells.every(cell => cell.isExist())) break;//如果每个cell都存在,成功
tableXpath.pop();//向上一级找
}
if (tableXpath.length < 1) return _isVerified;//如果没有共同父节点,返回false
this.cells.forEach(cell => cell.confirm());//对所有单元格进行确认
_isVerified = true;
this.xpath = tableXpath.join("/");
return _isVerified;
}
/**
* 返回当前表格的数据
*/
this.getData = function () {
if (!_isVerified) return null;//如果还没通过验证不返回数据
}
}
/**
* 定义的表格获取时要传入的对象信息
* @param {string} xpath 元素的XPath路径
* @param {string} name 元素取值后返回的属性名
* @param {string} type 元素取值类型,文本,链接,元素路径(点击动作用)
* @param {string} title 标题信息
*/
function cell (xpath, name, type, title) {
// 初始化
function cell (xpath, name="", type="", title="") {
/**当前单元格的绝对路径,存入Action时有用 */
this.xpath = xpath;
/**当前单元格存储数据时的属性名 */
this.name = name;
/**单元格取值类型, 文本,链接,元素路径(点击动作用)*/
this.type = type;
/** 单元格在表上的表头信息*/
this.title = title;
var _xpathArray = this.xpath.split('/');
this.ParentXpath = null;
this.RelativeXpath = null;
/**当表结构验证成功后,正确的表绝对路径 */
this.tableXpath = null;
/**当表结构验证成功后,正确的单元格相对路径 */
this.relativeXpath = null;
/**当前XPath的数组结构 */
let _xpathArray = this.xpath.split('/');
/**当前表路径的数组结构 */
let _tableXpathArray = null;
/**当前单元格的相对路径的数组结构 */
let _relativeXpathArray = null;
/**
* 根据父路径更新当前的相对路径
* @param {string[]} parentXpath 父路径
*/
this.updateRelativePath = function (parentXpath) {
this.ParentXpath = parentXpath;//其实这边严谨的来说要验证一下XPath是否真的有相同的根
this.RelativeXpath = _xpathArray.slice(parentXpath.length);
// console.log(this.ParentXpath)
let absolutePath = this.ParentXpath.join('/') + '/' + this.RelativeXpath.join('/');
return absolutePath
_tableXpathArray = parentXpath;//其实这边严谨的来说要验证一下XPath是否真的有相同的根
_relativeXpathArray = _xpathArray.slice(_tableXpathArray.length);
}
/**
* 单元格是否存在
* @returns {boolean}
*/
this.isExist = function () {
let existCount = 0;
//table[0]+relativeXpath,可以不存在,因为可能是表头,1,2
for (let i = 0; i < 3; i++) {
}
return existCount>1;
}
/**当所有单元格验证成功后,由表发起确认动作 */
this.confirm = function () {
this.tableXpath = _tableXpathArray.join("/");
this.relativePath = _relativeXpathArray.join("/");
}
/**
* 根据索引获取值
......
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