Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | 7x 7x 7x 7x 8x 8x 7x 6x 7x 7x 7x 7x 7x 7x 7x 7x 2x 2x 2x 1x 2x 2x 2x 1x 2x 1x 7x 2x 2x 7x | <script setup>
import { computed, onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { Building2, GalleryVerticalEnd, KeyRound, User } from '@lucide/vue'
import Form from '@/components/ui/form/form.vue'
import FormItem from '@/components/ui/form/form-item.vue'
import Input from '@/components/ui/input/input.vue'
import Button from '@/components/ui/button/button.vue'
import Message from '@/components/ui/message/message-manager.js'
import { loginApi } from '@/services/api'
import { useAuthStore } from '@/stores/auth'
const router = useRouter()
const route = useRoute()
const authStore = useAuthStore()
/* ---------- 登录提示(携带 reason 跳转时展示) ---------- */
const loginHint = computed(() => {
const reason = String(route.query.reason || '')
if (reason === 'session-replaced') return '账号已在其他设备登录,请重新登录'
if (reason === 'expired') return '登录已过期,请重新登录'
return ''
})
/* ---------- 表单 ---------- */
const formModel = reactive({
orgId: '',
account: '',
password: '',
})
const formRules = {
orgId: [{ required: true, message: '请输入机构码' }],
account: [{ required: true, message: '请输入账号' }],
}
const submitting = ref(false)
onMounted(() => {
// 回填上次登录信息:由 persist 插件在启动时恢复,不手动碰 localStorage
formModel.orgId = authStore.userInfo.orgId || ''
formModel.account = authStore.userInfo.account || ''
formModel.password = ''
// 聚焦机构码输入框(id 落在 Input 根元素上,需定位内部 input)
document.querySelector('#orgId input')?.focus()
})
/* ---------- 提交 ---------- */
async function onSubmit(values) {
submitting.value = true
try {
const res = await loginApi(values.orgId, values.account, values.password ?? '')
authStore.setSession(
{ token: res.data.token, user: { ...res.data.user } },
res.data.orgid ?? values.orgId,
)
// 记住本次登录(机构码 + 账号),供下次回填;统一由 persist 插件持久化
authStore.saveLastLogin(values.orgId, values.account)
// 权限数据由路由守卫在跳转 /dashboard 时统一加载,无需在此预加载
Message.success('登录成功')
router.replace(String(route.query.redirect || '/dashboard'))
} catch (e) {
Message.error(e.message || '登录失败,请稍后重试')
} finally {
submitting.value = false
}
}
function onFailed() {
Message.warning('请填写完整的登录信息')
}
</script>
<template>
<div class="login-page">
<div class="login-card">
<!-- 品牌区 -->
<div class="login-brand">
<div class="login-logo" aria-hidden="true">
<GalleryVerticalEnd />
</div>
<h1 class="login-title">登录 FMS</h1>
<p class="login-subtitle">企业管理系统</p>
</div>
<!-- 会话提示条 -->
<div v-if="loginHint" class="login-hint" role="alert">
{{ loginHint }}
</div>
<!-- 表单 -->
<Form
class="login-form"
:model="formModel"
:rules="formRules"
layout="vertical"
@submit="onSubmit"
@submit-failed="onFailed"
>
<FormItem name="orgId" label="机构码">
<Input
id="orgId"
v-model="formModel.orgId"
placeholder="请输入机构码"
:disabled="submitting"
>
<template #prefix><Building2 /></template>
</Input>
</FormItem>
<FormItem name="account" label="账号">
<Input
id="account"
v-model="formModel.account"
autocomplete="username"
placeholder="请输入账号"
:disabled="submitting"
>
<template #prefix><User /></template>
</Input>
</FormItem>
<FormItem name="password" label="密码">
<Input
id="password"
v-model="formModel.password"
type="password"
autocomplete="current-password"
placeholder="请输入密码"
:disabled="submitting"
>
<template #prefix><KeyRound /></template>
</Input>
</FormItem>
<Button type="primary" block :loading="submitting" html-type="submit" class="login-submit">
登录
</Button>
</Form>
<p class="login-footer">© 2026 FMS · 企业管理系统</p>
</div>
</div>
</template>
<style scoped>
.login-page {
display: flex;
align-items: center;
justify-content: center;
min-height: 100svh;
padding: 24px;
background: var(--fms-background);
color: var(--fms-text);
transition:
background-color 200ms ease,
color 200ms ease;
}
.login-card {
width: 100%;
max-width: 400px;
padding: 40px 36px 28px;
background: var(--fms-card);
border: 1px solid var(--fms-border);
border-radius: 12px;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
transition:
background-color 200ms ease,
border-color 200ms ease;
}
.login-brand {
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
margin-bottom: 28px;
text-align: center;
}
.login-logo {
display: flex;
align-items: center;
justify-content: center;
width: 48px;
height: 48px;
margin-bottom: 8px;
border-radius: 12px;
background: var(--fms-primary);
color: var(--fms-primary-text);
:deep(svg) {
width: 26px;
height: 26px;
}
}
.login-title {
margin: 0;
font-size: 24px;
font-weight: 600;
line-height: 32px;
}
.login-subtitle {
margin: 0;
font-size: 14px;
color: var(--fms-text-secondary);
}
.login-hint {
margin-bottom: 20px;
padding: 10px 14px;
border-radius: var(--fms-control-radius);
background: color-mix(in srgb, var(--fms-warning) 12%, var(--fms-card));
border: 1px solid color-mix(in srgb, var(--fms-warning) 30%, transparent);
color: var(--fms-warning);
font-size: 13px;
text-align: center;
}
.login-form {
width: 100%;
}
.login-submit {
margin-top: 8px;
min-height: 40px;
}
.login-footer {
margin: 24px 0 0;
font-size: 12px;
color: var(--fms-text-secondary);
text-align: center;
}
@media (max-width: 480px) {
.login-card {
padding: 32px 24px 24px;
}
}
@media (prefers-reduced-motion: reduce) {
.login-page,
.login-card {
transition: none;
}
}
</style>
|