You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.0 KiB

<template>
<view class="login-bg">
<view class="login-card">
<view class="login-title">欢迎登录</view>
<view class="login-subtitle">河道防汛物资管理系统</view>
<view class="form-group">
<text class="form-label">用户名</text>
<input class="form-input" type="text" v-model="username" placeholder="请输入用户名" />
</view>
<view class="form-group">
<text class="form-label">密码</text>
<input class="form-input" type="password" v-model="password" placeholder="请输入密码" />
</view>
<button class="login-btn" @click="handleLogin"> </button>
</view>
</view>
</template>
<script>
import { login } from '@/api.js'
export default {
data() {
return {
username: '',
password: ''
}
},
methods: {
handleLogin() {
if (!this.username || !this.password) {
uni.showToast({
title: '请输入用户名和密码',
icon: 'none'
});
return;
}
uni.showLoading({ title: '登录中...', mask: true });
login(this.username, this.password)
.then(response => {
uni.hideLoading();
console.log(response)
if (response.data && response.data.errcode !== undefined) {
uni.showToast({
title: response.data.errmsg || '登录失败',
icon: 'none'
});
} else if (response.data) {
console.log(response.data.access_token)
if (response.data.access_token) {
uni.setStorageSync('token', response.data.access_token)
}
uni.showToast({
title: '登录成功',
icon: 'success',
duration: 1500
});
setTimeout(() => {
uni.switchTab({
url: '/pages/index/index'
});
}, 1500);
}
})
.catch(() => {
uni.hideLoading();
uni.showToast({ title: '网络错误', icon: 'none' });
});
}
}
}
</script>
<style>
.login-bg {
min-height: 100vh;
background: linear-gradient(180deg, #eaf1fb 0%, #f7fafd 100%);
display: flex;
align-items: center;
justify-content: center;
}
.login-card {
width: 92vw;
max-width: 420px;
background: #fff;
border-radius: 28px;
box-shadow: 0 8px 32px rgba(64,158,255,0.10);
padding: 56px 24px 40px 24px;
display: flex;
flex-direction: column;
align-items: stretch;
}
.login-title {
font-size: 28px;
font-weight: 700;
color: #222;
text-align: center;
margin-bottom: 10px;
letter-spacing: 2px;
}
.login-subtitle {
font-size: 16px;
color: #7a8ca3;
text-align: center;
margin-bottom: 38px;
letter-spacing: 1px;
}
.form-group {
margin-bottom: 28px;
display: flex;
flex-direction: column;
}
.form-label {
font-size: 16px;
color: #3a3a3a;
margin-bottom: 10px;
font-weight: 500;
}
.form-input {
height: 52px;
border: 1.5px solid #e3e8f0;
border-radius: 14px;
padding: 0 16px;
font-size: 17px;
background: #f6f8fa;
color: #222;
transition: border 0.2s;
}
.form-input:focus {
border: 1.5px solid #409eff;
background: #fff;
}
.login-btn {
margin-top: 18px;
height: 58px;
background: linear-gradient(90deg, #409eff 0%, #3b7cff 100%);
color: #fff;
font-size: 22px;
font-weight: 800;
border-radius: 18px;
letter-spacing: 10px;
box-shadow: 0 6px 18px rgba(64,158,255,0.18);
transition: background 0.2s, box-shadow 0.2s;
border: none;
outline: none;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.login-btn:active {
background: linear-gradient(90deg, #337ecc 0%, #2a5db0 100%);
box-shadow: 0 2px 8px rgba(64,158,255,0.10);
}
@media (max-width: 400px) {
.login-card {
padding: 32px 8px 24px 8px;
}
.form-input, .login-btn {
height: 44px;
font-size: 16px;
}
}
</style>