login.vue
3.2 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
<template>
<view class="body">
<text>首次登录创建新帐号</text>
<view class="input">
<text>手机号</text>
<input type="text" v-model="mobile" placeholder="请填写手机号" placeholder-style="color:#ACACAC;" />
</view>
<view class="input">
<text>验证码</text>
<input type="text" v-model="code" placeholder-style="color:#ACACAC;" placeholder="请填写手机验证码" />
<text :class="'yzm '+yzm.class" @click="sendMobileCode">获取验证码 {{yzm.djs}}</text>
</view>
<button type="default" class="btn" @click="login">下一步</button>
</view>
</template>
<script>
export default {
data() {
return {
mobile: '',
code: '',
yzm: {
class: '',
djs: '',
setIntervalId: 0
},
from: '/center'
}
},
async onLoad(e) {
if (e.from) this.from = e.from
},
methods: {
async login() {
if (this.mobile.length != 11) {
uni.showToast({
icon: "none",
icon: 'error',
title: "手机号有误",
});
return;
}
if (this.code.length != 6) {
uni.showToast({
icon: "none",
icon: 'error',
title: "验证码有误",
});
return;
}
const res = await uni.$u.request.post({
data: {
query: `mutation{ydn_sms_login(mobile:"${this.mobile}",code:"${this.code}",type:"web")}`
}
}).then(a => a.data.data.ydn_sms_login);
if (res.Error) {
uni.showToast({
title: res.Error,
icon: 'error',
duration: 2000
});
return
}
uni.redirectTo({
url: decodeURIComponent(this.from)
})
},
async sendMobileCode() {
if (this.mobile.length != 11) {
uni.showToast({
icon: "none",
icon: 'error',
title: "手机号有误",
});
return;
}
var yzm = this.yzm
if (yzm.class == 'disabled') {
uni.showToast({
title: '请稍后再试试',
icon: 'error',
duration: 2000
});
return
}
yzm.class = 'disabled'
const res = await uni.$u.request.post({
data: {
query: `mutation{ydn_send_mobile_code(mobile:"${this.mobile}",type:7)}`
}
}).then(a => a.data.data.ydn_send_mobile_code);
if (res.success == '1') {
uni.showToast({
title: '验证码发送成功',
icon: 'success',
duration: 2000
});
}
yzm.setIntervalId = setInterval(() => {
if (yzm.djs == '') yzm.djs = 60;
else yzm.djs--
if (yzm.djs == 0) {
yzm.djs = ''
yzm.class = ''
clearInterval(yzm.setIntervalId)
yzm.setIntervalId = 0
}
}, 999)
}
}
}
</script>
<style>
.body {
font-family: Helvetica;
font-weight: 400;
font-size: 14px;
color: #333333;
padding: 20px;
margin-top: 30px;
}
.input {
display: flex;
margin: 30px 0;
padding: 5px 0;
border-bottom: solid 1px #ACACAC;
}
.input input {
margin-left: 20px;
color: #909399;
}
.input .yzm {
color: #4F6FD9;
}
.input .disabled {
color: rgb(204, 204, 204) !important;
}
.btn {
height: 44px;
margin-top: 30px;
background-color: #D23338;
color: #FFFFFF;
}
</style>