Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
施宇
/
icsalesProgram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6caf8244
authored
Jul 25, 2019
by
梁建民
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
验证码
parent
21d0e8e2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
325 additions
and
307 deletions
app.json
pages/person/verifycode/index.js
pages/person/verifycode/index.wxml
app.json
View file @
6caf8244
{
"pages"
:
[
"pages/person/verifycode/index"
,
"pages/person/auth/index"
,
"pages/person/verifycode/index"
,
"pages/person/login/index"
,
"pages/person/getphone/index"
,
"pages/person/agreement/index"
,
...
...
pages/person/verifycode/index.js
View file @
6caf8244
const
http
=
require
(
'../../../utils/util.js'
);
import
{
apis
apis
}
from
'../../../utils/api.js'
;
Page
({
/**
* 页面的初始数据
*/
data
:
{
error
:
false
,
errorText
:
''
,
mobileFlag
:
false
,
codeFlag
:
false
,
disabled
:
false
,
disabledBtn
:
false
,
loading
:
false
,
currentTime
:
61
,
vcode
:
true
,
vcodeFlag
:
true
,
timeText
:
'发送验证码'
,
formData
:
{
mobile
:
''
,
code
:
''
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad
:
function
(
options
)
{
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady
:
function
()
{
},
/**
* 生命周期函数--监听页面显示
*/
onShow
:
function
()
{
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide
:
function
()
{
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload
:
function
()
{
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh
:
function
()
{
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom
:
function
()
{
},
/**
* 用户点击右上角分享
*/
onShareAppMessage
:
function
()
{
},
/**
* 获取验证码
*/
getCode
:
function
()
{
let
self
=
this
;
var
currentTime
=
this
.
data
.
currentTime
;
var
interval
=
setInterval
(
function
()
{
currentTime
--
;
self
.
setData
({
timeText
:
currentTime
+
's'
});
if
(
currentTime
<=
0
)
{
clearInterval
(
interval
);
self
.
setData
({
timeText
:
'重新发送'
,
currentTime
:
61
,
disabled
:
false
});
}
},
1000
)
},
/**
* 发送验证码
*/
getVerificationCode
:
function
(
e
)
{
let
self
=
this
;
if
(
self
.
data
.
formData
.
mobile
)
{
http
.
getData
(
apis
.
getWxCode
,
{
mobile
:
self
.
data
.
formData
.
code
,
code_type
:
2
},
function
(
res
)
{
if
(
res
.
err_code
===
0
)
{
self
.
getCode
();
self
.
setData
({
disabled
:
true
});
}
else
{
wx
.
showToast
({
title
:
'发送失败'
,
icon
:
'none'
,
duration
:
2000
});
}
},
true
);
}
else
{
this
.
setData
({
error
:
true
,
errorText
:
'手机号不能为空'
,
mobileFlag
:
true
});
}
},
/**
* 刷新验证码
*/
verificationFn
:
function
(){
},
/**
* 校验字段
*/
bindinputFn
:
function
(
e
)
{
let
value
=
e
.
detail
.
value
let
reg_mobile
=
/^
(
13
[
0-9
]
|14
[
579
]
|15
[
0-3,5-9
]
|16
[
6
]
|17
[
0135678
]
|18
[
0-9
]
|19
[
89
])\d{8}
$/
;
if
(
e
.
currentTarget
.
dataset
.
type
==
1
)
{
this
.
setData
({
'formData.mobile'
:
value
});
if
(
value
)
{
this
.
setData
({
error
:
true
,
errorText
:
'请填写正确的手机号'
,
mobileFlag
:
true
});
if
(
reg_mobile
.
test
(
value
))
{
this
.
setData
({
error
:
false
,
errorText
:
''
,
mobileFlag
:
false
});
}
}
}
else
{
if
(
value
)
{
this
.
setData
({
error
:
false
,
errorText
:
''
,
codeFlag
:
false
});
}
}
},
/**
* 校验字段
*/
calcForm
:
function
(
val
,
type
)
{
let
mobile
=
val
.
mobile
;
let
code
=
val
.
code
;
let
reg_mobile
=
/^
(
13
[
0-9
]
|14
[
579
]
|15
[
0-3,5-9
]
|16
[
6
]
|17
[
0135678
]
|18
[
0-9
]
|19
[
89
])\d{8}
$/
;
if
(
!
mobile
)
{
this
.
setData
({
error
:
true
,
errorText
:
'手机号不能为空'
,
mobileFlag
:
true
});
return
false
;
}
if
(
!
reg_mobile
.
test
(
mobile
))
{
this
.
setData
({
error
:
true
,
errorText
:
'请填写正确的手机号'
,
mobileFlag
:
true
});
return
false
;
}
if
(
!
code
)
{
this
.
setData
({
error
:
true
,
errorText
:
'验证码不能为空'
,
codeFlag
:
true
});
return
false
;
}
this
.
setData
({
error
:
false
,
errorText
:
''
,
codeFlag
:
false
,
mobileFlag
:
false
});
return
true
;
},
/**
* 登录
*/
formSubmit
:
function
(
e
)
{
var
self
=
this
;
if
(
this
.
calcForm
(
e
.
detail
.
value
))
{
self
.
setData
({
disabledBtn
:
true
,
loading
:
true
});
http
.
postData
(
apis
.
authMobilelogin
,
e
.
detail
.
value
,
function
(
res
)
{
if
(
res
.
err_code
===
0
)
{
//注入token
wx
.
setStorage
({
key
:
"access_token"
,
data
:
res
.
data
.
access_token
});
// wx.switchTab({
// url: '/pages/tab/home/home'
// })
}
else
{
wx
.
showToast
({
title
:
res
.
err_msg
,
icon
:
'none'
,
duration
:
2000
});
}
self
.
setData
({
disabledBtn
:
false
,
loading
:
false
});
});
}
}
})
\ No newline at end of file
/**
* 页面的初始数据
*/
data
:
{
error
:
false
,
errorText
:
''
,
mobileFlag
:
false
,
codeFlag
:
false
,
disabled
:
false
,
disabledBtn
:
false
,
loading
:
false
,
currentTime
:
61
,
vcode
:
false
,
vcodeFlag
:
false
,
timeText
:
'发送验证码'
,
captchaUrl
:
''
,
captchaUuid
:
''
,
captcha
:
''
,
formData
:
{
mobile
:
''
,
code
:
''
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad
:
function
(
options
)
{
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady
:
function
()
{
},
/**
* 生命周期函数--监听页面显示
*/
onShow
:
function
()
{
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide
:
function
()
{
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload
:
function
()
{
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh
:
function
()
{
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom
:
function
()
{
},
/**
* 用户点击右上角分享
*/
onShareAppMessage
:
function
()
{
},
/**
* 获取验证码
*/
getCode
:
function
()
{
let
self
=
this
;
let
currentTime
=
this
.
data
.
currentTime
;
let
interval
=
setInterval
(
function
()
{
currentTime
--
;
self
.
setData
({
timeText
:
currentTime
+
's'
});
if
(
currentTime
<=
0
)
{
clearInterval
(
interval
);
self
.
setData
({
timeText
:
'重新发送'
,
currentTime
:
61
,
disabled
:
false
});
}
},
1000
)
},
/**
* 发送验证码
*/
getVerificationCode
:
function
(
e
)
{
//验证必填手机号
if
(
this
.
data
.
formData
.
mobile
)
{
//验证是否发送了验证码
if
(
this
.
data
.
captchaUuid
)
{
//是否填写了验证码
if
(
this
.
data
.
captcha
)
{
http
.
getData
(
apis
.
getRegistCode
,
{
captchaUuid
:
this
.
data
.
captchaUuid
,
captcha
:
this
.
data
.
captcha
,
mobile
:
this
.
data
.
formData
.
mobile
,
code_type
:
2
},
(
res
)
=>
{
if
(
res
.
err_code
===
0
)
{
this
.
getCode
();
this
.
setData
({
disabled
:
true
});
}
else
{
wx
.
showToast
({
title
:
res
.
err_msg
,
icon
:
'none'
,
duration
:
2000
});
}
},
true
);
}
else
{
this
.
setData
({
error
:
true
,
errorText
:
'图形验证码不能为空'
,
vcodeFlag
:
true
});
}
}
else
{
this
.
refreshVerification
();
}
}
else
{
this
.
setData
({
error
:
true
,
errorText
:
'手机号不能为空'
,
mobileFlag
:
true
});
}
},
/**
* 刷新图形验证码
*/
refreshVerification
:
function
()
{
this
.
setData
({
vcode
:
true
});
http
.
getData
(
apis
.
captchaInfo
,
null
,
(
res
)
=>
{
this
.
setData
({
captchaUrl
:
res
.
captchaUrl
,
captchaUuid
:
res
.
captchaUuid
});
});
},
/**
* 校验字段
*/
bindinputFn
:
function
(
e
)
{
let
value
=
e
.
detail
.
value
let
reg_mobile
=
/^
(
13
[
0-9
]
|14
[
579
]
|15
[
0-3,5-9
]
|16
[
6
]
|17
[
0135678
]
|18
[
0-9
]
|19
[
89
])\d{8}
$/
;
if
(
e
.
currentTarget
.
dataset
.
type
==
1
)
{
this
.
setData
({
'formData.mobile'
:
value
});
if
(
value
)
{
this
.
setData
({
error
:
true
,
errorText
:
'请填写正确的手机号'
,
mobileFlag
:
true
});
if
(
reg_mobile
.
test
(
value
))
{
this
.
setData
({
error
:
false
,
errorText
:
''
,
mobileFlag
:
false
});
}
}
}
else
if
(
e
.
currentTarget
.
dataset
.
type
==
2
)
{
if
(
value
)
{
this
.
setData
({
error
:
false
,
errorText
:
''
,
codeFlag
:
false
});
}
}
else
if
(
e
.
currentTarget
.
dataset
.
type
==
3
)
{
if
(
value
)
{
this
.
setData
({
captcha
:
value
});
this
.
setData
({
error
:
false
,
errorText
:
''
,
vcodeFlag
:
false
});
}
}
},
/**
* 校验字段
*/
calcForm
:
function
(
val
,
type
)
{
let
mobile
=
val
.
mobile
;
let
code
=
val
.
code
;
let
reg_mobile
=
/^
(
13
[
0-9
]
|14
[
579
]
|15
[
0-3,5-9
]
|16
[
6
]
|17
[
0135678
]
|18
[
0-9
]
|19
[
89
])\d{8}
$/
;
if
(
!
mobile
)
{
this
.
setData
({
error
:
true
,
errorText
:
'手机号不能为空'
,
mobileFlag
:
true
});
return
false
;
}
if
(
!
reg_mobile
.
test
(
mobile
))
{
this
.
setData
({
error
:
true
,
errorText
:
'请填写正确的手机号'
,
mobileFlag
:
true
});
return
false
;
}
if
(
!
code
)
{
this
.
setData
({
error
:
true
,
errorText
:
'验证码不能为空'
,
codeFlag
:
true
});
return
false
;
}
this
.
setData
({
error
:
false
,
errorText
:
''
,
codeFlag
:
false
,
mobileFlag
:
false
});
return
true
;
},
/**
* 登录
*/
formSubmit
:
function
(
e
)
{
var
self
=
this
;
if
(
this
.
calcForm
(
e
.
detail
.
value
))
{
self
.
setData
({
disabledBtn
:
true
,
loading
:
true
});
http
.
postData
(
apis
.
authMobilelogin
,
e
.
detail
.
value
,
(
res
)
=>
{
if
(
res
.
err_code
===
0
)
{
//注入token
wx
.
setStorage
({
key
:
"access_token"
,
data
:
res
.
data
.
access_token
});
wx
.
switchTab
({
url
:
'/pages/tab/home/home'
})
}
else
{
wx
.
showToast
({
title
:
res
.
err_msg
,
icon
:
'none'
,
duration
:
2000
});
}
self
.
setData
({
disabledBtn
:
false
,
loading
:
false
});
});
}
}
})
pages/person/verifycode/index.wxml
View file @
6caf8244
...
...
@@ -5,7 +5,6 @@
<text class="t1">Hi,上午好</text>
<text class="t1">欢迎使用IC业务助手!</text>
</view>
<form bindsubmit="formSubmit">
<view class="inp-wrap row verCenter {{mobileFlag ? 'inp-error':''}}">
<text class="icon iconfont iconiconxiantiaoshouji21"></text>
...
...
@@ -21,9 +20,9 @@
<view class="inp-wrap row verCenter {{vcodeFlag ? 'inp-error':''}}" wx:if="{{vcode}}">
<text class="icon iconfont iconiconxiantiaoshouji"></text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入图形验证码" placeholder-class="placeholderClass" name='c
ode
' data-type="3" bindinput='bindinputFn'></input>
<input placeholder="请输入图形验证码" placeholder-class="placeholderClass" name='c
aptcha
' data-type="3" bindinput='bindinputFn'></input>
<view class='code-img'>
<cover-image src="
http://authapi.icsales.cc/captcha/default/d162987e-6aa8-545e-3b73-8c2cf3c361cc" class="img" bindtap='verificationF
n'></cover-image>
<cover-image src="
{{captchaUrl}}" class="img" bindtap='refreshVerificatio
n'></cover-image>
</view>
</view>
</view>
...
...
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