Files
FT541-WMS/RuoYi-App-master/pages/login.vue
2026-06-16 13:29:22 +08:00

413 lines
11 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="normal-login-container">
<view class="logo-content align-center justify-center flex">
<image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
</image>
<text class="title">{{ $t('login.appTitle') }}</text>
</view>
<view class="login-form-content">
<view class="input-item flex align-center">
<view class="iconfont icon-user icon"></view>
<input v-model="loginForm.username" class="input" type="text" :placeholder="$t('login.usernamePlaceholder')" maxlength="30" @focus="showAccountList = true" @input="handleUsernameInput" />
<view class="history-accounts" v-if="showAccountList && historyAccounts.length > 0">
<view v-for="(account, index) in historyAccounts" :key="index" class="account-item" @click="selectAccount(account)">
{{ account }}
</view>
</view>
</view>
<view class="input-item flex align-center">
<view class="iconfont icon-password icon"></view>
<input v-model="loginForm.password" type="password" class="input" :placeholder="$t('login.passwordPlaceholder')" maxlength="20" />
</view>
<view class="remember-account flex align-center">
<checkbox :checked="rememberAccount" @click="toggleRememberAccount" style="transform:scale(0.7)" />
<text class="text-grey1" >{{ $t('login.rememberAccount') }}</text>
</view>
<view class="action-btn">
<button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">{{ $t('login.login') }}</button>
<button @click="goToSettings" class="settings-btn cu-btn block lg round">{{ $t('login.serverSettings') }}</button>
</view>
<!-- <view class="reg text-center" v-if="register">
<text class="text-grey1">没有账号?</text>
<text @click="handleUserRegister" class="text-blue">立即注册</text>
</view> -->
<!-- <view class="xieyi text-center">
<text class="text-grey1">登录即代表同意</text>
<text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
<text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
</view> -->
</view>
<view class="copyright-section text-center">
<text class="version">{{ $t('login.version') }}</text>
<text class="copyright">{{ $t('login.copyright') }}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
globalConfig: getApp().globalData.config,
rememberAccount: false,
historyAccounts: [],
showAccountList: false,
loginForm: {
username: "",
password: ""
}
}
},
created() {
// 检查服务器配置
const serverSettings = uni.getStorageSync('serverSettings')
console.log(serverSettings)
if (!serverSettings) {
// 如果没有服务器配置,跳转到设置页面
uni.reLaunch({
url: '/pages/setting'
})
return
}
// 获取历史账号列表
const accounts = uni.getStorageSync('historyAccounts')
if (accounts) {
this.historyAccounts = JSON.parse(accounts)
}
// 添加点击事件监听器
uni.onWindowResize(() => {
this.showAccountList = false
})
},
mounted() {
// 添加全局点击事件监听
document.addEventListener('click', this.handleGlobalClick)
},
beforeDestroy() {
// 移除全局点击事件监听
document.removeEventListener('click', this.handleGlobalClick)
},
methods: {
// 登录方法
async handleLogin() {
if (this.loginForm.username === "") {
this.$modal.msgError(this.$t('login.usernameRequired'))
} else if (this.loginForm.password === "") {
this.$modal.msgError(this.$t('login.passwordRequired'))
} else {
this.$modal.loading(this.$t('login.loggingIn'))
this.pwdLogin()
}
},
// 密码登录
async pwdLogin() {
this.$store.dispatch('Login', this.loginForm).then(() => {
this.$modal.closeLoading()
this.loginSuccess()
}).catch(() => {
if (this.captchaEnabled) {
this.getCode()
}
})
},
// 登录成功后,处理函数
loginSuccess(result) {
// 如果勾选了记住账号,保存到本地存储
if (this.rememberAccount && this.loginForm.username) {
let accounts = this.historyAccounts || []
if (!accounts.includes(this.loginForm.username)) {
accounts.unshift(this.loginForm.username)
if (accounts.length > 5) {
accounts = accounts.slice(0, 5)
}
uni.setStorageSync('historyAccounts', JSON.stringify(accounts))
this.historyAccounts = accounts
}
} else if (!this.rememberAccount && this.loginForm.username) {
// 如果未勾选记住账号,从历史账号列表中删除当前账号
const updatedAccounts = this.historyAccounts.filter(account => account !== this.loginForm.username)
uni.setStorageSync('historyAccounts', JSON.stringify(updatedAccounts))
this.historyAccounts = updatedAccounts
this.showAccountList = false
}
// 设置用户信息
this.$store.dispatch('GetInfo').then(res => {
if (res) {
uni.switchTab({
url: '/pages/index',
success: () => {
console.log('页面跳转成功')
},
fail: (err) => {
console.error('页面跳转失败:', err)
this.$modal.msgError('页面跳转失败,请重试')
}
})
}
}).catch(err => {
console.error('获取用户信息失败:', err)
this.$modal.msgError('获取用户信息失败,请重试')
})
},
//选择历史账号
selectAccount(account) {
this.loginForm.username = account
this.showAccountList = false
},
// 切换记住账号状态
toggleRememberAccount() {
this.rememberAccount = !this.rememberAccount
},
// 处理用户名输入
handleUsernameInput() {
if (!this.loginForm.username) {
this.showAccountList = false
return
}
// 检查输入是否与任何历史账号匹配
const hasMatch = this.historyAccounts.some(account =>
account.startsWith(this.loginForm.username)
)
this.showAccountList = hasMatch
},
// 处理全局点击事件
handleGlobalClick(event) {
const loginForm = document.querySelector('.login-form-content')
if (loginForm && !loginForm.contains(event.target)) {
this.showAccountList = false
}
},
// 跳转到设置页面
goToSettings() {
uni.navigateTo({
url: '/pages/setting'
})
}
}
}
</script>
<style lang="scss">
page {
background-color: #f8f9fa;
}
.normal-login-container {
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
.logo-content {
width: 100%;
font-size: 24px;
text-align: center;
padding-top: 10%;
margin-bottom: 40px;
animation: fadeInDown 0.8s ease;
image {
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
transition: transform 0.3s ease;
&:hover {
transform: scale(1.05);
}
}
.title {
margin-left: 15px;
font-weight: 600;
color: #2c3e50;
}
}
.login-form-content {
text-align: center;
margin: 20px auto;
width: 85%;
max-width: 400px;
background: #ffffff;
padding: 30px 20px;
border-radius: 16px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
animation: fadeInUp 0.8s ease;
.input-item {
margin: 25px auto;
background-color: #f8f9fa;
height: 50px;
border-radius: 25px;
position: relative;
transition: all 0.3s ease;
&:focus-within {
background-color: #fff;
box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}
.icon {
font-size: 20px;
margin-left: 20px;
color: #666;
}
.input {
width: 100%;
font-size: 15px;
line-height: 20px;
text-align: left;
padding-left: 15px;
color: #333;
&::placeholder {
color: #999;
}
}
.history-accounts {
position: absolute;
top: 110%;
left: 0;
width: 100%;
background-color: #fff;
border-radius: 12px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
z-index: 100;
overflow: hidden;
.account-item {
padding: 12px 20px;
text-align: left;
border-bottom: 1px solid #f0f0f0;
transition: background-color 0.2s ease;
&:last-child {
border-bottom: none;
}
&:hover {
background-color: #f5f7fa;
}
}
}
}
.remember-account {
width: 100%;
padding: 0 25px;
margin-top: -5px;
justify-content: flex-start;
.text-grey1 {
font-size: 14px;
margin-left: 8px;
color: #666;
}
}
.login-btn {
margin-top: 35px;
height: 50px;
font-size: 16px;
font-weight: 600;
letter-spacing: 1px;
background: linear-gradient(135deg, #4285f4, #34a853);
border: none;
transition: transform 0.2s ease, box-shadow 0.2s ease;
&:active {
transform: scale(0.98);
}
}
.settings-btn {
margin-top: 15px;
height: 50px;
font-size: 16px;
font-weight: 600;
letter-spacing: 1px;
background: #f8f9fa;
color: #666;
border: 1px solid #ddd;
transition: transform 0.2s ease, box-shadow 0.2s ease;
&:active {
transform: scale(0.98);
}
}
.reg {
margin-top: 20px;
}
.xieyi {
color: #666;
margin-top: 25px;
font-size: 14px;
.text-blue {
color: #4285f4;
margin: 0 4px;
transition: color 0.2s ease;
&:hover {
color: #2b579a;
}
}
}
}
.copyright-section {
position: fixed;
bottom: 20px;
left: 0;
width: 100%;
padding: 15px;
.version {
display: block;
font-size: 12px;
color: #999;
margin-bottom: 8px;
}
.copyright {
display: block;
font-size: 12px;
color: #999;
}
}
}
@keyframes fadeInDown {
from {
opacity: 0;
transform: translateY(-20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>