Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
69d0074a
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1061
Star
33
Fork
43
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello_uni-id-pages
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
69d0074a
编写于
6月 23, 2022
作者:
DCloud_JSON
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增修改密码功能
上级
7ac62e65
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
1051 addition
and
906 deletion
+1051
-906
App.vue
App.vue
+1
-1
manifest.json
manifest.json
+3
-1
pages.json
pages.json
+13
-5
uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha/index.js
...ptcha/uniCloud/cloudfunctions/common/uni-captcha/index.js
+1
-1
uni_modules/uni-id-pages/common/loginSuccess.js
uni_modules/uni-id-pages/common/loginSuccess.js
+28
-21
uni_modules/uni-id-pages/components/uni-id-pages-sms-form/uni-id-pages-sms-form.vue
...omponents/uni-id-pages-sms-form/uni-id-pages-sms-form.vue
+2
-2
uni_modules/uni-id-pages/init.js
uni_modules/uni-id-pages/init.js
+0
-23
uni_modules/uni-id-pages/pages/login/login-smscode.vue
uni_modules/uni-id-pages/pages/login/login-smscode.vue
+113
-113
uni_modules/uni-id-pages/pages/login/login-withoutpwd.vue
uni_modules/uni-id-pages/pages/login/login-withoutpwd.vue
+198
-198
uni_modules/uni-id-pages/pages/login/login-withpwd.vue
uni_modules/uni-id-pages/pages/login/login-withpwd.vue
+148
-148
uni_modules/uni-id-pages/pages/register/register.vue
uni_modules/uni-id-pages/pages/register/register.vue
+122
-122
uni_modules/uni-id-pages/pages/retrieve/retrieve.vue
uni_modules/uni-id-pages/pages/retrieve/retrieve.vue
+199
-199
uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue
...les/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue
+146
-0
uni_modules/uni-id-pages/pages/userinfo/userinfo.vue
uni_modules/uni-id-pages/pages/userinfo/userinfo.vue
+12
-7
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/account/update-pwd.js
...oud/cloudfunctions/uni-id-co/module/account/update-pwd.js
+65
-65
未找到文件。
App.vue
浏览文件 @
69d0074a
...
...
@@ -3,7 +3,7 @@
export
default
{
onLaunch
:
async
function
()
{
console
.
log
(
'
App Launch
'
)
await
uniIdPageInit
()
//
await uniIdPageInit()
},
onShow
:
function
()
{
console
.
log
(
'
App Show
'
)
...
...
manifest.json
浏览文件 @
69d0074a
...
...
@@ -137,5 +137,7 @@
"enable"
:
true
}
},
"_spaceID"
:
"9f641af8-e860-44e5-b18f-f68dd8fe3fe4"
"_spaceID"
:
"9f641af8-e860-44e5-b18f-f68dd8fe3fe4"
,
"fallbackLocale"
:
"zh-Hans"
,
"locale"
:
"zh-Hans"
}
pages.json
浏览文件 @
69d0074a
...
...
@@ -66,7 +66,16 @@
"enablePullDownRefresh"
:
false
}
}
],
,{
"path"
:
"uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd"
,
"style"
:
{
"navigationBarTitleText"
:
"修改密码"
,
"enablePullDownRefresh"
:
false
}
}
],
"globalStyle"
:
{
"navigationBarTextStyle"
:
"black"
,
"navigationBarTitleText"
:
"uni-app"
,
...
...
@@ -82,11 +91,10 @@
"query"
:
""
//启动参数,在页面的onLoad函数里面得到
}
]
}
,
"uniIdRouter"
:
{
"loginPage"
:
"uni_modules/uni-id-pages/pages/login/login-withoutpwd
?type=weixin
"
,
}
,
"uniIdRouter"
:
{
"loginPage"
:
"uni_modules/uni-id-pages/pages/login/login-withoutpwd"
,
"needLogin"
:
[
"pages/index/index"
,
"uni_modules/uni-id-pages/pages/userinfo/userinfo"
],
"resToLogin"
:
true
...
...
uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha/index.js
浏览文件 @
69d0074a
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
uni_modules/uni-id-pages/common/loginSuccess.js
浏览文件 @
69d0074a
export
default
function
(
e
=
{}){
const
{
showToast
=
true
,
toastText
=
'
登录成功
'
,
autoBack
=
true
}
=
e
console
.
log
({
toastText
,
autoBack
});
if
(
showToast
){
uni
.
showToast
({
title
:
toastText
,
icon
:
'
none
'
});
}
if
(
autoBack
){
let
delta
=
0
;
//判断需要返回几层
let
pages
=
getCurrentPages
();
console
.
log
(
pages
);
pages
.
forEach
((
page
,
index
)
=>
{
if
(
pages
[
pages
.
length
-
index
-
1
].
route
.
split
(
'
/
'
)[
3
]
==
'
login
'
){
delta
++
}
})
console
.
log
(
'
判断需要返回几层:
'
,
delta
);
uni
.
navigateBack
({
delta
})
}
export
default
function
(
e
=
{})
{
const
{
showToast
=
true
,
toastText
=
'
登录成功
'
,
autoBack
=
true
}
=
e
console
.
log
({
toastText
,
autoBack
});
if
(
showToast
)
{
uni
.
showToast
({
title
:
toastText
,
icon
:
'
none
'
});
}
if
(
autoBack
)
{
let
delta
=
0
;
//判断需要返回几层
let
pages
=
getCurrentPages
();
// console.log(pages);
pages
.
forEach
((
page
,
index
)
=>
{
if
(
pages
[
pages
.
length
-
index
-
1
].
route
.
split
(
'
/
'
)[
3
]
==
'
login
'
)
{
delta
++
}
})
console
.
log
(
'
判断需要返回几层:
'
,
delta
);
uni
.
navigateBack
({
delta
})
}
}
uni_modules/uni-id-pages/components/uni-id-pages-sms-form/uni-id-pages-sms-form.vue
浏览文件 @
69d0074a
...
...
@@ -101,7 +101,7 @@
},
computed
:
{
innerText
()
{
if
(
this
.
reverseNumber
==
0
)
return
"
获取验证码
"
;
if
(
this
.
reverseNumber
==
0
)
return
"
获取
短信
验证码
"
;
return
"
重新发送
"
+
'
(
'
+
this
.
reverseNumber
+
'
s)
'
;
}
},
...
...
@@ -195,7 +195,7 @@
.short-code-btn
{
padding
:
0
;
position
:
absolute
;
right
:
3
px
;
right
:
8
px
;
width
:
200rpx
;
max-width
:
100px
;
height
:
44px
;
...
...
uni_modules/uni-id-pages/init.js
浏览文件 @
69d0074a
...
...
@@ -72,27 +72,4 @@ export default async function() {
}
// 解绑clientDB错误事件
//db.off('error', onDBError)
//4. 同步客户端push_clientId至device表
if
(
uni
.
canIUse
(
'
onRefreshToken
'
)){
uniCloud
.
onRefreshToken
(()
=>
{
console
.
log
(
'
onRefreshToken
'
);
if
(
uni
.
canIUse
(
'
getPushClientId
'
)){
uni
.
getPushClientId
({
success
:
async
function
(
e
)
{
console
.
log
(
e
)
let
pushClientId
=
e
.
cid
console
.
log
(
pushClientId
);
let
res
=
await
uniIdCo
.
setPushCid
({
pushClientId
})
console
.
log
(
res
);
},
fail
(
e
)
{
console
.
log
(
e
)
}
})
}
})
}
}
uni_modules/uni-id-pages/pages/login/login-smscode.vue
浏览文件 @
69d0074a
<!-- 短信验证码登陆页 -->
<
template
>
<view
class=
"uni-content"
>
<!-- 顶部文字 -->
<text
class=
"title"
>
请输入验证码
</text>
<
template
>
<view
class=
"uni-content"
>
<!-- 顶部文字 -->
<text
class=
"title"
>
请输入验证码
</text>
<text
class=
"tip"
>
先输入图形验证码,再获取短信验证码
</text>
<uni-forms>
<uni-id-pages-sms-form
focusCaptchaInput
v-model=
"code"
type=
"login-by-sms"
ref=
"smsCode"
:phone=
"phone"
>
</uni-id-pages-sms-form>
<button
class=
"uni-btn send-btn"
type=
"primary"
@
click=
"submit"
>
登录
</button>
</uni-forms>
<uni-popup-captcha
@
confirm=
"submit"
v-model=
"captcha"
scene=
"login-by-sms"
ref=
"popup"
></uni-popup-captcha>
</view>
</
template
>
<
script
>
import
mixin
from
'
../../common/login-page.mixin.js
'
;
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
"
code
"
:
""
,
"
phone
"
:
""
,
"
captcha
"
:
""
,
}
},
computed
:
{
tipText
()
{
return
'
验证码已通过短信发送至
'
+
this
.
phone
;
},
},
onLoad
({
phoneNumber
})
{
this
.
phone
=
phoneNumber
;
},
<uni-id-pages-sms-form
focusCaptchaInput
v-model=
"code"
type=
"login-by-sms"
ref=
"smsCode"
:phone=
"phone"
>
</uni-id-pages-sms-form>
<button
class=
"uni-btn send-btn"
type=
"primary"
@
click=
"submit"
>
登录
</button>
</uni-forms>
<uni-popup-captcha
@
confirm=
"submit"
v-model=
"captcha"
scene=
"login-by-sms"
ref=
"popup"
></uni-popup-captcha>
</view>
</
template
>
<
script
>
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
"
code
"
:
""
,
"
phone
"
:
""
,
"
captcha
"
:
""
,
}
},
computed
:
{
tipText
()
{
return
'
验证码已通过短信发送至
'
+
this
.
phone
;
},
},
onLoad
({
phoneNumber
})
{
this
.
phone
=
phoneNumber
;
},
onShow
()
{
console
.
log
(
'
onShow
'
);
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
submit
()
}
};
// #endif
},
methods
:
{
submit
()
{
//完成并提交
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,
{
errorOptions
:
{
type
:
'
toast
'
}
})
if
(
this
.
code
.
length
!=
6
)
{
this
.
$refs
.
smsCode
.
focusSmsCodeInput
=
true
return
uni
.
showToast
({
title
:
'
验证码不能为空
'
,
icon
:
'
none
'
});
}
uniIdCo
.
loginBySms
({
"
mobile
"
:
this
.
phone
,
"
code
"
:
this
.
code
,
"
captcha
"
:
this
.
captcha
}).
then
(
e
=>
{
console
.
log
(
e
);
this
.
loginSuccess
(
e
)
}).
catch
(
e
=>
{
if
(
e
.
errCode
==
'
uni-id-captcha-required
'
)
{
this
.
$refs
.
popup
.
open
()
}
else
{
console
.
log
(
e
.
errMsg
);
console
.
log
(
e
.
errCode
);
}
}).
finally
(
e
=>
{
this
.
captcha
=
''
})
}
}
}
</
script
>
<
style
scoped
lang=
"scss"
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.tip
{
margin-top
:
-15px
;
margin-bottom
:
15px
;
}
.popup-captcha
{
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
padding
:
20rpx
;
background-color
:
#FFF
;
border-radius
:
2px
;
flex-direction
:
column
;
position
:
relative
;
}
.popup-captcha
.title
{
font-weight
:
normal
;
padding
:
0
;
padding-bottom
:
15px
;
color
:
#666
;
}
.popup-captcha
.close
{
position
:
absolute
;
bottom
:
-40px
;
margin-left
:
-13px
;
left
:
50%
;
}
.popup-captcha
.uni-btn
{
margin
:
0
;
}
console
.
log
(
'
onShow
'
);
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
submit
()
}
};
// #endif
},
methods
:
{
submit
()
{
//完成并提交
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,
{
errorOptions
:
{
type
:
'
toast
'
}
})
if
(
this
.
code
.
length
!=
6
)
{
this
.
$refs
.
smsCode
.
focusSmsCodeInput
=
true
return
uni
.
showToast
({
title
:
'
验证码不能为空
'
,
icon
:
'
none
'
});
}
uniIdCo
.
loginBySms
({
"
mobile
"
:
this
.
phone
,
"
code
"
:
this
.
code
,
"
captcha
"
:
this
.
captcha
}).
then
(
e
=>
{
console
.
log
(
e
);
this
.
loginSuccess
(
e
)
}).
catch
(
e
=>
{
if
(
e
.
errCode
==
'
uni-id-captcha-required
'
)
{
this
.
$refs
.
popup
.
open
()
}
else
{
console
.
log
(
e
.
errMsg
);
console
.
log
(
e
.
errCode
);
}
}).
finally
(
e
=>
{
this
.
captcha
=
''
})
}
}
}
</
script
>
<
style
scoped
lang=
"scss"
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.tip
{
margin-top
:
-15px
;
margin-bottom
:
15px
;
}
.popup-captcha
{
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
padding
:
20rpx
;
background-color
:
#FFF
;
border-radius
:
2px
;
flex-direction
:
column
;
position
:
relative
;
}
.popup-captcha
.title
{
font-weight
:
normal
;
padding
:
0
;
padding-bottom
:
15px
;
color
:
#666
;
}
.popup-captcha
.close
{
position
:
absolute
;
bottom
:
-40px
;
margin-left
:
-13px
;
left
:
50%
;
}
.popup-captcha
.uni-btn
{
margin
:
0
;
}
</
style
>
uni_modules/uni-id-pages/pages/login/login-withoutpwd.vue
浏览文件 @
69d0074a
<!-- 免密登陆页 -->
<
template
>
<view
class=
"uni-content"
>
<!-- 顶部文字 -->
<text
class=
"title"
>
请选择登录方式
</text>
<!-- 快捷登录框 当url带参数时有效 -->
<template
v-if=
"['apple','weixin'].includes(type)"
>
<text
class=
"tip"
>
将根据第三方账号服务平台的授权范围获取你的信息
</text>
<view
class=
"quickLogin"
>
<image
@
click=
"quickLogin"
:src=
"imgSrc"
mode=
"widthFix"
class=
"quickLoginBtn"
></image>
<uni-id-pages-agreements
scope=
"register"
ref=
"agreements"
></uni-id-pages-agreements>
</view>
</
template
>
<
template
v-else
>
<text
class=
"tip"
>
未注册的账号验证通过后将自动注册
</text>
<view
class=
"phone-box"
>
<view
@
click=
"chooseArea"
class=
"area"
>
+86
</view>
<uni-easyinput
:focus=
"focusPhone"
@
blur=
"focusPhone = false"
class=
"input-box"
type=
"number"
:inputBorder=
"false"
v-model=
"phone"
maxlength=
"11"
placeholder=
"请输入手机号"
/>
</view>
<uni-id-pages-agreements
scope=
"register"
ref=
"agreements"
></uni-id-pages-agreements>
<button
class=
"uni-btn"
type=
"primary"
@
click=
"toSmsPage"
>
获取验证码
</button>
</
template
>
<!-- 固定定位的快捷登录按钮 -->
<uni-id-pages-fab-login
ref=
"uniFabLogin"
></uni-id-pages-fab-login>
</view>
</template>
<
script
>
let
currentWebview
;
//当前窗口对象
import
config
from
'
@/uni_modules/uni-id-pages/config.js
'
import
mixin
from
'
../../common/login-page.mixin.js
'
;
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
type
:
""
,
//快捷登录方式
phone
:
""
,
//手机号码
focusPhone
:
false
}
},
computed
:
{
async
loginTypes
()
{
//读取配置的登录优先级
return
config
.
loginTypes
},
isPhone
()
{
//手机号码校验正则
return
/^1
\d{10}
$/
.
test
(
this
.
phone
);
},
imgSrc
()
{
//大快捷登录按钮图
return
'
/uni_modules/uni-id-pages/static/login/
'
+
this
.
type
+
'
.png
'
}
},
async
onLoad
(
e
)
{
console
.
log
(
e
);
let
type
=
e
.
type
// console.log({type});
this
.
type
=
type
if
(
type
!=
'
univerify
'
){
this
.
focusPhone
=
true
}
this
.
$nextTick
(()
=>
{
//关闭重复显示的登录快捷方式
if
([
'
weixin
'
,
'
apple
'
].
includes
(
type
))
{
this
.
$refs
.
uniFabLogin
.
servicesList
=
this
.
$refs
.
uniFabLogin
.
servicesList
.
filter
(
item
=>
item
.
id
!=
type
)
}
})
uni
.
$on
(
'
uni-id-pages-set-login-type
'
,
type
=>
{
this
.
type
=
type
})
},
onShow
()
{
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
toSmsPage
()
}
};
// #endif
},
onUnload
()
{
uni
.
$off
(
'
uni-id-pages-set-login-type
'
)
},
onReady
()
{
//是否优先启动一键登录。即:页面一加载就启动一键登录
//#ifdef APP-PLUS
if
(
this
.
type
==
"
univerify
"
)
{
this
.
type
==
this
.
loginTypes
[
1
]
// console.log('开始一键登录');
setTimeout
(()
=>
{
this
.
$refs
.
uniFabLogin
.
login_before
(
'
univerify
'
)
},
100
)
}
//#endif
},
methods
:
{
quickLogin
()
{
this
.
$refs
.
uniFabLogin
.
login_before
(
this
.
type
)
},
toSmsPage
()
{
console
.
log
(
'
toSmsPage
'
,
this
.
agree
);
if
(
!
this
.
isPhone
)
{
this
.
focusPhone
=
true
return
uni
.
showToast
({
title
:
"
手机号码格式不正确
"
,
icon
:
'
none
'
});
}
if
(
this
.
needAgreements
&&
!
this
.
agree
)
{
return
this
.
$refs
.
agreements
.
popup
(
this
.
toSmsPage
)
}
// 发送验证吗
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/login/login-smscode?phoneNumber=
'
+
this
.
phone
});
},
//去密码登录页
toPwdLogin
()
{
uni
.
navigateTo
({
url
:
'
../login/password
'
})
},
chooseArea
()
{
uni
.
showToast
({
title
:
'
暂不支持其他国家
'
,
icon
:
'
none
'
});
},
}
}
</
script
>
<
style
lang=
"scss"
scoped
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.uni-content
,
.quickLogin
{
/* #ifndef APP-NVUE */
display
:
flex
;
flex-direction
:
column
;
/* #endif */
}
.phone-box
{
position
:
relative
;
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
}
.area
{
position
:
absolute
;
left
:
10px
;
z-index
:
9
;
top
:
12px
;
font-size
:
14px
;
}
.
area
:
:
after
{
content
:
""
;
border
:
3px
solid
transparent
;
border-top-color
:
#000
;
top
:
12px
;
left
:
3px
;
position
:
relative
;
}
.input-box
{
/* #ifndef APP-NVUE */
box-sizing
:
border-box
;
/* #endif */
flex
:
1
;
padding-left
:
45px
;
margin-bottom
:
10px
;
border-radius
:
0
;
}
.quickLogin
{
width
:
650rpx
;
height
:
350px
;
align-items
:
center
;
justify-content
:
center
;
}
.quickLoginBtn
{
margin
:
20px
0
;
width
:
450rpx
;
height
:
82rpx
;
}
.tip
{
margin-top
:
-15px
;
margin-bottom
:
20px
;
}
</
style
>
<
template
>
<view
class=
"uni-content"
>
<!-- 顶部文字 -->
<text
class=
"title"
>
请选择登录方式
</text>
<!-- 快捷登录框 当url带参数时有效 -->
<template
v-if=
"['apple','weixin'].includes(type)"
>
<text
class=
"tip"
>
将根据第三方账号服务平台的授权范围获取你的信息
</text>
<view
class=
"quickLogin"
>
<image
@
click=
"quickLogin"
:src=
"imgSrc"
mode=
"widthFix"
class=
"quickLoginBtn"
></image>
<uni-id-pages-agreements
scope=
"register"
ref=
"agreements"
></uni-id-pages-agreements>
</view>
</
template
>
<
template
v-else
>
<text
class=
"tip"
>
未注册的账号验证通过后将自动注册
</text>
<view
class=
"phone-box"
>
<view
@
click=
"chooseArea"
class=
"area"
>
+86
</view>
<uni-easyinput
:focus=
"focusPhone"
@
blur=
"focusPhone = false"
class=
"input-box"
type=
"number"
:inputBorder=
"false"
v-model=
"phone"
maxlength=
"11"
placeholder=
"请输入手机号"
/>
</view>
<uni-id-pages-agreements
scope=
"register"
ref=
"agreements"
></uni-id-pages-agreements>
<button
class=
"uni-btn"
type=
"primary"
@
click=
"toSmsPage"
>
获取验证码
</button>
</
template
>
<!-- 固定定位的快捷登录按钮 -->
<uni-id-pages-fab-login
ref=
"uniFabLogin"
></uni-id-pages-fab-login>
</view>
</template>
<
script
>
let
currentWebview
;
//当前窗口对象
import
config
from
'
@/uni_modules/uni-id-pages/config.js
'
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
type
:
""
,
//快捷登录方式
phone
:
""
,
//手机号码
focusPhone
:
false
}
},
computed
:
{
async
loginTypes
()
{
//读取配置的登录优先级
return
config
.
loginTypes
},
isPhone
()
{
//手机号码校验正则
return
/^1
\d{10}
$/
.
test
(
this
.
phone
);
},
imgSrc
()
{
//大快捷登录按钮图
return
'
/uni_modules/uni-id-pages/static/login/
'
+
this
.
type
+
'
.png
'
}
},
async
onLoad
(
e
)
{
console
.
log
(
e
);
let
type
=
e
.
type
// console.log({type});
this
.
type
=
type
if
(
type
!=
'
univerify
'
){
this
.
focusPhone
=
true
}
this
.
$nextTick
(()
=>
{
//关闭重复显示的登录快捷方式
if
([
'
weixin
'
,
'
apple
'
].
includes
(
type
))
{
this
.
$refs
.
uniFabLogin
.
servicesList
=
this
.
$refs
.
uniFabLogin
.
servicesList
.
filter
(
item
=>
item
.
id
!=
type
)
}
})
uni
.
$on
(
'
uni-id-pages-set-login-type
'
,
type
=>
{
this
.
type
=
type
})
},
onShow
()
{
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
toSmsPage
()
}
};
// #endif
},
onUnload
()
{
uni
.
$off
(
'
uni-id-pages-set-login-type
'
)
},
onReady
()
{
//是否优先启动一键登录。即:页面一加载就启动一键登录
//#ifdef APP-PLUS
if
(
this
.
type
==
"
univerify
"
)
{
this
.
type
==
this
.
loginTypes
[
1
]
// console.log('开始一键登录');
setTimeout
(()
=>
{
this
.
$refs
.
uniFabLogin
.
login_before
(
'
univerify
'
)
},
100
)
}
//#endif
},
methods
:
{
quickLogin
()
{
this
.
$refs
.
uniFabLogin
.
login_before
(
this
.
type
)
},
toSmsPage
()
{
console
.
log
(
'
toSmsPage
'
,
this
.
agree
);
if
(
!
this
.
isPhone
)
{
this
.
focusPhone
=
true
return
uni
.
showToast
({
title
:
"
手机号码格式不正确
"
,
icon
:
'
none
'
});
}
if
(
this
.
needAgreements
&&
!
this
.
agree
)
{
return
this
.
$refs
.
agreements
.
popup
(
this
.
toSmsPage
)
}
// 发送验证吗
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/login/login-smscode?phoneNumber=
'
+
this
.
phone
});
},
//去密码登录页
toPwdLogin
()
{
uni
.
navigateTo
({
url
:
'
../login/password
'
})
},
chooseArea
()
{
uni
.
showToast
({
title
:
'
暂不支持其他国家
'
,
icon
:
'
none
'
});
},
}
}
</
script
>
<
style
lang=
"scss"
scoped
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.uni-content
,
.quickLogin
{
/* #ifndef APP-NVUE */
display
:
flex
;
flex-direction
:
column
;
/* #endif */
}
.phone-box
{
position
:
relative
;
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
}
.area
{
position
:
absolute
;
left
:
10px
;
z-index
:
9
;
top
:
12px
;
font-size
:
14px
;
}
.
area
:
:
after
{
content
:
""
;
border
:
3px
solid
transparent
;
border-top-color
:
#000
;
top
:
12px
;
left
:
3px
;
position
:
relative
;
}
.input-box
{
/* #ifndef APP-NVUE */
box-sizing
:
border-box
;
/* #endif */
flex
:
1
;
padding-left
:
45px
;
margin-bottom
:
10px
;
border-radius
:
0
;
}
.quickLogin
{
width
:
650rpx
;
height
:
350px
;
align-items
:
center
;
justify-content
:
center
;
}
.quickLoginBtn
{
margin
:
20px
0
;
width
:
450rpx
;
height
:
82rpx
;
}
.tip
{
margin-top
:
-15px
;
margin-bottom
:
20px
;
}
</
style
>
uni_modules/uni-id-pages/pages/login/login-withpwd.vue
浏览文件 @
69d0074a
<!-- 账号密码登陆页 -->
<
template
>
<view
class=
"uni-content"
>
<!-- 顶部文字 -->
<text
class=
"title title-box"
>
账号密码登录
</text>
<uni-forms>
<uni-forms-item
name=
"username"
>
<uni-easyinput
:focus=
"focusUsername"
@
blur=
"focusUsername = false"
class=
"input-box"
:inputBorder=
"false"
v-model=
"username"
placeholder=
"请输入手机号/用户名"
/>
</uni-forms-item>
<uni-forms-item
name=
"password"
>
<uni-easyinput
:focus=
"focusPassword"
@
blur=
"focusPassword = false"
class=
"input-box"
clearable
type=
"password"
:inputBorder=
"false"
v-model=
"password"
placeholder=
"请输入密码"
/>
</uni-forms-item>
</uni-forms>
<uni-captcha
v-if=
"needCaptcha"
focus
ref=
"captcha"
scene=
"login-by-pwd"
v-model=
"captcha"
/>
<!-- 带选择框的隐私政策协议组件 -->
<uni-id-pages-agreements
scope=
"login"
ref=
"agreements"
></uni-id-pages-agreements>
<button
class=
"uni-btn"
type=
"primary"
@
click=
"pwdLogin"
>
登录
</button>
<!-- 忘记密码 -->
<view
class=
"link-box"
>
<view>
<text
class=
"forget"
>
忘记了?
</text>
<text
class=
"link"
@
click=
"toRetrievePwd"
>
找回密码
</text>
</view>
<text
class=
"link"
@
click=
"toRegister"
>
注册账号
</text>
</view>
<!-- 悬浮登录方式组件 -->
<uni-id-pages-fab-login
ref=
"uniFabLogin"
></uni-id-pages-fab-login>
</view>
</
template
>
<
script
>
import
mixin
from
'
../../common/login-page.mixin.js
'
;
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,{
errorOptions
:{
type
:
'
toast
'
}
})
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
"
password
"
:
""
,
"
username
"
:
""
,
"
captcha
"
:
""
,
"
needCaptcha
"
:
false
,
"
focusUsername
"
:
false
,
"
focusPassword
"
:
false
}
},
onShow
()
{
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
pwdLogin
()
}
};
// #endif
},
methods
:
{
// 页面跳转,找回密码
toRetrievePwd
()
{
let
url
=
'
/uni_modules/uni-id-pages/pages/retrieve/retrieve
'
//如果
更好用户名输入框的值为手机号码,就把它传到根据手机验证码找回密码页面
if
(
/^1
\d{10}
$/
.
test
(
this
.
username
))
{
url
+=
`?phoneNumber=
${
this
.
username
}
`
}
uni
.
navigateTo
({
url
})
},
/**
* 密码登录
*/
pwdLogin
()
{
if
(
!
this
.
password
.
length
){
this
.
focusPassword
=
true
return
uni
.
showToast
({
title
:
'
请输入密码
'
,
icon
:
'
none
'
});
}
if
(
!
this
.
username
.
length
){
this
.
focusUsername
=
true
return
uni
.
showToast
({
title
:
'
请输入手机号/用户名
'
,
icon
:
'
none
'
});
}
if
(
this
.
needCaptcha
&&
this
.
captcha
.
length
!=
4
){
this
.
$refs
.
captcha
.
getImageCaptcha
()
return
uni
.
showToast
({
title
:
'
请输入验证码
'
,
icon
:
'
none
'
});
}
if
(
this
.
needAgreements
&&
!
this
.
agree
)
{
return
this
.
$refs
.
agreements
.
popup
(
this
.
pwdLogin
)
<
template
>
<view
class=
"uni-content"
>
<!-- 顶部文字 -->
<text
class=
"title title-box"
>
账号密码登录
</text>
<uni-forms>
<uni-forms-item
name=
"username"
>
<uni-easyinput
:focus=
"focusUsername"
@
blur=
"focusUsername = false"
class=
"input-box"
:inputBorder=
"false"
v-model=
"username"
placeholder=
"请输入手机号/用户名"
/>
</uni-forms-item>
<uni-forms-item
name=
"password"
>
<uni-easyinput
:focus=
"focusPassword"
@
blur=
"focusPassword = false"
class=
"input-box"
clearable
type=
"password"
:inputBorder=
"false"
v-model=
"password"
placeholder=
"请输入密码"
/>
</uni-forms-item>
</uni-forms>
<uni-captcha
v-if=
"needCaptcha"
focus
ref=
"captcha"
scene=
"login-by-pwd"
v-model=
"captcha"
/>
<!-- 带选择框的隐私政策协议组件 -->
<uni-id-pages-agreements
scope=
"login"
ref=
"agreements"
></uni-id-pages-agreements>
<button
class=
"uni-btn"
type=
"primary"
@
click=
"pwdLogin"
>
登录
</button>
<!-- 忘记密码 -->
<view
class=
"link-box"
>
<view>
<text
class=
"forget"
>
忘记了?
</text>
<text
class=
"link"
@
click=
"toRetrievePwd"
>
找回密码
</text>
</view>
<text
class=
"link"
@
click=
"toRegister"
>
注册账号
</text>
</view>
<!-- 悬浮登录方式组件 -->
<uni-id-pages-fab-login
ref=
"uniFabLogin"
></uni-id-pages-fab-login>
</view>
</
template
>
<
script
>
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,{
errorOptions
:{
type
:
'
toast
'
}
})
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
"
password
"
:
""
,
"
username
"
:
""
,
"
captcha
"
:
""
,
"
needCaptcha
"
:
false
,
"
focusUsername
"
:
false
,
"
focusPassword
"
:
false
}
},
onShow
()
{
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
pwdLogin
()
}
};
// #endif
},
methods
:
{
// 页面跳转,找回密码
toRetrievePwd
()
{
let
url
=
'
/uni_modules/uni-id-pages/pages/retrieve/retrieve
'
//如果
刚好用户名输入框的值为手机号码,就把它传到根据手机验证码找回密码页面
if
(
/^1
\d{10}
$/
.
test
(
this
.
username
))
{
url
+=
`?phoneNumber=
${
this
.
username
}
`
}
uni
.
navigateTo
({
url
})
},
/**
* 密码登录
*/
pwdLogin
()
{
if
(
!
this
.
password
.
length
){
this
.
focusPassword
=
true
return
uni
.
showToast
({
title
:
'
请输入密码
'
,
icon
:
'
none
'
});
}
if
(
!
this
.
username
.
length
){
this
.
focusUsername
=
true
return
uni
.
showToast
({
title
:
'
请输入手机号/用户名
'
,
icon
:
'
none
'
});
}
if
(
this
.
needCaptcha
&&
this
.
captcha
.
length
!=
4
){
this
.
$refs
.
captcha
.
getImageCaptcha
()
return
uni
.
showToast
({
title
:
'
请输入验证码
'
,
icon
:
'
none
'
});
}
if
(
this
.
needAgreements
&&
!
this
.
agree
)
{
return
this
.
$refs
.
agreements
.
popup
(
this
.
pwdLogin
)
}
let
data
=
{
...
...
@@ -111,52 +111,52 @@
data
.
username
=
this
.
username
}
uniIdCo
.
login
(
data
).
then
(
e
=>
{
this
.
loginSuccess
(
e
)
}).
catch
(
e
=>
{
console
.
log
(
JSON
.
stringify
(
e
));
switch
(
e
.
errCode
){
case
'
uni-id-captcha-required
'
:
this
.
needCaptcha
=
true
break
;
case
10104
:
//
更好的体验:登录错误,直接刷新验证码
this
.
$refs
.
captcha
.
getImageCaptcha
()
break
;
default
:
break
;
}
})
},
/* 前往注册 */
toRegister
(
e
)
{
console
.
log
(
e
);
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/register/register
'
})
}
}
}
</
script
>
<
style
lang=
"scss"
scoped
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.forget
{
font-size
:
12px
;
color
:
#8a8f8b
;
}
.link-box
{
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
flex-direction
:
row
;
justify-content
:
space-between
;
margin-top
:
20px
;
}
.link
{
font-size
:
12px
;
}
</
style
>
uniIdCo
.
login
(
data
).
then
(
e
=>
{
this
.
loginSuccess
(
e
)
}).
catch
(
e
=>
{
console
.
log
(
JSON
.
stringify
(
e
));
switch
(
e
.
errCode
){
case
'
uni-id-captcha-required
'
:
this
.
needCaptcha
=
true
break
;
case
'
uni-captcha-verify-fail
'
:
//
当验证码错误,重新获取
this
.
$refs
.
captcha
.
getImageCaptcha
()
break
;
default
:
break
;
}
})
},
/* 前往注册 */
toRegister
(
e
)
{
console
.
log
(
e
);
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/register/register
'
})
}
}
}
</
script
>
<
style
lang=
"scss"
scoped
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.forget
{
font-size
:
12px
;
color
:
#8a8f8b
;
}
.link-box
{
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
flex-direction
:
row
;
justify-content
:
space-between
;
margin-top
:
20px
;
}
.link
{
font-size
:
12px
;
}
</
style
>
uni_modules/uni-id-pages/pages/register/register.vue
浏览文件 @
69d0074a
<!-- 账号注册页 -->
<
template
>
<view
class=
"uni-content"
>
<uni-forms
ref=
"form"
:value=
"formData"
:rules=
"rules"
validate-trigger=
"submit"
err-show-type=
"toast"
>
<uni-forms-item
name=
"username"
required
>
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusUsername"
@
blur=
"focusUsername = false"
class=
"input-box"
placeholder=
"请输入用户名"
v-model=
"formData.username"
trim=
"both"
/>
</uni-forms-item>
<uni-forms-item
name=
"nickname"
>
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusNickname"
@
blur=
"focusNickname = false"
class=
"input-box"
placeholder=
"请输入用户昵称"
v-model=
"formData.nickname"
trim=
"both"
/>
</uni-forms-item>
<uni-forms-item
name=
"password"
v-model=
"formData.password"
required
>
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusPassword"
@
blur=
"focusPassword = false"
class=
"input-box"
maxlength=
"20"
placeholder=
"请输入6-20位密码"
type=
"password"
v-model=
"formData.password"
trim=
"both"
/>
</uni-forms-item>
<uni-forms-item
name=
"password2"
v-model=
"formData.password2"
required
>
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusPassword2"
@
blur=
"focusPassword2 =false"
class=
"input-box"
placeholder=
"再次输入密码"
maxlength=
"20"
type=
"password"
v-model=
"formData.password2"
trim=
"both"
/>
</uni-forms-item>
<uni-forms-item>
<uni-captcha
ref=
"captcha"
scene=
"register"
v-model=
"formData.captcha"
/>
</uni-forms-item>
<uni-id-pages-agreements
scope=
"register"
ref=
"agreements"
></uni-id-pages-agreements>
<button
class=
"uni-btn"
type=
"primary"
@
click=
"submit"
>
注册
</button>
<button
@
click=
"navigateBack"
>
返回
</button>
</uni-forms>
</view>
</
template
>
<
script
>
import
rules
from
'
./validator.js
'
;
import
mixin
from
'
../../common/login-page.mixin.js
'
;
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
)
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
formData
:
{
username
:
""
,
nickname
:
""
,
password
:
""
,
password2
:
""
,
captcha
:
""
},
rules
,
<
template
>
<view
class=
"uni-content"
>
<uni-forms
ref=
"form"
:value=
"formData"
:rules=
"rules"
validate-trigger=
"submit"
err-show-type=
"toast"
>
<uni-forms-item
name=
"username"
required
>
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusUsername"
@
blur=
"focusUsername = false"
class=
"input-box"
placeholder=
"请输入用户名"
v-model=
"formData.username"
trim=
"both"
/>
</uni-forms-item>
<uni-forms-item
name=
"nickname"
>
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusNickname"
@
blur=
"focusNickname = false"
class=
"input-box"
placeholder=
"请输入用户昵称"
v-model=
"formData.nickname"
trim=
"both"
/>
</uni-forms-item>
<uni-forms-item
name=
"password"
v-model=
"formData.password"
required
>
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusPassword"
@
blur=
"focusPassword = false"
class=
"input-box"
maxlength=
"20"
placeholder=
"请输入6-20位密码"
type=
"password"
v-model=
"formData.password"
trim=
"both"
/>
</uni-forms-item>
<uni-forms-item
name=
"password2"
v-model=
"formData.password2"
required
>
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusPassword2"
@
blur=
"focusPassword2 =false"
class=
"input-box"
placeholder=
"再次输入密码"
maxlength=
"20"
type=
"password"
v-model=
"formData.password2"
trim=
"both"
/>
</uni-forms-item>
<uni-forms-item>
<uni-captcha
ref=
"captcha"
scene=
"register"
v-model=
"formData.captcha"
/>
</uni-forms-item>
<uni-id-pages-agreements
scope=
"register"
ref=
"agreements"
></uni-id-pages-agreements>
<button
class=
"uni-btn"
type=
"primary"
@
click=
"submit"
>
注册
</button>
<button
@
click=
"navigateBack"
>
返回
</button>
</uni-forms>
</view>
</
template
>
<
script
>
import
rules
from
'
./validator.js
'
;
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
)
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
formData
:
{
username
:
""
,
nickname
:
""
,
password
:
""
,
password2
:
""
,
captcha
:
""
},
rules
,
focusUsername
:
false
,
focusNickname
:
false
,
focusPassword
:
false
,
focusPassword2
:
false
}
},
onReady
()
{
this
.
$refs
.
form
.
setRules
(
this
.
rules
)
},
onShow
()
{
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
submit
()
}
};
// #endif
},
methods
:
{
/**
* 触发表单提交
*/
submit
()
{
this
.
$refs
.
form
.
validate
().
then
((
res
)
=>
{
if
(
this
.
formData
.
captcha
.
length
!=
4
){
this
.
$refs
.
captcha
.
focusCaptchaInput
=
true
return
uni
.
showToast
({
title
:
'
请输入验证码
'
,
icon
:
'
none
'
});
}
if
(
this
.
needAgreements
&&
!
this
.
agree
)
{
return
this
.
$refs
.
agreements
.
popup
(()
=>
{
this
.
submitForm
(
res
)
})
}
this
.
submitForm
(
res
)
}).
catch
((
errors
)
=>
{
let
key
=
errors
[
0
].
key
key
=
key
.
replace
(
key
[
0
],
key
[
0
].
toUpperCase
())
console
.
log
(
key
);
this
[
'
focus
'
+
key
]
=
true
})
},
submitForm
(
params
)
{
uniIdCo
.
registerUser
(
this
.
formData
).
then
(
e
=>
{
console
.
log
(
e
);
uni
.
navigateBack
()
})
.
catch
(
e
=>
{
console
.
log
(
e
);
console
.
log
(
e
.
message
);
//更好的体验:登录错误,直接刷新验证码
this
.
$refs
.
captcha
.
getImageCaptcha
()
})
},
navigateBack
()
{
uni
.
navigateBack
()
}
}
}
</
script
>
<
style
lang=
"scss"
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.
uni-content
:
:
v-deep
.
uni-forms-item__label
{
position
:
absolute
;
left
:
-15px
;
}
button
{
margin-top
:
15px
;
}
</
style
>
focusNickname
:
false
,
focusPassword
:
false
,
focusPassword2
:
false
}
},
onReady
()
{
this
.
$refs
.
form
.
setRules
(
this
.
rules
)
},
onShow
()
{
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
submit
()
}
};
// #endif
},
methods
:
{
/**
* 触发表单提交
*/
submit
()
{
this
.
$refs
.
form
.
validate
().
then
((
res
)
=>
{
if
(
this
.
formData
.
captcha
.
length
!=
4
){
this
.
$refs
.
captcha
.
focusCaptchaInput
=
true
return
uni
.
showToast
({
title
:
'
请输入验证码
'
,
icon
:
'
none
'
});
}
if
(
this
.
needAgreements
&&
!
this
.
agree
)
{
return
this
.
$refs
.
agreements
.
popup
(()
=>
{
this
.
submitForm
(
res
)
})
}
this
.
submitForm
(
res
)
}).
catch
((
errors
)
=>
{
let
key
=
errors
[
0
].
key
key
=
key
.
replace
(
key
[
0
],
key
[
0
].
toUpperCase
())
console
.
log
(
key
);
this
[
'
focus
'
+
key
]
=
true
})
},
submitForm
(
params
)
{
uniIdCo
.
registerUser
(
this
.
formData
).
then
(
e
=>
{
console
.
log
(
e
);
uni
.
navigateBack
()
})
.
catch
(
e
=>
{
console
.
log
(
e
);
console
.
log
(
e
.
message
);
//更好的体验:登录错误,直接刷新验证码
this
.
$refs
.
captcha
.
getImageCaptcha
()
})
},
navigateBack
()
{
uni
.
navigateBack
()
}
}
}
</
script
>
<
style
lang=
"scss"
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.
uni-content
:
:
v-deep
.
uni-forms-item__label
{
position
:
absolute
;
left
:
-15px
;
}
button
{
margin-top
:
15px
;
}
</
style
>
uni_modules/uni-id-pages/pages/retrieve/retrieve.vue
浏览文件 @
69d0074a
<!-- 找回密码页 -->
<
template
>
<view
class=
"uni-content"
>
<uni-forms
ref=
"form"
:value=
"formData"
err-show-type=
"toast"
>
<uni-forms-item
name=
"phone"
>
<uni-easyinput
:focus=
"focusPhone"
@
blur=
"focusPhone = false"
class=
"input-box"
:disabled=
"lock"
type=
"number"
:inputBorder=
"false"
v-model=
"formData.phone"
maxlength=
"11"
placeholder=
"请输入手机号"
>
</uni-easyinput>
</uni-forms-item>
<uni-forms-item
name=
"code"
>
<uni-id-pages-sms-form
ref=
"shortCode"
:phone=
"formData.phone"
type=
"reset-pwd-by-sms"
v-model=
"formData.code"
>
</uni-id-pages-sms-form>
</uni-forms-item>
<uni-forms-item
name=
"password"
>
<uni-easyinput
:focus=
"focusPassword"
@
blur=
"focusPassword = false"
class=
"input-box"
type=
"password"
:inputBorder=
"false"
v-model=
"formData.password"
placeholder=
"请输入新密码"
></uni-easyinput>
</uni-forms-item>
<uni-forms-item
name=
"password2"
>
<uni-easyinput
:focus=
"focusPassword2"
@
blur=
"focusPassword2 = false"
class=
"input-box"
type=
"password"
:inputBorder=
"false"
v-model=
"formData.password2"
placeholder=
"请
确认新密码"
></uni-easyinput>
</uni-forms-item>
<button
class=
"uni-btn send-btn-box"
type=
"primary"
@
click=
"submit"
>
完成
</button>
</uni-forms>
<uni-popup-captcha
@
confirm=
"submit"
v-model=
"formData.captcha"
scene=
"reset-pwd-by-sms"
ref=
"popup"
></uni-popup-captcha>
</view>
</
template
>
<
script
>
import
mixin
from
'
../../common/login-page.mixin.js
'
;
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,{
errorOptions
:{
type
:
'
toast
'
}
})
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
lock
:
false
,
focusPhone
:
true
,
focusPassword
:
false
,
focusPassword2
:
false
,
formData
:
{
"
phone
"
:
""
,
"
code
"
:
""
,
'
password
'
:
''
,
'
password2
'
:
''
,
"
captcha
"
:
""
},
rules
:
{
phone
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请输入手机号
'
,
},
{
pattern
:
/^1
\d{10}
$/
,
errorMessage
:
'
手机号码格式不正确
'
,
}
]
},
code
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请输入短信验证码
'
,
},
{
pattern
:
/^.
{6}
$/
,
errorMessage
:
'
请输入6位验证码
'
,
}
]
},
password
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请输入新密码
'
,
},
{
pattern
:
/^.
{6,20}
$/
,
errorMessage
:
'
密码为6 - 20位
'
,
}
]
},
password2
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请确认密码
'
,
},
{
pattern
:
/^.
{6,20}
$/
,
errorMessage
:
'
密码为6 - 20位
'
,
},
{
validateFunction
:
function
(
rule
,
value
,
data
,
callback
)
{
// console.log(value);
if
(
value
!=
data
.
password
)
{
callback
(
'
两次输入密码不一致
'
)
};
return
true
}
}
]
}
}
}
},
computed
:
{
isPhone
()
{
let
reg_phone
=
/^1
\d{10}
$/
;
let
isPhone
=
reg_phone
.
test
(
this
.
formData
.
phone
);
return
isPhone
;
},
isPwd
()
{
let
reg_pwd
=
/^.
{6,20}
$/
;
let
isPwd
=
reg_pwd
.
test
(
this
.
formData
.
password
);
return
isPwd
;
},
isCode
()
{
let
reg_code
=
/^
\d{6}
$/
;
let
isCode
=
reg_code
.
test
(
this
.
formData
.
code
);
return
isCode
;
}
},
onLoad
(
event
)
{
<
template
>
<view
class=
"uni-content"
>
<uni-forms
ref=
"form"
:value=
"formData"
err-show-type=
"toast"
>
<uni-forms-item
name=
"phone"
>
<uni-easyinput
:focus=
"focusPhone"
@
blur=
"focusPhone = false"
class=
"input-box"
:disabled=
"lock"
type=
"number"
:inputBorder=
"false"
v-model=
"formData.phone"
maxlength=
"11"
placeholder=
"请输入手机号"
>
</uni-easyinput>
</uni-forms-item>
<uni-forms-item
name=
"code"
>
<uni-id-pages-sms-form
ref=
"shortCode"
:phone=
"formData.phone"
type=
"reset-pwd-by-sms"
v-model=
"formData.code"
>
</uni-id-pages-sms-form>
</uni-forms-item>
<uni-forms-item
name=
"password"
>
<uni-easyinput
:focus=
"focusPassword"
@
blur=
"focusPassword = false"
class=
"input-box"
type=
"password"
:inputBorder=
"false"
v-model=
"formData.password"
placeholder=
"请输入新密码"
></uni-easyinput>
</uni-forms-item>
<uni-forms-item
name=
"password2"
>
<uni-easyinput
:focus=
"focusPassword2"
@
blur=
"focusPassword2 = false"
class=
"input-box"
type=
"password"
:inputBorder=
"false"
v-model=
"formData.password2"
placeholder=
"请
再次输入新密码"
></uni-easyinput>
</uni-forms-item>
<button
class=
"uni-btn send-btn-box"
type=
"primary"
@
click=
"submit"
>
提交
</button>
</uni-forms>
<uni-popup-captcha
@
confirm=
"submit"
v-model=
"formData.captcha"
scene=
"reset-pwd-by-sms"
ref=
"popup"
></uni-popup-captcha>
</view>
</
template
>
<
script
>
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,{
errorOptions
:{
type
:
'
toast
'
}
})
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
lock
:
false
,
focusPhone
:
true
,
focusPassword
:
false
,
focusPassword2
:
false
,
formData
:
{
"
phone
"
:
""
,
"
code
"
:
""
,
'
password
'
:
''
,
'
password2
'
:
''
,
"
captcha
"
:
""
},
rules
:
{
phone
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请输入手机号
'
,
},
{
pattern
:
/^1
\d{10}
$/
,
errorMessage
:
'
手机号码格式不正确
'
,
}
]
},
code
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请输入短信验证码
'
,
},
{
pattern
:
/^.
{6}
$/
,
errorMessage
:
'
请输入6位验证码
'
,
}
]
},
password
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请输入新密码
'
,
},
{
pattern
:
/^.
{6,20}
$/
,
errorMessage
:
'
密码为6 - 20位
'
,
}
]
},
password2
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请确认密码
'
,
},
{
pattern
:
/^.
{6,20}
$/
,
errorMessage
:
'
密码为6 - 20位
'
,
},
{
validateFunction
:
function
(
rule
,
value
,
data
,
callback
)
{
// console.log(value);
if
(
value
!=
data
.
password
)
{
callback
(
'
两次输入密码不一致
'
)
};
return
true
}
}
]
}
}
}
},
computed
:
{
isPhone
()
{
let
reg_phone
=
/^1
\d{10}
$/
;
let
isPhone
=
reg_phone
.
test
(
this
.
formData
.
phone
);
return
isPhone
;
},
isPwd
()
{
let
reg_pwd
=
/^.
{6,20}
$/
;
let
isPwd
=
reg_pwd
.
test
(
this
.
formData
.
password
);
return
isPwd
;
},
isCode
()
{
let
reg_code
=
/^
\d{6}
$/
;
let
isCode
=
reg_code
.
test
(
this
.
formData
.
code
);
return
isCode
;
}
},
onLoad
(
event
)
{
if
(
event
&&
event
.
phoneNumber
)
{
this
.
formData
.
phone
=
event
.
phoneNumber
;
if
(
event
.
lock
){
this
.
lock
=
event
.
lock
//如果是已经登录的账号,点击找回密码就锁定指定的账号绑定的手机号码
this
.
focusPhone
=
true
}
}
},
onReady
()
{
if
(
this
.
formData
.
phone
)
{
this
.
$refs
.
shortCode
.
start
();
}
this
.
$refs
.
form
.
setRules
(
this
.
rules
)
},
onShow
()
{
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
submit
()
}
};
// #endif
},
methods
:
{
/**
* 完成并提交
*/
submit
()
{
console
.
log
(
"
formData
"
,
this
.
formData
);
console
.
log
(
'
rules
'
,
this
.
rules
);
this
.
$refs
.
form
.
validate
()
.
then
(
res
=>
{
let
{
"
phone
"
:
mobile
,
"
password
"
:
password
,
captcha
,
code
}
=
this
.
formData
uniIdCo
.
resetPwdBySms
({
mobile
,
code
,
password
,
captcha
}).
then
(
e
=>
{
console
.
log
(
e
);
uni
.
navigateBack
()
})
.
catch
(
e
=>
{
if
(
e
.
errCode
==
'
uni-id-captcha-required
'
)
{
this
.
$refs
.
popup
.
open
()
}
}).
finally
(
e
=>
{
this
.
formData
.
captcha
=
""
})
}).
catch
(
errors
=>
{
let
key
=
errors
[
0
].
key
if
(
key
==
'
code
'
){
console
.
log
(
this
.
$refs
.
shortCode
);
return
this
.
$refs
.
shortCode
.
focusSmsCodeInput
=
true
}
key
=
key
.
replace
(
key
[
0
],
key
[
0
].
toUpperCase
())
console
.
log
(
key
,
'
focus
'
+
key
);
this
[
'
focus
'
+
key
]
=
true
})
}
}
}
</
script
>
<
style
lang=
"scss"
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.uni-content
{
margin-top
:
15px
;
}
</
style
>
this
.
formData
.
phone
=
event
.
phoneNumber
;
if
(
event
.
lock
){
this
.
lock
=
event
.
lock
//如果是已经登录的账号,点击找回密码就锁定指定的账号绑定的手机号码
this
.
focusPhone
=
true
}
}
},
onReady
()
{
if
(
this
.
formData
.
phone
)
{
this
.
$refs
.
shortCode
.
start
();
}
this
.
$refs
.
form
.
setRules
(
this
.
rules
)
},
onShow
()
{
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
submit
()
}
};
// #endif
},
methods
:
{
/**
* 完成并提交
*/
submit
()
{
console
.
log
(
"
formData
"
,
this
.
formData
);
console
.
log
(
'
rules
'
,
this
.
rules
);
this
.
$refs
.
form
.
validate
()
.
then
(
res
=>
{
let
{
"
phone
"
:
mobile
,
"
password
"
:
password
,
captcha
,
code
}
=
this
.
formData
uniIdCo
.
resetPwdBySms
({
mobile
,
code
,
password
,
captcha
}).
then
(
e
=>
{
console
.
log
(
e
);
uni
.
navigateBack
()
})
.
catch
(
e
=>
{
if
(
e
.
errCode
==
'
uni-id-captcha-required
'
)
{
this
.
$refs
.
popup
.
open
()
}
}).
finally
(
e
=>
{
this
.
formData
.
captcha
=
""
})
}).
catch
(
errors
=>
{
let
key
=
errors
[
0
].
key
if
(
key
==
'
code
'
){
console
.
log
(
this
.
$refs
.
shortCode
);
return
this
.
$refs
.
shortCode
.
focusSmsCodeInput
=
true
}
key
=
key
.
replace
(
key
[
0
],
key
[
0
].
toUpperCase
())
console
.
log
(
key
,
'
focus
'
+
key
);
this
[
'
focus
'
+
key
]
=
true
})
}
}
}
</
script
>
<
style
lang=
"scss"
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.uni-content
{
margin-top
:
15px
;
}
</
style
>
uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue
0 → 100644
浏览文件 @
69d0074a
<!-- 修改密码 -->
<
template
>
<view
class=
"uni-content"
>
<uni-forms
ref=
"form"
:value=
"formData"
err-show-type=
"toast"
>
<uni-forms-item
name=
"oldPassword"
>
<uni-easyinput
:focus=
"focusOldPassword"
@
blur=
"focusOldPassword = false"
class=
"input-box"
type=
"password"
:inputBorder=
"false"
v-model=
"formData.oldPassword"
placeholder=
"请输入旧密码"
>
</uni-easyinput>
</uni-forms-item>
<uni-forms-item
name=
"newPassword"
>
<uni-easyinput
:focus=
"focusNewPassword"
@
blur=
"focusNewPassword = false"
class=
"input-box"
type=
"password"
:inputBorder=
"false"
v-model=
"formData.newPassword"
placeholder=
"请输入新密码"
>
</uni-easyinput>
</uni-forms-item>
<uni-forms-item
name=
"newPassword2"
>
<uni-easyinput
:focus=
"focusNewPassword2"
@
blur=
"focusNewPassword2 = false"
class=
"input-box"
type=
"password"
:inputBorder=
"false"
v-model=
"formData.newPassword2"
placeholder=
"请再次输入新密码"
>
</uni-easyinput>
</uni-forms-item>
<button
class=
"uni-btn send-btn-box"
type=
"primary"
@
click=
"submit"
>
提交
</button>
</uni-forms>
</view>
</
template
>
<
script
>
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,
{
customUI
:
true
})
export
default
{
mixins
:
[
mixin
],
data
()
{
return
{
focusOldPassword
:
false
,
focusNewPassword
:
false
,
focusNewPassword2
:
false
,
formData
:
{
'
oldPassword
'
:
''
,
'
newPassword
'
:
''
,
'
newPassword2
'
:
''
,
},
rules
:
{
oldPassword
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请输入新密码
'
,
},
{
pattern
:
/^.
{6,20}
$/
,
errorMessage
:
'
密码为6 - 20位
'
,
}
]
},
newPassword
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请输入新密码
'
,
},
{
pattern
:
/^.
{6,20}
$/
,
errorMessage
:
'
密码为6 - 20位
'
,
}
]
},
newPassword2
:
{
rules
:
[{
required
:
true
,
errorMessage
:
'
请确认密码
'
,
},
{
pattern
:
/^.
{6,20}
$/
,
errorMessage
:
'
密码为6 - 20位
'
,
},
{
validateFunction
:
function
(
rule
,
value
,
data
,
callback
)
{
if
(
value
!=
data
.
newPassword
)
{
callback
(
'
两次输入密码不一致
'
)
};
return
true
}
}
]
}
}
}
},
onReady
()
{
this
.
$refs
.
form
.
setRules
(
this
.
rules
)
},
onShow
()
{
// #ifdef H5
document
.
onkeydown
=
event
=>
{
var
e
=
event
||
window
.
event
;
if
(
e
&&
e
.
keyCode
==
13
)
{
//回车键的键值为13
this
.
submit
()
}
};
// #endif
},
methods
:
{
/**
* 完成并提交
*/
submit
()
{
console
.
log
(
"
formData
"
,
this
.
formData
);
console
.
log
(
'
rules
'
,
this
.
rules
);
this
.
$refs
.
form
.
validate
()
.
then
(
res
=>
{
let
{
oldPassword
,
newPassword
}
=
this
.
formData
uniIdCo
.
updatePwd
({
oldPassword
,
newPassword
}).
then
(
e
=>
{
console
.
log
(
e
);
uni
.
removeStorageSync
(
'
uni_id_token
'
);
uni
.
setStorageSync
(
'
uni_id_token_expired
'
,
0
)
uni
.
redirectTo
({
url
:
'
/uni_modules/uni-id-pages/pages/login/login-withpwd
'
})
}).
catch
(
e
=>
{
uni
.
showModal
({
content
:
e
.
message
,
showCancel
:
false
});
})
}).
catch
(
errors
=>
{
let
key
=
errors
[
0
].
key
key
=
key
.
replace
(
key
[
0
],
key
[
0
].
toUpperCase
())
console
.
log
(
key
,
'
focus
'
+
key
);
this
[
'
focus
'
+
key
]
=
true
})
}
}
}
</
script
>
<
style
lang=
"scss"
>
@import
"@/uni_modules/uni-id-pages/common/login-page.scss"
;
.uni-content
{
margin-top
:
15px
;
}
</
style
>
uni_modules/uni-id-pages/pages/userinfo/userinfo.vue
浏览文件 @
69d0074a
...
...
@@ -9,7 +9,7 @@
</uni-list-item>
<uni-list-item
class=
"item"
@
click=
"bindMobile"
title=
"手机号"
:rightText=
"userInfo.mobile||'未绑定'"
link
>
</uni-list-item>
<uni-list-item
v-if=
"
userInfo.mobile
"
class=
"item"
@
click=
"changePassword"
title=
"修改密码"
link
>
<uni-list-item
v-if=
"
hasPwd
"
class=
"item"
@
click=
"changePassword"
title=
"修改密码"
link
>
</uni-list-item>
</uni-list>
<uni-list
class=
"mt10"
>
...
...
@@ -44,15 +44,19 @@
mobile
:
''
,
nickname
:
''
},
hasLogin
:
false
hasLogin
:
false
,
hasPwd
:
false
}
},
async
onShow
()
{
this
.
univerifyStyle
.
authButton
.
title
=
"
本机号码一键绑定
"
this
.
univerifyStyle
.
otherLoginButton
.
title
=
"
其他号码绑定
"
},
onLoad
()
{
this
.
getUserInfo
()
async
onLoad
()
{
this
.
getUserInfo
()
//判断当前用户是否有密码,否则就不显示密码修改功能
let
res
=
await
uniIdCo
.
getAccountInfo
()
this
.
hasPwd
=
res
.
isPasswordSet
},
methods
:
{
login
()
{
...
...
@@ -64,7 +68,7 @@
})
},
async
logout
()
{
await
uni
Cloud
.
importObject
(
"
uni-id-co
"
)
.
logout
()
await
uni
IdCo
.
logout
()
uni
.
removeStorageSync
(
'
uni_id_token
'
);
uni
.
setStorageSync
(
'
uni_id_token_expired
'
,
0
)
uni
.
redirectTo
({
...
...
@@ -73,7 +77,7 @@
},
changePassword
(){
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/
retrieve/retrieve?lock=true&phoneNumber=
'
+
this
.
userInfo
?.
mobile
,
url
:
'
/uni_modules/uni-id-pages/pages/
userinfo/change_pwd/change_pwd
'
,
complete
:
(
e
)
=>
{
console
.
log
(
e
);
}
...
...
@@ -83,7 +87,8 @@
uni
.
showLoading
({
mask
:
true
});
usersTable
.
where
(
"
'_id' == $cloudEnv_uid
"
).
field
(
'
mobile,nickname
'
).
get
().
then
(
res
=>
{
usersTable
.
where
(
"
'_id' == $cloudEnv_uid
"
).
field
(
'
mobile,nickname
'
).
get
().
then
(
res
=>
{
console
.
log
({
res
});
this
.
userInfo
=
res
.
result
.
data
[
0
]
console
.
log
(
'
this.userInfo
'
,
this
.
userInfo
);
this
.
hasLogin
=
true
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/account/update-pwd.js
浏览文件 @
69d0074a
const
{
userCollection
}
=
require
(
'
../../common/constants
'
)
const
{
ERROR
}
=
require
(
'
../../common/error
'
)
const
PasswordUtils
=
require
(
'
../../lib/utils/password
'
)
/**
* 更新密码
* @param {object} params
* @param {string} params.oldPassword 旧密码
* @param {string} params.newPassword 新密码
* @returns {object}
*/
module
.
exports
=
async
function
(
params
=
{})
{
const
schema
=
{
oldPassword
:
'
string
'
,
// 防止密码规则调整导致旧密码无法更新
newPassword
:
'
password
'
}
this
.
middleware
.
validate
(
params
,
schema
)
const
uid
=
this
.
authInfo
.
uid
const
getUserRes
=
await
userCollection
.
doc
(
uid
).
get
()
const
userRecord
=
getUserRes
.
data
[
0
]
if
(
!
userRecord
)
{
throw
{
errCode
:
ERROR
.
ACCOUNT_NOT_EXISTS
}
}
const
{
oldPassword
,
newPassword
}
=
params
const
passwordUtils
=
new
PasswordUtils
({
passwordSecret
:
this
.
config
.
passwordSecret
})
const
{
success
:
checkPasswordSuccess
}
=
passwordUtils
.
checkUserPassword
({
password
:
oldPassword
,
passwordHash
:
userRecord
.
password
,
passwordSecretVersion
:
userRecord
.
password_secret_version
,
autoRefresh
:
false
})
if
(
!
checkPasswordSuccess
)
{
throw
{
errCode
:
ERROR
.
PASSWORD_ERROR
}
}
const
{
passwordHash
,
version
}
=
passwordUtils
.
generatePasswordHash
({
password
:
newPassword
})
await
userCollection
.
doc
(
uid
).
update
({
password
:
passwordHash
,
password_secret_version
:
version
,
valid_token_date
:
Date
.
now
()
// refreshToken时会校验,如果创建token时间在此时间点之前,则拒绝下发新token,返回token失效错误码
})
// 执行更新密码操作后客户端应将用户退出重新登录
return
{
errCode
:
0
}
const
{
userCollection
}
=
require
(
'
../../common/constants
'
)
const
{
ERROR
}
=
require
(
'
../../common/error
'
)
const
PasswordUtils
=
require
(
'
../../lib/utils/password
'
)
/**
* 更新密码
* @param {object} params
* @param {string} params.oldPassword 旧密码
* @param {string} params.newPassword 新密码
* @returns {object}
*/
module
.
exports
=
async
function
(
params
=
{})
{
const
schema
=
{
oldPassword
:
'
string
'
,
// 防止密码规则调整导致旧密码无法更新
newPassword
:
'
password
'
}
this
.
middleware
.
validate
(
params
,
schema
)
const
uid
=
this
.
authInfo
.
uid
const
getUserRes
=
await
userCollection
.
doc
(
uid
).
get
()
const
userRecord
=
getUserRes
.
data
[
0
]
if
(
!
userRecord
)
{
throw
{
errCode
:
ERROR
.
ACCOUNT_NOT_EXISTS
}
}
const
{
oldPassword
,
newPassword
}
=
params
const
passwordUtils
=
new
PasswordUtils
({
passwordSecret
:
this
.
config
.
passwordSecret
})
const
{
success
:
checkPasswordSuccess
}
=
passwordUtils
.
checkUserPassword
({
password
:
oldPassword
,
passwordHash
:
userRecord
.
password
,
passwordSecretVersion
:
userRecord
.
password_secret_version
,
autoRefresh
:
false
})
if
(
!
checkPasswordSuccess
)
{
throw
{
errCode
:
ERROR
.
PASSWORD_ERROR
}
}
const
{
passwordHash
,
version
}
=
passwordUtils
.
generatePasswordHash
({
password
:
newPassword
})
await
userCollection
.
doc
(
uid
).
update
({
password
:
passwordHash
,
password_secret_version
:
version
,
valid_token_date
:
Date
.
now
()
// refreshToken时会校验,如果创建token时间在此时间点之前,则拒绝下发新token,返回token失效错误码
})
// 执行更新密码操作后客户端应将用户退出重新登录
return
{
errCode
:
0
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录