2023-04-28 11:42:16 +08:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<el-drawer
|
|
|
|
v-model="drawerVisiable"
|
|
|
|
:destroy-on-close="true"
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
@close="handleClose"
|
|
|
|
size="30%"
|
|
|
|
>
|
|
|
|
<template #header>
|
|
|
|
<DrawerHeader :header="$t('setting.mfa')" :back="handleClose" />
|
|
|
|
</template>
|
2023-05-06 14:27:33 +08:00
|
|
|
<el-alert :closable="false" type="warning">
|
|
|
|
<template #default>
|
|
|
|
<span>
|
|
|
|
<span>{{ $t('setting.mfaAlert') }}</span>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
</el-alert>
|
|
|
|
<el-form
|
|
|
|
:model="form"
|
|
|
|
style="margin-top: 20px"
|
|
|
|
ref="formRef"
|
|
|
|
@submit.prevent
|
|
|
|
v-loading="loading"
|
|
|
|
label-position="top"
|
|
|
|
>
|
2023-04-28 14:48:19 +08:00
|
|
|
<el-row type="flex" justify="center">
|
|
|
|
<el-col :span="22">
|
|
|
|
<el-form-item :label="$t('setting.mfaHelper1')">
|
2023-05-09 15:15:46 +08:00
|
|
|
<ul class="help-ul">
|
2023-04-28 14:48:19 +08:00
|
|
|
<li>Google Authenticator</li>
|
|
|
|
<li>Microsoft Authenticator</li>
|
|
|
|
<li>1Password</li>
|
|
|
|
<li>LastPass</li>
|
|
|
|
<li>Authenticator</li>
|
|
|
|
</ul>
|
|
|
|
</el-form-item>
|
2023-04-28 15:58:19 +08:00
|
|
|
<el-form-item :label="$t('setting.mfaHelper2')">
|
2023-04-28 14:48:19 +08:00
|
|
|
<el-image style="width: 120px; height: 120px" :src="qrImage" />
|
2023-04-28 15:58:19 +08:00
|
|
|
<span class="input-help">
|
|
|
|
<span style="float: left">{{ $t('setting.secret') }}: {{ form.secret }}</span>
|
|
|
|
<div style="float: left; margin-top: 2px">
|
|
|
|
<el-icon
|
|
|
|
color="#409EFC"
|
|
|
|
style="cursor: pointer; margin-left: 10px"
|
|
|
|
:size="18"
|
|
|
|
@click="onCopy()"
|
|
|
|
>
|
|
|
|
<DocumentCopy />
|
|
|
|
</el-icon>
|
|
|
|
</div>
|
|
|
|
</span>
|
2023-04-28 14:48:19 +08:00
|
|
|
</el-form-item>
|
2023-04-28 15:58:19 +08:00
|
|
|
<el-form-item :label="$t('setting.mfaCode')" prop="code" :rules="Rules.requiredInput">
|
2023-04-28 14:48:19 +08:00
|
|
|
<el-input v-model="form.code"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
2023-04-28 11:42:16 +08:00
|
|
|
</el-form>
|
|
|
|
<template #footer>
|
|
|
|
<span class="dialog-footer">
|
|
|
|
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
|
|
|
|
<el-button :disabled="loading" type="primary" @click="onBind(formRef)">
|
|
|
|
{{ $t('commons.button.confirm') }}
|
|
|
|
</el-button>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
</el-drawer>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { bindMFA, getMFA } from '@/api/modules/setting';
|
|
|
|
import { reactive, ref } from 'vue';
|
|
|
|
import { Rules } from '@/global/form-rules';
|
|
|
|
import i18n from '@/lang';
|
2023-05-17 18:45:48 +08:00
|
|
|
import { MsgError, MsgSuccess } from '@/utils/message';
|
2023-04-28 11:42:16 +08:00
|
|
|
import { FormInstance } from 'element-plus';
|
2023-05-17 18:45:48 +08:00
|
|
|
import useClipboard from 'vue-clipboard3';
|
|
|
|
const { toClipboard } = useClipboard();
|
2023-04-28 11:42:16 +08:00
|
|
|
|
|
|
|
const loading = ref();
|
|
|
|
const qrImage = ref();
|
|
|
|
const drawerVisiable = ref();
|
|
|
|
const formRef = ref();
|
|
|
|
|
|
|
|
const form = reactive({
|
|
|
|
code: '',
|
|
|
|
secret: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
const emit = defineEmits<{ (e: 'search'): void }>();
|
|
|
|
const acceptParams = (): void => {
|
|
|
|
loadMfaCode();
|
|
|
|
drawerVisiable.value = true;
|
|
|
|
};
|
|
|
|
|
2023-05-17 18:45:48 +08:00
|
|
|
const onCopy = async () => {
|
|
|
|
try {
|
|
|
|
await toClipboard(form.secret);
|
|
|
|
MsgSuccess(i18n.global.t('commons.msg.copySuccess'));
|
|
|
|
} catch (e) {
|
|
|
|
MsgError(i18n.global.t('commons.msg.copyfailed'));
|
|
|
|
}
|
2023-04-28 15:58:19 +08:00
|
|
|
};
|
|
|
|
|
2023-04-28 11:42:16 +08:00
|
|
|
const loadMfaCode = async () => {
|
|
|
|
const res = await getMFA();
|
|
|
|
form.secret = res.data.secret;
|
|
|
|
qrImage.value = res.data.qrImage;
|
|
|
|
};
|
|
|
|
|
|
|
|
const onBind = async (formEl: FormInstance | undefined) => {
|
|
|
|
if (!formEl) return;
|
|
|
|
formEl.validate(async (valid) => {
|
|
|
|
if (!valid) return;
|
|
|
|
loading.value = true;
|
|
|
|
await bindMFA(form)
|
|
|
|
.then(() => {
|
|
|
|
loading.value = false;
|
|
|
|
drawerVisiable.value = false;
|
|
|
|
emit('search');
|
|
|
|
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
loading.value = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
emit('search');
|
|
|
|
drawerVisiable.value = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
acceptParams,
|
|
|
|
});
|
|
|
|
</script>
|
2023-05-09 15:15:46 +08:00
|
|
|
<style scoped>
|
|
|
|
.help-ul {
|
|
|
|
color: #8f959e;
|
|
|
|
}
|
|
|
|
</style>
|