Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
Vue-WebDriver
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
高源
Vue-WebDriver
Commits
95dc7433
Commit
95dc7433
authored
Nov 28, 2023
by
郁子恒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化采集表单功能
parent
913e0cbf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
80 deletions
+86
-80
collectionForm.vue
src/components/collectionForm.vue
+86
-80
No files found.
src/components/collectionForm.vue
View file @
95dc7433
...
@@ -2,27 +2,19 @@
...
@@ -2,27 +2,19 @@
<div
class=
"collectionForm"
>
<div
class=
"collectionForm"
>
<div
style=
"display: flex;height: 40px;padding-left: 15px;text-align: left;align-items: center;justify-content: space-between;"
>
<div
style=
"display: flex;height: 40px;padding-left: 15px;text-align: left;align-items: center;justify-content: space-between;"
>
<div
style=
"display: flex;"
>
<div
style=
"display: flex;"
>
<el-button
style=
"width:
60px;height: 30px;"
size=
"mini"
class=
"button-new-tag"
@
click=
"selectElement"
v-if=
"isSelectTable"
>
选择元素
</el-button>
<el-button
style=
"width:
80px;height: 30px;"
size=
"mini"
class=
"button-new-tag"
@
click=
"selectElement"
v-if=
"isSelectForm"
>
批量
选择元素
</el-button>
<el-button
style=
"width: 60px;height: 30px;margin-left: 10px !important;"
size=
"small"
class=
"button-new-tag"
@
click=
"cancelSelect"
v-if=
"isSelect
Table
"
>
取消选择
</el-button>
<el-button
style=
"width: 60px;height: 30px;margin-left: 10px !important;"
size=
"small"
class=
"button-new-tag"
@
click=
"cancelSelect"
v-if=
"isSelect
Form
"
>
取消选择
</el-button>
<el-button
style=
"width: 60px;height: 30px;"
size=
"mini"
class=
"button-new-tag"
@
click=
"columnBack"
v-else
>
返回
</el-button>
<el-button
style=
"width: 60px;height: 30px;"
size=
"mini"
class=
"button-new-tag"
@
click=
"columnBack"
v-else
>
返回
</el-button>
</div>
</div>
<el-button
style=
"margin-right: 15px;"
size=
"small"
class=
"button-new-tag"
@
click=
"getForm"
v-if=
"isSelect
Table
"
>
获取表单信息
</el-button>
<el-button
style=
"margin-right: 15px;"
size=
"small"
class=
"button-new-tag"
@
click=
"getForm"
v-if=
"isSelect
Form
"
>
获取表单信息
</el-button>
</div>
</div>
<!-- 全部表格信息 -->
<!-- 全部表格信息 -->
<div
style=
"overflow: auto;height: 290px;"
:style=
"
{ width: widthResize + 'px' }">
<div
style=
"overflow: auto;height: 305px;"
:style=
"
{ width: widthResize + 'px' }">
<vxe-table
key=
"1"
:data=
"SelectTableData"
ref=
"xTableColumn"
border
class=
"mytable-scrollbar"
height=
"250"
auto-resize
style=
"margin-bottom: 5px;"
v-if=
"isSelectTable"
>
<vxe-table
key=
"1"
:data=
"SelectFormData"
ref=
"xTableColumn"
border
class=
"mytable-scrollbar"
height=
"250"
auto-resize
style=
"margin-bottom: 5px;"
v-if=
"isSelectForm"
>
<vxe-column
field=
""
title=
"字段名"
min-width=
"150"
>
<template
v-slot=
"
{ row }">
<div
style=
"display: flex;flex-direction: column;"
>
<span>
选中内容:
{{
row
.
contentText
}}
</span>
<vxe-input
v-model=
"row.title"
placeholder=
"请填写列名"
size=
"mini"
></vxe-input>
</div>
</
template
>
</vxe-column>
<vxe-column
field=
""
title=
"属性名"
min-width=
"150"
>
<vxe-column
field=
""
title=
"属性名"
min-width=
"150"
>
<template
v-slot=
"
{ row }">
<template
v-slot=
"
{ row }">
<div
style=
"display: flex;flex-direction: column;"
>
<div
style=
"display: flex;flex-direction: column;"
>
<span>
选中内容:
{{
row
.
contentT
ext
}}
</span>
<span>
选中内容:
{{
row
.
t
ext
}}
</span>
<vxe-input
v-model=
"row.name"
placeholder=
"请填写属性名"
size=
"mini"
></vxe-input>
<vxe-input
v-model=
"row.name"
placeholder=
"请填写属性名"
size=
"mini"
></vxe-input>
</div>
</div>
</
template
>
</
template
>
...
@@ -30,7 +22,7 @@
...
@@ -30,7 +22,7 @@
<vxe-column
field=
""
title=
"值类型"
min-width=
"170"
>
<vxe-column
field=
""
title=
"值类型"
min-width=
"170"
>
<
template
v-slot=
"{ row }"
>
<
template
v-slot=
"{ row }"
>
<div
style=
"display: flex;flex-direction: column;"
>
<div
style=
"display: flex;flex-direction: column;"
>
<span>
选中内容:
{{
row
.
contentT
ext
}}
</span>
<span>
选中内容:
{{
row
.
t
ext
}}
</span>
<el-select
style=
"height: 28px;"
v-model=
"row.type"
placeholder=
"选择值类型"
v-if=
"row.typeOptions.length > 1"
:popper-append-to-body=
"false"
filterable
remote
>
<el-select
style=
"height: 28px;"
v-model=
"row.type"
placeholder=
"选择值类型"
v-if=
"row.typeOptions.length > 1"
:popper-append-to-body=
"false"
filterable
remote
>
<el-option
v-for=
"num in row.typeOptions"
:key=
"num.xpath"
:value=
"num.value"
:label=
"num.label"
></el-option>
<el-option
v-for=
"num in row.typeOptions"
:key=
"num.xpath"
:value=
"num.value"
:label=
"num.label"
></el-option>
</el-select>
</el-select>
...
@@ -44,7 +36,7 @@
...
@@ -44,7 +36,7 @@
</
template
>
</
template
>
</vxe-column>
</vxe-column>
</vxe-table>
</vxe-table>
<vxe-table
key=
"2"
:data=
"
table
Data"
ref=
"xTableColumn2"
border
class=
"mytable-scrollbar"
height=
"250"
auto-resize
style=
"margin-bottom: 5px;"
v-else
>
<vxe-table
key=
"2"
:data=
"
form
Data"
ref=
"xTableColumn2"
border
class=
"mytable-scrollbar"
height=
"250"
auto-resize
style=
"margin-bottom: 5px;"
v-else
>
<vxe-column
field=
""
title=
"属性名"
min-width=
"150"
>
<vxe-column
field=
""
title=
"属性名"
min-width=
"150"
>
<
template
v-slot=
"{ row }"
>
<
template
v-slot=
"{ row }"
>
<div
style=
"display: flex;flex-direction: column;"
>
<div
style=
"display: flex;flex-direction: column;"
>
...
@@ -65,42 +57,40 @@
...
@@ -65,42 +57,40 @@
</template>
</template>
<
script
>
<
script
>
import
VXETable
,
{
t
}
from
'vxe-table'
//
import VXETable, { t } from 'vxe-table'
export
default
{
export
default
{
name
:
'collectionForm'
,
name
:
'collectionForm'
,
components
:
{},
components
:
{},
props
:
[
'activedAction'
,
'widthResize'
],
props
:
[
'activedAction'
,
'widthResize'
],
data
()
{
data
()
{
return
{
return
{
tableColumn
:
[],
isSelectForm
:
true
,
tableData
:
[],
SelectFormData
:
[],
SelectTableData
:
[],
formData
:
[],
isSelectTable
:
true
,
form
:
null
,
table
:
null
,
contextMenuListenerAdded
:
false
,
contextMenuListenerAdded
:
false
,
index
:
0
,
index
:
0
,
tableName
:
''
,
}
}
},
},
created
()
{
created
()
{
if
(
this
.
activedAction
.
table
!==
undefined
)
{
if
(
this
.
activedAction
.
form
!==
undefined
)
{
for
(
let
i
=
0
;
i
<
this
.
activedAction
.
table
.
cells
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
this
.
activedAction
.
form
.
cells
.
length
;
i
++
)
{
let
info
=
{};
let
info
=
{};
info
.
type
=
this
.
activedAction
.
table
.
cells
[
i
].
type
;
info
.
type
=
this
.
activedAction
.
form
.
cells
[
i
].
type
;
info
.
name
=
this
.
activedAction
.
table
.
cells
[
i
].
name
;
info
.
name
=
this
.
activedAction
.
form
.
cells
[
i
].
name
;
info
.
title
=
this
.
activedAction
.
table
.
cells
[
i
].
title
;
info
.
title
=
this
.
activedAction
.
form
.
cells
[
i
].
title
;
info
.
typeOptions
=
this
.
activedAction
.
table
.
cells
[
i
].
types
;
info
.
typeOptions
=
this
.
activedAction
.
form
.
cells
[
i
].
types
;
info
.
x
Path
=
this
.
activedAction
.
table
.
cells
[
i
].
xpath
;
info
.
x
path
=
this
.
activedAction
.
form
.
cells
[
i
].
xpath
;
this
.
Select
Table
Data
.
push
(
info
)
this
.
Select
Form
Data
.
push
(
info
)
}
}
}
}
},
},
mounted
()
{
},
mounted
()
{
},
watch
:
{
watch
:
{
Select
Table
Data
:
{
Select
Form
Data
:
{
handler
(
newVal
)
{
handler
(
newVal
)
{
this
.
activedAction
.
formList
=
[];
this
.
activedAction
.
formList
=
[];
this
.
activedAction
.
formList
=
this
.
Select
Table
Data
this
.
activedAction
.
formList
=
this
.
Select
Form
Data
this
.
$emit
(
'dataChanged'
,
this
.
activedAction
);
this
.
$emit
(
'dataChanged'
,
this
.
activedAction
);
console
.
log
(
this
.
activedAction
)
console
.
log
(
this
.
activedAction
)
},
},
...
@@ -115,20 +105,19 @@ export default {
...
@@ -115,20 +105,19 @@ export default {
methods
:
{
methods
:
{
getForm
()
{
getForm
()
{
let
_this
=
this
let
_this
=
this
for
(
let
i
=
0
;
i
<
_this
.
Select
Table
Data
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
_this
.
Select
Form
Data
.
length
;
i
++
)
{
let
obj
=
{};
let
obj
=
{};
obj
.
name
=
_this
.
Select
Table
Data
[
i
].
name
;
obj
.
name
=
_this
.
Select
Form
Data
[
i
].
name
;
obj
.
title
=
_this
.
Select
Table
Data
[
i
].
title
;
obj
.
title
=
_this
.
Select
Form
Data
[
i
].
title
;
obj
.
typeOptions
=
_this
.
Select
Table
Data
[
i
].
typeOptions
;
obj
.
typeOptions
=
_this
.
Select
Form
Data
[
i
].
typeOptions
;
obj
.
type
=
_this
.
Select
Table
Data
[
i
].
type
;
obj
.
type
=
_this
.
Select
Form
Data
[
i
].
type
;
let
content
=
_this
.
getFormData
(
_this
.
Select
TableData
[
i
].
xpath
,
_this
.
SelectTable
Data
[
i
].
type
)
let
content
=
_this
.
getFormData
(
_this
.
Select
FormData
[
i
].
xpath
,
_this
.
SelectForm
Data
[
i
].
type
)
obj
.
content
=
content
obj
.
content
=
content
_this
.
table
Data
.
push
(
obj
)
_this
.
form
Data
.
push
(
obj
)
}
}
console
.
log
(
_this
.
SelectTableData
)
console
.
log
(
_this
.
SelectFormData
)
// 验证name属性是否唯一
// 验证name属性是否唯一
_this
.
validateNames
(
_this
.
Select
Table
Data
)
_this
.
validateNames
(
_this
.
Select
Form
Data
)
},
},
getFormData
(
xpath
,
type
)
{
getFormData
(
xpath
,
type
)
{
...
@@ -137,7 +126,7 @@ export default {
...
@@ -137,7 +126,7 @@ export default {
// 获取查询结果的第一个元素
// 获取查询结果的第一个元素
let
element
=
result
.
iterateNext
();
let
element
=
result
.
iterateNext
();
console
.
log
(
element
)
console
.
log
(
element
)
if
(
type
==
'x
P
ath'
)
{
if
(
type
==
'x
p
ath'
)
{
return
xpath
return
xpath
}
else
{
}
else
{
return
element
[
type
]
return
element
[
type
]
...
@@ -146,90 +135,97 @@ export default {
...
@@ -146,90 +135,97 @@ export default {
// 删除数据行
// 删除数据行
columnDelete
(
row
)
{
columnDelete
(
row
)
{
let
_this
=
this
let
_this
=
this
_this
.
Select
TableData
=
this
.
SelectTable
Data
.
filter
(
item
=>
item
.
_X_ROW_KEY
_this
.
Select
FormData
=
this
.
SelectForm
Data
.
filter
(
item
=>
item
.
_X_ROW_KEY
!==
row
.
_X_ROW_KEY
!==
row
.
_X_ROW_KEY
)
)
_this
.
Select
TableData
=
_this
.
SelectTable
Data
.
filter
(
xpath
=>
xpath
.
xpath
!==
row
.
xpath
);
_this
.
Select
FormData
=
_this
.
SelectForm
Data
.
filter
(
xpath
=>
xpath
.
xpath
!==
row
.
xpath
);
// _this.
table.cells = _this.table
.cells.filter(xpath => xpath !== row.xpath);
// _this.
form.cells = _this.form
.cells.filter(xpath => xpath !== row.xpath);
},
},
columnBack
()
{
columnBack
()
{
let
_this
=
this
let
_this
=
this
_this
.
isSelect
Table
=
true
_this
.
isSelect
Form
=
true
_this
.
table
Data
=
[]
_this
.
form
Data
=
[]
},
},
// 定义事件处理函数
// 定义事件处理函数
contextMenuHandler
(
event
)
{
contextMenuHandler
(
event
)
{
let
_this
=
this
let
_this
=
this
event
.
preventDefault
();
// 阻止默认的右击菜单
// 阻止默认的右击菜单
event
.
preventDefault
();
// 标记右击菜单事件已经被处理
_this
.
contextMenuListenerAdded
=
true
_this
.
contextMenuListenerAdded
=
true
//
表格展示配置
//
获取右击事件的目标元素
let
targetElement
=
event
.
target
;
let
targetElement
=
event
.
target
;
// 检查目标元素是否位于ID为'realcontent'的元素内部
// 检查目标元素是否位于ID为'realcontent'的元素内部
let
isInRealContent
=
targetElement
.
closest
(
'#realcontent'
);
let
isInRealContent
=
targetElement
.
closest
(
'#realcontent'
);
// 如果目标元素在'realcontent'内,则阻止默认行为
// 如果目标元素在'realcontent'内,则阻止默认行为
if
(
isInRealContent
)
return
;
if
(
isInRealContent
)
return
;
//
判断元素类型并提取
信息
//
定义一个对象用于存储提取的
信息
let
info
=
{};
let
info
=
{};
// 定义一个数组用于存储类型选项
let
typeOptions
=
[]
let
typeOptions
=
[]
// 如果右击的目标元素是链接(
<
a
>
标签)
if
(
targetElement
.
tagName
===
'A'
)
{
if
(
targetElement
.
tagName
===
'A'
)
{
//
链接
//
定义一个对象info,用于存储提取的信息
info
=
{
info
=
{
x
Path
:
'xP
ath'
,
x
path
:
'xp
ath'
,
url
:
'href'
,
url
:
'href'
,
text
:
'text
Content
'
text
:
'text'
};
};
// 将info对象的属性转换为选项数组,每个选项是一个对象包含label和value属性
typeOptions
=
Object
.
entries
(
info
).
map
(([
label
,
value
])
=>
{
typeOptions
=
Object
.
entries
(
info
).
map
(([
label
,
value
])
=>
{
return
{
label
,
value
};
return
{
label
,
value
};
});
});
info
.
typeOptions
=
[]
info
.
typeOptions
=
[]
// 将生成的typeOptions数组赋值给info对象的typeOptions属性
info
.
typeOptions
=
typeOptions
info
.
typeOptions
=
typeOptions
// 获取目标元素的XPath,赋值给info对象的xpath属性
info
.
xpath
=
_this
.
getElementXPath
(
targetElement
)
info
.
xpath
=
_this
.
getElementXPath
(
targetElement
)
info
.
contentText
=
targetElement
.
textContent
// 获取目标元素的文本内容,赋值给info对象的contentText属性
info
.
title
=
'columnName'
info
.
text
=
targetElement
.
textContent
// 设置info对象的title属性为字符串 'columnName'
// info.title = 'columnName'
// 如果右击的目标元素是图片(IMG标签)
}
else
if
(
targetElement
.
tagName
===
'IMG'
)
{
}
else
if
(
targetElement
.
tagName
===
'IMG'
)
{
//
图片
//
定义一个对象info,用于存储提取的信息
info
=
{
info
=
{
x
Path
:
'xP
ath'
,
x
path
:
'xp
ath'
,
src
:
'src'
,
src
:
'src'
,
alt
:
'alt'
alt
:
'alt'
};
};
// 将info对象的属性转换为选项数组,每个选项是一个对象包含label和value属性
typeOptions
=
Object
.
entries
(
info
).
map
(([
label
,
value
])
=>
{
typeOptions
=
Object
.
entries
(
info
).
map
(([
label
,
value
])
=>
{
return
{
label
,
value
};
return
{
label
,
value
};
});
});
info
.
typeOptions
=
[]
info
.
typeOptions
=
[]
// 将生成的typeOptions数组赋值给info对象的typeOptions属性
info
.
typeOptions
=
typeOptions
info
.
typeOptions
=
typeOptions
// 获取目标元素的XPath,赋值给info对象的xpath属性
info
.
xpath
=
_this
.
getElementXPath
(
targetElement
)
info
.
xpath
=
_this
.
getElementXPath
(
targetElement
)
info
.
contentText
=
targetElement
.
textContent
// 获取目标元素的文本内容,赋值给info对象的contentText属性
info
.
title
=
'columnName'
info
.
text
=
targetElement
.
textContent
// info.title = 'columnName'
}
else
{
}
else
{
//
其他标签
//
定义一个对象info,用于存储提取的信息
info
=
{
info
=
{
// xPath:'xPath',
text
:
'text'
text
:
'textContent'
};
};
// 将info对象的属性转换为选项数组,每个选项是一个对象包含label和value属性
typeOptions
=
Object
.
entries
(
info
).
map
(([
label
,
value
])
=>
{
typeOptions
=
Object
.
entries
(
info
).
map
(([
label
,
value
])
=>
{
return
{
label
,
value
};
return
{
label
,
value
};
});
});
info
.
typeOptions
=
[]
info
.
typeOptions
=
[]
// 将生成的typeOptions数组赋值给info对象的typeOptions属性
info
.
typeOptions
=
typeOptions
info
.
typeOptions
=
typeOptions
// 获取目标元素的XPath,赋值给info对象的xpath属性
info
.
xpath
=
_this
.
getElementXPath
(
targetElement
)
info
.
xpath
=
_this
.
getElementXPath
(
targetElement
)
info
.
contentText
=
targetElement
.
textContent
// 获取目标元素的文本内容,赋值给info对象的contentText属性
info
.
title
=
'columnName'
info
.
text
=
targetElement
.
textContent
// info.title = 'columnName'
}
}
info
.
name
=
'ID'
+
_this
.
index
++
info
.
name
=
'ID'
+
_this
.
index
++
info
.
type
=
''
info
.
type
=
''
_this
.
SelectTableData
.
push
(
info
)
_this
.
SelectFormData
.
push
(
info
)
console
.
log
(
_this
.
SelectTableData
)
console
.
log
(
_this
.
SelectFormData
)
},
// 选择元素按钮调用
selectElement
()
{
// 添加事件监听器
document
.
addEventListener
(
'contextmenu'
,
this
.
contextMenuHandler
,
false
);
},
// 取消按钮调用
cancelSelect
()
{
// 在取消按钮点击时移除事件监听器
document
.
removeEventListener
(
'contextmenu'
,
this
.
contextMenuHandler
);
},
},
// 获取xpath
// 获取xpath
getElementXPath
(
element
)
{
getElementXPath
(
element
)
{
...
@@ -248,11 +244,21 @@ export default {
...
@@ -248,11 +244,21 @@ export default {
}
}
}
}
},
},
// 选择元素按钮调用
selectElement
()
{
// 添加事件监听器
document
.
addEventListener
(
'contextmenu'
,
this
.
contextMenuHandler
,
false
);
},
// 取消按钮调用
cancelSelect
()
{
// 在取消按钮点击时移除事件监听器
document
.
removeEventListener
(
'contextmenu'
,
this
.
contextMenuHandler
);
},
validateNames
(
arr
)
{
validateNames
(
arr
)
{
// let _this = this;
// let _this = this;
let
names
=
new
Set
();
let
names
=
new
Set
();
// 检查元素是否为空
// 检查元素是否为空
if
(
this
.
Select
Table
Data
.
length
==
0
)
{
if
(
this
.
Select
Form
Data
.
length
==
0
)
{
this
.
$message
.
error
(
"还未选择元素"
);
this
.
$message
.
error
(
"还未选择元素"
);
return
return
}
}
...
@@ -270,7 +276,7 @@ export default {
...
@@ -270,7 +276,7 @@ export default {
if
(
item
.
type
==
''
)
{
if
(
item
.
type
==
''
)
{
this
.
$message
.
error
(
"类型值不能为空"
);
this
.
$message
.
error
(
"类型值不能为空"
);
return
;
return
;
}
else
{
this
.
isSelect
Table
=
false
}
}
else
{
this
.
isSelect
Form
=
false
}
}
}
names
.
add
(
item
.
name
);
names
.
add
(
item
.
name
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment