1 parent
18b6dfbdf7
commit
dd04bdb49e
83 files changed
+4547
-583
No files matched your search
+3
-1
@@ -2,13 +2,14 @@
|
||||
import {RouterView, useRoute} from 'vue-router'
|
||||
import HomeHeader from '@/views/components/HomeHeader/HomeHeader.vue'
|
||||
import HomeAside from '@/views/components/HomeAside/HomeAside.vue';
|
||||
import RecoverySetupPrompt from '@/views/components/RecoverySetupPrompt/RecoverySetupPrompt.vue'
|
||||
import {ref, watch, onMounted} from 'vue'
|
||||
import {useGlobalStatusStore} from "@/stores/useGlobalStatusStore";
|
||||
|
||||
const route = useRoute()
|
||||
const pageName = ref(route.name)
|
||||
const globalStatus = useGlobalStatusStore();
|
||||
const standalonePages = ['login', 'setup', 'forgot-password', 'reset-blocked']
|
||||
const standalonePages = ['login', 'login-verification', 'force-password-change', 'setup', 'forgot-password', 'reset-blocked']
|
||||
|
||||
onMounted(() => {
|
||||
if (!standalonePages.includes(route.name)) {
|
||||
@@ -55,6 +56,7 @@ watch(
|
||||
</transition>
|
||||
</RouterView>
|
||||
</div>
|
||||
<RecoverySetupPrompt v-if="!standalonePages.includes(pageName)" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+99
-52
@@ -1,61 +1,108 @@
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import ListView from '../views/List/List.vue'
|
||||
import EditerView from '../views/Editer/Editer.vue'
|
||||
import LoginView from '../views/Login/Login.vue'
|
||||
import EmailDetailView from '../views/EmailDetail/EmailDetail.vue'
|
||||
import SetupView from '../views/Setup/Setup.vue'
|
||||
import PasswordRecoveryView from '../views/PasswordRecovery/PasswordRecovery.vue'
|
||||
import ResetBlockedView from '../views/ResetBlocked/ResetBlocked.vue'
|
||||
|
||||
import { createRouter, createWebHashHistory } from "vue-router";
|
||||
import ListView from "../views/List/List.vue";
|
||||
import EditerView from "../views/Editer/Editer.vue";
|
||||
import LoginView from "../views/Login/Login.vue";
|
||||
import EmailDetailView from "../views/EmailDetail/EmailDetail.vue";
|
||||
import SetupView from "../views/Setup/Setup.vue";
|
||||
import PasswordRecoveryView from "../views/PasswordRecovery/PasswordRecovery.vue";
|
||||
import ResetBlockedView from "../views/ResetBlocked/ResetBlocked.vue";
|
||||
import LoginVerificationView from "../views/LoginVerification/LoginVerification.vue";
|
||||
import ForcePasswordChangeView from "../views/ForcePasswordChange/ForcePasswordChange.vue";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: ListView
|
||||
},
|
||||
{
|
||||
path: '/list',
|
||||
name: 'list',
|
||||
component: ListView
|
||||
},
|
||||
{
|
||||
path: '/editer',
|
||||
name: "editer",
|
||||
component: EditerView
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: "login",
|
||||
component: LoginView
|
||||
},
|
||||
{
|
||||
path: '/setup',
|
||||
name: "setup",
|
||||
component: SetupView
|
||||
},
|
||||
{
|
||||
path: '/forgot-password',
|
||||
name: "forgot-password",
|
||||
component: PasswordRecoveryView
|
||||
},
|
||||
{
|
||||
path: '/reset-blocked',
|
||||
name: 'reset-blocked',
|
||||
component: ResetBlockedView
|
||||
},
|
||||
{
|
||||
path: '/detail/:id',
|
||||
name: "detail",
|
||||
component: EmailDetailView
|
||||
history: createWebHashHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: "/",
|
||||
name: "home",
|
||||
component: ListView,
|
||||
meta: {requiresAuth: true}
|
||||
},
|
||||
{
|
||||
path: "/list",
|
||||
name: "list",
|
||||
component: ListView,
|
||||
meta: {requiresAuth: true}
|
||||
},
|
||||
{
|
||||
path: "/editer",
|
||||
name: "editer",
|
||||
component: EditerView,
|
||||
meta: {requiresAuth: true}
|
||||
},
|
||||
{
|
||||
path: "/login",
|
||||
name: "login",
|
||||
component: LoginView
|
||||
},
|
||||
{
|
||||
path: "/login-verification",
|
||||
name: "login-verification",
|
||||
component: LoginVerificationView
|
||||
},
|
||||
{
|
||||
path: "/force-password-change",
|
||||
name: "force-password-change",
|
||||
component: ForcePasswordChangeView,
|
||||
meta: {requiresAuth: true}
|
||||
},
|
||||
{
|
||||
path: "/setup",
|
||||
name: "setup",
|
||||
component: SetupView
|
||||
},
|
||||
{
|
||||
path: "/forgot-password",
|
||||
name: "forgot-password",
|
||||
component: PasswordRecoveryView
|
||||
},
|
||||
{
|
||||
path: "/reset-blocked",
|
||||
name: "reset-blocked",
|
||||
component: ResetBlockedView
|
||||
},
|
||||
{
|
||||
path: "/detail/:id",
|
||||
name: "detail",
|
||||
component: EmailDetailView,
|
||||
meta: {requiresAuth: true}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
router.beforeEach(async (to) => {
|
||||
const {useGlobalStatusStore} = await import("@/stores/useGlobalStatusStore");
|
||||
const globalStatus = useGlobalStatusStore();
|
||||
const needsAuthentication = to.meta.requiresAuth || to.name === "force-password-change";
|
||||
const authenticated = globalStatus.isLogin || (needsAuthentication && await globalStatus.refresh());
|
||||
|
||||
if (!authenticated && needsAuthentication) {
|
||||
return {
|
||||
name: "login",
|
||||
query: {redirect: to.fullPath}
|
||||
};
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
if (to.name === "force-password-change") {
|
||||
if (!globalStatus.userInfos.must_change_password) {
|
||||
return {name: "list"};
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (authenticated && globalStatus.userInfos.must_change_password) {
|
||||
return {name: "force-password-change"};
|
||||
}
|
||||
|
||||
if (!to.meta.requiresAuth) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (to.meta.capability && !globalStatus.hasCapability(to.meta.capability)) {
|
||||
return {name: "list"};
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
export {router};
|
||||
@@ -1,31 +1,97 @@
|
||||
import {defineStore} from "pinia";
|
||||
import {http} from "@/utils/axios";
|
||||
import { defineStore } from "pinia";
|
||||
import { http } from "@/utils/axios";
|
||||
|
||||
const useGlobalStatusStore = defineStore('useGlobalStatusStore', {
|
||||
const useGlobalStatusStore = defineStore("useGlobalStatusStore", {
|
||||
state() {
|
||||
return {
|
||||
userInfos: {},
|
||||
mobileDrawerVisible: false,
|
||||
settingsDrawerVisible: false
|
||||
}
|
||||
settingsDrawerVisible: false,
|
||||
authChecked: false,
|
||||
authLoading: false,
|
||||
pendingLogin: null,
|
||||
recoveryPromptDismissed: false
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
isLogin(state) {
|
||||
return Object.keys(state.userInfos).length !== 0
|
||||
return Object.keys(state.userInfos).length !== 0;
|
||||
},
|
||||
role(state) {
|
||||
return state.userInfos.role || "";
|
||||
},
|
||||
capabilities(state) {
|
||||
return Array.isArray(state.userInfos.capabilities)
|
||||
? state.userInfos.capabilities
|
||||
: [];
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
init(callback) {
|
||||
let that = this
|
||||
http.post("/api/user/info", {}).then(res => {
|
||||
if (res.errorNo === 0) {
|
||||
Object.assign(that.userInfos, res.data)
|
||||
callback()
|
||||
async refresh() {
|
||||
if (this.authLoading) {
|
||||
return this.isLogin;
|
||||
}
|
||||
|
||||
this.authLoading = true;
|
||||
try {
|
||||
const response = await http.post("/api/user/info", {});
|
||||
if (response.errorNo === 0 && response.data) {
|
||||
this.setUser(response.data, false);
|
||||
this.authChecked = true;
|
||||
return true;
|
||||
}
|
||||
})
|
||||
this.clear();
|
||||
return false;
|
||||
} catch (error) {
|
||||
this.clear();
|
||||
return false;
|
||||
} finally {
|
||||
this.authLoading = false;
|
||||
}
|
||||
},
|
||||
init(callback) {
|
||||
this.refresh().then(() => {
|
||||
if (typeof callback === "function") {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
clear() {
|
||||
this.userInfos = {};
|
||||
this.pendingLogin = null;
|
||||
this.recoveryPromptDismissed = false;
|
||||
this.authChecked = true;
|
||||
},
|
||||
setUser(payload, resetPrompt = false) {
|
||||
const previousAccount = this.userInfos?.account || "";
|
||||
this.userInfos = payload && typeof payload === "object" ? { ...payload } : {};
|
||||
if (resetPrompt || previousAccount !== this.userInfos.account) {
|
||||
this.recoveryPromptDismissed = false;
|
||||
}
|
||||
this.authChecked = true;
|
||||
},
|
||||
dismissRecoveryPrompt() {
|
||||
this.recoveryPromptDismissed = true;
|
||||
},
|
||||
setPendingLogin(payload) {
|
||||
this.pendingLogin = {
|
||||
challengeId: payload?.challenge_id || "",
|
||||
account: payload?.account || "",
|
||||
email: payload?.email || "",
|
||||
expiresAt: payload?.expires_at || "",
|
||||
redirect: payload?.redirect || "/"
|
||||
};
|
||||
},
|
||||
clearPendingLogin() {
|
||||
this.pendingLogin = null;
|
||||
},
|
||||
hasCapability(capability) {
|
||||
if (!capability) {
|
||||
return true;
|
||||
}
|
||||
return this.role === "super_admin" || this.capabilities.includes(capability);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
export {useGlobalStatusStore};
|
||||
export { useGlobalStatusStore };
|
||||
@@ -33,7 +33,7 @@ function normalizeDescriptors(items) {
|
||||
export function normalizeCreationOptions(options) {
|
||||
const source = options?.publicKey || options?.response || options;
|
||||
if (!source?.challenge || !source?.user?.id) {
|
||||
throw new Error('??????????');
|
||||
throw new Error('安全密钥参数无效');
|
||||
}
|
||||
return {
|
||||
...source,
|
||||
@@ -46,7 +46,7 @@ export function normalizeCreationOptions(options) {
|
||||
export function normalizeRequestOptions(options) {
|
||||
const source = options?.publicKey || options?.response || options;
|
||||
if (!source?.challenge) {
|
||||
throw new Error('??????????');
|
||||
throw new Error('安全密钥参数无效');
|
||||
}
|
||||
return {
|
||||
...source,
|
||||
@@ -56,7 +56,7 @@ export function normalizeRequestOptions(options) {
|
||||
}
|
||||
|
||||
export function serializeCredential(credential) {
|
||||
if (!credential) throw new Error('??????????');
|
||||
if (!credential) throw new Error('安全密钥参数无效');
|
||||
const response = credential.response;
|
||||
const result = {
|
||||
id: credential.id,
|
||||
|
||||
@@ -39,14 +39,14 @@ export function usePage() {
|
||||
try {
|
||||
tos.value = JSON.parse(res.data.to)
|
||||
} catch (error) {
|
||||
console.warn('收件人地址解析失败', error)
|
||||
tos.value = []
|
||||
}
|
||||
}
|
||||
if (res.data.cc && res.data.cc !== "") {
|
||||
try {
|
||||
ccs.value = JSON.parse(res.data.cc)
|
||||
} catch (error) {
|
||||
console.warn('抄送地址解析失败', error)
|
||||
ccs.value = []
|
||||
}
|
||||
}
|
||||
showCC.value = ccs.value && ccs.value.length > 0
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
.force-password-content {
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
padding: clamp(32px, 6vw, 64px);
|
||||
}
|
||||
|
||||
.force-password-card {
|
||||
width: 100%;
|
||||
max-width: 480px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.force-password-heading {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.force-password-eyebrow {
|
||||
display: inline-block;
|
||||
margin-bottom: 12px;
|
||||
color: var(--pm-primary-color);
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.force-password-heading h2 {
|
||||
margin: 0 0 10px;
|
||||
color: var(--pm-text-primary);
|
||||
font-size: 34px;
|
||||
font-weight: 700;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.force-password-heading p {
|
||||
margin: 0;
|
||||
color: var(--pm-text-secondary);
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.force-password-alert {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.force-password-form :deep(.el-form-item) {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.force-password-form :deep(.el-input__wrapper) {
|
||||
min-height: 46px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 0 0 1px var(--pm-border-color) inset !important;
|
||||
}
|
||||
|
||||
.force-password-submit {
|
||||
width: 100%;
|
||||
min-height: 48px;
|
||||
margin-top: 4px;
|
||||
border-radius: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.force-password-logout {
|
||||
display: flex;
|
||||
margin: 14px auto 0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.force-password-content {
|
||||
min-height: 0;
|
||||
padding: 32px 24px 36px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 380px) {
|
||||
.force-password-content {
|
||||
padding: 24px 14px 28px;
|
||||
}
|
||||
|
||||
.force-password-heading h2 {
|
||||
font-size: 28px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { reactive, ref } from "vue"
|
||||
|
||||
import { ElMessage } from "element-plus"
|
||||
|
||||
import { useRouter } from "vue-router"
|
||||
|
||||
import { http } from "@/utils/axios"
|
||||
|
||||
import { useGlobalStatusStore } from "@/stores/useGlobalStatusStore"
|
||||
|
||||
export function usePage() {
|
||||
const router = useRouter()
|
||||
const globalStatus = useGlobalStatusStore()
|
||||
const loading = ref(false)
|
||||
const form = reactive({
|
||||
currentPassword: "",
|
||||
newPassword: "",
|
||||
confirmPassword: ""
|
||||
})
|
||||
|
||||
const submit = async () => {
|
||||
if (!form.currentPassword || !form.newPassword || !form.confirmPassword) {
|
||||
ElMessage.warning("请完整填写密码信息")
|
||||
return
|
||||
}
|
||||
if (form.newPassword !== form.confirmPassword) {
|
||||
ElMessage.warning("两次输入的新密码不一致")
|
||||
return
|
||||
}
|
||||
if (new TextEncoder().encode(form.newPassword).length < 8) {
|
||||
ElMessage.warning("新密码长度至少为 8 个字节")
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await http.post("/api/settings/modify_password", {
|
||||
current_password: form.currentPassword,
|
||||
password: form.newPassword
|
||||
})
|
||||
if (response.errorNo !== 0) {
|
||||
ElMessage.error(response.errorMsg || "密码修改失败")
|
||||
return
|
||||
}
|
||||
globalStatus.clear()
|
||||
ElMessage.success("密码已修改,请使用新密码重新登录")
|
||||
await router.replace({ name: "login" })
|
||||
} catch (error) {
|
||||
ElMessage.error("密码修改失败,请稍后重试")
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const logout = async () => {
|
||||
try {
|
||||
await http.post("/api/logout", {})
|
||||
} finally {
|
||||
globalStatus.clear()
|
||||
await router.replace({ name: "login" })
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
form,
|
||||
loading,
|
||||
submit,
|
||||
logout
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<template>
|
||||
<AuthLayout
|
||||
brand-caption="账户安全"
|
||||
intro-title="首次登录安全设置"
|
||||
intro-description="当前账号使用的是临时密码。完成密码修改前,其他业务功能将保持锁定。"
|
||||
>
|
||||
<section class="force-password-content">
|
||||
<div class="force-password-card">
|
||||
<div class="force-password-heading">
|
||||
<span class="force-password-eyebrow">必须完成</span>
|
||||
<h2>修改临时密码</h2>
|
||||
<p>请设置一个仅由您本人掌握的新密码,修改成功后需要重新登录。</p>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
title="为了保护账号安全,修改密码前不能访问邮件、设置和管理功能。"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="force-password-alert"
|
||||
/>
|
||||
|
||||
<el-form
|
||||
class="force-password-form"
|
||||
label-position="top"
|
||||
@submit.prevent="submit"
|
||||
>
|
||||
<el-form-item label="当前临时密码">
|
||||
<el-input
|
||||
v-model="form.currentPassword"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
placeholder="请输入当前临时密码"
|
||||
show-password
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="新密码">
|
||||
<el-input
|
||||
v-model="form.newPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
placeholder="请输入新的登录密码"
|
||||
show-password
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="确认新密码">
|
||||
<el-input
|
||||
v-model="form.confirmPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
placeholder="请再次输入新的登录密码"
|
||||
show-password
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-button
|
||||
type="primary"
|
||||
native-type="submit"
|
||||
size="large"
|
||||
class="force-password-submit"
|
||||
:loading="loading"
|
||||
>
|
||||
修改密码并重新登录
|
||||
</el-button>
|
||||
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
class="force-password-logout"
|
||||
:disabled="loading"
|
||||
@click="logout"
|
||||
>
|
||||
退出当前账号
|
||||
</el-button>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
</AuthLayout>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import AuthLayout from "@/views/components/AuthLayout/AuthLayout.vue"
|
||||
import { usePage } from "./ForcePasswordChange.js"
|
||||
|
||||
const {
|
||||
form,
|
||||
loading,
|
||||
submit,
|
||||
logout
|
||||
} = usePage()
|
||||
</script>
|
||||
|
||||
<style scoped src="./ForcePasswordChange.css"></style>
|
||||
+36
-39
@@ -1,66 +1,63 @@
|
||||
import {reactive, ref} from 'vue'
|
||||
import { reactive, ref } from "vue"
|
||||
|
||||
import {ElMessage} from 'element-plus'
|
||||
import { ElMessage } from "element-plus"
|
||||
|
||||
import {useRouter} from 'vue-router'
|
||||
import { useRouter } from "vue-router"
|
||||
|
||||
import lang from '../../i18n/i18n';
|
||||
import lang from "../../i18n/i18n"
|
||||
|
||||
import {http} from "@/utils/axios";
|
||||
import { http } from "@/utils/axios"
|
||||
|
||||
import {useGlobalStatusStore} from "@/stores/useGlobalStatusStore";
|
||||
import { useGlobalStatusStore } from "@/stores/useGlobalStatusStore"
|
||||
|
||||
export function usePage() {
|
||||
const router = useRouter()
|
||||
const globalStatus = useGlobalStatusStore();
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
const globalStatus = useGlobalStatusStore()
|
||||
const loading = ref(false)
|
||||
const form = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
account: "",
|
||||
password: "",
|
||||
})
|
||||
|
||||
const onSubmit = () => {
|
||||
|
||||
const onSubmit = async () => {
|
||||
if (!form.account || !form.password) {
|
||||
ElMessage.warning(lang.login_fill_required);
|
||||
return;
|
||||
ElMessage.warning(lang.login_fill_required)
|
||||
return
|
||||
}
|
||||
loading.value = true;
|
||||
http.post("/api/login", form).then(res => {
|
||||
loading.value = false;
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await http.post("/api/login", form)
|
||||
if (res.errorNo !== 0) {
|
||||
ElMessage.error(res.errorMsg)
|
||||
} else {
|
||||
Object.assign(globalStatus.userInfos , res.data)
|
||||
router.replace({
|
||||
path: '/',
|
||||
query: {
|
||||
redirect: router.currentRoute.fullPath
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
}).catch(() => {
|
||||
loading.value = false;
|
||||
})
|
||||
const redirect = typeof router.currentRoute.value.query.redirect === "string"
|
||||
? router.currentRoute.value.query.redirect
|
||||
: "/"
|
||||
if (res.data?.pending) {
|
||||
globalStatus.setPendingLogin({ ...res.data, redirect })
|
||||
await router.replace({ name: "login-verification" })
|
||||
return
|
||||
}
|
||||
globalStatus.clearPendingLogin()
|
||||
globalStatus.setUser(res.data, true)
|
||||
await router.replace(redirect)
|
||||
} catch (error) {
|
||||
ElMessage.error("登录请求失败,请稍后重试")
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const goForgotPassword = () => {
|
||||
router.push({name: 'forgot-password'})
|
||||
router.push({ name: "forgot-password" })
|
||||
}
|
||||
|
||||
return {
|
||||
reactive,
|
||||
ref,
|
||||
ElMessage,
|
||||
router,
|
||||
lang,
|
||||
http,
|
||||
useGlobalStatusStore,
|
||||
globalStatus,
|
||||
loading,
|
||||
form,
|
||||
onSubmit,
|
||||
loading,
|
||||
goForgotPassword
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
.verification-content {
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
padding: clamp(32px, 6vw, 64px);
|
||||
}
|
||||
|
||||
.verification-card {
|
||||
width: 100%;
|
||||
max-width: 460px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.verification-heading {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.verification-eyebrow {
|
||||
display: inline-block;
|
||||
margin-bottom: 12px;
|
||||
color: var(--pm-primary-color);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.verification-heading h2 {
|
||||
margin: 0 0 10px;
|
||||
color: var(--pm-text-primary);
|
||||
font-size: 34px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.verification-heading p {
|
||||
margin: 0;
|
||||
color: var(--pm-text-secondary);
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.verification-heading strong {
|
||||
color: var(--pm-text-primary);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.verification-input :deep(.el-input__wrapper) {
|
||||
min-height: 48px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 0 0 1px var(--pm-border-color) inset !important;
|
||||
}
|
||||
|
||||
.verification-expiry {
|
||||
margin: 14px 0 0;
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.verification-submit,
|
||||
.webauthn-login-button {
|
||||
width: 100%;
|
||||
min-height: 48px;
|
||||
border-radius: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.verification-submit {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.verification-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.webauthn-unavailable {
|
||||
margin: 0;
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.verification-content {
|
||||
min-height: 0;
|
||||
padding: 32px 24px 36px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 380px) {
|
||||
.verification-content {
|
||||
padding: 24px 14px 28px;
|
||||
}
|
||||
|
||||
.verification-heading h2 {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.verification-actions {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from "vue"
|
||||
|
||||
import { ElMessage } from "element-plus"
|
||||
|
||||
import { useRouter } from "vue-router"
|
||||
|
||||
import { useGlobalStatusStore } from "@/stores/useGlobalStatusStore"
|
||||
import { http } from "@/utils/axios"
|
||||
import {
|
||||
normalizeRequestOptions,
|
||||
serializeCredential,
|
||||
webAuthnSupported
|
||||
} from "@/utils/webauthn"
|
||||
|
||||
export function usePage() {
|
||||
const router = useRouter()
|
||||
const globalStatus = useGlobalStatusStore()
|
||||
const pending = computed(() => globalStatus.pendingLogin)
|
||||
const code = ref("")
|
||||
const loading = ref(false)
|
||||
const resending = ref(false)
|
||||
const webAuthnLoading = ref(false)
|
||||
const remainingSeconds = ref(0)
|
||||
const errorMessage = ref("")
|
||||
let timer = null
|
||||
|
||||
const expiresAt = computed(() => pending.value?.expiresAt || "")
|
||||
const webAuthnAvailable = computed(() => webAuthnSupported())
|
||||
|
||||
const updateRemaining = () => {
|
||||
const timestamp = Date.parse(expiresAt.value)
|
||||
remainingSeconds.value = Number.isFinite(timestamp)
|
||||
? Math.max(0, Math.ceil((timestamp - Date.now()) / 1000))
|
||||
: 0
|
||||
}
|
||||
|
||||
const startTimer = () => {
|
||||
updateRemaining()
|
||||
timer = window.setInterval(updateRemaining, 1000)
|
||||
}
|
||||
|
||||
const stopTimer = () => {
|
||||
if (timer !== null) {
|
||||
window.clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
}
|
||||
|
||||
const goBackToLogin = async () => {
|
||||
globalStatus.clearPendingLogin()
|
||||
await router.replace({ name: "login" })
|
||||
}
|
||||
|
||||
const verifyCode = async () => {
|
||||
if (!pending.value?.challengeId) {
|
||||
await goBackToLogin()
|
||||
return
|
||||
}
|
||||
if (!code.value.trim()) {
|
||||
ElMessage.warning("请输入邮箱验证码")
|
||||
return
|
||||
}
|
||||
if (remainingSeconds.value <= 0) {
|
||||
errorMessage.value = "验证码已过期,请重新登录"
|
||||
ElMessage.warning(errorMessage.value)
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
errorMessage.value = ""
|
||||
try {
|
||||
const response = await http.post("/api/security/login/verify", {
|
||||
id: pending.value.challengeId,
|
||||
account: pending.value.account,
|
||||
code: code.value.trim()
|
||||
})
|
||||
if (response.errorNo !== 0) {
|
||||
throw new Error(response.errorMsg || "验证码验证失败")
|
||||
}
|
||||
const redirect = pending.value.redirect || "/"
|
||||
globalStatus.clearPendingLogin()
|
||||
globalStatus.setUser(response.data, true)
|
||||
await router.replace(redirect)
|
||||
} catch (error) {
|
||||
errorMessage.value = error?.message || "验证码验证失败,请重试"
|
||||
ElMessage.error(errorMessage.value)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resendCode = async () => {
|
||||
if (!pending.value?.challengeId || resending.value) {
|
||||
return
|
||||
}
|
||||
resending.value = true
|
||||
errorMessage.value = ""
|
||||
try {
|
||||
const response = await http.post("/api/security/login/resend", {
|
||||
id: pending.value.challengeId,
|
||||
account: pending.value.account
|
||||
})
|
||||
if (response.errorNo !== 0 || !response.data?.pending) {
|
||||
throw new Error(response.errorMsg || "验证码发送失败")
|
||||
}
|
||||
globalStatus.setPendingLogin({
|
||||
...response.data,
|
||||
redirect: pending.value.redirect
|
||||
})
|
||||
code.value = ""
|
||||
ElMessage.success("验证码已重新发送")
|
||||
stopTimer()
|
||||
startTimer()
|
||||
} catch (error) {
|
||||
errorMessage.value = error?.message || "验证码发送失败,请稍后重试"
|
||||
ElMessage.error(errorMessage.value)
|
||||
} finally {
|
||||
resending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const verifyWithWebAuthn = async () => {
|
||||
if (!webAuthnAvailable.value || webAuthnLoading.value) {
|
||||
return
|
||||
}
|
||||
webAuthnLoading.value = true
|
||||
errorMessage.value = ""
|
||||
try {
|
||||
const begin = await http.post("/api/security/webauthn/login/begin", {
|
||||
challenge_id: pending.value.challengeId,
|
||||
account: pending.value.account
|
||||
})
|
||||
if (begin.errorNo !== 0) {
|
||||
throw new Error(begin.errorMsg || "安全密钥登录不可用")
|
||||
}
|
||||
const credential = await navigator.credentials.get({
|
||||
publicKey: normalizeRequestOptions(begin.data.options)
|
||||
})
|
||||
const finish = await http.post("/api/security/webauthn/login/finish", {
|
||||
challenge_id: pending.value.challengeId,
|
||||
account: pending.value.account,
|
||||
session_id: begin.data.session_id,
|
||||
credential: serializeCredential(credential)
|
||||
})
|
||||
if (finish.errorNo !== 0) {
|
||||
throw new Error(finish.errorMsg || "安全密钥验证失败")
|
||||
}
|
||||
const redirect = pending.value?.redirect || "/"
|
||||
globalStatus.clearPendingLogin()
|
||||
globalStatus.setUser(finish.data, true)
|
||||
await router.replace(redirect)
|
||||
} catch (error) {
|
||||
if (error?.name !== "NotAllowedError") {
|
||||
errorMessage.value = error?.message || "安全密钥验证失败,请重试"
|
||||
ElMessage.error(errorMessage.value)
|
||||
}
|
||||
} finally {
|
||||
webAuthnLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (!pending.value?.challengeId) {
|
||||
router.replace({ name: "login" })
|
||||
return
|
||||
}
|
||||
startTimer()
|
||||
})
|
||||
|
||||
onBeforeUnmount(stopTimer)
|
||||
|
||||
return {
|
||||
pending,
|
||||
code,
|
||||
loading,
|
||||
resending,
|
||||
webAuthnLoading,
|
||||
remainingSeconds,
|
||||
errorMessage,
|
||||
webAuthnAvailable,
|
||||
verifyCode,
|
||||
resendCode,
|
||||
verifyWithWebAuthn,
|
||||
goBackToLogin
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<template>
|
||||
<AuthLayout
|
||||
brand-caption="安全、简洁的邮件管理"
|
||||
intro-title="完成安全验证"
|
||||
intro-description="密码验证通过后,还需要确认已绑定的外部安全邮箱或安全密钥。"
|
||||
>
|
||||
<section class="verification-content">
|
||||
<div class="verification-card">
|
||||
<div class="verification-heading">
|
||||
<span class="verification-eyebrow">登录保护</span>
|
||||
<h2>输入邮箱验证码</h2>
|
||||
<p>
|
||||
验证码已发送至
|
||||
<strong>{{ pending?.email || "已绑定邮箱" }}</strong>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<el-form class="verification-form" @submit.prevent="verifyCode">
|
||||
<el-form-item label="邮箱验证码">
|
||||
<el-input
|
||||
v-model="code"
|
||||
maxlength="8"
|
||||
inputmode="numeric"
|
||||
autocomplete="one-time-code"
|
||||
placeholder="请输入验证码"
|
||||
size="large"
|
||||
class="verification-input"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-alert
|
||||
v-if="errorMessage"
|
||||
:title="errorMessage"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
|
||||
<p class="verification-expiry">
|
||||
{{ remainingSeconds > 0
|
||||
? `验证码将在 ${remainingSeconds} 秒后过期`
|
||||
: "验证码已过期,请重新登录" }}
|
||||
</p>
|
||||
|
||||
<el-button
|
||||
type="primary"
|
||||
size="large"
|
||||
class="verification-submit"
|
||||
:loading="loading"
|
||||
:disabled="remainingSeconds <= 0"
|
||||
@click="verifyCode"
|
||||
>
|
||||
验证并登录
|
||||
</el-button>
|
||||
|
||||
<div class="verification-actions">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
:loading="resending"
|
||||
:disabled="remainingSeconds > 540"
|
||||
@click="resendCode"
|
||||
>
|
||||
重新发送验证码
|
||||
</el-button>
|
||||
<el-button link @click="goBackToLogin">返回登录</el-button>
|
||||
</div>
|
||||
</el-form>
|
||||
|
||||
<el-divider>或</el-divider>
|
||||
|
||||
<el-button
|
||||
v-if="webAuthnAvailable"
|
||||
plain
|
||||
size="large"
|
||||
class="webauthn-login-button"
|
||||
:loading="webAuthnLoading"
|
||||
@click="verifyWithWebAuthn"
|
||||
>
|
||||
使用安全密钥验证
|
||||
</el-button>
|
||||
<p v-else class="webauthn-unavailable">
|
||||
当前浏览器不支持安全密钥验证,请使用邮箱验证码。
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
</AuthLayout>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import AuthLayout from "@/views/components/AuthLayout/AuthLayout.vue"
|
||||
import { usePage } from "./LoginVerification.js"
|
||||
|
||||
const {
|
||||
pending,
|
||||
code,
|
||||
loading,
|
||||
resending,
|
||||
webAuthnLoading,
|
||||
remainingSeconds,
|
||||
errorMessage,
|
||||
webAuthnAvailable,
|
||||
verifyCode,
|
||||
resendCode,
|
||||
verifyWithWebAuthn,
|
||||
goBackToLogin
|
||||
} = usePage()
|
||||
</script>
|
||||
|
||||
<style scoped src="./LoginVerification.css"></style>
|
||||
@@ -244,7 +244,6 @@ export function usePage() {
|
||||
ElMessage.error(res.errorMsg)
|
||||
} else {
|
||||
sslSettings.paramsList = res.data
|
||||
console.log(sslSettings.paramsList)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
.config-settings {
|
||||
display: grid;
|
||||
gap: 24px;
|
||||
padding-bottom: 28px;
|
||||
}
|
||||
.settings-header,
|
||||
.panel-heading,
|
||||
.status-heading {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
}
|
||||
.settings-header h3,
|
||||
.panel-heading h4,
|
||||
.status-heading h4 {
|
||||
margin: 0;
|
||||
color: var(--pm-text-primary);
|
||||
}
|
||||
.settings-header h3 {
|
||||
font-size: 22px;
|
||||
}
|
||||
.panel-heading h4,
|
||||
.status-heading h4 {
|
||||
margin-top: 5px;
|
||||
font-size: 18px;
|
||||
}
|
||||
.settings-desc {
|
||||
max-width: 680px;
|
||||
margin: 8px 0 0;
|
||||
color: var(--pm-text-secondary);
|
||||
line-height: 1.65;
|
||||
}
|
||||
.section-eyebrow {
|
||||
color: var(--pm-primary-color);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .08em;
|
||||
}
|
||||
.status-panel,
|
||||
.editor-panel,
|
||||
.rollback-panel,
|
||||
.audit-panel {
|
||||
padding: 20px;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-lg);
|
||||
background: var(--pm-bg-secondary);
|
||||
}
|
||||
.status-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
.status-item {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
padding: 14px;
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-primary);
|
||||
}
|
||||
.status-item span {
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.status-item strong {
|
||||
color: var(--pm-text-primary);
|
||||
font-size: 14px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.status-wide {
|
||||
grid-column: span 3;
|
||||
}
|
||||
.tag-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.config-alert,
|
||||
.degraded-alert {
|
||||
margin-top: 16px;
|
||||
}
|
||||
.section-select {
|
||||
width: 150px;
|
||||
}
|
||||
.editor-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px 20px;
|
||||
margin: 18px 0 10px;
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.config-editor :deep(.el-textarea__inner) {
|
||||
min-height: 300px !important;
|
||||
padding: 14px;
|
||||
color: var(--pm-text-primary);
|
||||
font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
|
||||
line-height: 1.6;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-primary);
|
||||
}
|
||||
.secret-editor {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: 16px;
|
||||
padding: 14px;
|
||||
border: 1px dashed var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-primary);
|
||||
}
|
||||
.secret-editor strong {
|
||||
color: var(--pm-text-primary);
|
||||
}
|
||||
.secret-editor p {
|
||||
margin: 5px 0 0;
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.confirmation-check {
|
||||
margin-top: 16px;
|
||||
}
|
||||
.action-row,
|
||||
.audit-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
.backup-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
.backup-item {
|
||||
display: grid;
|
||||
gap: 5px;
|
||||
padding: 12px;
|
||||
color: var(--pm-text-primary);
|
||||
text-align: left;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-primary);
|
||||
cursor: pointer;
|
||||
}
|
||||
.backup-item:hover,
|
||||
.backup-item.selected {
|
||||
border-color: var(--pm-primary-color);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--pm-primary-color) 16%, transparent);
|
||||
}
|
||||
.backup-item small {
|
||||
color: var(--pm-text-secondary);
|
||||
}
|
||||
.preview-box,
|
||||
.result-box {
|
||||
display: grid;
|
||||
gap: 7px;
|
||||
margin-top: 16px;
|
||||
padding: 14px;
|
||||
border-radius: var(--pm-radius-sm);
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.preview-box {
|
||||
color: var(--pm-text-primary);
|
||||
background: color-mix(in srgb, var(--pm-primary-color) 8%, var(--pm-bg-primary));
|
||||
}
|
||||
.result-success {
|
||||
color: #166534;
|
||||
background: #f0fdf4;
|
||||
}
|
||||
.result-error {
|
||||
color: #991b1b;
|
||||
background: #fef2f2;
|
||||
}
|
||||
.result-box ul {
|
||||
margin: 0;
|
||||
padding-left: 18px;
|
||||
}
|
||||
.audit-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
.audit-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 12px 14px;
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-primary);
|
||||
}
|
||||
.audit-item div {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
}
|
||||
.audit-item strong {
|
||||
color: var(--pm-text-primary);
|
||||
}
|
||||
.audit-item span,
|
||||
.audit-item time {
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.audit-item time {
|
||||
flex: none;
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.status-panel,
|
||||
.editor-panel,
|
||||
.rollback-panel,
|
||||
.audit-panel {
|
||||
padding: 16px;
|
||||
}
|
||||
.status-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.status-wide {
|
||||
grid-column: auto;
|
||||
}
|
||||
.settings-header,
|
||||
.panel-heading,
|
||||
.status-heading,
|
||||
.audit-item {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
.section-select {
|
||||
width: 100%;
|
||||
}
|
||||
.action-row .el-button,
|
||||
.audit-actions .el-button {
|
||||
flex: 1;
|
||||
min-width: 120px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { http } from '@/utils/axios'
|
||||
import { useGlobalStatusStore } from '@/stores/useGlobalStatusStore'
|
||||
|
||||
const sections = [
|
||||
{ value: 'base', label: '基础配置' },
|
||||
{ value: 'smtp', label: 'SMTP 配置' },
|
||||
{ value: 'email', label: '邮箱策略' },
|
||||
{ value: 'ssl', label: 'SSL 配置' },
|
||||
{ value: 'plugins', label: '插件配置' }
|
||||
]
|
||||
|
||||
const serviceLabels = {
|
||||
smtp: 'SMTP 服务',
|
||||
email: '邮箱服务',
|
||||
ssl: 'SSL 服务',
|
||||
plugins: '插件服务'
|
||||
}
|
||||
|
||||
const sectionLabels = Object.fromEntries(sections.map(item => [item.value, item.label]))
|
||||
const operationLabels = {
|
||||
validate: '验证配置',
|
||||
update: '保存配置',
|
||||
apply: '应用配置',
|
||||
rollback_preview: '预览回滚',
|
||||
rollback_ticket: '签发回滚票据',
|
||||
rollback: '执行回滚'
|
||||
}
|
||||
|
||||
export function usePage() {
|
||||
const globalStatus = useGlobalStatusStore()
|
||||
const loading = ref(false)
|
||||
const working = ref('')
|
||||
const backupsLoading = ref(false)
|
||||
const auditLoading = ref(false)
|
||||
const status = reactive({
|
||||
setupState: '',
|
||||
activeGeneration: 0,
|
||||
lastValidAt: '',
|
||||
pendingRestart: [],
|
||||
degradedReasons: []
|
||||
})
|
||||
const selectedSection = ref('base')
|
||||
const editorText = ref('')
|
||||
const sectionError = ref('')
|
||||
const secretValue = ref('')
|
||||
const confirmed = ref(false)
|
||||
const savedGeneration = ref(0)
|
||||
const validationResult = ref(null)
|
||||
const backups = ref([])
|
||||
const rollbackGeneration = ref(0)
|
||||
const rollbackConfirmed = ref(false)
|
||||
const rollbackPreview = ref(null)
|
||||
const auditItems = ref([])
|
||||
|
||||
const canWrite = computed(() => globalStatus.hasCapability('config.write_global'))
|
||||
const canRollback = computed(() => globalStatus.hasCapability('config.rollback'))
|
||||
const canAudit = computed(() => globalStatus.hasCapability('audit.read'))
|
||||
const canExportAudit = computed(() => globalStatus.hasCapability('audit.export'))
|
||||
const stateLabel = computed(() => ({ new: '未初始化', bootstrap: '初始化中', ready: '就绪', degraded: '降级' }[status.setupState] || status.setupState || '未知'))
|
||||
const stateTagType = computed(() => ({ ready: 'success', degraded: 'warning', bootstrap: 'info', new: 'danger' }[status.setupState] || 'info'))
|
||||
const secretField = computed(() => {
|
||||
if (selectedSection.value === 'base') {
|
||||
return { label: '数据库密码', description: '只在本次请求内传输,保存后仅保留密文状态。留空表示保持原值。', placeholder: '输入新数据库密码(可选)' }
|
||||
}
|
||||
if (selectedSection.value === 'smtp') {
|
||||
return { label: 'SMTP Relay 密码', description: '只在本次请求内传输,保存后仅保留密文状态。留空表示保持原值。', placeholder: '输入新的 Relay 密码(可选)' }
|
||||
}
|
||||
return null
|
||||
})
|
||||
const sensitiveHint = computed(() => secretField.value ? '密码字段已脱敏,修改请使用下方输入框' : '当前分区不包含可编辑密文')
|
||||
|
||||
const notifyResponseError = (response, fallback) => {
|
||||
if (!response || response.errorNo !== 0) {
|
||||
throw new Error(response?.errorMsg || fallback)
|
||||
}
|
||||
}
|
||||
|
||||
const formatTime = value => value ? new Date(value).toLocaleString('zh-CN', { hour12: false }) : '-'
|
||||
const serviceLabel = value => serviceLabels[value] || value
|
||||
const sectionLabel = value => sectionLabels[value] || value || '-'
|
||||
const operationLabel = value => operationLabels[value] || value || '-'
|
||||
|
||||
const loadStatus = async () => {
|
||||
const response = await http.get('/api/v1/config/status')
|
||||
notifyResponseError(response, '配置状态读取失败')
|
||||
Object.assign(status, response.data || {})
|
||||
}
|
||||
|
||||
const loadSection = async () => {
|
||||
sectionError.value = ''
|
||||
secretValue.value = ''
|
||||
validationResult.value = null
|
||||
savedGeneration.value = 0
|
||||
try {
|
||||
const response = await http.get(`/api/v1/config/${selectedSection.value}`)
|
||||
notifyResponseError(response, '配置分区读取失败')
|
||||
editorText.value = JSON.stringify(response.data || {}, null, 2)
|
||||
} catch (error) {
|
||||
sectionError.value = error.message || '配置分区读取失败'
|
||||
editorText.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const loadBackups = async () => {
|
||||
if (!canRollback.value) return
|
||||
backupsLoading.value = true
|
||||
try {
|
||||
const response = await http.get('/api/v1/config/backups')
|
||||
notifyResponseError(response, '配置备份读取失败')
|
||||
backups.value = Array.isArray(response.data) ? response.data : []
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '配置备份读取失败')
|
||||
} finally {
|
||||
backupsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadAudit = async () => {
|
||||
if (!canAudit.value) return
|
||||
auditLoading.value = true
|
||||
try {
|
||||
const response = await http.get('/api/v1/audits/config?limit=50')
|
||||
notifyResponseError(response, '配置审计读取失败')
|
||||
auditItems.value = Array.isArray(response.data) ? response.data : []
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '配置审计读取失败')
|
||||
} finally {
|
||||
auditLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadAll = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
await Promise.all([loadStatus(), loadSection(), loadBackups(), loadAudit()])
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '配置管理数据读取失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const parsePayload = () => {
|
||||
try {
|
||||
const payload = JSON.parse(editorText.value)
|
||||
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
||||
throw new Error('配置必须是 JSON 对象')
|
||||
}
|
||||
if (selectedSection.value === 'base') {
|
||||
delete payload.databasePasswordStatus
|
||||
}
|
||||
if (selectedSection.value === 'smtp') {
|
||||
delete payload.relayPasswordStatus
|
||||
}
|
||||
if (selectedSection.value === 'plugins' && payload.plugins && typeof payload.plugins === 'object') {
|
||||
Object.values(payload.plugins).forEach(plugin => {
|
||||
if (plugin && typeof plugin === 'object') {
|
||||
delete plugin.settingsConfigured
|
||||
}
|
||||
})
|
||||
}
|
||||
return payload
|
||||
} catch (error) {
|
||||
throw new Error(error.message || 'JSON 格式错误')
|
||||
}
|
||||
}
|
||||
|
||||
const buildRequest = () => {
|
||||
const secretChanges = {}
|
||||
const value = secretValue.value.trim()
|
||||
if (value && selectedSection.value === 'base') {
|
||||
secretChanges['database.password'] = { operation: 'replace', value: { plaintext: value } }
|
||||
}
|
||||
if (value && selectedSection.value === 'smtp') {
|
||||
secretChanges['relay.password'] = { operation: 'replace', value: { plaintext: value } }
|
||||
}
|
||||
return {
|
||||
expectedGeneration: Number(status.activeGeneration),
|
||||
payload: parsePayload(),
|
||||
secretChanges,
|
||||
confirmation: { confirmed: confirmed.value, method: 'recent_auth' }
|
||||
}
|
||||
}
|
||||
|
||||
const validateConfig = async () => {
|
||||
working.value = 'validate'
|
||||
try {
|
||||
const request = buildRequest()
|
||||
const response = await http.post(`/api/v1/config/${selectedSection.value}/validate`, request)
|
||||
notifyResponseError(response, '配置验证失败')
|
||||
validationResult.value = response.data || null
|
||||
ElMessage[validationResult.value?.valid ? 'success' : 'warning'](validationResult.value?.valid ? '配置验证通过' : '配置验证未通过')
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '配置验证失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const saveConfig = async () => {
|
||||
working.value = 'save'
|
||||
try {
|
||||
const request = buildRequest()
|
||||
const response = await http.put(`/api/v1/config/${selectedSection.value}`, request)
|
||||
notifyResponseError(response, '配置保存失败')
|
||||
savedGeneration.value = response.data?.generation || 0
|
||||
validationResult.value = { valid: true, generation: savedGeneration.value, issues: [] }
|
||||
await loadStatus()
|
||||
ElMessage.success(`候选配置已保存,代次 ${savedGeneration.value} 等待应用`)
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '配置保存失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const applyConfig = async () => {
|
||||
if (!savedGeneration.value) return
|
||||
working.value = 'apply'
|
||||
try {
|
||||
const response = await http.post(`/api/v1/config/${selectedSection.value}/apply`, { generation: savedGeneration.value })
|
||||
notifyResponseError(response, '配置应用失败')
|
||||
savedGeneration.value = 0
|
||||
await Promise.all([loadStatus(), loadSection()])
|
||||
ElMessage.success('配置已应用')
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '配置应用失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const previewRollback = async () => {
|
||||
if (!rollbackGeneration.value) return
|
||||
working.value = 'preview'
|
||||
rollbackPreview.value = null
|
||||
try {
|
||||
const response = await http.post('/api/v1/config/rollback/preview', { targetGeneration: rollbackGeneration.value })
|
||||
notifyResponseError(response, '回滚预览失败')
|
||||
rollbackPreview.value = response.data || null
|
||||
ElMessage.success('回滚预览已生成,请确认变更分区')
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '回滚预览失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const executeRollback = async () => {
|
||||
if (!rollbackPreview.value || !rollbackConfirmed.value) return
|
||||
try {
|
||||
await ElMessageBox.confirm('回滚会替换当前候选配置并可能需要重启服务,确定继续吗?', '确认执行回滚', { type: 'warning', confirmButtonText: '继续回滚', cancelButtonText: '取消' })
|
||||
working.value = 'rollback'
|
||||
const ticketResponse = await http.post('/api/v1/config/rollback/ticket', {
|
||||
targetGeneration: rollbackPreview.value.targetGeneration,
|
||||
confirmation: { confirmed: true, method: 'recent_auth' }
|
||||
})
|
||||
notifyResponseError(ticketResponse, '回滚票据签发失败')
|
||||
const response = await http.post('/api/v1/config/rollback', { ticket: ticketResponse.data?.ticket })
|
||||
notifyResponseError(response, '配置回滚失败')
|
||||
rollbackPreview.value = null
|
||||
rollbackConfirmed.value = false
|
||||
await Promise.all([loadStatus(), loadSection(), loadBackups()])
|
||||
ElMessage.success('配置已回滚')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') ElMessage.error(error.message || '配置回滚失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const exportAudit = async format => {
|
||||
working.value = format === 'csv' ? 'export-csv' : 'export'
|
||||
try {
|
||||
const response = await http.post('/api/v1/audits/config', { format, limit: 500 }, { responseType: 'blob' })
|
||||
const blob = response.data instanceof Blob ? response.data : new Blob([response.data], { type: format === 'csv' ? 'text/csv' : 'application/json' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
anchor.download = `smail-config-audit.${format}`
|
||||
anchor.click()
|
||||
URL.revokeObjectURL(url)
|
||||
ElMessage.success('审计记录已导出')
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '审计导出失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadAll)
|
||||
|
||||
return {
|
||||
loading, working, status, stateLabel, stateTagType, sectionOptions: sections,
|
||||
selectedSection, editorText, sectionError, sensitiveHint, secretField, secretValue,
|
||||
confirmed, savedGeneration, validationResult, canWrite, canRollback, canAudit, canExportAudit,
|
||||
backupsLoading, backups, rollbackGeneration, rollbackConfirmed, rollbackPreview,
|
||||
auditLoading, auditItems, loadAll, loadSection, validateConfig, saveConfig, applyConfig,
|
||||
loadBackups, previewRollback, executeRollback, loadAudit, exportAudit, formatTime,
|
||||
serviceLabel, sectionLabel, operationLabel
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
<template>
|
||||
<div class="config-settings" v-loading="loading">
|
||||
<div class="settings-header">
|
||||
<h3>配置管理</h3>
|
||||
<p class="settings-desc">按配置分区安全编辑、验证、应用和回滚,敏感凭据只显示状态,不会回显明文。</p>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
v-if="!canWrite"
|
||||
title="当前账号仅能查看配置,保存、应用和回滚操作已隐藏。"
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="config-alert"
|
||||
/>
|
||||
|
||||
<section class="status-panel">
|
||||
<div class="status-heading">
|
||||
<div>
|
||||
<span class="section-eyebrow">运行状态</span>
|
||||
<h4>配置快照</h4>
|
||||
</div>
|
||||
<el-button size="small" plain :loading="loading" @click="loadAll">刷新</el-button>
|
||||
</div>
|
||||
<div class="status-grid">
|
||||
<div class="status-item">
|
||||
<span>状态</span>
|
||||
<el-tag :type="stateTagType">{{ stateLabel }}</el-tag>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<span>当前生效代次</span>
|
||||
<strong>{{ status.activeGeneration || '-' }}</strong>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<span>最近校验时间</span>
|
||||
<strong>{{ formatTime(status.lastValidAt) }}</strong>
|
||||
</div>
|
||||
<div class="status-item status-wide">
|
||||
<span>待重启服务</span>
|
||||
<div v-if="status.pendingRestart?.length" class="tag-list">
|
||||
<el-tag v-for="service in status.pendingRestart" :key="service" type="warning" effect="plain">
|
||||
{{ serviceLabel(service) }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<strong v-else>无</strong>
|
||||
</div>
|
||||
</div>
|
||||
<el-alert
|
||||
v-for="issue in status.degradedReasons || []"
|
||||
:key="`${issue.code}-${issue.message}`"
|
||||
:title="`${issue.code}:${issue.message}`"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="degraded-alert"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section class="editor-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<span class="section-eyebrow">分区配置</span>
|
||||
<h4>编辑候选配置</h4>
|
||||
</div>
|
||||
<el-select v-model="selectedSection" class="section-select" aria-label="配置分区" @change="loadSection">
|
||||
<el-option v-for="item in sectionOptions" :key="item.value" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
v-if="sectionError"
|
||||
:title="sectionError"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="config-alert"
|
||||
/>
|
||||
|
||||
<div class="editor-meta">
|
||||
<span>编辑代次:{{ status.activeGeneration || '-' }}</span>
|
||||
<span>敏感字段:{{ sensitiveHint }}</span>
|
||||
</div>
|
||||
<el-input
|
||||
v-model="editorText"
|
||||
type="textarea"
|
||||
:rows="16"
|
||||
resize="vertical"
|
||||
spellcheck="false"
|
||||
class="config-editor"
|
||||
:readonly="!canWrite"
|
||||
aria-label="配置 JSON 编辑器"
|
||||
/>
|
||||
|
||||
<div v-if="secretField" class="secret-editor">
|
||||
<div>
|
||||
<strong>{{ secretField.label }}</strong>
|
||||
<p>{{ secretField.description }}</p>
|
||||
</div>
|
||||
<el-input
|
||||
v-model="secretValue"
|
||||
type="password"
|
||||
show-password
|
||||
clearable
|
||||
:disabled="!canWrite"
|
||||
:placeholder="secretField.placeholder"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<el-checkbox v-if="canWrite" v-model="confirmed" class="confirmation-check">
|
||||
我已确认这是受控变更,并允许使用最近认证完成高风险配置操作
|
||||
</el-checkbox>
|
||||
<div class="action-row">
|
||||
<el-button :loading="working === 'validate'" :disabled="!canWrite" @click="validateConfig">只验证</el-button>
|
||||
<el-button type="primary" :loading="working === 'save'" :disabled="!canWrite" @click="saveConfig">保存候选配置</el-button>
|
||||
<el-button type="success" plain :loading="working === 'apply'" :disabled="!canWrite || !savedGeneration" @click="applyConfig">
|
||||
应用 {{ savedGeneration ? `代次 ${savedGeneration}` : '' }}
|
||||
</el-button>
|
||||
</div>
|
||||
<div v-if="validationResult" class="result-box" :class="validationResult.valid ? 'result-success' : 'result-error'">
|
||||
<strong>{{ validationResult.valid ? '验证通过' : '验证未通过' }}</strong>
|
||||
<span v-if="validationResult.generation">候选代次:{{ validationResult.generation }}</span>
|
||||
<ul v-if="validationResult.issues?.length">
|
||||
<li v-for="issue in validationResult.issues" :key="`${issue.code}-${issue.message}`">{{ issue.code }}:{{ issue.message }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="canRollback" class="rollback-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<span class="section-eyebrow">受控回滚</span>
|
||||
<h4>备份与回滚</h4>
|
||||
</div>
|
||||
<el-button size="small" plain :loading="backupsLoading" @click="loadBackups">刷新备份</el-button>
|
||||
</div>
|
||||
<el-empty v-if="!backups.length && !backupsLoading" description="暂无可用配置备份" :image-size="72" />
|
||||
<div v-else class="backup-list">
|
||||
<button
|
||||
v-for="backup in backups"
|
||||
:key="backup.generation"
|
||||
type="button"
|
||||
class="backup-item"
|
||||
:class="{ selected: rollbackGeneration === backup.generation }"
|
||||
@click="rollbackGeneration = backup.generation"
|
||||
>
|
||||
<span>代次 {{ backup.generation }}</span>
|
||||
<small>{{ formatTime(backup.createdAt) }}</small>
|
||||
</button>
|
||||
</div>
|
||||
<el-checkbox v-model="rollbackConfirmed" class="confirmation-check">我已阅读回滚预览,并确认执行一次性回滚</el-checkbox>
|
||||
<div class="action-row">
|
||||
<el-button :loading="working === 'preview'" :disabled="!rollbackGeneration" @click="previewRollback">预览回滚</el-button>
|
||||
<el-button type="danger" plain :loading="working === 'rollback'" :disabled="!rollbackPreview || !rollbackConfirmed" @click="executeRollback">执行回滚</el-button>
|
||||
</div>
|
||||
<div v-if="rollbackPreview" class="preview-box">
|
||||
<strong>回滚预览</strong>
|
||||
<span>当前代次 {{ rollbackPreview.currentGeneration }} → 目标代次 {{ rollbackPreview.targetGeneration }}</span>
|
||||
<span>候选代次:{{ rollbackPreview.candidateGeneration }}</span>
|
||||
<span>变更分区:{{ rollbackPreview.changedSections?.map(sectionLabel).join('、') || '无' }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="canAudit" class="audit-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<span class="section-eyebrow">审计记录</span>
|
||||
<h4>配置操作审计</h4>
|
||||
</div>
|
||||
<div class="audit-actions">
|
||||
<el-button size="small" plain :loading="auditLoading" @click="loadAudit">查询</el-button>
|
||||
<el-button v-if="canExportAudit" size="small" type="primary" plain :loading="working === 'export'" @click="exportAudit('json')">导出 JSON</el-button>
|
||||
<el-button v-if="canExportAudit" size="small" plain :loading="working === 'export-csv'" @click="exportAudit('csv')">导出 CSV</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="auditItems.length" class="audit-list">
|
||||
<div v-for="item in auditItems" :key="item.id || `${item.createdAt}-${item.operation}`" class="audit-item">
|
||||
<div>
|
||||
<strong>{{ operationLabel(item.operation) }}</strong>
|
||||
<span>{{ sectionLabel(item.section) }} · {{ item.actorId || '系统' }}</span>
|
||||
</div>
|
||||
<time>{{ formatTime(item.createdAt) }}</time>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else description="暂无配置审计记录" :image-size="72" />
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { usePage } from './ConfigSettings.js'
|
||||
|
||||
const {
|
||||
loading,
|
||||
working,
|
||||
status,
|
||||
stateLabel,
|
||||
stateTagType,
|
||||
sectionOptions,
|
||||
selectedSection,
|
||||
editorText,
|
||||
sectionError,
|
||||
sensitiveHint,
|
||||
secretField,
|
||||
secretValue,
|
||||
confirmed,
|
||||
savedGeneration,
|
||||
validationResult,
|
||||
canWrite,
|
||||
canRollback,
|
||||
canAudit,
|
||||
canExportAudit,
|
||||
backupsLoading,
|
||||
backups,
|
||||
rollbackGeneration,
|
||||
rollbackConfirmed,
|
||||
rollbackPreview,
|
||||
auditLoading,
|
||||
auditItems,
|
||||
loadAll,
|
||||
loadSection,
|
||||
validateConfig,
|
||||
saveConfig,
|
||||
applyConfig,
|
||||
loadBackups,
|
||||
previewRollback,
|
||||
executeRollback,
|
||||
loadAudit,
|
||||
exportAudit,
|
||||
formatTime,
|
||||
serviceLabel,
|
||||
sectionLabel,
|
||||
operationLabel
|
||||
} = usePage()
|
||||
|
||||
void computed
|
||||
</script>
|
||||
|
||||
<style scoped src="./ConfigSettings.css"></style>
|
||||
@@ -1,9 +1,11 @@
|
||||
import {EpMenu} from "vue-icons-plus/ep";
|
||||
|
||||
import {ref, onMounted, onUnmounted} from 'vue'
|
||||
import {computed, ref, onMounted, onUnmounted} from 'vue'
|
||||
|
||||
import SecuritySettings from '@/views/components/SecuritySettings/SecuritySettings.vue'
|
||||
|
||||
import ConfigSettings from '@/views/components/ConfigSettings/ConfigSettings.vue'
|
||||
|
||||
import lang from '../../../i18n/i18n';
|
||||
|
||||
import GroupSettings from '../GroupSettings/GroupSettings.vue';
|
||||
@@ -43,6 +45,7 @@ export function usePage() {
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
SecuritySettings,
|
||||
ConfigSettings,
|
||||
lang,
|
||||
GroupSettings,
|
||||
RuleSettings,
|
||||
@@ -53,7 +56,10 @@ export function usePage() {
|
||||
globalStatus,
|
||||
userInfos,
|
||||
isMobile,
|
||||
handleResize
|
||||
handleResize,
|
||||
canReadConfig: computed(() => globalStatus.hasCapability("config.read")),
|
||||
canManageUsers: computed(() => globalStatus.hasCapability("user.manage")),
|
||||
canReadPlugins: computed(() => globalStatus.hasCapability("plugin.read"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +67,7 @@ export {
|
||||
EpMenu,
|
||||
BrandLogo,
|
||||
SecuritySettings,
|
||||
ConfigSettings,
|
||||
GroupSettings,
|
||||
RuleSettings,
|
||||
UserManagement,
|
||||
|
||||
@@ -23,16 +23,19 @@
|
||||
<el-tab-pane :label="lang.security">
|
||||
<SecuritySettings/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane v-if="canReadConfig" label="配置管理">
|
||||
<ConfigSettings />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="lang.group_settings">
|
||||
<GroupSettings/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="lang.rule_setting">
|
||||
<RuleSettings/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane v-if="userInfos.is_admin" :label="lang.user_management">
|
||||
<el-tab-pane v-if="canManageUsers" :label="lang.user_management">
|
||||
<UserManagement/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="lang.plugin_settings">
|
||||
<el-tab-pane v-if="canReadPlugins" :label="lang.plugin_settings">
|
||||
<PluginSettings/>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
@@ -40,13 +43,15 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { usePage, EpMenu, BrandLogo, SecuritySettings, GroupSettings, RuleSettings, UserManagement, PluginSettings } from './HomeHeader.js'
|
||||
import { usePage, EpMenu, BrandLogo, SecuritySettings, ConfigSettings, GroupSettings, RuleSettings, UserManagement, PluginSettings } from './HomeHeader.js'
|
||||
|
||||
const {
|
||||
globalStatus,
|
||||
isMobile,
|
||||
lang,
|
||||
userInfos
|
||||
canReadConfig,
|
||||
canManageUsers,
|
||||
canReadPlugins
|
||||
} = usePage()
|
||||
</script>
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
.recovery-prompt-content {
|
||||
color: var(--pm-text-primary);
|
||||
}
|
||||
|
||||
.recovery-prompt-icon {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
margin-bottom: 16px;
|
||||
border-radius: 14px;
|
||||
color: var(--pm-primary-color);
|
||||
background: var(--el-color-primary-light-9);
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.recovery-prompt-content h3 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 20px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.recovery-prompt-content p {
|
||||
margin: 0 0 18px;
|
||||
color: var(--pm-text-secondary);
|
||||
line-height: 1.75;
|
||||
}
|
||||
|
||||
.recovery-code-result {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.recovery-code-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
padding: 14px;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-md);
|
||||
background: var(--pm-bg-secondary);
|
||||
}
|
||||
|
||||
.recovery-code-list code {
|
||||
padding: 8px 10px;
|
||||
border-radius: 8px;
|
||||
color: var(--pm-text-primary);
|
||||
background: var(--pm-bg-primary);
|
||||
font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
|
||||
text-align: center;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.recovery-prompt-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.recovery-code-list {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.recovery-prompt-actions {
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
|
||||
.recovery-prompt-actions .el-button {
|
||||
width: 100%;
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
title="完善账户安全"
|
||||
width="min(520px, calc(100vw - 32px))"
|
||||
:close-on-click-modal="false"
|
||||
class="recovery-setup-dialog"
|
||||
@close="dismiss"
|
||||
>
|
||||
<div class="recovery-prompt-content">
|
||||
<div class="recovery-prompt-icon">盾</div>
|
||||
<h3>建议立即配置离线恢复码</h3>
|
||||
<p>
|
||||
离线恢复码可以在外部邮箱不可用时帮助您完成账户恢复。恢复码只会显示一次,生成后请保存到安全位置。
|
||||
</p>
|
||||
<el-alert
|
||||
v-if="generatedCodes.length === 0"
|
||||
title="当前尚未配置有效离线恢复码,高风险账户操作可能受到限制。"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<div v-else class="recovery-code-result">
|
||||
<el-alert
|
||||
title="恢复码已生成,请立即复制并妥善保存。离开此提示后将无法再次读取。"
|
||||
type="success"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<div class="recovery-code-list" aria-label="离线恢复码列表">
|
||||
<code v-for="code in generatedCodes" :key="code">{{ code }}</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="recovery-prompt-actions">
|
||||
<el-button v-if="generatedCodes.length === 0" @click="dismiss">稍后处理</el-button>
|
||||
<el-button
|
||||
v-if="generatedCodes.length === 0"
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
@click="generateRecoveryCodes"
|
||||
>
|
||||
立即生成恢复码
|
||||
</el-button>
|
||||
<el-button v-else type="primary" @click="dismiss">我已安全保存</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from "vue"
|
||||
|
||||
import { ElMessage } from "element-plus"
|
||||
|
||||
import { http } from "@/utils/axios"
|
||||
import { useGlobalStatusStore } from "@/stores/useGlobalStatusStore"
|
||||
|
||||
const globalStatus = useGlobalStatusStore()
|
||||
const loading = ref(false)
|
||||
const generatedCodes = ref([])
|
||||
|
||||
const visible = computed({
|
||||
get: () => Boolean(
|
||||
globalStatus.userInfos.showRecoverySetupPrompt
|
||||
&& !globalStatus.recoveryPromptDismissed
|
||||
&& globalStatus.role !== "super_admin"
|
||||
),
|
||||
set: value => {
|
||||
if (!value) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const dismiss = () => {
|
||||
generatedCodes.value = []
|
||||
globalStatus.dismissRecoveryPrompt()
|
||||
}
|
||||
|
||||
const generateRecoveryCodes = async () => {
|
||||
if (loading.value) {
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await http.post("/api/security/credentials/recovery-codes/generate", { count: 10 })
|
||||
if (response.errorNo !== 0 || !Array.isArray(response.data?.codes)) {
|
||||
throw new Error(response.errorMsg || "离线恢复码生成失败")
|
||||
}
|
||||
generatedCodes.value = response.data.codes
|
||||
globalStatus.userInfos.recoveryCodesConfigured = true
|
||||
globalStatus.userInfos.showRecoverySetupPrompt = false
|
||||
ElMessage.success("恢复码已生成,请仅保存这一次显示的内容")
|
||||
} catch (error) {
|
||||
ElMessage.error(error?.message || "离线恢复码生成失败,请稍后重试")
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped src="./RecoverySetupPrompt.css"></style>
|
||||
@@ -1,152 +1,242 @@
|
||||
import {onMounted, reactive, ref} from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
|
||||
import {ElMessageBox, ElNotification} from 'element-plus'
|
||||
import { ElMessageBox, ElNotification } from 'element-plus'
|
||||
|
||||
import lang from '../../../i18n/i18n';
|
||||
|
||||
import {http} from '@/utils/axios';
|
||||
|
||||
import {normalizeCreationOptions, serializeCredential, webAuthnSupported} from '@/utils/webauthn';
|
||||
import lang from '../../../i18n/i18n'
|
||||
import { http } from '@/utils/axios'
|
||||
import { useGlobalStatusStore } from '@/stores/useGlobalStatusStore'
|
||||
import { normalizeCreationOptions, serializeCredential, webAuthnSupported } from '@/utils/webauthn'
|
||||
|
||||
export function usePage() {
|
||||
const supported = webAuthnSupported();
|
||||
|
||||
const registering = ref(false);
|
||||
|
||||
const credentialsLoading = ref(false);
|
||||
|
||||
const credentials = ref([]);
|
||||
|
||||
const ruleForm = reactive({current_pwd: '', new_pwd: '', new_pwd2: ''})
|
||||
|
||||
const globalStatus = useGlobalStatusStore()
|
||||
const isSuperAdmin = computed(() => globalStatus.role === 'super_admin')
|
||||
const supported = webAuthnSupported()
|
||||
|
||||
const registering = ref(false)
|
||||
const credentialsLoading = ref(false)
|
||||
const credentials = ref([])
|
||||
const securityLoading = ref(false)
|
||||
const securityQuestion = reactive({ configured: false, question: '' })
|
||||
const questionForm = reactive({ question: '', answer: '' })
|
||||
const recoveryConfigured = ref(false)
|
||||
const generatedCodes = ref([])
|
||||
const externalEmails = ref([])
|
||||
const externalLoading = ref(false)
|
||||
const bindForm = reactive({ email: '', type: 'backup', challengeId: '', bindingId: 0, code: '' })
|
||||
|
||||
const ruleForm = reactive({ current_pwd: '', new_pwd: '', new_pwd2: '' })
|
||||
const rules = reactive({
|
||||
current_pwd: [{required: true, message: lang.err_required_pwd, trigger: 'blur'}],
|
||||
new_pwd: [{required: true, message: lang.err_required_pwd, trigger: 'blur'}],
|
||||
new_pwd2: [{required: true, message: lang.err_required_pwd, trigger: 'blur'}],
|
||||
current_pwd: [{ required: true, message: lang.err_required_pwd, trigger: 'blur' }],
|
||||
new_pwd: [{ required: true, message: lang.err_required_pwd, trigger: 'blur' }],
|
||||
new_pwd2: [{ required: true, message: lang.err_required_pwd, trigger: 'blur' }],
|
||||
})
|
||||
|
||||
|
||||
const notify = (message, type = 'error') => {
|
||||
ElNotification({title: type === 'success' ? '操作成功' : '操作失败', message, type});
|
||||
ElNotification({ title: type === 'success' ? '操作成功' : '操作失败', message, type })
|
||||
}
|
||||
|
||||
|
||||
const loadCredentials = async () => {
|
||||
credentialsLoading.value = true;
|
||||
if (!supported) return
|
||||
credentialsLoading.value = true
|
||||
try {
|
||||
const res = await http.get('/api/security/webauthn/credentials');
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '加载安全密钥失败');
|
||||
credentials.value = Array.isArray(res.data) ? res.data : [];
|
||||
const res = await http.get('/api/security/webauthn/credentials')
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '加载安全密钥失败')
|
||||
credentials.value = Array.isArray(res.data) ? res.data : []
|
||||
} catch (error) {
|
||||
notify(error?.message || '加载安全密钥失败');
|
||||
notify(error?.message || '加载安全密钥失败')
|
||||
} finally {
|
||||
credentialsLoading.value = false;
|
||||
credentialsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const loadSecurityData = async () => {
|
||||
securityLoading.value = true
|
||||
try {
|
||||
const requests = [
|
||||
http.get('/api/security/credentials/question'),
|
||||
http.get('/api/security/external-email/list'),
|
||||
]
|
||||
if (!isSuperAdmin.value) {
|
||||
requests.push(http.get('/api/security/credentials/recovery-codes'))
|
||||
}
|
||||
const [question, external, recovery] = await Promise.all(requests)
|
||||
if (question.errorNo === 0 && question.data) {
|
||||
securityQuestion.configured = Boolean(question.data.configured)
|
||||
securityQuestion.question = question.data.question || ''
|
||||
questionForm.question = question.data.question || ''
|
||||
}
|
||||
if (recovery && recovery.errorNo === 0) recoveryConfigured.value = Boolean(recovery.data?.configured)
|
||||
if (external.errorNo === 0) externalEmails.value = Array.isArray(external.data) ? external.data : []
|
||||
} catch (error) {
|
||||
notify(error?.message || '读取账户安全设置失败')
|
||||
} finally {
|
||||
securityLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const registerCredential = async () => {
|
||||
if (!supported || registering.value) return;
|
||||
registering.value = true;
|
||||
if (!supported || registering.value) return
|
||||
registering.value = true
|
||||
try {
|
||||
const prompt = await ElMessageBox.prompt('请为新安全密钥设置一个名称', '注册安全密钥', {
|
||||
confirmButtonText: '确定', cancelButtonText: '取消', inputPlaceholder: '例如:工作电脑',
|
||||
inputValidator: value => String(value || '').trim().length > 0 || '请输入密钥名称',
|
||||
});
|
||||
const displayName = String(prompt.value).trim();
|
||||
const begin = await http.post('/api/security/webauthn/registration/begin', {});
|
||||
if (begin.errorNo !== 0) throw new Error(begin.errorMsg || '无法开始安全密钥注册');
|
||||
const credential = await navigator.credentials.create({publicKey: normalizeCreationOptions(begin.data.options)});
|
||||
})
|
||||
const begin = await http.post('/api/security/webauthn/registration/begin', {})
|
||||
if (begin.errorNo !== 0) throw new Error(begin.errorMsg || '无法开始安全密钥注册')
|
||||
const credential = await navigator.credentials.create({ publicKey: normalizeCreationOptions(begin.data.options) })
|
||||
const finish = await http.post('/api/security/webauthn/registration/finish', {
|
||||
session_id: begin.data.session_id,
|
||||
display_name: displayName,
|
||||
display_name: String(prompt.value).trim(),
|
||||
credential: serializeCredential(credential),
|
||||
});
|
||||
if (finish.errorNo !== 0) throw new Error(finish.errorMsg || '安全密钥注册失败');
|
||||
notify('安全密钥注册成功', 'success');
|
||||
await loadCredentials();
|
||||
})
|
||||
if (finish.errorNo !== 0) throw new Error(finish.errorMsg || '安全密钥注册失败')
|
||||
notify('安全密钥注册成功', 'success')
|
||||
await loadCredentials()
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close' && error?.name !== 'NotAllowedError') {
|
||||
notify(error?.message || '安全密钥注册失败');
|
||||
}
|
||||
if (error !== 'cancel' && error !== 'close' && error?.name !== 'NotAllowedError') notify(error?.message || '安全密钥注册失败')
|
||||
} finally {
|
||||
registering.value = false;
|
||||
registering.value = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const renameCredential = async item => {
|
||||
try {
|
||||
const prompt = await ElMessageBox.prompt('请输入新的密钥名称', '重命名', {
|
||||
confirmButtonText: '确定', cancelButtonText: '取消', inputValue: item.display_name,
|
||||
inputValidator: value => String(value || '').trim().length > 0 || '请输入密钥名称',
|
||||
});
|
||||
const res = await http.post('/api/security/webauthn/credentials/rename', {
|
||||
id: item.id, display_name: String(prompt.value).trim(),
|
||||
});
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '密钥重命名失败');
|
||||
notify('密钥重命名成功', 'success');
|
||||
await loadCredentials();
|
||||
})
|
||||
const res = await http.post('/api/security/webauthn/credentials/rename', { id: item.id, display_name: String(prompt.value).trim() })
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '密钥重命名失败')
|
||||
notify('密钥重命名成功', 'success')
|
||||
await loadCredentials()
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '密钥重命名失败');
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '密钥重命名失败')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const revokeCredential = async item => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要撤销密钥“${item.display_name}”吗?撤销后将不能用于登录`, '撤销安全密钥', {
|
||||
confirmButtonText: '确定撤销', cancelButtonText: '取消', type: 'warning',
|
||||
});
|
||||
const res = await http.post('/api/security/webauthn/credentials/revoke', {id: item.id});
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '撤销安全密钥失败');
|
||||
notify('安全密钥已撤销', 'success');
|
||||
await loadCredentials();
|
||||
})
|
||||
const res = await http.post('/api/security/webauthn/credentials/revoke', { id: item.id })
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '撤销安全密钥失败')
|
||||
notify('安全密钥已撤销', 'success')
|
||||
await loadCredentials()
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '撤销安全密钥失败');
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '撤销安全密钥失败')
|
||||
}
|
||||
}
|
||||
|
||||
const formatTime = value => value ? new Date(value).toLocaleString('zh-CN', {hour12: false}) : '-';
|
||||
|
||||
const logout = () => http.post('/api/logout', {}).then(() => location.reload());
|
||||
|
||||
const submit = () => {
|
||||
if (!ruleForm.current_pwd || !ruleForm.new_pwd) return;
|
||||
|
||||
const saveSecurityQuestion = async () => {
|
||||
if (!questionForm.question.trim() || !questionForm.answer.trim()) {
|
||||
notify('请填写密保问题和答案')
|
||||
return
|
||||
}
|
||||
const res = await http.post('/api/security/credentials/question', questionForm)
|
||||
if (res.errorNo !== 0) {
|
||||
notify(res.errorMsg || '密保问题设置失败')
|
||||
return
|
||||
}
|
||||
securityQuestion.configured = true
|
||||
securityQuestion.question = questionForm.question.trim()
|
||||
questionForm.answer = ''
|
||||
notify('密保问题已保存', 'success')
|
||||
}
|
||||
|
||||
const generateRecoveryCodes = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm('生成新恢复码会撤销当前仍有效的恢复码,请确认已准备好安全保存。', '生成离线恢复码', { type: 'warning' })
|
||||
const res = await http.post('/api/security/credentials/recovery-codes/generate', { count: 10 })
|
||||
if (res.errorNo !== 0 || !Array.isArray(res.data?.codes)) throw new Error(res.errorMsg || '离线恢复码生成失败')
|
||||
generatedCodes.value = res.data.codes
|
||||
recoveryConfigured.value = true
|
||||
notify('恢复码已生成,请仅保存这一次显示的内容', 'success')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '离线恢复码生成失败')
|
||||
}
|
||||
}
|
||||
|
||||
const revokeRecoveryCodes = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm('撤销后现有离线恢复码将立即失效,是否继续?', '撤销离线恢复码', { type: 'warning' })
|
||||
const res = await http.post('/api/security/credentials/recovery-codes/revoke', {})
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '撤销恢复码失败')
|
||||
recoveryConfigured.value = false
|
||||
generatedCodes.value = []
|
||||
notify('离线恢复码已撤销', 'success')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '撤销恢复码失败')
|
||||
}
|
||||
}
|
||||
|
||||
const bindExternalEmail = async () => {
|
||||
if (!bindForm.email.trim()) {
|
||||
notify('请输入外部安全邮箱')
|
||||
return
|
||||
}
|
||||
externalLoading.value = true
|
||||
try {
|
||||
const res = await http.post('/api/security/external-email/bind', { email: bindForm.email.trim(), type: bindForm.type })
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '外部邮箱绑定失败')
|
||||
bindForm.challengeId = res.data.challenge_id
|
||||
bindForm.bindingId = res.data.id
|
||||
const prompt = await ElMessageBox.prompt(`验证码已发送到 ${res.data.email},请输入验证码`, '验证外部邮箱', {
|
||||
confirmButtonText: '验证', cancelButtonText: '取消', inputPlaceholder: '请输入验证码',
|
||||
})
|
||||
bindForm.code = String(prompt.value).trim()
|
||||
const verified = await http.post('/api/security/external-email/verify', {
|
||||
id: bindForm.challengeId, binding_id: bindForm.bindingId, email: bindForm.email.trim(), code: bindForm.code,
|
||||
})
|
||||
if (verified.errorNo !== 0) throw new Error(verified.errorMsg || '外部邮箱验证失败')
|
||||
bindForm.email = ''
|
||||
bindForm.challengeId = ''
|
||||
bindForm.bindingId = 0
|
||||
await loadSecurityData()
|
||||
notify('外部安全邮箱绑定成功', 'success')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '外部邮箱绑定失败')
|
||||
} finally {
|
||||
externalLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const disableExternalEmail = async item => {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定停用 ${item.email} 吗?停用后不能用于登录验证和恢复。`, '停用外部邮箱', { type: 'warning' })
|
||||
const res = await http.post('/api/security/external-email/disable', { id: item.id })
|
||||
if (res.errorNo !== 0) throw new Error(res.errorMsg || '外部邮箱停用失败')
|
||||
await loadSecurityData()
|
||||
notify('外部邮箱已停用', 'success')
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') notify(error?.message || '外部邮箱停用失败')
|
||||
}
|
||||
}
|
||||
|
||||
const formatTime = value => value ? new Date(value).toLocaleString('zh-CN', { hour12: false }) : '-'
|
||||
const logout = () => http.post('/api/logout', {}).then(() => location.reload())
|
||||
|
||||
const submit = async () => {
|
||||
if (!ruleForm.current_pwd || !ruleForm.new_pwd) return
|
||||
if (ruleForm.new_pwd !== ruleForm.new_pwd2) {
|
||||
notify(lang.err_pwd_diff);
|
||||
return;
|
||||
notify(lang.err_pwd_diff)
|
||||
return
|
||||
}
|
||||
http.post('/api/settings/modify_password', {
|
||||
current_password: ruleForm.current_pwd,
|
||||
password: ruleForm.new_pwd,
|
||||
}).then(res => {
|
||||
notify(res.errorNo === 0 ? res.data : res.errorMsg, res.errorNo === 0 ? 'success' : 'error');
|
||||
if (res.errorNo === 0) Object.assign(ruleForm, {current_pwd: '', new_pwd: '', new_pwd2: ''});
|
||||
});
|
||||
const res = await http.post('/api/settings/modify_password', { current_password: ruleForm.current_pwd, password: ruleForm.new_pwd })
|
||||
notify(res.errorNo === 0 ? '密码修改成功' : res.errorMsg, res.errorNo === 0 ? 'success' : 'error')
|
||||
if (res.errorNo === 0) Object.assign(ruleForm, { current_pwd: '', new_pwd: '', new_pwd2: '' })
|
||||
}
|
||||
|
||||
onMounted(loadCredentials);
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([loadSecurityData(), loadCredentials()])
|
||||
})
|
||||
|
||||
return {
|
||||
onMounted,
|
||||
reactive,
|
||||
ref,
|
||||
ElMessageBox,
|
||||
ElNotification,
|
||||
lang,
|
||||
http,
|
||||
normalizeCreationOptions,
|
||||
serializeCredential,
|
||||
webAuthnSupported,
|
||||
supported,
|
||||
registering,
|
||||
credentialsLoading,
|
||||
credentials,
|
||||
ruleForm,
|
||||
rules,
|
||||
notify,
|
||||
loadCredentials,
|
||||
registerCredential,
|
||||
renameCredential,
|
||||
revokeCredential,
|
||||
formatTime,
|
||||
logout,
|
||||
submit
|
||||
lang, isSuperAdmin, supported, registering, credentialsLoading, credentials, securityLoading,
|
||||
securityQuestion, questionForm, recoveryConfigured, generatedCodes, externalEmails, externalLoading,
|
||||
bindForm, ruleForm, rules, submit, registerCredential, renameCredential, revokeCredential,
|
||||
saveSecurityQuestion, generateRecoveryCodes, revokeRecoveryCodes, bindExternalEmail,
|
||||
disableExternalEmail, formatTime, logout,
|
||||
}
|
||||
}
|
||||
@@ -1,74 +1,75 @@
|
||||
<template>
|
||||
<div class="settings-card">
|
||||
<div class="settings-header">
|
||||
<h3>{{ lang.modify_pwd }}</h3>
|
||||
<p class="settings-desc">{{ lang.modify_pwd_desc }}</p>
|
||||
</div>
|
||||
<template>
|
||||
<div class="settings-card" v-loading="securityLoading">
|
||||
<section v-if="!isSuperAdmin" class="security-section">
|
||||
<div class="settings-header">
|
||||
<h3>{{ lang.modify_pwd }}</h3>
|
||||
<p class="settings-desc">{{ lang.modify_pwd_desc }}</p>
|
||||
</div>
|
||||
<div class="settings-body">
|
||||
<el-form :model="ruleForm" :rules="rules" status-icon label-position="top" class="settings-form">
|
||||
<el-form-item :label="lang.current_pwd" prop="current_pwd"><el-input v-model="ruleForm.current_pwd" type="password" :placeholder="lang.enter_current_pwd" show-password class="premium-input" /></el-form-item>
|
||||
<el-form-item :label="lang.modify_pwd" prop="new_pwd"><el-input v-model="ruleForm.new_pwd" type="password" :placeholder="lang.enter_new_pwd" show-password class="premium-input" /></el-form-item>
|
||||
<el-form-item :label="lang.enter_again" prop="new_pwd2"><el-input v-model="ruleForm.new_pwd2" type="password" :placeholder="lang.confirm_new_pwd" show-password class="premium-input" /></el-form-item>
|
||||
<div class="form-actions"><el-button type="primary" @click="submit" class="submit-btn">{{ lang.submit }}</el-button></div>
|
||||
</el-form>
|
||||
</div>
|
||||
<el-divider class="settings-divider" />
|
||||
</section>
|
||||
|
||||
<div class="settings-body">
|
||||
<el-form :model="ruleForm" :rules="rules" status-icon label-position="top" class="settings-form">
|
||||
<el-form-item :label="lang.current_pwd" prop="current_pwd">
|
||||
<el-input type="password" v-model="ruleForm.current_pwd" :placeholder="lang.enter_current_pwd" show-password class="premium-input"/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="lang.modify_pwd" prop="new_pwd">
|
||||
<el-input type="password" v-model="ruleForm.new_pwd" :placeholder="lang.enter_new_pwd" show-password class="premium-input"/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="lang.enter_again" prop="new_pwd2">
|
||||
<el-input type="password" v-model="ruleForm.new_pwd2" :placeholder="lang.confirm_new_pwd" show-password class="premium-input"/>
|
||||
</el-form-item>
|
||||
<div class="form-actions">
|
||||
<el-button type="primary" @click="submit" class="submit-btn">{{ lang.submit }}</el-button>
|
||||
</div>
|
||||
<el-alert v-else title="超级管理员密码只能通过部署端专用本机通道重置,网页不会提供修改入口。" type="warning" :closable="false" show-icon class="security-alert" />
|
||||
|
||||
<section class="security-section">
|
||||
<div class="settings-header">
|
||||
<h3>密保问题</h3>
|
||||
<p class="settings-desc">密保问题不能单独重置密码,必须与离线恢复码组合使用。</p>
|
||||
</div>
|
||||
<el-form :model="questionForm" label-position="top" class="settings-form">
|
||||
<el-form-item label="密保问题"><el-input v-model="questionForm.question" maxlength="128" placeholder="例如:我最喜欢的颜色是什么?" /></el-form-item>
|
||||
<el-form-item label="密保答案"><el-input v-model="questionForm.answer" type="password" show-password maxlength="256" placeholder="请输入答案,保存后不会回显" /></el-form-item>
|
||||
<div class="form-actions"><el-button type="primary" @click="saveSecurityQuestion">{{ securityQuestion.configured ? '更新密保问题' : '设置密保问题' }}</el-button></div>
|
||||
</el-form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<el-divider class="settings-divider"/>
|
||||
|
||||
<div class="settings-header security-key-header">
|
||||
<div>
|
||||
<h3>WebAuthn 安全密钥</h3>
|
||||
<p class="settings-desc">使用设备或浏览器内置的安全密钥无密码登录。</p>
|
||||
<el-divider v-if="!isSuperAdmin" class="settings-divider" />
|
||||
<section v-if="!isSuperAdmin" class="security-section">
|
||||
<div class="settings-header security-key-header">
|
||||
<div><h3>离线恢复码</h3><p class="settings-desc">恢复码只在生成时显示一次,请保存到安全位置。</p></div>
|
||||
<div class="section-actions"><el-button type="primary" @click="generateRecoveryCodes">生成新恢复码</el-button><el-button v-if="recoveryConfigured" type="danger" plain @click="revokeRecoveryCodes">撤销</el-button></div>
|
||||
</div>
|
||||
<el-button type="primary" :loading="registering" :disabled="!supported" @click="registerCredential">
|
||||
注册安全密钥
|
||||
</el-button>
|
||||
</div>
|
||||
<el-alert
|
||||
v-if="!supported"
|
||||
title="当前浏览器不支持安全密钥,请使用 HTTPS 访问并确保浏览器支持 WebAuthn"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="security-alert"
|
||||
/>
|
||||
<div class="credential-list" v-loading="credentialsLoading">
|
||||
<el-empty v-if="!credentialsLoading && credentials.length === 0" description="暂无已注册的安全密钥"/>
|
||||
<div v-for="item in credentials" :key="item.id" class="credential-item">
|
||||
<div class="credential-info">
|
||||
<strong>{{ item.display_name }}</strong>
|
||||
<span>创建于{{ formatTime(item.created_at) }}</span>
|
||||
<span v-if="item.last_used_at">最后使用于{{ formatTime(item.last_used_at) }}</span>
|
||||
<el-tag v-if="item.revoked_at" type="info" size="small">已撤销</el-tag>
|
||||
<el-tag v-else-if="item.requires_re_registration" type="warning" size="small">需要重新注册</el-tag>
|
||||
<el-tag v-else type="success" size="small">有效</el-tag>
|
||||
<span v-if="item.requires_re_registration" class="credential-warning">该密钥为旧版本,请重新注册后再用于登录。</span>
|
||||
</div>
|
||||
<div class="credential-actions">
|
||||
<el-button size="small" :disabled="Boolean(item.revoked_at)" @click="renameCredential(item)">重命名</el-button>
|
||||
<el-button size="small" type="danger" plain :disabled="Boolean(item.revoked_at)" @click="revokeCredential(item)">撤销</el-button>
|
||||
<el-alert v-if="recoveryConfigured" title="当前已配置有效离线恢复码" type="success" :closable="false" show-icon />
|
||||
<el-alert v-else title="当前未配置有效离线恢复码,高风险操作可能无法进行。" type="warning" :closable="false" show-icon />
|
||||
<div v-if="generatedCodes.length" class="recovery-code-panel">
|
||||
<div class="one-time-tip">以下内容只显示本次,请立即复制并妥善保存;离开页面后不会再次读取。</div>
|
||||
<code v-for="code in generatedCodes" :key="code" class="recovery-code">{{ code }}</code>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<el-divider class="settings-divider" />
|
||||
<section class="security-section">
|
||||
<div class="settings-header"><h3>外部安全邮箱</h3><p class="settings-desc">用于登录二次验证和密码恢复,只显示脱敏地址。</p></div>
|
||||
<div class="external-bind-form">
|
||||
<el-input v-model="bindForm.email" placeholder="请输入完整邮箱地址" clearable />
|
||||
<el-select v-model="bindForm.type" aria-label="邮箱用途"><el-option label="备用邮箱" value="backup" /><el-option label="主要邮箱" value="primary" /></el-select>
|
||||
<el-button type="primary" :loading="externalLoading" @click="bindExternalEmail">绑定并验证</el-button>
|
||||
</div>
|
||||
<div v-if="externalEmails.length" class="external-list">
|
||||
<div v-for="item in externalEmails" :key="item.id" class="external-item">
|
||||
<div><strong>{{ item.email }}</strong><span>{{ item.type === 'primary' ? '主要邮箱' : '备用邮箱' }}</span><el-tag size="small" :type="item.status === 'verified' ? 'success' : 'warning'">{{ item.status === 'verified' ? '已验证' : item.status === 'pending' ? '待验证' : '已停用' }}</el-tag></div>
|
||||
<el-button v-if="item.status !== 'disabled'" type="danger" plain size="small" @click="disableExternalEmail(item)">停用</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else description="暂无外部安全邮箱" />
|
||||
</section>
|
||||
|
||||
<el-divider class="settings-divider"/>
|
||||
<el-divider class="settings-divider" />
|
||||
<section v-if="supported" class="security-section">
|
||||
<div class="settings-header security-key-header"><div><h3>WebAuthn 安全密钥</h3><p class="settings-desc">使用设备或浏览器内置的安全密钥无密码登录。</p></div><el-button type="primary" :loading="registering" @click="registerCredential">注册安全密钥</el-button></div>
|
||||
<div class="credential-list" v-loading="credentialsLoading"><el-empty v-if="!credentialsLoading && credentials.length === 0" description="暂无已注册的安全密钥" /><div v-for="item in credentials" :key="item.id" class="credential-item"><div class="credential-info"><strong>{{ item.display_name }}</strong><span>创建于{{ formatTime(item.created_at) }}</span><span v-if="item.last_used_at">最后使用于{{ formatTime(item.last_used_at) }}</span><el-tag v-if="item.revoked_at" type="info" size="small">已撤销</el-tag><el-tag v-else-if="item.requires_re_registration" type="warning" size="small">需要重新注册</el-tag><el-tag v-else type="success" size="small">有效</el-tag></div><div class="credential-actions"><el-button size="small" :disabled="Boolean(item.revoked_at)" @click="renameCredential(item)">重命名</el-button><el-button size="small" type="danger" plain :disabled="Boolean(item.revoked_at)" @click="revokeCredential(item)">撤销</el-button></div></div></div>
|
||||
</section>
|
||||
<el-alert v-else title="当前浏览器不支持 WebAuthn,请使用 HTTPS 和受支持的浏览器。" type="warning" :closable="false" show-icon />
|
||||
|
||||
<div class="settings-header">
|
||||
<h3 class="danger-text">{{ lang.logout }}</h3>
|
||||
<p class="settings-desc">{{ lang.logout_desc }}</p>
|
||||
</div>
|
||||
<div class="settings-body">
|
||||
<el-button type="danger" plain @click="logout" class="logout-btn">{{ lang.logout }}</el-button>
|
||||
</div>
|
||||
<el-divider class="settings-divider" />
|
||||
<section class="security-section"><div class="settings-header"><h3 class="danger-text">{{ lang.logout }}</h3><p class="settings-desc">{{ lang.logout_desc }}</p></div><el-button type="danger" plain @click="logout" class="logout-btn">{{ lang.logout }}</el-button></section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -76,19 +77,11 @@
|
||||
import { usePage } from './SecuritySettings.js'
|
||||
|
||||
const {
|
||||
lang,
|
||||
ruleForm,
|
||||
rules,
|
||||
submit,
|
||||
registering,
|
||||
supported,
|
||||
registerCredential,
|
||||
credentialsLoading,
|
||||
credentials,
|
||||
formatTime,
|
||||
renameCredential,
|
||||
revokeCredential,
|
||||
logout
|
||||
lang, isSuperAdmin, supported, registering, credentialsLoading, credentials, securityLoading,
|
||||
securityQuestion, questionForm, recoveryConfigured, generatedCodes, externalEmails, externalLoading,
|
||||
bindForm, ruleForm, rules, submit, registerCredential, renameCredential, revokeCredential,
|
||||
saveSecurityQuestion, generateRecoveryCodes, revokeRecoveryCodes, bindExternalEmail,
|
||||
disableExternalEmail, formatTime, logout,
|
||||
} = usePage()
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="settings-card">
|
||||
<div class="settings-card">
|
||||
<div class="settings-header">
|
||||
<h3>{{ lang.account_management }}</h3>
|
||||
<p class="settings-desc">{{ lang.account_management_desc }}</p>
|
||||
@@ -7,12 +7,17 @@
|
||||
|
||||
<div class="table-container">
|
||||
<el-table :data="userList" class="modern-table" style="width: 100%">
|
||||
<el-table-column label="ID" prop="ID" width="80"/>
|
||||
<el-table-column :label="lang.account" prop="Account" min-width="150" show-overflow-tooltip/>
|
||||
<el-table-column :label="lang.user_name" prop="Name" min-width="120" show-overflow-tooltip/>
|
||||
<el-table-column label="ID" prop="ID" width="80" />
|
||||
<el-table-column :label="lang.account" prop="Account" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column :label="lang.user_name" prop="Name" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column :label="lang.disabled" prop="Disabled" width="120">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.Disabled === 1 ? 'info' : 'success'" size="small" effect="plain" class="status-tag">
|
||||
<el-tag
|
||||
:type="scope.row.Disabled === 1 ? 'info' : 'success'"
|
||||
size="small"
|
||||
effect="plain"
|
||||
class="status-tag"
|
||||
>
|
||||
{{ scope.row.Disabled === 1 ? lang.disabled : lang.enabled }}
|
||||
</el-tag>
|
||||
</template>
|
||||
@@ -20,12 +25,19 @@
|
||||
<el-table-column align="right" width="100">
|
||||
<template #header>
|
||||
<el-button type="primary" size="small" @click="createUser" class="new-btn" plain>
|
||||
<el-icon><Plus/></el-icon> New
|
||||
<el-icon><Plus /></el-icon> 新建
|
||||
</el-button>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<el-button size="small" type="primary" text bg @click="handleEdit(scope.$index, scope.row)" class="action-btn">
|
||||
Edit
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
text
|
||||
bg
|
||||
@click="handleEdit(scope.$index, scope.row)"
|
||||
class="action-btn"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -33,12 +45,12 @@
|
||||
</div>
|
||||
|
||||
<div class="pagination-wrapper">
|
||||
<el-pagination
|
||||
v-model:current-page="currentPage"
|
||||
small
|
||||
background
|
||||
<el-pagination
|
||||
v-model:current-page="currentPage"
|
||||
small
|
||||
background
|
||||
layout="prev, pager, next"
|
||||
:page-count="totalPage"
|
||||
:page-count="totalPage"
|
||||
@current-change="reflushList"
|
||||
/>
|
||||
</div>
|
||||
@@ -47,23 +59,28 @@
|
||||
<div class="dialog-content">
|
||||
<el-form label-position="top">
|
||||
<el-form-item :label="lang.account">
|
||||
<el-input :disabled="editModel === 'edit'" v-model="editUserInfo.account"/>
|
||||
<el-input :disabled="editModel === 'edit'" v-model="editUserInfo.account" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="lang.user_name">
|
||||
<el-input v-model="editUserInfo.name"/>
|
||||
<el-input v-model="editUserInfo.name" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="lang.password">
|
||||
<el-input :placeholder="lang.resetPwd" v-model="editUserInfo.password" type="password" show-password/>
|
||||
<el-input
|
||||
:placeholder="lang.resetPwd"
|
||||
v-model="editUserInfo.password"
|
||||
type="password"
|
||||
show-password
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<div class="status-switch">
|
||||
<span class="switch-label">{{ lang.status }}</span>
|
||||
<el-switch
|
||||
v-model="editUserInfo.disabled"
|
||||
class="ml-2"
|
||||
<el-switch
|
||||
v-model="editUserInfo.disabled"
|
||||
class="ml-2"
|
||||
:active-text="lang.disabled"
|
||||
:inactive-text="lang.enabled"
|
||||
active-color="#ef4444"
|
||||
@@ -84,7 +101,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { usePage, Plus } from './UserManagement.js'
|
||||
import { usePage, Plus } from "./UserManagement.js";
|
||||
|
||||
const {
|
||||
lang,
|
||||
@@ -99,7 +116,7 @@ const {
|
||||
submit,
|
||||
editModel,
|
||||
editUserInfo
|
||||
} = usePage()
|
||||
} = usePage();
|
||||
</script>
|
||||
|
||||
<style scoped src="./UserManagement.css"></style>
|
||||
Reference in new issue
Block a user