20260819101952
This commit is contained in:
1 parent
e91fd1d8de
commit
1ffc8e1ac9
14 files changed
+258
-886
No files matched your search
@@ -9,6 +9,7 @@ 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'
|
||||
import { usePermissionStore } from '@/stores/permissions'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
@@ -36,9 +37,24 @@ const formRules = {
|
||||
|
||||
const submitting = ref(false)
|
||||
|
||||
const LAST_LOGIN_KEY = 'fms-last-login'
|
||||
|
||||
onMounted(() => {
|
||||
formModel.orgId = authStore.orgId || ''
|
||||
formModel.userId = authStore.user?.account || ''
|
||||
// 从独立存储读取上次登录信息回填,与认证状态分离
|
||||
let lastOrgId = ''
|
||||
let lastAccount = ''
|
||||
try {
|
||||
const raw = localStorage.getItem(LAST_LOGIN_KEY)
|
||||
if (raw) {
|
||||
const last = JSON.parse(raw)
|
||||
lastOrgId = last.orgId || ''
|
||||
lastAccount = last.account || ''
|
||||
}
|
||||
} catch {
|
||||
// 解析失败不影响登录
|
||||
}
|
||||
formModel.orgId = lastOrgId
|
||||
formModel.userId = lastAccount
|
||||
formModel.password = ''
|
||||
// 聚焦机构码输入框(id 落在 Input 根元素上,需定位内部 input)
|
||||
document.querySelector('#orgId input')?.focus()
|
||||
@@ -53,6 +69,8 @@ async function onSubmit(values) {
|
||||
{ token: res.data.token, user: { ...res.data.user, account: values.userId } },
|
||||
res.data.orgid ?? values.orgId,
|
||||
)
|
||||
// 登录成功后、进入布局前先把菜单/权限数据拉齐,避免 /dashboard 挂载时菜单异步“跳出”
|
||||
await usePermissionStore().load().catch(() => {})
|
||||
Message.success('登录成功')
|
||||
router.replace(String(route.query.redirect || '/dashboard'))
|
||||
} catch (e) {
|
||||
@@ -127,7 +145,7 @@ function onFailed() {
|
||||
</Input>
|
||||
</FormItem>
|
||||
|
||||
<Button type="default" block :loading="submitting" html-type="submit" class="login-submit">
|
||||
<Button type="primary" block :loading="submitting" html-type="submit" class="login-submit">
|
||||
登录
|
||||
</Button>
|
||||
</Form>
|
||||
|
||||
Reference in new issue
Block a user