login.vue
4.27 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="login-page">
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<view class="u-flex login-main">
<view class="content">
<view class="hello">您好,</view>
<view class="hello-welcome">欢迎来到ThingsKit!</view>
<view class="circleStyle"></view>
</view>
</view>
<view class="f__login">
<view class="loginPhone">
<view class="form-row">
<u--input border="bottom" class="input" prefixIcon="account-fill" type="text" placeholder="登录账号" v-model="loginForm.username"></u--input>
</view>
<view class="form-row">
<u-input
border="bottom"
class="input"
prefixIcon="lock-fill"
suffixIconStyle="color: #909399"
:type="passwordText"
placeholder="请输入密码"
v-model="loginForm.password"
>
<template slot="suffix">
<u-icon @click="showPasswordMode" :name="showPassword ? showTextIcon : showPasswordIcon"></u-icon>
</template>
</u-input>
</view>
<button class="submit" size="default" @click="onSubmitFunc"><text class="text">登录</text></button>
<view class="u-flex row-item">
<view class="row-phone" @click="openCodeFunc">手机验证码登录</view>
<view class="row-reset" @click="findPassrordFunc">忘记密码</view>
</view>
<view @click="onAuthorization" class="u-flex link-login">
<view class="link-text">第三方账号登录</view>
<view style="height:20rpx"></view>
<view class="link-image"><image class="image" src="../../static/weixin.png" mode="aspectFill"></image></view>
<view class="circleStyleBottom"></view>
</view>
</view>
</view>
</view>
</template>
<script>
import { mapMutations } from 'vuex';
import { getUserInfo } from '@/components/module/f-login/f-login.js';
export default {
data() {
return {
showPasswordIcon: 'eye-off',
showTextIcon: 'eye-fill',
loginForm: {
username: '',
password: ''
},
showPassword: false,
passwordText: 'password'
};
},
methods: {
...mapMutations(['setUserInfo']),
onAuthorization(e) {
getUserInfo(
info => {
console.log(info, '授权信息');
let httpData = {
code: this.code,
nickName: info.nickName || '', //昵称
avatarUrl: info.avatarUrl || '', //头像
gender: info.gender || '' //性别 0:未知 1:男 2:女
};
// uni.$u.http.post('您的接口', httpData).then(res => {
let userInfo = {
// ...res,
token: true //token用于判断是否登录
};
// this.setUserInfo(userInfo)
// setTimeout(()=>{
// uni.showToast({
// title: '登录成功',
// icon: 'none'
// });
// this.closeLogin();
// },100)
// })
},
err => {
// this.closeLogin();
}
);
},
onSubmitFunc() {
if (this.loginForm.username == '' || this.loginForm.password == '') {
return uni.$u.toast('请输入用户名或密码');
}
uni.$u.http
.post('/auth/login', this.loginForm)
.then(res => {
if (res) {
// 储存登录信息
let resObj = {
refreshToken: res.refreshToken,
isToken: res.token
};
let userInfo = {
...resObj,
token: true //token用于判断是否登录
};
if (userInfo.token) {
this.setUserInfo(userInfo);
}
uni.showToast({
title: '登录成功~',
icon: 'none'
});
this.saveUserInfo();
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 500);
//#ifndef MP
setTimeout(() => {
uni.navigateTo({
url: 'personal'
});
}, 500);
//#endif
}
})
.catch(e => {
uni.$u.toast(e.data.message);
});
},
saveUserInfo() {
//储存个人信息
uni.$u.http.get('/yt/user/me/info').then(res => {
if (res) {
this.setUserInfo(res);
}
});
},
openCodeFunc() {
uni.navigateTo({
url: './code'
});
},
findPassrordFunc() {
uni.navigateTo({
url: './findPassword'
});
},
showPasswordMode() {
this.showPassword = !this.showPassword;
if (!this.showPassword) {
this.passwordText = 'password';
} else {
this.passwordText = 'text';
}
}
}
};
</script>
<style lang="scss" scoped>
@import './static/login.scss';
</style>