feat: 接入真实平台登录态
- login/session: 对接后端登录、鉴权恢复和首次改密 - api/store: 恢复 BPMN XML 真实接口并携带 Bearer token - layout/settings: 展示真实角色、审计 JSON 和通知平台配置文档
This commit is contained in:
+165
-21
@@ -1,22 +1,94 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 登录页对接后端真实鉴权,并处理普通成员首次登录强制改密。
|
||||
*/
|
||||
import { Lock, Monitor } from '@element-plus/icons-vue'
|
||||
import { reactive } from 'vue'
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useSessionStore } from '../stores/session'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const session = useSessionStore()
|
||||
const loading = ref(false)
|
||||
|
||||
const form = reactive({
|
||||
operator: 'ops-admin',
|
||||
const loginForm = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
})
|
||||
|
||||
const passwordForm = reactive({
|
||||
currentPassword: '',
|
||||
newPassword: '',
|
||||
confirmPassword: '',
|
||||
})
|
||||
|
||||
const redirect = computed(() =>
|
||||
typeof route.query.redirect === 'string' ? route.query.redirect : '/overview',
|
||||
)
|
||||
|
||||
async function submitLogin() {
|
||||
loading.value = true
|
||||
|
||||
try {
|
||||
const user = await session.login(loginForm)
|
||||
passwordForm.currentPassword = loginForm.password
|
||||
|
||||
if (user.mustChangePassword) {
|
||||
ElMessage.warning('首次登录请先修改密码')
|
||||
return
|
||||
}
|
||||
|
||||
await router.push(redirect.value)
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '登录失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function submitPasswordChange() {
|
||||
if (passwordForm.newPassword !== passwordForm.confirmPassword) {
|
||||
ElMessage.error('两次输入的新密码不一致')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
|
||||
try {
|
||||
await session.changePassword({
|
||||
currentPassword: passwordForm.currentPassword,
|
||||
newPassword: passwordForm.newPassword,
|
||||
})
|
||||
ElMessage.success('密码已更新')
|
||||
await router.push(redirect.value)
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '修改密码失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function logoutForAccountSwitch() {
|
||||
await session.logout()
|
||||
loginForm.password = ''
|
||||
passwordForm.currentPassword = ''
|
||||
passwordForm.newPassword = ''
|
||||
passwordForm.confirmPassword = ''
|
||||
}
|
||||
|
||||
function submit() {
|
||||
session.login(form.operator)
|
||||
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : '/overview'
|
||||
void router.push(redirect)
|
||||
if (session.mustChangePassword) {
|
||||
void submitPasswordChange()
|
||||
return
|
||||
}
|
||||
|
||||
void submitLogin()
|
||||
}
|
||||
|
||||
function accountLabel() {
|
||||
return session.displayName || session.operator
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -26,24 +98,78 @@ function submit() {
|
||||
<div class="login-copy">
|
||||
<ElIcon><Monitor /></ElIcon>
|
||||
<h1>DevOps 运维平台</h1>
|
||||
<p>当前使用本地操作员会话进入控制台;真实身份、RBAC 和审计由后端认证模块接入。</p>
|
||||
<p>使用平台账号进入控制台。</p>
|
||||
</div>
|
||||
<ElForm class="login-form" label-position="top" @submit.prevent="submit">
|
||||
<ElFormItem label="操作员">
|
||||
<ElInput v-model="form.operator" size="large" autocomplete="username" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="口令">
|
||||
<ElInput
|
||||
v-model="form.password"
|
||||
<template v-if="!session.mustChangePassword">
|
||||
<ElFormItem label="账号">
|
||||
<ElInput v-model="loginForm.account" size="large" autocomplete="username" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="密码">
|
||||
<ElInput
|
||||
v-model="loginForm.password"
|
||||
size="large"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElButton
|
||||
type="primary"
|
||||
size="large"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElButton type="primary" size="large" :icon="Lock" native-type="submit">
|
||||
进入控制台
|
||||
</ElButton>
|
||||
:icon="Lock"
|
||||
:loading="loading"
|
||||
native-type="submit"
|
||||
>
|
||||
登录
|
||||
</ElButton>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div class="change-title">
|
||||
<strong>{{ accountLabel() }}</strong>
|
||||
<span>需要更新密码</span>
|
||||
</div>
|
||||
<ElFormItem label="当前密码">
|
||||
<ElInput
|
||||
v-model="passwordForm.currentPassword"
|
||||
size="large"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="新密码">
|
||||
<ElInput
|
||||
v-model="passwordForm.newPassword"
|
||||
size="large"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="确认新密码">
|
||||
<ElInput
|
||||
v-model="passwordForm.confirmPassword"
|
||||
size="large"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElButton
|
||||
type="primary"
|
||||
size="large"
|
||||
:icon="Lock"
|
||||
:loading="loading"
|
||||
native-type="submit"
|
||||
>
|
||||
更新并进入
|
||||
</ElButton>
|
||||
<ElButton class="switch-account" text @click="logoutForAccountSwitch">
|
||||
切换账号
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElForm>
|
||||
</section>
|
||||
</main>
|
||||
@@ -103,6 +229,24 @@ function submit() {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.change-title {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
margin-bottom: 18px;
|
||||
color: #111827;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.change-title span {
|
||||
color: #697386;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.switch-account {
|
||||
width: 100%;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
@media (max-width: 780px) {
|
||||
.login-panel {
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
Reference in New Issue
Block a user