|
1
|
|
-<template>
|
|
2
|
|
- <view class="code-page">
|
|
3
|
|
- <!-- 公共组件-每个页面必须引入 -->
|
|
4
|
|
- <public-module></public-module>
|
|
5
|
|
- <view class="f__login">
|
|
6
|
|
- <view class="loginPhone">
|
|
7
|
|
- <view class="phone-main" style="margin-top: 240rpx;">
|
|
8
|
|
- <text class="text">手机验证码登录</text>
|
|
9
|
|
- <view class="circleStyle"></view>
|
|
10
|
|
- </view>
|
|
11
|
|
- <view class="form-row">
|
|
12
|
|
- <u-input v-model="phone" type="number" placeholder="请输入手机号码" border="bottom"></u-input>
|
|
13
|
|
- </view>
|
|
14
|
|
- <view class="form-row">
|
|
15
|
|
- <u-input type="number" v-model="vCode" placeholder="请输入验证码" border="bottom">
|
|
16
|
|
- <template slot="suffix" @click="getVcode">
|
|
17
|
|
- <view class="getvcode" >{{ codeText }}</view>
|
|
18
|
|
- </template>
|
|
19
|
|
- </u-input>
|
|
20
|
|
- </view>
|
|
21
|
|
- <button class="submit" size="default" @click="onSubmit"><text class="text">登录</text></button>
|
|
22
|
|
- <view class="u-flex account-style"><view class="content" @click="openAccountFunc">账号密码登录</view></view>
|
|
23
|
|
- <view class="circleStyleBottom"></view>
|
|
24
|
|
- </view>
|
|
25
|
|
- </view>
|
|
26
|
|
- </view>
|
|
27
|
|
-</template>
|
|
28
|
|
-
|
|
29
|
|
-<script>
|
|
30
|
|
- var clear;
|
|
31
|
|
- import { mapState, mapMutations } from 'vuex';
|
|
32
|
|
- export default {
|
|
33
|
|
- data() {
|
|
34
|
|
- return {
|
|
35
|
|
- readonly: false,
|
|
36
|
|
- codeText: '发送验证码',
|
|
37
|
|
- phone: '', //号码
|
|
38
|
|
- vCode: '', //验证码
|
|
39
|
|
- }
|
|
40
|
|
- },
|
|
41
|
|
- methods: {
|
|
42
|
|
- ...mapMutations(['setUserInfo']),
|
|
43
|
|
- //验证码按钮文字状态
|
|
44
|
|
- getCodeState() {
|
|
45
|
|
- const _this = this;
|
|
46
|
|
- this.readonly = true;
|
|
47
|
|
- this.codeText = '60S后重新获取';
|
|
48
|
|
- var s = 60;
|
|
49
|
|
- clear = setInterval(() => {
|
|
50
|
|
- s--;
|
|
51
|
|
- _this.codeText = s + 'S后重新获取';
|
|
52
|
|
- if (s <= 0) {
|
|
53
|
|
- clearInterval(clear);
|
|
54
|
|
- _this.codeText = '发送验证码';
|
|
55
|
|
- _this.readonly = false;
|
|
56
|
|
- }
|
|
57
|
|
- }, 1000);
|
|
58
|
|
- },
|
|
59
|
|
- //获取验证码
|
|
60
|
|
- getVcode() {
|
|
61
|
|
- if (this.readonly) {
|
|
62
|
|
- uni.showToast({
|
|
63
|
|
- title: '验证码已发送~',
|
|
64
|
|
- icon: 'none'
|
|
65
|
|
- });
|
|
66
|
|
- return;
|
|
67
|
|
- }
|
|
68
|
|
- if (this.phone == '') {
|
|
69
|
|
- uni.showToast({
|
|
70
|
|
- title: '请输入手机号~',
|
|
71
|
|
- icon: 'none'
|
|
72
|
|
- });
|
|
73
|
|
- return;
|
|
74
|
|
- }
|
|
75
|
|
- const phoneRegular = /^1\d{10}$/;
|
|
76
|
|
- if (!phoneRegular.test(this.phone)) {
|
|
77
|
|
- uni.showToast({
|
|
78
|
|
- title: '手机号格式不正确~',
|
|
79
|
|
- icon: 'none'
|
|
80
|
|
- });
|
|
81
|
|
- return;
|
|
82
|
|
- }
|
|
83
|
|
- // 获取验证码接口
|
|
84
|
|
- uni.$u.http.post(`/yt/noauth/sendLoginSmsCode/${this.phone}` ).then(res => {
|
|
85
|
|
- if(res){
|
|
86
|
|
- this.getCodeState(); //开始倒计时
|
|
87
|
|
- }
|
|
88
|
|
- })
|
|
89
|
|
- },
|
|
90
|
|
- onSubmit() {
|
|
91
|
|
- const phoneRegular = /^1\d{10}$/;
|
|
92
|
|
- if(this.phone==''){
|
|
93
|
|
- uni.showToast({
|
|
94
|
|
- title: '请输入手机号码~',
|
|
95
|
|
- icon: 'none'
|
|
96
|
|
- });
|
|
97
|
|
- return;
|
|
98
|
|
- }else if (!phoneRegular.test(this.phone)) {
|
|
99
|
|
- uni.showToast({
|
|
100
|
|
- title: '手机号格式不正确~',
|
|
101
|
|
- icon: 'none'
|
|
102
|
|
- });
|
|
103
|
|
- return;
|
|
104
|
|
- }
|
|
105
|
|
- if (this.vCode == '') {
|
|
106
|
|
- uni.showToast({
|
|
107
|
|
- title: '请输入验证码~',
|
|
108
|
|
- icon: 'none'
|
|
109
|
|
- });
|
|
110
|
|
- return;
|
|
111
|
|
- } else if(!(/^\d{6}$/.test(this.vCode))){
|
|
112
|
|
- uni.showToast({
|
|
113
|
|
- title: '验证码格式不正确~',
|
|
114
|
|
- icon: 'none'
|
|
115
|
|
- });
|
|
116
|
|
- return
|
|
117
|
|
- }
|
|
118
|
|
- let httpData = {
|
|
119
|
|
- code: this.vCode,
|
|
120
|
|
- phoneNumber: this.phone
|
|
121
|
|
- }
|
|
122
|
|
- uni.$u.http.post('/yt/auth/code/login', httpData).then(res => {
|
|
123
|
|
- if (res) {
|
|
124
|
|
- // 储存登录信息
|
|
125
|
|
- let resObj = {
|
|
126
|
|
- refreshToken: res.refreshToken,
|
|
127
|
|
- isToken: res.token
|
|
128
|
|
- };
|
|
129
|
|
- let userInfo = {
|
|
130
|
|
- ...resObj,
|
|
131
|
|
- token: true ,//token用于判断是否登录
|
|
132
|
|
- isThirdLogin: false
|
|
133
|
|
- };
|
|
134
|
|
- if (userInfo.token) {
|
|
135
|
|
- this.setUserInfo(userInfo);
|
|
136
|
|
- }
|
|
137
|
|
- uni.showToast({
|
|
138
|
|
- title: '登录成功~',
|
|
139
|
|
- icon: 'none'
|
|
140
|
|
- }).then(res => {
|
|
141
|
|
- uni.reLaunch({
|
|
142
|
|
- url: '/pages/personal/personal'
|
|
143
|
|
- });
|
|
144
|
|
- });
|
|
145
|
|
- this.saveUserInfo();
|
|
146
|
|
-
|
|
147
|
|
- }
|
|
148
|
|
- });
|
|
149
|
|
- },
|
|
150
|
|
- saveUserInfo() {
|
|
151
|
|
- //储存个人信息
|
|
152
|
|
- uni.$u.http.get('/yt/user/me/info').then(res => {
|
|
153
|
|
- if (res) {
|
|
154
|
|
- this.setUserInfo(res);
|
|
155
|
|
- }
|
|
156
|
|
- });
|
|
157
|
|
- },
|
|
158
|
|
- openAccountFunc(){
|
|
159
|
|
- uni.navigateTo({
|
|
160
|
|
- url:"../public/login"
|
|
161
|
|
- })
|
|
162
|
|
- }
|
|
163
|
|
- }
|
|
164
|
|
- }
|
|
165
|
|
-</script>
|
|
166
|
|
-
|
|
167
|
|
-<style lang="scss" scoped>
|
|
168
|
|
- @import './static/code.scss';
|
|
|
1
|
+<template>
|
|
|
2
|
+ <view class="code-page">
|
|
|
3
|
+ <!-- 公共组件-每个页面必须引入 -->
|
|
|
4
|
+ <public-module></public-module>
|
|
|
5
|
+ <view class="f__login">
|
|
|
6
|
+ <view class="loginPhone">
|
|
|
7
|
+ <view class="phone-main" style="margin-top: 240rpx;">
|
|
|
8
|
+ <text class="text">手机验证码登录</text>
|
|
|
9
|
+ <view class="circleStyle"></view>
|
|
|
10
|
+ </view>
|
|
|
11
|
+ <view class="form-row"><u-input v-model="phone" type="number" placeholder="请输入手机号码" border="bottom"></u-input></view>
|
|
|
12
|
+ <view class="form-row">
|
|
|
13
|
+ <u-input type="number" v-model="vCode" placeholder="请输入验证码" border="bottom">
|
|
|
14
|
+ <template slot="suffix" @click="getVcode">
|
|
|
15
|
+ <view class="getvcode">{{ codeText }}</view>
|
|
|
16
|
+ </template>
|
|
|
17
|
+ </u-input>
|
|
|
18
|
+ </view>
|
|
|
19
|
+ <button class="submit" size="default" @click="onSubmit"><text class="text">登录</text></button>
|
|
|
20
|
+ <view class="u-flex account-style"><view class="content" @click="openAccountFunc">账号密码登录</view></view>
|
|
|
21
|
+ <view class="circleStyleBottom"></view>
|
|
|
22
|
+ </view>
|
|
|
23
|
+ </view>
|
|
|
24
|
+ </view>
|
|
|
25
|
+</template>
|
|
|
26
|
+
|
|
|
27
|
+<script>
|
|
|
28
|
+var clear;
|
|
|
29
|
+import { mapState, mapMutations } from 'vuex';
|
|
|
30
|
+export default {
|
|
|
31
|
+ data() {
|
|
|
32
|
+ return {
|
|
|
33
|
+ readonly: false,
|
|
|
34
|
+ codeText: '发送验证码',
|
|
|
35
|
+ phone: '', //号码
|
|
|
36
|
+ vCode: '' //验证码
|
|
|
37
|
+ };
|
|
|
38
|
+ },
|
|
|
39
|
+ methods: {
|
|
|
40
|
+ ...mapMutations(['setUserInfo']),
|
|
|
41
|
+ //验证码按钮文字状态
|
|
|
42
|
+ getCodeState() {
|
|
|
43
|
+ const _this = this;
|
|
|
44
|
+ this.readonly = true;
|
|
|
45
|
+ this.codeText = '60s后重新获取';
|
|
|
46
|
+ var s = 60;
|
|
|
47
|
+ clear = setInterval(() => {
|
|
|
48
|
+ s--;
|
|
|
49
|
+ _this.codeText = s + 's后重新获取';
|
|
|
50
|
+ if (s <= 0) {
|
|
|
51
|
+ clearInterval(clear);
|
|
|
52
|
+ _this.codeText = '发送验证码';
|
|
|
53
|
+ _this.readonly = false;
|
|
|
54
|
+ }
|
|
|
55
|
+ }, 1000);
|
|
|
56
|
+ },
|
|
|
57
|
+ //获取验证码
|
|
|
58
|
+ getVcode() {
|
|
|
59
|
+ if (this.readonly) {
|
|
|
60
|
+ uni.showToast({
|
|
|
61
|
+ title: '验证码已发送~',
|
|
|
62
|
+ icon: 'none'
|
|
|
63
|
+ });
|
|
|
64
|
+ return;
|
|
|
65
|
+ }
|
|
|
66
|
+ if (this.phone == '') {
|
|
|
67
|
+ uni.showToast({
|
|
|
68
|
+ title: '请输入手机号~',
|
|
|
69
|
+ icon: 'none'
|
|
|
70
|
+ });
|
|
|
71
|
+ return;
|
|
|
72
|
+ }
|
|
|
73
|
+ const phoneRegular = /^1\d{10}$/;
|
|
|
74
|
+ if (!phoneRegular.test(this.phone)) {
|
|
|
75
|
+ uni.showToast({
|
|
|
76
|
+ title: '手机号格式不正确~',
|
|
|
77
|
+ icon: 'none'
|
|
|
78
|
+ });
|
|
|
79
|
+ return;
|
|
|
80
|
+ }
|
|
|
81
|
+ // 获取验证码接口
|
|
|
82
|
+ uni.$u.http
|
|
|
83
|
+ .post(`/yt/noauth/sendLoginSmsCode/${this.phone}`)
|
|
|
84
|
+ .then(res => {
|
|
|
85
|
+ if (res) {
|
|
|
86
|
+ this.getCodeState(); //开始倒计时
|
|
|
87
|
+ }
|
|
|
88
|
+ })
|
|
|
89
|
+ .catch(err => {
|
|
|
90
|
+ uni.showToast({
|
|
|
91
|
+ title: err.data.msg,
|
|
|
92
|
+ icon: 'none'
|
|
|
93
|
+ });
|
|
|
94
|
+ });
|
|
|
95
|
+ },
|
|
|
96
|
+ onSubmit() {
|
|
|
97
|
+ const phoneRegular = /^1\d{10}$/;
|
|
|
98
|
+ if (this.phone == '') {
|
|
|
99
|
+ uni.showToast({
|
|
|
100
|
+ title: '请输入手机号码~',
|
|
|
101
|
+ icon: 'none'
|
|
|
102
|
+ });
|
|
|
103
|
+ return;
|
|
|
104
|
+ } else if (!phoneRegular.test(this.phone)) {
|
|
|
105
|
+ uni.showToast({
|
|
|
106
|
+ title: '手机号格式不正确~',
|
|
|
107
|
+ icon: 'none'
|
|
|
108
|
+ });
|
|
|
109
|
+ return;
|
|
|
110
|
+ }
|
|
|
111
|
+ if (this.vCode == '') {
|
|
|
112
|
+ uni.showToast({
|
|
|
113
|
+ title: '请输入验证码~',
|
|
|
114
|
+ icon: 'none'
|
|
|
115
|
+ });
|
|
|
116
|
+ return;
|
|
|
117
|
+ } else if (!/^\d{6}$/.test(this.vCode)) {
|
|
|
118
|
+ uni.showToast({
|
|
|
119
|
+ title: '验证码格式不正确~',
|
|
|
120
|
+ icon: 'none'
|
|
|
121
|
+ });
|
|
|
122
|
+ return;
|
|
|
123
|
+ }
|
|
|
124
|
+ let httpData = {
|
|
|
125
|
+ code: this.vCode,
|
|
|
126
|
+ phoneNumber: this.phone
|
|
|
127
|
+ };
|
|
|
128
|
+ uni.$u.http.post('/yt/auth/code/login', httpData).then(res => {
|
|
|
129
|
+ if (res) {
|
|
|
130
|
+ // 储存登录信息
|
|
|
131
|
+ let resObj = {
|
|
|
132
|
+ refreshToken: res.refreshToken,
|
|
|
133
|
+ isToken: res.token
|
|
|
134
|
+ };
|
|
|
135
|
+ let userInfo = {
|
|
|
136
|
+ ...resObj,
|
|
|
137
|
+ token: true, //token用于判断是否登录
|
|
|
138
|
+ isThirdLogin: false
|
|
|
139
|
+ };
|
|
|
140
|
+ if (userInfo.token) {
|
|
|
141
|
+ this.setUserInfo(userInfo);
|
|
|
142
|
+ }
|
|
|
143
|
+ uni
|
|
|
144
|
+ .showToast({
|
|
|
145
|
+ title: '登录成功~',
|
|
|
146
|
+ icon: 'none'
|
|
|
147
|
+ })
|
|
|
148
|
+ .then(res => {
|
|
|
149
|
+ uni.reLaunch({
|
|
|
150
|
+ url: '/pages/personal/personal'
|
|
|
151
|
+ });
|
|
|
152
|
+ });
|
|
|
153
|
+ this.saveUserInfo();
|
|
|
154
|
+ }
|
|
|
155
|
+ });
|
|
|
156
|
+ },
|
|
|
157
|
+ saveUserInfo() {
|
|
|
158
|
+ //储存个人信息
|
|
|
159
|
+ uni.$u.http.get('/yt/user/me/info').then(res => {
|
|
|
160
|
+ if (res) {
|
|
|
161
|
+ this.setUserInfo(res);
|
|
|
162
|
+ }
|
|
|
163
|
+ });
|
|
|
164
|
+ },
|
|
|
165
|
+ openAccountFunc() {
|
|
|
166
|
+ uni.navigateTo({
|
|
|
167
|
+ url: '../public/login'
|
|
|
168
|
+ });
|
|
|
169
|
+ }
|
|
|
170
|
+ }
|
|
|
171
|
+};
|
|
|
172
|
+</script>
|
|
|
173
|
+
|
|
|
174
|
+<style lang="scss" scoped>
|
|
|
175
|
+@import './static/code.scss';
|
|
169
|
176
|
</style> |
...
|
...
|
|