login.vue
6.89 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<template>
<view class="login-container">
<!-- 状态栏占位 -->
<view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
<!-- 登录卡片容器 -->
<view class="login-card">
<!-- 头部区域 -->
<view class="login-header">
<view class="title">绿纤协同平台</view>
<view class="subtitle">用户登录</view>
</view>
<!-- 登录表单 -->
<view class="login-form">
<view class="form-group">
<view class="form-label">用户名</view>
<view class="input-wrapper">
<u-icon name="account" size="20" color="#6a9c6a" class="input-icon"></u-icon>
<u-input
v-model="formData.username"
placeholder="请输入用户名"
:clearable="true"
border="none"
class="custom-input"
></u-input>
</view>
</view>
<view class="form-group">
<view class="form-label">密码</view>
<view class="input-wrapper">
<u-icon name="lock" size="20" color="#6a9c6a" class="input-icon"></u-icon>
<u-input
v-model="formData.password"
placeholder="请输入密码"
:password="!showPassword"
:clearable="true"
border="none"
class="custom-input"
></u-input>
<u-icon
:name="showPassword ? 'eye-off' : 'eye'"
size="20"
color="#6a9c6a"
@click="togglePassword"
class="password-toggle"
></u-icon>
</view>
</view>
<view class="form-actions">
<!-- type="success"
:loading="loading" -->
<button
:disabled="loading"
@click="handleLogin"
class="login-btn"
>
{{ loading ? '登录中...' : '登录' }}
</button>
</view>
</view>
</view>
<!-- 底部信息 -->
<view class="footer">
<view class="footer-text">绿纤协同办公平台 v1.0.0</view>
</view>
</view>
</template>
<script>
import md5 from '@/service/md5.js'
export default {
data() {
return {
statusBarHeight: 0,
loading: false,
showPassword: false,
formData: {
username: '',
password: ''
}
}
},
onLoad() {
this.getSystemInfo()
},
methods: {
// 获取系统信息
getSystemInfo() {
uni.getSystemInfo({
success: (res) => {
this.statusBarHeight = res.statusBarHeight
}
})
},
// 切换密码显示
togglePassword() {
this.showPassword = !this.showPassword
},
// 表单验证
validateForm() {
if (!this.formData.username.trim()) {
uni.showToast({
title: '请输入用户名',
icon: 'none'
})
return false
}
if (!this.formData.password.trim()) {
uni.showToast({
title: '请输入密码',
icon: 'none'
})
return false
}
return true
},
async getuser(){
await this.API.getCurrentUser().then(res=>{
console.error(res)
if(res.code === 200){
let date = new Date();
uni.setStorageSync('userInfo', res.data.userInfo)
}
})
},
// 处理登录
async handleLogin() {
if (!this.validateForm()) {
return
}
this.loading = true
try {
// 对密码进行MD5加密
const password = md5.hex_md5(this.formData.password)
const res = await this.API.AppLogin({
account: this.formData.username,
password: password
})
if (res.code === 200 || res.success) {
// 登录成功
const { token} = res.data
// 保存token和用户信息
uni.setStorageSync('token', token)
await this.getuser()
uni.showToast({
title: '登录成功',
icon: 'success'
})
// 延迟跳转
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index'
})
}, 1500)
} else {
// 登录失败
uni.showToast({
title: res.message || '登录失败,请重试',
icon: 'none'
})
}
} catch (error) {
console.error('登录失败:', error)
uni.showToast({
title: '网络错误,请稍后重试',
icon: 'none'
})
} finally {
this.loading = false
}
}
}
}
</script>
<style lang="scss" scoped>
.login-container {
min-height: 100vh;
background: linear-gradient(135deg, #e8f5e9 0%, #b2dfdb 100%);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40rpx;
}
.status-bar {
background: linear-gradient(120deg, #43e97b 0%, #38f9d7 100%);
}
.login-card {
width: 100%;
max-width: 840rpx;
background: #fff;
border-radius: 36rpx;
box-shadow: 0 8rpx 48rpx 0 rgba(76, 175, 80, 0.10), 0 3rpx 12rpx 0 rgba(76, 175, 80, 0.08);
border: 3rpx solid #c8e6c9;
overflow: hidden;
}
.login-header {
background: linear-gradient(120deg, #43e97b 0%, #38f9d7 100%);
padding: 64rpx 48rpx 48rpx 48rpx;
text-align: center;
position: relative;
}
.login-header::after {
content: '';
position: absolute;
bottom: -40rpx;
left: 50%;
transform: translateX(-50%);
width: 80rpx;
height: 80rpx;
background: #fff;
border-radius: 50%;
box-shadow: 0 4rpx 24rpx 0 rgba(67, 233, 123, 0.08);
}
.title {
color: #fff;
font-size: 56rpx;
font-weight: bold;
letter-spacing: 4rpx;
margin-bottom: 16rpx;
}
.subtitle {
color: #e0f2f1;
font-size: 30rpx;
margin-bottom: 0;
}
.login-form {
padding: 80rpx 48rpx 64rpx 48rpx;
}
.form-group {
margin-bottom: 40rpx;
}
.form-group:last-child {
margin-bottom: 0;
}
.form-label {
display: block;
margin-bottom: 16rpx;
font-weight: bold;
color: #388e3c;
letter-spacing: 2rpx;
font-size: 30rpx;
}
.input-wrapper {
position: relative;
display: flex;
align-items: center;
background: #f9fff9;
border: 3rpx solid #c8e6c9;
border-radius: 20rpx;
padding: 0 24rpx;
height: 88rpx;
transition: all 0.2s ease;
}
.input-wrapper:focus-within {
border-color: #43a047;
box-shadow: 0 0 0 6rpx rgba(67, 233, 123, 0.15);
background: #fff;
}
.input-icon {
position: absolute;
left: 24rpx;
z-index: 2;
}
.custom-input {
flex: 1;
margin: 0 16rpx 0 80rpx;
}
.password-toggle {
position: absolute;
right: 24rpx;
z-index: 2;
}
.form-actions {
margin-top: 16rpx;
}
.login-btn {
width: 100%;
height: 88rpx;
background: linear-gradient(90deg, #43a047 60%, #66bb6a 100%);
border-radius: 20rpx;
font-size: 34rpx;
font-weight: bold;
letter-spacing: 4rpx;
box-shadow: 0 4rpx 16rpx #a5d6a7;
transition: all 0.2s ease;
color: #fff;
}
.login-btn:active {
background: linear-gradient(90deg, #388e3c 60%, #43a047 100%);
box-shadow: 0 8rpx 32rpx #a5d6a7;
transform: translateY(-2rpx);
color: #fff;
}
.login-btn:disabled {
background: #ccc;
cursor: not-allowed;
transform: none;
box-shadow: none;
color: #fff;
}
.footer {
text-align: center;
padding: 40rpx;
margin-top: 40rpx;
}
.footer-text {
color: #6a9c6a;
font-size: 24rpx;
opacity: 0.8;
}
/* 移动端适配 */
// @media (max-width: 750rpx) {
// .login-container {
// padding: 32rpx;
// }
// .login-header {
// padding: 48rpx 40rpx 40rpx 40rpx;
// }
// .login-form {
// padding: 64rpx 40rpx 48rpx 40rpx;
// }
// .title {
// font-size: 52rpx;
// }
// }
</style>