Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
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
黄庭坚
jinfa-platform
Commits
47bc416d
Commit
47bc416d
authored
Oct 13, 2021
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复发送验证码无法正常操作
parent
7cea348f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
20 deletions
+54
-20
Phone.tsx
src/components/NiceForm/components/Phone.tsx
+36
-2
register.tsx
src/pages/user/register.tsx
+18
-18
No files found.
src/components/NiceForm/components/Phone.tsx
View file @
47bc416d
...
...
@@ -11,6 +11,10 @@ const FLAG_SIZE = 60
const
IMG_WIDTH
=
352
const
IMG_HEIGHT
=
180
// 国家前缀 暂时写死
const
prefixCode
=
'+86'
const
Phone
=
(
props
)
=>
{
const
{
value
,
form
,
schema
}
=
props
const
{
text
,
isActive
,
start
}
=
useCountDown
({
...
...
@@ -18,6 +22,7 @@ const Phone = (props) => {
minTime
:
0
,
initText
:
'获取验证码'
,
onEnd
:
()
=>
{
instanceRef
.
current
.
canIUseSms
=
false
form
.
setFieldState
(
'phone'
,
state
=>
{
state
.
smsLoading
=
instanceRef
.
current
.
canIUseSms
})
...
...
@@ -74,10 +79,39 @@ const Phone = (props) => {
}
},
[
isShowValidate
,
isActive
])
const
validatePhoneRequest
=
async
()
=>
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
try
{
const
{
code
}
=
await
PublicApi
.
getMemberRegisterPhoneCheck
({
countryCode
:
prefixCode
,
phone
:
form
.
getFieldValue
(
'phone'
)
},
{
ctlType
:
'none'
,
useCache
:
true
,
ttl
:
60
*
1000
})
if
(
code
!==
1000
)
{
form
.
setFieldState
(
'phone'
,
state
=>
{
state
.
errors
=
[
'手机号已存在'
]
resolve
(
false
)
godEvent
.
emit
(
'SHOW_PHONE_VALIDATE'
,
false
)
})
}
else
{
resolve
(
true
)
}
}
catch
(
err
)
{
console
.
log
(
err
)
resolve
(
false
)
}
})
}
const
handleClickSms
=
async
()
=>
{
const
validateState
=
await
form
.
validate
(
'phone'
)
// 注册页手机号字段
const
validatePhoneState
=
await
form
.
validate
(
'phone'
)
// 忘记密码 手机号或邮箱字段
const
validateAccountState
=
await
form
.
validate
(
'account'
)
const
phoneAsyncValidate
=
await
validatePhoneRequest
()
// 手机号未通过校验
if
(
validate
State
.
errors
>
0
)
{
if
(
validate
PhoneState
.
errors
>
0
||
validateAccountState
.
errors
>
0
||
!
phoneAsyncValidate
)
{
return
false
}
...
...
src/pages/user/register.tsx
View file @
47bc416d
...
...
@@ -48,24 +48,24 @@ const useLinkageValidateEffects = () => {
})
})
onFieldValidateEnd$
(
'phone'
).
subscribe
(
fieldState
=>
{
if
(
fieldState
.
valid
&&
!
fieldState
.
smsLoading
)
{
// 校验手机号格式通过时, 需请求接口判断手机号是否存在数据库
PublicApi
.
getMemberRegisterPhoneCheck
({
countryCode
:
prefixCode
,
phone
:
fieldState
.
value
},
{
ctlType
:
'none'
,
useCache
:
true
,
ttl
:
60
*
1000
}).
then
(({
code
,
data
})
=>
{
if
(
code
!==
1000
)
{
setFieldState
(
'phone'
,
state
=>
{
state
.
errors
=
[
'手机号已存在'
]
eventEmitter
.
emit
(
'SHOW_PHONE_VALIDATE'
,
false
)
})
}
else
{
eventEmitter
.
emit
(
'SHOW_PHONE_VALIDATE'
,
true
)
}
})
}
else
{
eventEmitter
.
emit
(
'SHOW_PHONE_VALIDATE'
,
false
)
}
//
if (fieldState.valid && !fieldState.smsLoading) {
//
// 校验手机号格式通过时, 需请求接口判断手机号是否存在数据库
//
PublicApi.getMemberRegisterPhoneCheck({
//
countryCode: prefixCode,
//
phone: fieldState.value
//
}, { ctlType: 'none', useCache: true, ttl: 60 * 1000 }).then(({ code, data }) => {
//
if (code !== 1000) {
//
setFieldState('phone', state => {
//
state.errors = ['手机号已存在']
//
eventEmitter.emit('SHOW_PHONE_VALIDATE', false)
//
})
//
} else {
//
eventEmitter.emit('SHOW_PHONE_VALIDATE', true)
//
}
//
})
//
} else {
//
eventEmitter.emit('SHOW_PHONE_VALIDATE', false)
//
}
})
onFieldValueChange$
(
'*(confirmPassword)'
).
subscribe
(
fieldState
=>
{
const
selfValue
=
fieldState
.
value
...
...
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