code.vue
3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<template>
<view class="f-page">
<view class="f-title">{{ t('rules.codeY') }}</view>
<view class="f-desc">{{ t('app.resetPassword.sendCodeTips').replace('{value}',verifyText) }}</view>
<uv-code-input v-model="code" space="88rpx" color="#202328" mode="line" :hairline="true" size="96rpx"
fontSize="44rpx" :maxlength="4" :bold="true" @finish="handleFinishVerify" />
<view class="re-send" :class="{'disabled-send':waitTime!==0}" @tap="handleReSendMsg">
{{ t('app.resetPassword.reSendCode') }}
<text v-if="waitTime!==0">
({{waitTime}}s)
</text>
</view>
<!-- <uv-input
placeholder="请输入用户名"
placeholder-style="font-size: 30rpx;color: #656a72;font-weight:400"
custom-style="padding: 0;height: 96rpx;font-size:30rpx;padding-left:32rpx;border: 2rpx solid #E1E4EA;border-radius: 16rpx"
v-model.trim="loginName"
@change="change"
/> -->
</view>
</template>
<script setup>
import {
ref
} from 'vue'
import {
onLoad,
onShow,
onHide
} from '@dcloudio/uni-app'
import{
sendVerifyCodeApi,
checkVerifyCodeApi
} from '@/api'
import { t } from '@/plugins/index.js'
// 获取用户名
const verifyInfo = ref({})
const verifyText = ref('')
onLoad((options) => {
if (options.loginName) {
verifyInfo.value = {
...options
}
verifyText.value = (options.selectType === 'email' ? t('maintenance.monitor.panel.email') : t('format.phoneNumber')) + options.val
}
})
// 发送验证码
const waitTime = ref(60)
const timer = ref(null)
onShow(() => {
clearInterval(timer.value)
timer.value = setInterval(() => {
if (waitTime.value) {
waitTime.value -= 1
} else {
// 结束计时
clearInterval(timer)
}
}, 1000)
})
onHide(() => {
clearInterval(timer.value)
})
// 重新发送验证码
const handleReSendMsg = async () =>{
try{
if(waitTime.value){
return false
}
const res = await sendVerifyCodeApi({
unid: verifyInfo.value.unid,
verifyType: 'email'
})
if(res.code === 200){
waitTime.value = 60
uni.showToast({
title: t('table.sendSuccess')
})
}
}catch(e){
console.log(e);
}
}
const code = ref('')
const handleFinishVerify = async ()=>{
try{
const res = await checkVerifyCodeApi({
loginName: verifyInfo.value.loginName,
code:code.value
})
if(res.code === 200){
// 跳转到重置密码页面
uni.redirectTo({
url:`/subPackages/accountGroup/pages/login/forget/reset?loginName=${verifyInfo.value.loginName}&code=${res.data}`
})
}
}catch(e){
console.log(e);
}
}
const loginName = ref('')
const goNext = () => {
if (!loginName.value) {
uni.showToast({
title: t('rules.loginName')
})
return
}
uni.navigateTo({
url: '/subPackages/accountGroup/pages/login/forget/verify?loginName=' + loginName.value
})
}
</script>
<style lang="scss" scoped>
.f-page {
padding: 64rpx 50rpx 0;
.f-title {
font-weight: bold;
font-size: 46rpx;
color: #202328;
line-height: 64rpx;
}
.f-desc {
font-weight: 400;
font-size: 28rpx;
color: #90949D;
line-height: 40rpx;
margin: 16rpx 0 80rpx;
}
.re-send{
width: 100%;
text-align: right;
margin-top: 52rpx;
font-size: 26rpx;
color: #387CF5;
line-height: 36rpx;
}
.disabled-send{
color: #90949D;
}
}
</style>