<template>
	<view class="login-container">
		<view class="login-box">
			<view class="title">宿舍管理系统</view>

			<view class="input-group">
				<view class="input-item">
					<input type="text" v-model="username" placeholder="请输入账号" />
				</view>

				<view class="input-item">
					<input type="password" v-model="password" placeholder="请输入密码" />
				</view>
			</view>

			<button class="login-btn" @click="handleLogin">
				<text>登录</text>
			</button>

			<view class="tips">
				<text>账号: 20030229</text>
				<text>密码: hahaha</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	
	const username = ref('')
	const password = ref('')
	const handleLogin = function() {
			if (!username.value & password.value) {
				uni.showToast({
					title: '请输入账号',
					icon:'none'
				})
				return
			}
			if (username.value & !password.value) {
				uni.showToast({
					title: '请输入密码',
					icon:'none'
				})
				return
			}
			if (!username.value & !password.value) {
				uni.showToast({
					title: '请输入账号和密码',
					icon:'none'
				})
				return
			}

			if (username.value === '20030229' && password.value === 'hahaha') {
				setTimeout(() => {
					uni.setStorageSync('isLogin', true)
					uni.switchTab({
						url: '/pages/index/index'
					})
				}, 1000)
			} else {
				uni.showToast({
					title: '账号或密码错误',
					icon:'none'
				})
			}
			}
</script>
<style scoped>
	.login-container {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100vh;
		background-color: #f5f5f5;
	}

	.login-box {
		width: 70vw;
		background-color: #fff;
		border-radius: 20rpx;
		padding: 60rpx 40rpx;
		box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
	}

	.title {
		text-align: center;
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 10vh;
	}

	.input-group {
		margin-bottom: 60rpx;
	}

	.input-item {
		display: flex;
		align-items: center;
		border-bottom: 1px solid #eee;
		padding: 20rpx 20rpx;
	}

	.login-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 40vw;
		height: 4vh;
		background-color: #36bffa;
		color: #fff;
		border-radius: 40rpx;
		font-size: 30rpx;
	}

	.tips {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 5vh;
		color: #999;
		font-size: 24rpx;
	}

	.tips text {
		margin-top: 10rpx;
	}
</style>