Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vue-gjjs
Overview
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
fukai
vue-gjjs
Commits
d5ad7c80
Commit
d5ad7c80
authored
Sep 16, 2021
by
潘际乾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
错误信息切换定位
parent
e6d95fdf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
16 deletions
+55
-16
BusinessButton.vue
src/components/BusinessButton.vue
+3
-16
index.js
src/utils/index.js
+52
-0
No files found.
src/components/BusinessButton.vue
View file @
d5ad7c80
...
...
@@ -8,12 +8,11 @@
</
template
>
<
script
>
import
commonApi
from
"~/mixin/commonApi"
import
Utils
from
"~/utils"
export
default
{
props
:[
"$pntvm"
],
data
(){
return
{
return
{
}
},
methods
:{
...
...
@@ -62,19 +61,7 @@ export default {
}
else
{
const
fields
=
this
.
getVM
().
$refs
.
modelForm
.
fields
const
fieldErrors
=
result
.
fieldErrors
;
for
(
const
key
in
fieldErrors
)
{
if
(
Object
.
hasOwnProperty
.
call
(
fieldErrors
,
key
))
{
const
fieldError
=
fieldErrors
[
key
];
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
const
field
=
fields
[
i
];
if
(
field
.
prop
===
key
)
{
field
.
validateState
=
'error'
;
field
.
validateMessage
=
fieldError
;
break
;
}
}
}
}
Utils
.
positioningErrorMsg
(
fieldErrors
,
fields
)
}
},
exit
(){
...
...
src/utils/index.js
View file @
d5ad7c80
...
...
@@ -157,4 +157,55 @@ export default class Utils {
}
return
fn
;
}
static
positioningErrorMsg
(
fieldErrors
,
formFields
)
{
let
firstErrorItem
=
null
for
(
let
i
=
0
;
i
<
formFields
.
length
;
i
++
)
{
const
field
=
formFields
[
i
];
for
(
const
key
in
fieldErrors
)
{
if
(
Object
.
hasOwnProperty
.
call
(
fieldErrors
,
key
))
{
if
(
field
.
prop
===
key
)
{
const
fieldError
=
fieldErrors
[
key
];
field
.
validateState
=
'error'
;
field
.
validateMessage
=
fieldError
;
if
(
!
firstErrorItem
)
{
firstErrorItem
=
field
}
break
;
}
}
}
}
if
(
firstErrorItem
)
{
let
firstErrorTab
=
null
let
parentVC
=
firstErrorItem
while
(
!
firstErrorTab
)
{
const
tag
=
parentVC
.
$vnode
.
tag
const
tagsArr
=
tag
.
split
(
"-"
)
const
vcName
=
tagsArr
[
tagsArr
.
length
-
1
]
// 没有Tabs的表单
if
(
vcName
===
"ElForm"
)
{
break
;
}
if
(
vcName
===
"ElTabPane"
)
{
firstErrorTab
=
parentVC
break
;
}
parentVC
=
parentVC
.
$parent
;
}
if
(
firstErrorTab
)
{
const
tabs
=
firstErrorTab
.
$parent
tabs
.
currentName
=
firstErrorTab
.
paneName
}
setTimeout
(()
=>
{
// 滚动到指定节点
firstErrorItem
.
$el
.
scrollIntoView
({
// 值有start,center,end,nearest,当前显示在视图区域中间
block
:
'center'
,
// 值有auto、instant,smooth,缓动动画(当前是慢速的)
behavior
:
'smooth'
})
},
0
)
}
}
}
\ No newline at end of file
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