c293da23
刘淇
新园林init
|
1
2
|
<template>
<view class="login-page">
|
37c26bd3
刘淇
巡查计划
|
3
4
5
6
|
<!-- 纯CSS渐变动效背景(替代粒子动画,兼容所有版本) -->
<view class="bg-animation"></view>
<!-- 登录表单区域(悬浮层) -->
|
c293da23
刘淇
新园林init
|
7
|
<view class="login-form">
|
37c26bd3
刘淇
巡查计划
|
8
9
10
|
<!-- 登录标题(简约大气) -->
<view class="login-title">园林登录</view>
|
c293da23
刘淇
新园林init
|
11
12
13
14
15
16
17
18
19
20
|
<!-- 账号输入框 -->
<view class="form-item">
<up-input
v-model="form.account"
placeholder="请输入登录账号"
border="surround"
clearable
input-align="left"
:disabled="isLoading"
@blur="checkAccount"
|
37c26bd3
刘淇
巡查计划
|
21
22
23
24
|
:custom-style="{
backgroundColor: 'rgba(255, 255, 255, 0.9)',
borderColor: '#e5e7eb'
}"
|
c293da23
刘淇
新园林init
|
25
26
|
>
<template #prefix>
|
37c26bd3
刘淇
巡查计划
|
27
|
<up-icon name="account" color="#6b7280" size="20"></up-icon>
|
c293da23
刘淇
新园林init
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
</template>
</up-input>
<!-- 账号错误提示 -->
<view class="error-tip" v-if="error.account">{{ error.account }}</view>
</view>
<!-- 密码输入框(移除查看密码功能) -->
<view class="form-item">
<up-input
v-model="form.password"
placeholder="请输入登录密码"
border="surround"
clearable
input-align="left"
type="password"
:disabled="isLoading"
@blur="checkPassword"
|
37c26bd3
刘淇
巡查计划
|
45
46
47
48
|
:custom-style="{
backgroundColor: 'rgba(255, 255, 255, 0.9)',
borderColor: '#e5e7eb'
}"
|
c293da23
刘淇
新园林init
|
49
50
|
>
<template #prefix>
|
37c26bd3
刘淇
巡查计划
|
51
|
<up-icon name="lock" color="#6b7280" size="20"></up-icon>
|
c293da23
刘淇
新园林init
|
52
53
54
55
56
57
58
59
60
61
62
63
64
|
</template>
</up-input>
<!-- 密码错误提示 -->
<view class="error-tip" v-if="error.password">{{ error.password }}</view>
</view>
<!-- 登录按钮 -->
<up-button
class="login-btn"
type="primary"
size="large"
:loading="isLoading"
@click="handleLogin"
|
37c26bd3
刘淇
巡查计划
|
65
66
67
68
69
70
71
72
|
:custom-style="{
backgroundColor: '#3b82f6',
borderColor: '#3b82f6',
borderRadius: '44rpx',
height: '88rpx',
lineHeight: '88rpx',
fontSize: '32rpx'
}"
|
c293da23
刘淇
新园林init
|
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
|
>
登录
</up-button>
</view>
</view>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue';
import { useUserStore } from '@/pinia/user';
import globalConfig from '@/common/config/global';
// 表单数据
const form = reactive({
account: '', // 账号
password: '' // 密码
});
// 状态管理
const isLoading = ref(false);
const error = reactive({
account: '',
password: ''
});
// 实例化 Pinia 用户仓库
const userStore = useUserStore();
|
37c26bd3
刘淇
巡查计划
|
101
|
// 页面加载时初始化
|
c293da23
刘淇
新园林init
|
102
|
onMounted(() => {
|
37c26bd3
刘淇
巡查计划
|
103
104
105
106
107
108
|
// 检查登录态
checkLoginStatus();
});
// 检查登录状态
const checkLoginStatus = () => {
|
c293da23
刘淇
新园林init
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
try {
// 已登录则直接跳首页
if (userStore.isLogin) {
uni.switchTab({
url: globalConfig.router.tabBarList[1].path,
fail: () => {
// 非tabBar页面用redirectTo
uni.redirectTo({ url: '/pages/workbench/index' });
}
});
return;
}
} catch (err) {
console.warn('检查登录状态失败:', err);
}
|
37c26bd3
刘淇
巡查计划
|
124
|
};
|
c293da23
刘淇
新园林init
|
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
|
// 校验账号
const checkAccount = () => {
if (!form.account) {
error.account = '请输入登录账号';
} else if (!/^[a-zA-Z0-9_-]{4,16}$/.test(form.account)) {
error.account = '账号格式错误(4-16位字母/数字/下划线)';
} else {
error.account = '';
}
};
// 校验密码
const checkPassword = () => {
if (!form.password) {
error.password = '请输入登录密码';
} else if (form.password.length < 6) {
error.password = '密码长度不能少于6位';
} else {
error.password = '';
}
};
// 表单整体校验
const validateForm = () => {
checkAccount();
checkPassword();
return !error.account && !error.password;
};
|
37c26bd3
刘淇
巡查计划
|
155
|
// 登录处理
|
c293da23
刘淇
新园林init
|
156
157
158
159
160
161
162
163
164
165
166
167
168
|
const handleLogin = async () => {
if (!validateForm()) return;
isLoading.value = true;
try {
await userStore.login({
username: form.account,
password: form.password
});
uni.showToast({ title: '登录成功', icon: 'success', duration: 1500 });
|
37c26bd3
刘淇
巡查计划
|
169
|
// 登录成功后跳转首页
|
c293da23
刘淇
新园林init
|
170
|
setTimeout(() => {
|
c293da23
刘淇
新园林init
|
171
172
173
174
|
uni.switchTab({
url: globalConfig.router.tabBarList[1].path,
fail: (err) => {
console.warn('tabBar跳转失败,切换为普通跳转:', err);
|
c293da23
刘淇
新园林init
|
175
176
177
178
|
uni.redirectTo({ url: '/pages/workbench/index' });
}
});
}, 1500);
|
c293da23
刘淇
新园林init
|
179
180
|
} catch (err) {
console.error('登录失败详情:', err);
|
37c26bd3
刘淇
巡查计划
|
181
182
183
184
|
const errorMsg =
err.message === '网络异常,请稍后重试'
? '网络异常,请稍后重试'
: err.message || '登录失败,请检查账号密码';
|
c293da23
刘淇
新园林init
|
185
186
187
188
189
190
191
192
193
194
195
196
|
uni.showToast({
title: errorMsg,
icon: 'none',
duration: 2000
});
} finally {
isLoading.value = false;
}
};
</script>
<style scoped lang="scss">
|
37c26bd3
刘淇
巡查计划
|
197
|
// 核心布局
|
c293da23
刘淇
新园林init
|
198
199
|
.login-page {
min-height: 100vh;
|
37c26bd3
刘淇
巡查计划
|
200
|
position: relative;
|
c293da23
刘淇
新园林init
|
201
202
|
padding: 40rpx 30rpx;
box-sizing: border-box;
|
37c26bd3
刘淇
巡查计划
|
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
|
overflow: hidden; // 隐藏动效溢出
// 适配小程序安全区
/* #ifdef MP-WEIXIN */
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
/* #endif */
}
// 纯CSS渐变动效背景(替代粒子,兼容所有版本)
.bg-animation {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
// 基础渐变底色
background: linear-gradient(120deg, #f0f9ff 0%, #e6f7ff 100%);
// 伪粒子动效(多个透明渐变圆缓慢移动)
&::before,
&::after {
content: '';
position: absolute;
border-radius: 50%;
background: rgba(59, 130, 246, 0.05);
animation: float 20s infinite linear;
}
&::before {
width: 600rpx;
height: 600rpx;
top: -200rpx;
left: -200rpx;
}
&::after {
width: 800rpx;
height: 800rpx;
bottom: -300rpx;
right: -300rpx;
animation-delay: -10s; // 错开动画时间
}
// 额外小动效点(模拟粒子)
& > view {
position: absolute;
width: 400rpx;
height: 400rpx;
border-radius: 50%;
background: rgba(59, 130, 246, 0.03);
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: float 15s infinite linear reverse;
}
}
// 浮动动画(模拟粒子运动)
@keyframes float {
0% {
transform: translate(0, 0) rotate(0deg);
}
25% {
transform: translate(50rpx, 30rpx) rotate(90deg);
}
50% {
transform: translate(0, 60rpx) rotate(180deg);
}
75% {
transform: translate(-50rpx, 30rpx) rotate(270deg);
}
100% {
transform: translate(0, 0) rotate(360deg);
}
|
c293da23
刘淇
新园林init
|
278
279
|
}
|
37c26bd3
刘淇
巡查计划
|
280
|
// 登录表单(悬浮层)
|
c293da23
刘淇
新园林init
|
281
|
.login-form {
|
37c26bd3
刘淇
巡查计划
|
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
position: relative;
z-index: 10;
background-color: rgba(255, 255, 255, 0.95);
padding: 60rpx 40rpx;
border-radius: 16rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
max-width: 600rpx;
margin: 0 auto;
margin-top: 100rpx;
// 登录标题
.login-title {
font-size: 36rpx;
font-weight: 600;
color: #111827;
text-align: center;
margin-bottom: 40rpx;
letter-spacing: 2rpx;
}
|
c293da23
刘淇
新园林init
|
301
302
|
}
|
37c26bd3
刘淇
巡查计划
|
303
|
// 表单项
|
c293da23
刘淇
新园林init
|
304
305
306
|
.form-item {
margin-bottom: 30rpx;
position: relative;
|
c293da23
刘淇
新园林init
|
307
|
|
37c26bd3
刘淇
巡查计划
|
308
309
310
311
312
313
314
315
|
// 错误提示
.error-tip {
font-size: 24rpx;
color: #ef4444;
margin-top: 10rpx;
line-height: 1.2;
padding-left: 10rpx;
}
|
c293da23
刘淇
新园林init
|
316
317
|
}
|
37c26bd3
刘淇
巡查计划
|
318
|
// 登录按钮
|
c293da23
刘淇
新园林init
|
319
320
|
.login-btn {
width: 100%;
|
37c26bd3
刘淇
巡查计划
|
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
margin-top: 20rpx;
// 按钮点击反馈
&:active {
transform: scale(0.98);
transition: transform 0.1s ease;
}
}
// 覆盖uview默认样式
:deep(.up-input) {
border-radius: 8rpx !important;
height: 80rpx !important;
line-height: 80rpx !important;
}
:deep(.up-input__prefix) {
margin-right: 15rpx !important;
}
:deep(.up-button__loading) {
color: #fff !important;
|
c293da23
刘淇
新园林init
|
343
344
|
}
</style>
|