1 parent
3456b9d481
commit
31ee54942a
22 files changed
+1728
-5
No files matched your search
+94
@@ -0,0 +1,94 @@
|
||||
.recovery-code-summary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-secondary);
|
||||
}
|
||||
|
||||
.recovery-code-summary > div {
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.summary-label {
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.recovery-code-description {
|
||||
margin: 16px 0 0;
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.recovery-code-result {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.result-title {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
color: var(--el-color-warning-dark-2);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.result-title span {
|
||||
color: var(--pm-text-secondary);
|
||||
}
|
||||
|
||||
.recovery-code-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.recovery-code-grid code {
|
||||
padding: 9px 10px;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-secondary);
|
||||
color: var(--pm-text-primary);
|
||||
text-align: center;
|
||||
user-select: all;
|
||||
}
|
||||
|
||||
.copy-button {
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
.dialog-feedback.error {
|
||||
margin: 12px 0 0;
|
||||
padding: 9px 12px;
|
||||
border-radius: var(--pm-radius-sm);
|
||||
color: var(--el-color-danger-dark-2);
|
||||
background: var(--el-color-danger-light-9);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.recovery-dialog-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.recovery-dialog-actions :deep(.el-button + .el-button) {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.recovery-code-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.recovery-dialog-actions {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
import { http } from '@/utils/axios'
|
||||
import {
|
||||
isRecentAuthenticationCancelled,
|
||||
requestWithRecentAuthentication,
|
||||
} from '@/utils/recentAuthentication'
|
||||
|
||||
export const recoveryCodeDialogProps = {
|
||||
modelValue: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
user: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
}
|
||||
|
||||
function assertSuccess(response, fallback) {
|
||||
if (!response || response.errorNo !== 0) {
|
||||
const error = new Error(response?.errorMsg || fallback)
|
||||
if (typeof response?.data?.code === 'string') {
|
||||
error.apiErrorCode = response.data.code
|
||||
}
|
||||
throw error
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export function useRecoveryCodeDialog(props, emit) {
|
||||
const configured = ref(false)
|
||||
const codes = ref([])
|
||||
const generating = ref(false)
|
||||
const revoking = ref(false)
|
||||
const errorMessage = ref('')
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: value => emit('update:modelValue', value),
|
||||
})
|
||||
const busy = computed(() => generating.value || revoking.value)
|
||||
|
||||
const loadStatus = async () => {
|
||||
if (!props.user?.ID) return false
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(async () => {
|
||||
const result = await http.get('/api/v1/user/security/recovery-codes', {
|
||||
params: { id: props.user.ID },
|
||||
})
|
||||
return assertSuccess(result, '读取安全码状态失败')
|
||||
})
|
||||
configured.value = Boolean(response.data?.configured)
|
||||
return true
|
||||
} catch (error) {
|
||||
if (!isRecentAuthenticationCancelled(error)) {
|
||||
errorMessage.value = error?.message || '读取安全码状态失败'
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const generateCodes = async () => {
|
||||
if (busy.value || !props.user?.ID) return false
|
||||
generating.value = true
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(async () => {
|
||||
const result = await http.post('/api/v1/user/security/recovery-codes/generate', {
|
||||
user_id: props.user.ID,
|
||||
count: 10,
|
||||
})
|
||||
return assertSuccess(result, '安全码生成失败')
|
||||
})
|
||||
codes.value = Array.isArray(response.data?.codes) ? response.data.codes : []
|
||||
if (!codes.value.length) {
|
||||
throw new Error('服务器未返回安全码,请稍后重试')
|
||||
}
|
||||
configured.value = true
|
||||
emit('changed')
|
||||
return true
|
||||
} catch (error) {
|
||||
if (!isRecentAuthenticationCancelled(error)) {
|
||||
errorMessage.value = error?.message || '安全码生成失败'
|
||||
}
|
||||
return false
|
||||
} finally {
|
||||
generating.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const revokeCodes = async () => {
|
||||
if (busy.value || !props.user?.ID) return false
|
||||
revoking.value = true
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(async () => {
|
||||
const result = await http.post('/api/v1/user/security/recovery-codes/revoke', {
|
||||
user_id: props.user.ID,
|
||||
})
|
||||
return assertSuccess(result, '安全码撤销失败')
|
||||
})
|
||||
configured.value = false
|
||||
codes.value = []
|
||||
emit('changed')
|
||||
return true
|
||||
} catch (error) {
|
||||
if (!isRecentAuthenticationCancelled(error)) {
|
||||
errorMessage.value = error?.message || '安全码撤销失败'
|
||||
}
|
||||
return false
|
||||
} finally {
|
||||
revoking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const copyCodes = async () => {
|
||||
if (!codes.value.length) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(codes.value.join('\n'))
|
||||
ElMessage.success('安全码已复制')
|
||||
} catch {
|
||||
errorMessage.value = '复制失败,请手动选择安全码复制'
|
||||
}
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
configured.value = Boolean(props.user?.RecoveryCodeConfigured)
|
||||
codes.value = []
|
||||
errorMessage.value = ''
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
if (busy.value) return
|
||||
visible.value = false
|
||||
reset()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
value => {
|
||||
if (value) {
|
||||
reset()
|
||||
void loadStatus()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
return {
|
||||
visible,
|
||||
configured,
|
||||
codes,
|
||||
generating,
|
||||
revoking,
|
||||
busy,
|
||||
errorMessage,
|
||||
close,
|
||||
generateCodes,
|
||||
revokeCodes,
|
||||
copyCodes,
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="管理安全码"
|
||||
width="min(560px, calc(100vw - 32px))"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!busy"
|
||||
:show-close="!busy"
|
||||
class="recovery-code-dialog"
|
||||
@update:model-value="value => { if (!value) close() }"
|
||||
>
|
||||
<div class="recovery-code-summary">
|
||||
<div>
|
||||
<span class="summary-label">账号</span>
|
||||
<strong>{{ user?.Account || '-' }}</strong>
|
||||
</div>
|
||||
<el-tag :type="configured ? 'success' : 'info'" effect="plain">
|
||||
{{ configured ? '已设置安全码' : '未设置安全码' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
|
||||
<div v-if="codes.length" class="recovery-code-result">
|
||||
<div class="result-title">
|
||||
<strong>新安全码仅显示这一次</strong>
|
||||
<span>请立即交给用户妥善保存,关闭弹窗后无法再次查看。</span>
|
||||
</div>
|
||||
<div class="recovery-code-grid">
|
||||
<code v-for="code in codes" :key="code">{{ code }}</code>
|
||||
</div>
|
||||
<el-button class="copy-button" @click="copyCodes">复制全部安全码</el-button>
|
||||
</div>
|
||||
|
||||
<p v-else class="recovery-code-description">
|
||||
重新生成会立即撤销该用户原有的全部安全码。安全码明文不会写入用户列表或普通编辑请求。
|
||||
</p>
|
||||
|
||||
<p v-if="errorMessage" class="dialog-feedback error" role="alert">
|
||||
{{ errorMessage }}
|
||||
</p>
|
||||
|
||||
<template #footer>
|
||||
<div class="recovery-dialog-actions">
|
||||
<el-button :disabled="busy" @click="close">关闭</el-button>
|
||||
<el-button
|
||||
v-if="configured && !codes.length"
|
||||
type="danger"
|
||||
plain
|
||||
:loading="revoking"
|
||||
:disabled="generating"
|
||||
@click="revokeCodes"
|
||||
>
|
||||
撤销安全码
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="generating"
|
||||
:disabled="revoking"
|
||||
@click="generateCodes"
|
||||
>
|
||||
{{ configured ? '重新生成安全码' : '生成安全码' }}
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
recoveryCodeDialogProps,
|
||||
useRecoveryCodeDialog,
|
||||
} from './RecoveryCodeDialog.js'
|
||||
|
||||
const props = defineProps(recoveryCodeDialogProps)
|
||||
const emit = defineEmits(['update:modelValue', 'changed'])
|
||||
|
||||
const {
|
||||
visible,
|
||||
configured,
|
||||
codes,
|
||||
generating,
|
||||
revoking,
|
||||
busy,
|
||||
errorMessage,
|
||||
close,
|
||||
generateCodes,
|
||||
revokeCodes,
|
||||
copyCodes,
|
||||
} = useRecoveryCodeDialog(props, emit)
|
||||
</script>
|
||||
|
||||
<style scoped src="./RecoveryCodeDialog.css"></style>
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
.external-email-account {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
gap: 4px 12px;
|
||||
margin-bottom: 16px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.external-email-account span {
|
||||
color: var(--pm-text-secondary);
|
||||
}
|
||||
|
||||
.external-email-account span:last-child {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.external-email-form,
|
||||
.external-email-verification {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.external-email-form :deep(.el-select) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.verification-target {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr) auto;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 14px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-secondary);
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.verification-target strong {
|
||||
min-width: 0;
|
||||
color: var(--pm-text-primary);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.verification-target .expired {
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
|
||||
.replacement-note {
|
||||
margin: 10px 0 0;
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.dialog-feedback {
|
||||
margin: 10px 0 0;
|
||||
padding: 9px 12px;
|
||||
border-radius: var(--pm-radius-sm);
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.dialog-feedback.success {
|
||||
color: var(--el-color-success-dark-2);
|
||||
background: var(--el-color-success-light-9);
|
||||
}
|
||||
|
||||
.dialog-feedback.error {
|
||||
color: var(--el-color-danger-dark-2);
|
||||
background: var(--el-color-danger-light-9);
|
||||
}
|
||||
|
||||
.external-dialog-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.external-dialog-actions :deep(.el-button + .el-button) {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.verification-target {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.external-dialog-actions {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue'
|
||||
|
||||
import { http } from '@/utils/axios'
|
||||
import {
|
||||
isRecentAuthenticationCancelled,
|
||||
requestWithRecentAuthentication,
|
||||
} from '@/utils/recentAuthentication'
|
||||
|
||||
export const userExternalEmailDialogProps = {
|
||||
modelValue: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
user: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
}
|
||||
|
||||
const verificationCodeLength = 8
|
||||
|
||||
function assertSuccess(response, fallback) {
|
||||
if (!response || response.errorNo !== 0) {
|
||||
const error = new Error(response?.errorMsg || fallback)
|
||||
if (typeof response?.data?.code === 'string') {
|
||||
error.apiErrorCode = response.data.code
|
||||
}
|
||||
throw error
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export function useUserExternalEmailDialog(props, emit) {
|
||||
const form = reactive({ email: '', type: 'primary', code: '' })
|
||||
const challenge = reactive({ id: '', bindingId: 0, maskedEmail: '', expiresAt: '' })
|
||||
const currentEmail = ref('')
|
||||
const step = ref('details')
|
||||
const sending = ref(false)
|
||||
const verifying = ref(false)
|
||||
const errorMessage = ref('')
|
||||
const statusMessage = ref('')
|
||||
const currentTime = ref(Date.now())
|
||||
let timer = null
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: value => emit('update:modelValue', value),
|
||||
})
|
||||
const busy = computed(() => sending.value || verifying.value)
|
||||
const hasChallenge = computed(() => Boolean(challenge.id && challenge.bindingId))
|
||||
const remainingSeconds = computed(() => {
|
||||
if (!challenge.expiresAt) return 0
|
||||
const expiresAt = new Date(challenge.expiresAt).getTime()
|
||||
if (!Number.isFinite(expiresAt)) return 0
|
||||
return Math.max(0, Math.ceil((expiresAt - currentTime.value) / 1000))
|
||||
})
|
||||
const expirationText = computed(() => {
|
||||
if (!hasChallenge.value) return ''
|
||||
if (remainingSeconds.value <= 0) return '验证码已过期,请重新发送'
|
||||
const minutes = Math.floor(remainingSeconds.value / 60)
|
||||
const seconds = remainingSeconds.value % 60
|
||||
return `${minutes}:${String(seconds).padStart(2, '0')} 后过期`
|
||||
})
|
||||
|
||||
const startTimer = () => {
|
||||
if (timer) return
|
||||
currentTime.value = Date.now()
|
||||
timer = window.setInterval(() => {
|
||||
currentTime.value = Date.now()
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const stopTimer = () => {
|
||||
if (!timer) return
|
||||
window.clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
|
||||
const clearMessages = () => {
|
||||
errorMessage.value = ''
|
||||
statusMessage.value = ''
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
Object.assign(form, { email: '', type: 'primary', code: '' })
|
||||
Object.assign(challenge, { id: '', bindingId: 0, maskedEmail: '', expiresAt: '' })
|
||||
currentEmail.value = ''
|
||||
step.value = 'details'
|
||||
clearMessages()
|
||||
}
|
||||
|
||||
const loadCurrentEmail = async () => {
|
||||
if (!props.user?.ID) return false
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(async () => {
|
||||
const result = await http.get('/api/v1/user/security/external-email/list', {
|
||||
params: { id: props.user.ID },
|
||||
})
|
||||
return assertSuccess(result, '读取外部邮箱失败')
|
||||
})
|
||||
const items = Array.isArray(response.data?.items) ? response.data.items : []
|
||||
const primary = items.find(item => item.type === 'primary') || items[0]
|
||||
currentEmail.value = primary?.email || ''
|
||||
if (primary?.type) form.type = primary.type
|
||||
return true
|
||||
} catch (error) {
|
||||
if (!isRecentAuthenticationCancelled(error)) {
|
||||
errorMessage.value = error?.message || '读取外部邮箱失败'
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const sendVerificationCode = async () => {
|
||||
if (busy.value || !props.user?.ID) return false
|
||||
const email = form.email.trim().toLowerCase()
|
||||
if (!email) {
|
||||
errorMessage.value = '请输入外部邮箱地址'
|
||||
return false
|
||||
}
|
||||
sending.value = true
|
||||
clearMessages()
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(async () => {
|
||||
const result = await http.post('/api/v1/user/security/external-email/change', {
|
||||
user_id: props.user.ID,
|
||||
email,
|
||||
type: form.type,
|
||||
})
|
||||
return assertSuccess(result, '验证码发送失败')
|
||||
})
|
||||
if (!response.data?.challenge_id || !response.data?.binding_id) {
|
||||
throw new Error('服务器返回的验证信息不完整,请稍后重试')
|
||||
}
|
||||
form.email = email
|
||||
form.code = ''
|
||||
Object.assign(challenge, {
|
||||
id: response.data.challenge_id,
|
||||
bindingId: response.data.binding_id,
|
||||
maskedEmail: response.data.email || email,
|
||||
expiresAt: response.data.expires_at || '',
|
||||
})
|
||||
currentTime.value = Date.now()
|
||||
step.value = 'verification'
|
||||
statusMessage.value = `验证码已发送到 ${challenge.maskedEmail}`
|
||||
return true
|
||||
} catch (error) {
|
||||
if (!isRecentAuthenticationCancelled(error)) {
|
||||
errorMessage.value = error?.message || '验证码发送失败,请稍后重试'
|
||||
}
|
||||
return false
|
||||
} finally {
|
||||
sending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const verifyAndReplace = async () => {
|
||||
if (busy.value || !hasChallenge.value || !props.user?.ID) return false
|
||||
const code = form.code.trim()
|
||||
if (!code) {
|
||||
errorMessage.value = '请输入邮箱验证码'
|
||||
return false
|
||||
}
|
||||
if (remainingSeconds.value <= 0) {
|
||||
errorMessage.value = '验证码已过期,请重新发送'
|
||||
return false
|
||||
}
|
||||
verifying.value = true
|
||||
clearMessages()
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(async () => {
|
||||
const result = await http.post('/api/v1/user/security/external-email/verify', {
|
||||
user_id: props.user.ID,
|
||||
challenge_id: challenge.id,
|
||||
binding_id: challenge.bindingId,
|
||||
email: form.email,
|
||||
code,
|
||||
})
|
||||
return assertSuccess(result, '外部邮箱验证失败')
|
||||
})
|
||||
emit('changed')
|
||||
visible.value = false
|
||||
reset()
|
||||
return true
|
||||
} catch (error) {
|
||||
if (!isRecentAuthenticationCancelled(error)) {
|
||||
errorMessage.value = error?.message || '外部邮箱验证失败,请检查验证码后重试'
|
||||
}
|
||||
form.code = ''
|
||||
return false
|
||||
} finally {
|
||||
verifying.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleCodeInput = value => {
|
||||
form.code = String(value || '').replace(/\s+/g, '').slice(0, verificationCodeLength)
|
||||
errorMessage.value = ''
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
if (busy.value) return
|
||||
visible.value = false
|
||||
reset()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
value => {
|
||||
if (value) {
|
||||
reset()
|
||||
startTimer()
|
||||
void loadCurrentEmail()
|
||||
} else {
|
||||
stopTimer()
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
onBeforeUnmount(stopTimer)
|
||||
|
||||
return {
|
||||
visible,
|
||||
form,
|
||||
step,
|
||||
currentEmail,
|
||||
sending,
|
||||
verifying,
|
||||
busy,
|
||||
challenge,
|
||||
errorMessage,
|
||||
statusMessage,
|
||||
remainingSeconds,
|
||||
expirationText,
|
||||
verificationCodeLength,
|
||||
close,
|
||||
sendVerificationCode,
|
||||
verifyAndReplace,
|
||||
handleCodeInput,
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
title="编辑外部邮箱"
|
||||
width="min(520px, calc(100vw - 32px))"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="!busy"
|
||||
:show-close="!busy"
|
||||
class="user-external-email-dialog"
|
||||
@update:model-value="value => { if (!value) close() }"
|
||||
>
|
||||
<div class="external-email-account">
|
||||
<span>目标账号</span>
|
||||
<strong>{{ user?.Account || '-' }}</strong>
|
||||
<span v-if="currentEmail">当前邮箱:{{ currentEmail }}</span>
|
||||
<span v-else>当前未绑定外部邮箱</span>
|
||||
</div>
|
||||
|
||||
<el-form
|
||||
v-if="step === 'details'"
|
||||
:model="form"
|
||||
label-position="top"
|
||||
class="external-email-form"
|
||||
@submit.prevent="sendVerificationCode"
|
||||
>
|
||||
<el-form-item label="新的外部邮箱地址" required>
|
||||
<el-input
|
||||
v-model="form.email"
|
||||
type="email"
|
||||
autocomplete="email"
|
||||
placeholder="请输入可接收验证码的外部邮箱"
|
||||
clearable
|
||||
:disabled="sending"
|
||||
@input="errorMessage = ''"
|
||||
@keyup.enter="sendVerificationCode"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="邮箱用途" required>
|
||||
<el-select v-model="form.type" aria-label="邮箱用途" :disabled="sending">
|
||||
<el-option label="主要邮箱" value="primary" />
|
||||
<el-option label="备用邮箱" value="backup" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div v-else class="external-email-verification">
|
||||
<div class="verification-target">
|
||||
<span>验证码已发送至</span>
|
||||
<strong>{{ challenge.maskedEmail }}</strong>
|
||||
<span :class="{ expired: remainingSeconds <= 0 }">{{ expirationText }}</span>
|
||||
</div>
|
||||
<el-form label-position="top" @submit.prevent="verifyAndReplace">
|
||||
<el-form-item label="邮箱验证码" required>
|
||||
<el-input
|
||||
:model-value="form.code"
|
||||
inputmode="numeric"
|
||||
autocomplete="one-time-code"
|
||||
:maxlength="verificationCodeLength"
|
||||
placeholder="请输入邮箱中的验证码"
|
||||
clearable
|
||||
:disabled="verifying"
|
||||
@update:model-value="handleCodeInput"
|
||||
@keyup.enter="verifyAndReplace"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<p class="replacement-note">
|
||||
新邮箱验证成功后才会替换同用途旧邮箱,验证失败不会影响现有绑定。
|
||||
</p>
|
||||
<p v-if="statusMessage" class="dialog-feedback success" role="status">
|
||||
{{ statusMessage }}
|
||||
</p>
|
||||
<p v-if="errorMessage" class="dialog-feedback error" role="alert">
|
||||
{{ errorMessage }}
|
||||
</p>
|
||||
|
||||
<template #footer>
|
||||
<div class="external-dialog-actions">
|
||||
<el-button :disabled="busy" @click="close">取消</el-button>
|
||||
<el-button
|
||||
v-if="step === 'verification'"
|
||||
:loading="sending"
|
||||
:disabled="verifying"
|
||||
@click="sendVerificationCode"
|
||||
>
|
||||
重新发送
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="step === 'details'"
|
||||
type="primary"
|
||||
:loading="sending"
|
||||
@click="sendVerificationCode"
|
||||
>
|
||||
发送验证码
|
||||
</el-button>
|
||||
<el-button
|
||||
v-else
|
||||
type="primary"
|
||||
:loading="verifying"
|
||||
:disabled="sending"
|
||||
@click="verifyAndReplace"
|
||||
>
|
||||
验证并保存
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
userExternalEmailDialogProps,
|
||||
useUserExternalEmailDialog,
|
||||
} from './UserExternalEmailDialog.js'
|
||||
|
||||
const props = defineProps(userExternalEmailDialogProps)
|
||||
const emit = defineEmits(['update:modelValue', 'changed'])
|
||||
|
||||
const {
|
||||
visible,
|
||||
form,
|
||||
step,
|
||||
currentEmail,
|
||||
sending,
|
||||
verifying,
|
||||
busy,
|
||||
challenge,
|
||||
errorMessage,
|
||||
statusMessage,
|
||||
remainingSeconds,
|
||||
expirationText,
|
||||
verificationCodeLength,
|
||||
close,
|
||||
sendVerificationCode,
|
||||
verifyAndReplace,
|
||||
handleCodeInput,
|
||||
} = useUserExternalEmailDialog(props, emit)
|
||||
</script>
|
||||
|
||||
<style scoped src="./UserExternalEmailDialog.css"></style>
|
||||
@@ -100,6 +100,44 @@
|
||||
padding: 0 8px;
|
||||
}
|
||||
|
||||
.security-edit-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.security-edit-item {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--pm-border-color);
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-secondary);
|
||||
}
|
||||
|
||||
.security-edit-item > div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.security-edit-item strong {
|
||||
color: var(--pm-text-primary);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.security-edit-item span {
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.security-edit-item :deep(.el-button) {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.status-switch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -116,3 +154,9 @@
|
||||
font-weight: 500;
|
||||
color: var(--pm-text-primary);
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.security-edit-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,12 @@ export function usePage() {
|
||||
const userInfoDialog = ref(false)
|
||||
|
||||
const editModel = ref("edit")
|
||||
|
||||
const selectedUser = ref(null)
|
||||
|
||||
const recoveryCodeDialogVisible = ref(false)
|
||||
|
||||
const externalEmailDialogVisible = ref(false)
|
||||
|
||||
const editUserInfo = reactive({
|
||||
"account": "",
|
||||
@@ -65,11 +71,15 @@ export function usePage() {
|
||||
totalPage.value = res.data.total_page
|
||||
if (res.data["list"]) {
|
||||
userList.push(...res.data["list"])
|
||||
if (selectedUser.value?.ID) {
|
||||
selectedUser.value = userList.find(item => item.ID === selectedUser.value.ID) || selectedUser.value
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const handleEdit = function (idx, row) {
|
||||
selectedUser.value = row
|
||||
editUserInfo.account = row.Account
|
||||
editUserInfo.name = row.Name
|
||||
editUserInfo.disabled = row.Disabled === 1
|
||||
@@ -80,6 +90,7 @@ export function usePage() {
|
||||
}
|
||||
|
||||
const createUser = function () {
|
||||
selectedUser.value = null
|
||||
editUserInfo.account = ""
|
||||
editUserInfo.name = ""
|
||||
editUserInfo.disabled = false
|
||||
@@ -88,6 +99,20 @@ export function usePage() {
|
||||
title.value = lang.newUser
|
||||
userInfoDialog.value = true
|
||||
}
|
||||
|
||||
const openRecoveryCodeDialog = function () {
|
||||
if (!selectedUser.value?.ID) return
|
||||
recoveryCodeDialogVisible.value = true
|
||||
}
|
||||
|
||||
const openExternalEmailDialog = function () {
|
||||
if (!selectedUser.value?.ID) return
|
||||
externalEmailDialogVisible.value = true
|
||||
}
|
||||
|
||||
const handleSecurityChanged = function () {
|
||||
reflushList()
|
||||
}
|
||||
|
||||
const submit = function () {
|
||||
if (editModel.value === 'edit') {
|
||||
@@ -148,6 +173,12 @@ export function usePage() {
|
||||
userInfoDialog,
|
||||
editModel,
|
||||
editUserInfo,
|
||||
selectedUser,
|
||||
recoveryCodeDialogVisible,
|
||||
externalEmailDialogVisible,
|
||||
openRecoveryCodeDialog,
|
||||
openExternalEmailDialog,
|
||||
handleSecurityChanged,
|
||||
title,
|
||||
reflushList,
|
||||
handleEdit,
|
||||
|
||||
@@ -111,6 +111,28 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<div v-if="editModel === 'edit'" class="security-edit-grid">
|
||||
<div class="security-edit-item">
|
||||
<div>
|
||||
<strong>安全码</strong>
|
||||
<span>{{ recoveryCodeMeta(selectedUser?.RecoveryCodeConfigured).label }}</span>
|
||||
</div>
|
||||
<el-button @click="openRecoveryCodeDialog">管理安全码</el-button>
|
||||
</div>
|
||||
<div class="security-edit-item">
|
||||
<div>
|
||||
<strong>外部邮箱</strong>
|
||||
<span>
|
||||
{{ externalEmailMeta(
|
||||
selectedUser?.ExternalEmailEnabled,
|
||||
selectedUser?.ExternalEmailConfigured
|
||||
).label }}
|
||||
</span>
|
||||
</div>
|
||||
<el-button @click="openExternalEmailDialog">编辑外部邮箱</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-form-item>
|
||||
<div class="status-switch">
|
||||
<span class="switch-label">{{ lang.status }}</span>
|
||||
@@ -133,11 +155,24 @@
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<RecoveryCodeDialog
|
||||
v-model="recoveryCodeDialogVisible"
|
||||
:user="selectedUser"
|
||||
@changed="handleSecurityChanged"
|
||||
/>
|
||||
<UserExternalEmailDialog
|
||||
v-model="externalEmailDialogVisible"
|
||||
:user="selectedUser"
|
||||
@changed="handleSecurityChanged"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { usePage, Plus } from "./UserManagement.js";
|
||||
import RecoveryCodeDialog from "./RecoveryCodeDialog/RecoveryCodeDialog.vue";
|
||||
import UserExternalEmailDialog from "./UserExternalEmailDialog/UserExternalEmailDialog.vue";
|
||||
|
||||
const {
|
||||
lang,
|
||||
@@ -152,6 +187,12 @@ const {
|
||||
submit,
|
||||
editModel,
|
||||
editUserInfo,
|
||||
selectedUser,
|
||||
recoveryCodeDialogVisible,
|
||||
externalEmailDialogVisible,
|
||||
openRecoveryCodeDialog,
|
||||
openExternalEmailDialog,
|
||||
handleSecurityChanged,
|
||||
roleMeta,
|
||||
recoveryCodeMeta,
|
||||
externalEmailMeta,
|
||||
|
||||
Reference in new issue
Block a user