create-librex 1.0.2 → 1.0.3
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.
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<style scoped>
|
|
13
13
|
.not-found-page {
|
|
14
14
|
display: flex; align-items: center; justify-content: center;
|
|
15
|
-
|
|
15
|
+
width: 100%; height: 100%;
|
|
16
16
|
background: var(--color-bg-viewport, #f0f2f5);
|
|
17
17
|
color: var(--color-text-primary, #333);
|
|
18
18
|
}
|
|
@@ -22,29 +22,38 @@ export const useUserStore = defineStore('user', () => {
|
|
|
22
22
|
async function login(credentials: { username: string; password: string }): Promise<boolean> {
|
|
23
23
|
loading.value = true
|
|
24
24
|
try {
|
|
25
|
-
//
|
|
25
|
+
// DEMO 账号 — 无后端时可用,替换为你的 API 后请删除
|
|
26
|
+
if (credentials.username === 'admin' && credentials.password === 'admin123') {
|
|
27
|
+
token.value = 'demo-token-librex'
|
|
28
|
+
currentUser.value = { id: 1, name: 'Admin', role: 'admin' }
|
|
29
|
+
localStorage.setItem(TOKEN_KEY, token.value)
|
|
30
|
+
localStorage.setItem(USER_KEY, JSON.stringify(currentUser.value))
|
|
31
|
+
loading.value = false
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 实际 API 登录
|
|
26
36
|
const res = await fetch('/api/admin/login', {
|
|
27
37
|
method: 'POST',
|
|
28
38
|
headers: { 'Content-Type': 'application/json' },
|
|
29
39
|
body: JSON.stringify({ account: credentials.username, password: credentials.password }),
|
|
30
40
|
})
|
|
31
41
|
const data = await res.json()
|
|
32
|
-
if (data.code !== 1 || !data.data) return false
|
|
42
|
+
if (data.code !== 1 || !data.data) { loading.value = false; return false }
|
|
33
43
|
|
|
34
44
|
token.value = data.data.token || data.data.session_id
|
|
35
45
|
localStorage.setItem(TOKEN_KEY, token.value || '')
|
|
36
46
|
|
|
37
|
-
// 获取用户信息
|
|
38
47
|
const user = await fetchUserInfo()
|
|
39
48
|
if (user) {
|
|
40
49
|
currentUser.value = user
|
|
41
50
|
localStorage.setItem(USER_KEY, JSON.stringify(user))
|
|
42
51
|
}
|
|
52
|
+
loading.value = false
|
|
43
53
|
return true
|
|
44
54
|
} catch {
|
|
45
|
-
return false
|
|
46
|
-
} finally {
|
|
47
55
|
loading.value = false
|
|
56
|
+
return false
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
|