xto-fronted 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,14 @@
1
1
  <script setup lang="ts">
2
2
  import { ref, reactive } from 'vue'
3
- import { useRouter } from 'vue-router'
3
+ import { useRouter, useRoute } from 'vue-router'
4
4
  import { Button } from '@xto/base'
5
5
  import { Form, FormItem, Input, Checkbox } from '@xto/form'
6
6
  import { Message } from '@xto/feedback'
7
- import { useAuthStore } from '@/stores/auth'
8
- import { useUserStore } from '@/stores/user'
9
- import { useMenuStore } from '@/stores/menu'
7
+ import { login } from '@/api/auth'
8
+ import { setTokenInfo } from '@/utils/auth'
10
9
 
11
10
  const router = useRouter()
12
- const authStore = useAuthStore()
13
- const userStore = useUserStore()
14
- const menuStore = useMenuStore()
11
+ const route = useRoute()
15
12
 
16
13
  const loading = ref(false)
17
14
  const rememberMe = ref(false)
@@ -39,85 +36,25 @@ const handleLogin = async () => {
39
36
  await formRef.value?.validate()
40
37
  loading.value = true
41
38
 
42
- // Mock 登录
43
- setTimeout(() => {
44
- // 设置 token
45
- authStore.login({
46
- token: 'mock_token_' + Date.now(),
47
- refreshToken: 'mock_refresh_token',
48
- expireTime: Date.now() + 7 * 24 * 60 * 60 * 1000
49
- })
50
-
51
- // 设置用户信息
52
- userStore.setUserInfo({
53
- id: 1,
54
- username: formData.username,
55
- nickname: '管理员',
56
- avatar: '',
57
- email: 'admin@example.com',
58
- phone: '13800138000',
59
- status: 1,
60
- roles: ['admin'],
61
- permissions: ['*'],
62
- createTime: new Date().toISOString()
63
- })
64
-
65
- // 设置菜单
66
- menuStore.setMenuList([
67
- {
68
- id: 1,
69
- name: 'Dashboard',
70
- path: '/dashboard',
71
- component: 'dashboard/index',
72
- icon: 'dashboard',
73
- title: '仪表盘',
74
- keepAlive: true,
75
- affix: true
76
- },
77
- {
78
- id: 2,
79
- name: 'System',
80
- path: '/system',
81
- redirect: '/system/user',
82
- icon: 'setting',
83
- title: '系统管理',
84
- children: [
85
- {
86
- id: 21,
87
- name: 'SystemUser',
88
- path: '/system/user',
89
- component: 'system/user/index',
90
- icon: 'user',
91
- title: '用户管理',
92
- keepAlive: true
93
- },
94
- {
95
- id: 22,
96
- name: 'SystemRole',
97
- path: '/system/role',
98
- component: 'system/role/index',
99
- icon: 'role',
100
- title: '角色管理',
101
- keepAlive: true
102
- },
103
- {
104
- id: 23,
105
- name: 'SystemMenu',
106
- path: '/system/menu',
107
- component: 'system/menu/index',
108
- icon: 'menu',
109
- title: '菜单管理',
110
- keepAlive: true
111
- }
112
- ]
113
- }
114
- ])
115
-
116
- Message.success('登录成功')
117
- router.push('/')
118
- loading.value = false
119
- }, 1000)
39
+ // 调用登录 API
40
+ const result = await login({
41
+ username: formData.username,
42
+ password: formData.password
43
+ })
44
+
45
+ // 保存 token
46
+ setTokenInfo(result)
47
+
48
+ Message.success('登录成功')
49
+
50
+ // 获取重定向地址
51
+ const redirect = route.query.redirect as string || '/'
52
+
53
+ // 跳转到目标页面(路由守卫会自动获取用户信息和菜单)
54
+ router.push(redirect)
120
55
  } catch (error) {
56
+ console.error('登录失败:', error)
57
+ } finally {
121
58
  loading.value = false
122
59
  }
123
60
  }
@@ -178,7 +115,7 @@ const handleLogin = async () => {
178
115
  </Form>
179
116
 
180
117
  <div class="login__footer">
181
- <p>提示: 任意用户名密码即可登录 (Mock 模式)</p>
118
+ <p>默认账号: admin / 123456</p>
182
119
  </div>
183
120
  </div>
184
121
  </div>