Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
najiu-frontend
najiu-admin-template
Commits
8b4b767f
Commit
8b4b767f
authored
Jul 21, 2021
by
无木
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(demo): add `async-validator` demo
添加表单使用后端接口异步验证的例子
parent
341bd633
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
6 deletions
+67
-6
system.ts
mock/demo/system.ts
+14
-1
system.ts
src/api/demo/system.ts
+4
-0
RuleForm.vue
src/views/demo/form/RuleForm.vue
+30
-3
account.data.ts
src/views/demo/system/account/account.data.ts
+19
-2
No files found.
mock/demo/system.ts
View file @
8b4b767f
import
{
MockMethod
}
from
'
vite-plugin-mock
'
;
import
{
resultPageSuccess
,
resultSuccess
}
from
'
../_util
'
;
import
{
result
Error
,
result
PageSuccess
,
resultSuccess
}
from
'
../_util
'
;
const
accountList
=
(()
=>
{
const
result
:
any
[]
=
[];
...
...
@@ -185,4 +185,17 @@ export default [
return
resultSuccess
(
menuList
);
},
},
{
url
:
'
/basic-api/system/accountExist
'
,
timeout
:
500
,
method
:
'
post
'
,
response
:
({
body
})
=>
{
const
{
account
}
=
body
||
{};
if
(
account
&&
account
.
indexOf
(
'
admin
'
)
!==
-
1
)
{
return
resultError
(
'
该字段不能包含admin
'
);
}
else
{
return
resultSuccess
(
`
${
account
}
can use`
);
}
},
},
]
as
MockMethod
[];
src/api/demo/system.ts
View file @
8b4b767f
...
...
@@ -14,6 +14,7 @@ import { defHttp } from '/@/utils/http/axios';
enum
Api
{
AccountList
=
'
/system/getAccountList
'
,
IsAccountExist
=
'
/system/accountExist
'
,
DeptList
=
'
/system/getDeptList
'
,
setRoleStatus
=
'
/system/setRoleStatus
'
,
MenuList
=
'
/system/getMenuList
'
,
...
...
@@ -38,3 +39,6 @@ export const getAllRoleList = (params?: RoleParams) =>
export
const
setRoleStatus
=
(
id
:
number
,
status
:
string
)
=>
defHttp
.
post
({
url
:
Api
.
setRoleStatus
,
params
:
{
id
,
status
}
});
export
const
isAccountExist
=
(
account
:
string
)
=>
defHttp
.
post
({
url
:
Api
.
IsAccountExist
,
params
:
{
account
}
},
{
errorMessageMode
:
'
none
'
});
src/views/demo/form/RuleForm.vue
View file @
8b4b767f
...
...
@@ -15,9 +15,10 @@
<
script
lang=
"ts"
>
import
{
defineComponent
}
from
'
vue
'
;
import
{
BasicForm
,
FormSchema
,
useForm
}
from
'
/@/components/Form/index
'
;
import
{
CollapseContainer
}
from
'
/@/components/Container
/index
'
;
import
{
CollapseContainer
}
from
'
/@/components/Container
'
;
import
{
useMessage
}
from
'
/@/hooks/web/useMessage
'
;
import
{
PageWrapper
}
from
'
/@/components/Page
'
;
import
{
isAccountExist
}
from
'
/@/api/demo/system
'
;
const
schemas
:
FormSchema
[]
=
[
{
...
...
@@ -120,11 +121,11 @@
validator
:
async
(
rule
,
value
)
=>
{
if
(
!
value
)
{
/* eslint-disable-next-line */
return
Promise
.
reject
(
'
值不能为空
'
);
return
Promise
.
reject
(
'
值不能为空
'
);
}
if
(
value
===
'
1
'
)
{
/* eslint-disable-next-line */
return
Promise
.
reject
(
'
值不能为1
'
);
return
Promise
.
reject
(
'
值不能为1
'
);
}
return
Promise
.
resolve
();
},
...
...
@@ -174,6 +175,32 @@
},
rules
:
[{
required
:
true
,
message
:
'
覆盖默认生成的校验信息
'
}],
},
{
field
:
'
field8
'
,
component
:
'
Input
'
,
label
:
'
后端异步验证
'
,
colProps
:
{
span
:
8
,
},
helpMessage
:
[
'
本字段演示异步验证
'
,
'
本地规则:必须填写
'
,
'
后端规则:不能包含admin
'
],
rules
:
[
{
required
:
true
,
message
:
'
请输入数据
'
,
},
{
validator
(
_
,
value
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
isAccountExist
(
value
)
.
then
(()
=>
resolve
())
.
catch
((
err
)
=>
{
reject
(
err
.
message
||
'
验证失败
'
);
});
});
},
},
],
},
];
export
default
defineComponent
({
...
...
src/views/demo/system/account/account.data.ts
View file @
8b4b767f
import
{
getAllRoleList
}
from
'
/@/api/demo/system
'
;
import
{
getAllRoleList
,
isAccountExist
}
from
'
/@/api/demo/system
'
;
import
{
BasicColumn
}
from
'
/@/components/Table
'
;
import
{
FormSchema
}
from
'
/@/components/Table
'
;
...
...
@@ -54,7 +54,24 @@ export const accountFormSchema: FormSchema[] = [
field
:
'
account
'
,
label
:
'
用户名
'
,
component
:
'
Input
'
,
helpMessage
:
[
'
本字段演示异步验证
'
,
'
不能输入带有admin的用户名
'
],
rules
:
[
{
required
:
true
,
message
:
'
请输入用户名
'
,
},
{
validator
(
_
,
value
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
isAccountExist
(
value
)
.
then
(()
=>
resolve
())
.
catch
((
err
)
=>
{
reject
(
err
.
message
||
'
验证失败
'
);
});
});
},
},
],
},
{
field
:
'
pwd
'
,
...
...
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