codeLogin.vue
3.6 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
<!-- 验证码登录 -->
<view class="codeLogin">
<!-- 验证 -->
<view class="verification">
<view class="codeSize">
<p class="BigSize">手机号登录</p>
<view class="firstLogin">
已发送6位验证码至<span>{{$Route.query.phone}}</span>,请留意短信
</view>
</view>
<u-message-input class="codeInput" :maxlength="6" @finish="finish" :breathe="true" :focus="true" mode="bottomLine">
</u-message-input>
<!-- 重新发送 -->
<view class="wrap">
<u-toast ref="uToast"></u-toast>
<u-verification-code @end="end" :keep-running="true" :seconds="60" ref="uCode" @change="codeChange">
</u-verification-code>
</view>
<view class="anew" @click="getCode" v-if="showTorF">
{{tips}}
</view>
<view class="anew" @click="againCode" v-if="!showTorF">
{{tips}}
</view>
</view>
<!-- 提示框 -->
<u-toast ref="uToast" />
</view>
</template>
<script>
export default {
data() {
return {
tips: '',
showTorF:true
};
},
onReady() {
this.getCode()
},
methods: {
// 自动登录
async finish(code) {
// uni.setStorageSync("token",1)
// if(this.$Route.query.redirect){
// this.$Router.push({
// path:this.$Route.query.redirect
// })
// }else{
// this.$Router.pushTab({
// path: "/pages/index/index"
// })
// }
try{
await this.$store.dispatch("codeLogin",{
phone:this.$Route.query.phone,
code:code
})
this.$Router.pushTab({
path: "/pages/index/index"
})
// if(this.$Route.query.redirect){
// this.$Router.push({
// path:this.$Route.query.redirect
// })
// }else{
// this.$Router.pushTab({
// path: "/pages/index/index"
// })
// }
}catch(e){
this.$refs.uToast.show({
title: '验证码错误',
type: 'error',
})
}
},
// 开始倒计时
codeChange(text) {
if(text!="获取验证码"){
this.tips = text;
}
},
getCode() {
if (this.$refs.uCode.canGetCode) {
// 模拟向后端请求验证码
uni.showLoading({
title: ''
})
setTimeout(() => {
uni.hideLoading();
// 这里此提示会被this.start()方法中的提示覆盖
this.$u.toast('验证码已发送');
// 通知验证码组件内部开始倒计时
this.$refs.uCode.start();
}, 1000);
} else {
this.$u.toast('不能重复获取');
}
},
end(){
this.showTorF=!this.showTorF
console.log(1);
},
againCode(){
this.showTorF=!this.showTorF
this.getCode()
this.$store.dispatch("gainCode",this.$Route.query.phone)
}
}
}
</script>
<style lang="scss" scoped>
// 验证码验证
* {
margin: 0;
padding: 0;
}
.codeLogin {
width: 750rpx;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
// 验证登录
.verification {
width: 680rpx;
height: 700rpx;
margin-top: 150rpx;
display: flex;
flex-direction: column;
align-items: center;
// 字体
.codeSize {
width: 600rpx;
height: 160rpx;
margin-bottom: 60rpx;
.BigSize {
font-size: 27px;
font-weight: 550;
margin-bottom: 15rpx;
}
.firstLogin {
color: darkgray;
font-size: 12px;
margin-bottom: 50rpx;
span {
color: red;
}
}
}
.anew{
color: darkgray;
text-align: center;
margin-top: 20rpx;
}
}
}
</style>