wanshenmean
2026-02-09 ae9517420d848e215a9eb807270d5ef6fbe92ae9
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
<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-header">
        <h1>WIDESEA WMS</h1>
        <p>仓库管理系统</p>
      </div>
      <a-form
        :model="formState"
        :rules="rules"
        @finish="handleLogin"
        class="login-form"
      >
        <a-form-item name="username">
          <a-input
            v-model:value="formState.username"
            size="large"
            placeholder="请输入用户名"
          >
            <template #prefix>
              <user-outlined />
            </template>
          </a-input>
        </a-form-item>
        <a-form-item name="password">
          <a-input-password
            v-model:value="formState.password"
            size="large"
            placeholder="请输入密码"
          >
            <template #prefix>
              <lock-outlined />
            </template>
          </a-input-password>
        </a-form-item>
        <a-form-item>
          <a-button
            type="primary"
            html-type="submit"
            size="large"
            :loading="loading"
            block
          >
            登录
          </a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { message } from 'ant-design-vue';
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue';
import { useAuthStore } from '../../stores/auth';
 
const router = useRouter();
const route = useRoute();
const authStore = useAuthStore();
 
const formState = reactive({
  username: '',
  password: '',
});
 
const rules = {
  username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
};
 
const loading = ref(false);
 
async function handleLogin() {
  loading.value = true;
  try {
    const success = await authStore.login(formState.username, formState.password);
    if (success) {
      message.success('登录成功');
      const redirect = (route.query.redirect as string) || '/';
      router.push(redirect);
    } else {
      message.error('登录失败,请检查用户名和密码');
    }
  } catch (error) {
    console.error('Login error:', error);
    message.error('登录失败');
  } finally {
    loading.value = false;
  }
}
</script>
 
<style scoped>
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
 
.login-box {
  width: 400px;
  padding: 40px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
 
.login-header {
  text-align: center;
  margin-bottom: 32px;
}
 
.login-header h1 {
  font-size: 32px;
  font-weight: bold;
  color: #333;
  margin: 0 0 8px 0;
}
 
.login-header p {
  font-size: 14px;
  color: #666;
  margin: 0;
}
 
.login-form {
  margin-top: 24px;
}
</style>