perf: 优化中英文翻译与切换

This commit is contained in:
xiaojunnuo
2025-06-28 23:57:01 +08:00
parent 082f47663d
commit acaa8b1731
43 changed files with 4121 additions and 4175 deletions
@@ -1,81 +1,89 @@
<template>
<a-drawer v-model:open="notificationDrawerVisible" placement="right" :closable="true" width="600px"
class="pi-notification-form" @after-open-change="notificationDrawerOnAfterVisibleChange">
<template #title>
<div>
{{ t('certd.edit_notification') }}
<a-button v-if="mode === 'edit'" @click="notificationDelete()">
<template #icon>
<DeleteOutlined />
</template>
</a-button>
</div>
</template>
<template v-if="currentNotification">
<pi-container>
<a-form ref="notificationFormRef" class="notification-form" :model="currentNotification"
:label-col="labelCol" :wrapper-col="wrapperCol">
<fs-form-item v-if="currentNotification.type === 'email'" v-model="currentNotification.type" :item="{
title: t('certd.type'),
key: 'type',
value: 'email',
component: {
name: 'a-select',
vModel: 'value',
disabled: !editMode,
options: [
{ value: 'email', label: t('certd.email') },
{ value: 'other', label: t('certd.other_notification_method') },
],
},
rules: [{ required: true, message: t('certd.required') }],
}" />
<fs-form-item v-model="currentNotification.when" :item="{
title: t('certd.trigger_time'),
key: 'when',
value: ['error'],
component: {
name: 'a-select',
vModel: 'value',
disabled: !editMode,
mode: 'multiple',
options: [
{ value: 'start', label: t('certd.start_time') },
{ value: 'success', label: t('certd.success_time') },
{ value: 'turnToSuccess', label: t('certd.fail_to_success_time') },
{ value: 'error', label: t('certd.fail_time') },
],
},
helper: t('certd.helper_suggest_fail_only'),
rules: [{ required: true, message: t('certd.required') }],
}" />
<pi-notification-form-email v-if="currentNotification.type === 'email'" ref="optionsRef"
v-model:options="currentNotification.options"></pi-notification-form-email>
<a-drawer v-model:open="notificationDrawerVisible" placement="right" :closable="true" width="600px" class="pi-notification-form" @after-open-change="notificationDrawerOnAfterVisibleChange">
<template #title>
<div>
{{ t("certd.edit_notification") }}
<a-button v-if="mode === 'edit'" @click="notificationDelete()">
<template #icon>
<DeleteOutlined />
</template>
</a-button>
</div>
</template>
<template v-if="currentNotification">
<pi-container>
<a-form ref="notificationFormRef" class="notification-form" :model="currentNotification" :label-col="labelCol" :wrapper-col="wrapperCol">
<fs-form-item
v-if="currentNotification.type === 'email'"
v-model="currentNotification.type"
:item="{
title: t('certd.type'),
key: 'type',
value: 'email',
component: {
name: 'a-select',
vModel: 'value',
disabled: !editMode,
options: [
{ value: 'email', label: t('certd.email') },
{ value: 'other', label: t('certd.other_notification_method') },
],
},
rules: [{ required: true, message: t('certd.required') }],
}"
/>
<fs-form-item
v-model="currentNotification.when"
:item="{
title: t('certd.trigger_time'),
key: 'when',
value: ['error'],
component: {
name: 'a-select',
vModel: 'value',
disabled: !editMode,
mode: 'multiple',
options: [
{ value: 'start', label: t('certd.start_time') },
{ value: 'success', label: t('certd.success_time') },
{ value: 'turnToSuccess', label: t('certd.fail_to_success_time') },
{ value: 'error', label: t('certd.fail_time') },
],
},
helper: t('certd.helper_suggest_fail_only'),
rules: [{ required: true, message: t('certd.required') }],
}"
/>
<pi-notification-form-email v-if="currentNotification.type === 'email'" ref="optionsRef" v-model:options="currentNotification.options"></pi-notification-form-email>
<fs-form-item v-else v-model="currentNotification.notificationId" :item="{
title: t('certd.notification_config'),
key: 'notificationId',
component: {
disabled: !editMode,
name: NotificationSelector,
onSelectedChange,
},
helper: t('certd.please_select_notification'),
rules: [{ required: true, message: t('certd.required') }],
}" />
</a-form>
<fs-form-item
v-else
v-model="currentNotification.notificationId"
:item="{
title: t('certd.notification_config'),
key: 'notificationId',
component: {
disabled: !editMode,
name: NotificationSelector,
onSelectedChange,
},
helper: t('certd.please_select_notification'),
rules: [{ required: true, message: t('certd.required') }],
}"
/>
</a-form>
<template #footer>
<a-form-item v-if="editMode" :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" @click="notificationSave"> {{ t('certd.confirm') }} </a-button>
</a-form-item>
</template>
</pi-container>
</template>
</a-drawer>
<template #footer>
<a-form-item v-if="editMode" :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" @click="notificationSave"> {{ t("certd.confirm") }} </a-button>
</a-form-item>
</template>
</pi-container>
</template>
</a-drawer>
</template>
<script lang="ts">
<script lang="ts" setup>
import { Modal } from "ant-design-vue";
import { ref, Ref } from "vue";
import * as _ from "lodash-es";
@@ -86,157 +94,125 @@ import { useI18n } from "vue-i18n";
const { t } = useI18n();
export default {
name: "PiNotificationForm",
// eslint-disable-next-line vue/no-unused-components
components: { NotificationSelector, PiNotificationFormEmail },
props: {
editMode: {
type: Boolean,
default: true,
},
},
emits: ["update"],
setup(props: any, context: any) {
/**
* notification drawer
* @returns
*/
function useNotificationForm() {
const mode = ref("add");
const callback = ref();
const currentNotification: Ref<any> = ref({ type: undefined, when: [], options: {}, notificationId: undefined, title: "" });
const currentPlugin = ref({});
const notificationFormRef = ref(null);
const notificationDrawerVisible = ref(false);
const optionsRef = ref();
const rules = ref({
type: [
{
type: "string",
required: true,
message: t('certd.please_select_type'),
},
],
when: [
{
type: "string",
required: true,
message: t('certd.please_select_trigger_time'),
},
],
notificationId: [
{
type: "number",
required: true,
message: t('certd.please_select_notification_config'),
},
],
});
const notificationDrawerShow = () => {
notificationDrawerVisible.value = true;
};
const notificationDrawerClose = () => {
notificationDrawerVisible.value = false;
};
defineOptions({
name: "PiNotificationForm",
});
const notificationDrawerOnAfterVisibleChange = (val: any) => {
console.log("notificationDrawerOnAfterVisibleChange", val);
};
const props = defineProps<{
editMode: boolean;
}>();
const notificationOpen = (notification: any, emit: any) => {
callback.value = emit;
currentNotification.value = _.cloneDeep(notification);
console.log("currentNotificationOpen", currentNotification.value);
notificationDrawerShow();
};
const emit = defineEmits(["update"]);
const notificationAdd = (emit: any) => {
mode.value = "add";
const notification = { id: nanoid(), type: "custom", when: ["error", "turnToSuccess"] };
notificationOpen(notification, emit);
};
const notificationEdit = (notification: any, emit: any) => {
mode.value = "edit";
notificationOpen(notification, emit);
};
const notificationView = (notification: any, emit: any) => {
mode.value = "view";
notificationOpen(notification, emit);
};
const notificationSave = async (e: any) => {
if (optionsRef.value) {
currentNotification.value.options = await optionsRef.value.getValue();
}
console.log("currentNotificationSave", currentNotification.value);
try {
await notificationFormRef.value.validate();
} catch (e) {
console.error("表单验证失败:", e);
return;
}
callback.value("save", currentNotification.value);
notificationDrawerClose();
};
const notificationDelete = () => {
Modal.confirm({
title: t('certd.confirm'),
content: t('certd.confirm_delete_trigger'),
async onOk() {
callback.value("delete");
notificationDrawerClose();
},
});
};
const blankFn = () => {
return {};
};
function onSelectedChange(node: any) {
currentNotification.value.title = node?.name || null;
}
return {
notificationFormRef,
onSelectedChange,
mode,
notificationAdd,
notificationEdit,
notificationView,
notificationDrawerShow,
notificationDrawerVisible,
notificationDrawerOnAfterVisibleChange,
currentNotification,
currentPlugin,
notificationSave,
notificationDelete,
rules,
blankFn,
optionsRef,
};
}
return {
...useNotificationForm(),
labelCol: { span: 6 },
wrapperCol: { span: 16 },
};
},
computed: {
NotificationSelector() {
return NotificationSelector;
},
},
/**
* notification drawer
* @returns
*/
const mode = ref("add");
const callback = ref();
const currentNotification: Ref<any> = ref({ type: undefined, when: [], options: {}, notificationId: undefined, title: "" });
const currentPlugin = ref({});
const notificationFormRef = ref(null);
const notificationDrawerVisible = ref(false);
const optionsRef = ref();
const rules = ref({
type: [
{
type: "string",
required: true,
message: t("certd.please_select_type"),
},
],
when: [
{
type: "string",
required: true,
message: t("certd.please_select_trigger_time"),
},
],
notificationId: [
{
type: "number",
required: true,
message: t("certd.please_select_notification_config"),
},
],
});
const notificationDrawerShow = () => {
notificationDrawerVisible.value = true;
};
const notificationDrawerClose = () => {
notificationDrawerVisible.value = false;
};
const notificationDrawerOnAfterVisibleChange = (val: any) => {
console.log("notificationDrawerOnAfterVisibleChange", val);
};
const notificationOpen = (notification: any, emit: any) => {
callback.value = emit;
currentNotification.value = _.cloneDeep(notification);
console.log("currentNotificationOpen", currentNotification.value);
notificationDrawerShow();
};
const notificationAdd = (emit: any) => {
mode.value = "add";
const notification = { id: nanoid(), type: "custom", when: ["error", "turnToSuccess"] };
notificationOpen(notification, emit);
};
const notificationEdit = (notification: any, emit: any) => {
mode.value = "edit";
notificationOpen(notification, emit);
};
const notificationView = (notification: any, emit: any) => {
mode.value = "view";
notificationOpen(notification, emit);
};
const notificationSave = async (e: any) => {
if (optionsRef.value) {
currentNotification.value.options = await optionsRef.value.getValue();
}
console.log("currentNotificationSave", currentNotification.value);
try {
await notificationFormRef.value.validate();
} catch (e) {
console.error("表单验证失败:", e);
return;
}
callback.value("save", currentNotification.value);
notificationDrawerClose();
};
const notificationDelete = () => {
Modal.confirm({
title: t("certd.confirm"),
content: t("certd.confirm_delete_trigger"),
async onOk() {
callback.value("delete");
notificationDrawerClose();
},
});
};
const blankFn = () => {
return {};
};
function onSelectedChange(node: any) {
currentNotification.value.title = node?.name || null;
}
const labelCol = { span: 6 };
const wrapperCol = { span: 16 };
</script>
<style lang="less">
.pi-notification-form {}
.pi-notification-form {
}
</style>
@@ -1,195 +1,201 @@
<template>
<a-drawer v-model:open="triggerDrawerVisible" placement="right" :closable="true" width="650px"
class="pi-trigger-form" @after-open-change="triggerDrawerOnAfterVisibleChange">
<template #title>
<div>
{{ t("certd.editTrigger") }}
<a-button v-if="mode === 'edit'" @click="triggerDelete()">
<template #icon>
<DeleteOutlined />
</template>
</a-button>
</div>
</template>
<template v-if="currentTrigger">
<pi-container>
<a-form ref="triggerFormRef" class="trigger-form" :model="currentTrigger" :label-col="labelCol"
:wrapper-col="wrapperCol">
<fs-form-item v-model="currentTrigger.title" :item="{
title: t('certd.triggerName'),
key: 'title',
component: {
name: 'a-input',
vModel: 'value',
disabled: !editMode,
},
rules: [{ required: true, message: t('certd.requiredField') }],
}" />
<a-drawer v-model:open="triggerDrawerVisible" placement="right" :closable="true" width="650px" class="pi-trigger-form" @after-open-change="triggerDrawerOnAfterVisibleChange">
<template #title>
<div>
{{ t("certd.editTrigger") }}
<a-button v-if="mode === 'edit'" @click="triggerDelete()">
<template #icon>
<DeleteOutlined />
</template>
</a-button>
</div>
</template>
<template v-if="currentTrigger">
<pi-container>
<a-form ref="triggerFormRef" class="trigger-form" :model="currentTrigger" :label-col="labelCol" :wrapper-col="wrapperCol">
<fs-form-item
v-model="currentTrigger.title"
:item="{
title: t('certd.triggerName'),
key: 'title',
component: {
name: 'a-input',
vModel: 'value',
disabled: !editMode,
},
rules: [{ required: true, message: t('certd.requiredField') }],
}"
/>
<fs-form-item
v-model="currentTrigger.type"
:item="{
title: t('certd.type'),
key: 'type',
value: 'timer',
component: {
name: 'a-select',
vModel: 'value',
disabled: !editMode,
options: [{ value: 'timer', label: t('certd.schedule') }],
},
rules: [{ required: true, message: t('certd.requiredField') }],
}"
/>
<fs-form-item v-model="currentTrigger.type" :item="{
title: t('certd.type'),
key: 'type',
value: 'timer',
component: {
name: 'a-select',
vModel: 'value',
disabled: !editMode,
options: [{ value: 'timer', label: t('certd.schedule') }],
},
rules: [{ required: true, message: t('certd.requiredField') }],
}" />
<fs-form-item
v-model="currentTrigger.props.cron"
:item="{
title: t('certd.cronForm.title'),
key: 'props.cron',
component: {
disabled: !editMode,
name: 'cron-editor',
vModel: 'modelValue',
},
helper: t('certd.cronForm.helper'),
rules: [{ required: true, message: t('certd.cronForm.required') }],
}"
/>
</a-form>
<fs-form-item v-model="currentTrigger.props.cron" :item="{
title: t('certd.cronForm.title'),
key: 'props.cron',
component: {
disabled: !editMode,
name: 'cron-editor',
vModel: 'modelValue',
},
helper: t('certd.cronForm.helper'),
rules: [{ required: true, message: t('certd.cronForm.required') }],
}" />
</a-form>
<template #footer>
<a-form-item v-if="editMode" :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" @click="triggerSave"> 确定 </a-button>
</a-form-item>
</template>
</pi-container>
</template>
</a-drawer>
<template #footer>
<a-form-item v-if="editMode" :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" @click="triggerSave"> 确定 </a-button>
</a-form-item>
</template>
</pi-container>
</template>
</a-drawer>
</template>
<script>
import { message, Modal } from "ant-design-vue";
import { inject, ref } from "vue";
import * as _ from "lodash-es";
import { useI18n } from "/src/locales/";
import { nanoid } from "nanoid";
export default {
name: "PiTriggerForm",
props: {
editMode: {
type: Boolean,
default: true,
},
},
emits: ["update"],
setup(props, context) {
/**
* trigger drawer
* @returns
*/
function useTriggerForm() {
const mode = ref("add");
const callback = ref();
const currentTrigger = ref({ title: undefined, input: {} });
const currentPlugin = ref({});
const triggerFormRef = ref(null);
const triggerDrawerVisible = ref(false);
const rules = ref({
name: [
{
type: "string",
required: true,
message: t("certd.enterName"),
},
],
});
name: "PiTriggerForm",
props: {
editMode: {
type: Boolean,
default: true,
},
},
emits: ["update"],
setup(props, context) {
/**
* trigger drawer
* @returns
*/
const { t } = useI18n();
function useTriggerForm() {
const mode = ref("add");
const callback = ref();
const currentTrigger = ref({ title: undefined, input: {} });
const currentPlugin = ref({});
const triggerFormRef = ref(null);
const triggerDrawerVisible = ref(false);
const rules = ref({
name: [
{
type: "string",
required: true,
message: t("certd.enterName"),
},
],
});
const triggerDrawerShow = () => {
triggerDrawerVisible.value = true;
};
const triggerDrawerClose = () => {
triggerDrawerVisible.value = false;
};
const triggerDrawerShow = () => {
triggerDrawerVisible.value = true;
};
const triggerDrawerClose = () => {
triggerDrawerVisible.value = false;
};
const triggerDrawerOnAfterVisibleChange = val => {
console.log("triggerDrawerOnAfterVisibleChange", val);
};
const triggerDrawerOnAfterVisibleChange = val => {
console.log("triggerDrawerOnAfterVisibleChange", val);
};
const triggerOpen = (trigger, emit) => {
callback.value = emit;
currentTrigger.value = _.cloneDeep(trigger);
console.log("currentTriggerOpen", currentTrigger.value);
triggerDrawerShow();
};
const triggerOpen = (trigger, emit) => {
callback.value = emit;
currentTrigger.value = _.cloneDeep(trigger);
console.log("currentTriggerOpen", currentTrigger.value);
triggerDrawerShow();
};
const triggerAdd = emit => {
mode.value = "add";
const trigger = { id: nanoid(), title: t("certd.timerTrigger"), type: "timer", props: {} };
triggerOpen(trigger, emit);
};
const triggerAdd = emit => {
mode.value = "add";
const trigger = { id: nanoid(), title: t("certd.timerTrigger"), type: "timer", props: {} };
triggerOpen(trigger, emit);
};
const triggerEdit = (trigger, emit) => {
mode.value = "edit";
triggerOpen(trigger, emit);
};
const triggerView = (trigger, emit) => {
mode.value = "view";
triggerOpen(trigger, emit);
};
const triggerEdit = (trigger, emit) => {
mode.value = "edit";
triggerOpen(trigger, emit);
};
const triggerSave = async e => {
console.log("currentTriggerSave", currentTrigger.value);
try {
await triggerFormRef.value.validate();
} catch (e) {
console.error("表单验证失败:", e);
return;
}
const triggerView = (trigger, emit) => {
mode.value = "view";
triggerOpen(trigger, emit);
};
callback.value("save", currentTrigger.value);
triggerDrawerClose();
};
const triggerSave = async e => {
console.log("currentTriggerSave", currentTrigger.value);
try {
await triggerFormRef.value.validate();
} catch (e) {
console.error("表单验证失败:", e);
return;
}
const triggerDelete = () => {
Modal.confirm({
title: t("certd.confirm"),
content: t("certd.confirmDeleteTrigger"),
async onOk() {
callback.value("delete");
triggerDrawerClose();
},
});
};
callback.value("save", currentTrigger.value);
triggerDrawerClose();
};
const blankFn = () => {
return {};
};
return {
triggerFormRef,
mode,
triggerAdd,
triggerEdit,
triggerView,
triggerDrawerShow,
triggerDrawerVisible,
triggerDrawerOnAfterVisibleChange,
currentTrigger,
currentPlugin,
triggerSave,
triggerDelete,
rules,
blankFn,
};
}
const triggerDelete = () => {
Modal.confirm({
title: t("certd.confirm"),
content: t("certd.confirmDeleteTrigger"),
async onOk() {
callback.value("delete");
triggerDrawerClose();
},
});
};
const blankFn = () => {
return {};
};
return {
triggerFormRef,
mode,
triggerAdd,
triggerEdit,
triggerView,
triggerDrawerShow,
triggerDrawerVisible,
triggerDrawerOnAfterVisibleChange,
currentTrigger,
currentPlugin,
triggerSave,
triggerDelete,
rules,
blankFn,
};
}
return {
...useTriggerForm(),
labelCol: { span: 6 },
wrapperCol: { span: 16 },
};
},
return {
...useTriggerForm(),
labelCol: { span: 6 },
wrapperCol: { span: 16 },
};
},
};
</script>
<style lang="less">
.pi-trigger-form {}
.pi-trigger-form {
}
</style>
@@ -1,96 +1,86 @@
<template>
<div class="main login-page">
<a-form v-if="!twoFactor.loginId" ref="formRef" class="user-layout-login" name="custom-validation"
:model="formState" v-bind="layout" @finish="handleFinish" @finish-failed="handleFinishFailed">
<!-- <div class="login-title">登录</div>-->
<a-tabs v-model:active-key="formState.loginType"
:tab-bar-style="{ textAlign: 'center', borderBottom: 'unset' }">
<a-tab-pane key="password" :tab="$t('authentication.passwordTab')"
:disabled="sysPublicSettings.passwordLoginEnabled !== true">
<template v-if="formState.loginType === 'password'">
<!-- <div class="login-title">登录</div>-->
<a-form-item required has-feedback name="username" :rules="rules.username">
<a-input v-model:value="formState.username"
:placeholder="$t('authentication.usernamePlaceholder')" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:phone-portrait-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
<a-form-item has-feedback name="password" :rules="rules.password">
<a-input-password v-model:value="formState.password"
:placeholder="$t('authentication.passwordPlaceholder')" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input-password>
</a-form-item>
</template>
</a-tab-pane>
<a-tab-pane key="sms" :tab="$t('authentication.smsTab')"
:disabled="sysPublicSettings.smsLoginEnabled !== true">
<template v-if="formState.loginType === 'sms'">
<a-form-item has-feedback name="mobile" :rules="rules.mobile">
<a-input v-model:value="formState.mobile"
:placeholder="$t('authentication.mobilePlaceholder')" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:phone-portrait-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
<div class="main login-page">
<a-form v-if="!twoFactor.loginId" ref="formRef" class="user-layout-login" name="custom-validation" :model="formState" v-bind="layout" @finish="handleFinish" @finish-failed="handleFinishFailed">
<!-- <div class="login-title">登录</div>-->
<a-tabs v-model:active-key="formState.loginType" :tab-bar-style="{ textAlign: 'center', borderBottom: 'unset' }">
<a-tab-pane key="password" :tab="t('authentication.passwordTab')" :disabled="sysPublicSettings.passwordLoginEnabled !== true">
<template v-if="formState.loginType === 'password'">
<!-- <div class="login-title">登录</div>-->
<a-form-item required has-feedback name="username" :rules="rules.username">
<a-input v-model:value="formState.username" :placeholder="t('authentication.usernamePlaceholder')" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:phone-portrait-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
<a-form-item has-feedback name="password" :rules="rules.password">
<a-input-password v-model:value="formState.password" :placeholder="t('authentication.passwordPlaceholder')" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input-password>
</a-form-item>
</template>
</a-tab-pane>
<a-tab-pane v-if="sysPublicSettings.smsLoginEnabled === true" key="sms" :tab="t('authentication.smsTab')">
<template v-if="formState.loginType === 'sms'">
<a-form-item has-feedback name="mobile" :rules="rules.mobile">
<a-input v-model:value="formState.mobile" :placeholder="t('authentication.mobilePlaceholder')" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:phone-portrait-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
<a-form-item has-feedback name="imgCode">
<image-code v-model:value="formState.imgCode"
v-model:random-str="formState.randomStr"></image-code>
</a-form-item>
<a-form-item has-feedback name="imgCode">
<image-code v-model:value="formState.imgCode" v-model:random-str="formState.randomStr"></image-code>
</a-form-item>
<a-form-item name="smsCode" :rules="rules.smsCode">
<sms-code v-model:value="formState.smsCode" :img-code="formState.imgCode"
:mobile="formState.mobile" :phone-code="formState.phoneCode"
:random-str="formState.randomStr" />
</a-form-item>
</template>
</a-tab-pane>
</a-tabs>
<a-form-item>
<a-button type="primary" size="large" html-type="submit" :loading="loading" class="login-button">
{{ $t('authentication.loginButton') }}
</a-button>
<a-form-item name="smsCode" :rules="rules.smsCode">
<sms-code v-model:value="formState.smsCode" :img-code="formState.imgCode" :mobile="formState.mobile" :phone-code="formState.phoneCode" :random-str="formState.randomStr" />
</a-form-item>
</template>
</a-tab-pane>
</a-tabs>
<a-form-item>
<a-button type="primary" size="large" html-type="submit" :loading="loading" class="login-button">
{{ t("authentication.loginButton") }}
</a-button>
<div v-if="!settingStore.isComm" class="mt-2">
<a href="https://certd.docmirror.cn/guide/use/forgotpasswd/" target="_blank">
{{ $t('authentication.forgotAdminPassword') }}
</a>
</div>
</a-form-item>
<div v-if="!settingStore.isComm" class="mt-2">
<a href="https://certd.docmirror.cn/guide/use/forgotpasswd/" target="_blank">
{{ t("authentication.forgotAdminPassword") }}
</a>
</div>
</a-form-item>
<a-form-item class="user-login-other">
<router-link v-if="hasRegisterTypeEnabled()" class="register" :to="{ name: 'register' }">
{{ $t('authentication.registerLink') }}
</router-link>
</a-form-item>
<a-form-item class="user-login-other">
<div class="flex flex-between justify-between items-center">
<language-toggle class="color-blue"></language-toggle>
<router-link v-if="hasRegisterTypeEnabled()" class="register" :to="{ name: 'register' }">
{{ t("authentication.registerLink") }}
</router-link>
</div>
</a-form-item>
</a-form>
<a-form v-else ref="twoFactorFormRef" class="user-layout-login" :model="twoFactor" v-bind="layout">
<div class="mb-10 flex flex-center">请打开您的Authenticator APP获取动态验证码</div>
<a-form-item name="verifyCode">
<a-input ref="verifyCodeInputRef" v-model:value="twoFactor.verifyCode" placeholder="请输入动态验证码" allow-clear @keydown.enter="handleTwoFactorSubmit">
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
<a-form-item>
<loading-button type="primary" size="large" html-type="button" class="login-button" :click="handleTwoFactorSubmit">OTP验证登录</loading-button>
</a-form-item>
</a-form>
<a-form v-else ref="twoFactorFormRef" class="user-layout-login" :model="twoFactor" v-bind="layout">
<div class="mb-10 flex flex-center">请打开您的Authenticator APP获取动态验证码</div>
<a-form-item name="verifyCode">
<a-input ref="verifyCodeInputRef" v-model:value="twoFactor.verifyCode" placeholder="请输入动态验证码"
allow-clear @keydown.enter="handleTwoFactorSubmit">
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
<a-form-item>
<loading-button type="primary" size="large" html-type="button" class="login-button"
:click="handleTwoFactorSubmit">OTP验证登录</loading-button>
</a-form-item>
<a-form-item class="user-login-other">
<a class="register" @click="twoFactor.loginId = null"> 返回 </a>
</a-form-item>
</a-form>
</div>
<a-form-item class="user-login-other">
<a class="register" @click="twoFactor.loginId = null"> 返回 </a>
</a-form-item>
</a-form>
</div>
</template>
<script lang="ts">
import { defineComponent, nextTick, reactive, ref, toRaw } from "vue";
@@ -99,126 +89,130 @@ import { useSettingStore } from "/@/store/settings";
import { utils } from "@fast-crud/fast-crud";
import ImageCode from "/@/views/framework/login/image-code.vue";
import SmsCode from "/@/views/framework/login/sms-code.vue";
import { useI18n } from "/@/locales";
import { LanguageToggle } from "/@/vben/layouts";
export default defineComponent({
name: "LoginPage",
components: { SmsCode, ImageCode },
setup() {
const verifyCodeInputRef = ref();
const loading = ref(false);
const userStore = useUserStore();
const settingStore = useSettingStore();
const formRef = ref();
const formState = reactive({
username: "",
phoneCode: "86",
mobile: "",
password: "",
loginType: "password", //password
imgCode: "",
smsCode: "",
randomStr: "",
});
name: "LoginPage",
components: { LanguageToggle, SmsCode, ImageCode },
setup() {
const { t } = useI18n();
const verifyCodeInputRef = ref();
const loading = ref(false);
const userStore = useUserStore();
const settingStore = useSettingStore();
const formRef = ref();
const formState = reactive({
username: "",
phoneCode: "86",
mobile: "",
password: "",
loginType: "password", //password
imgCode: "",
smsCode: "",
randomStr: "",
});
const rules = {
mobile: [
{
required: true,
message: "请输入手机号",
},
],
username: [
{
required: true,
message: "请输入用户名",
},
],
password: [
{
required: true,
message: "请输入登录密码",
},
],
smsCode: [
{
required: true,
message: "请输入短信验证码",
},
],
};
const layout = {
labelCol: {
span: 0,
},
wrapperCol: {
span: 24,
},
};
const rules = {
mobile: [
{
required: true,
message: "请输入手机号",
},
],
username: [
{
required: true,
message: "请输入用户名",
},
],
password: [
{
required: true,
message: "请输入登录密码",
},
],
smsCode: [
{
required: true,
message: "请输入短信验证码",
},
],
};
const layout = {
labelCol: {
span: 0,
},
wrapperCol: {
span: 24,
},
};
const twoFactor = reactive({
loginId: "",
verifyCode: "",
});
const twoFactor = reactive({
loginId: "",
verifyCode: "",
});
const handleTwoFactorSubmit = async () => {
await userStore.loginByTwoFactor(twoFactor);
};
const handleTwoFactorSubmit = async () => {
await userStore.loginByTwoFactor(twoFactor);
};
const handleFinish = async (values: any) => {
loading.value = true;
try {
const loginType = formState.loginType;
await userStore.login(loginType, toRaw(formState));
} catch (e: any) {
//@ts-ignore
if (e.code === 10020) {
//双重认证
//@ts-ignore
twoFactor.loginId = e.data;
await nextTick();
verifyCodeInputRef.value.focus();
} else {
throw e;
}
} finally {
loading.value = false;
}
};
const handleFinish = async (values: any) => {
loading.value = true;
try {
const loginType = formState.loginType;
await userStore.login(loginType, toRaw(formState));
} catch (e: any) {
//@ts-ignore
if (e.code === 10020) {
//双重认证
//@ts-ignore
twoFactor.loginId = e.data;
await nextTick();
verifyCodeInputRef.value.focus();
} else {
throw e;
}
} finally {
loading.value = false;
}
};
const handleFinishFailed = (errors: any) => {
utils.logger.log(errors);
};
const handleFinishFailed = (errors: any) => {
utils.logger.log(errors);
};
const resetForm = () => {
formRef.value.resetFields();
};
const resetForm = () => {
formRef.value.resetFields();
};
const isLoginError = ref();
const isLoginError = ref();
const sysPublicSettings = settingStore.getSysPublic;
const sysPublicSettings = settingStore.getSysPublic;
function hasRegisterTypeEnabled() {
return sysPublicSettings.registerEnabled && (sysPublicSettings.usernameRegisterEnabled || sysPublicSettings.emailRegisterEnabled);
}
function hasRegisterTypeEnabled() {
return sysPublicSettings.registerEnabled && (sysPublicSettings.usernameRegisterEnabled || sysPublicSettings.emailRegisterEnabled);
}
return {
loading,
formState,
formRef,
rules,
layout,
handleFinishFailed,
handleFinish,
resetForm,
isLoginError,
sysPublicSettings,
hasRegisterTypeEnabled,
twoFactor,
handleTwoFactorSubmit,
verifyCodeInputRef,
settingStore,
};
},
return {
t,
loading,
formState,
formRef,
rules,
layout,
handleFinishFailed,
handleFinish,
resetForm,
isLoginError,
sysPublicSettings,
hasRegisterTypeEnabled,
twoFactor,
handleTwoFactorSubmit,
verifyCodeInputRef,
settingStore,
};
},
});
</script>
@@ -226,83 +220,83 @@ export default defineComponent({
@import "../../../style/theme/index.less";
.login-page.main {
//margin: 20px !important;
margin-bottom: 100px;
//margin: 20px !important;
margin-bottom: 100px;
.user-layout-login {
//label {
// font-size: 14px;
//}
.user-layout-login {
//label {
// font-size: 14px;
//}
.login-title {
color: @primary-color;
font-size: 18px;
text-align: center;
margin: 20px;
}
.login-title {
color: @primary-color;
font-size: 18px;
text-align: center;
margin: 20px;
}
.getCaptcha {
display: block;
width: 100%;
}
.getCaptcha {
display: block;
width: 100%;
}
.image-code {
height: 34px;
}
.image-code {
height: 34px;
}
.input-right {
width: 160px;
margin-left: 10px;
}
.input-right {
width: 160px;
margin-left: 10px;
}
.forge-password {
font-size: 14px;
}
.forge-password {
font-size: 14px;
}
button.login-button {
padding: 0 15px;
font-size: 16px;
width: 100%;
}
button.login-button {
padding: 0 15px;
font-size: 16px;
width: 100%;
}
.user-login-other {
text-align: left;
margin-top: 30px;
margin-bottom: 30px;
//line-height: 22px;
.user-login-other {
text-align: left;
margin-top: 30px;
margin-bottom: 30px;
//line-height: 22px;
.item-icon {
font-size: 24px;
color: rgba(0, 0, 0, 0.2);
margin-left: 16px;
vertical-align: middle;
cursor: pointer;
transition: color 0.3s;
.item-icon {
font-size: 24px;
color: rgba(0, 0, 0, 0.2);
margin-left: 16px;
vertical-align: middle;
cursor: pointer;
transition: color 0.3s;
&:hover {
color: @primary-color;
}
}
&:hover {
color: @primary-color;
}
}
.register {
float: right;
}
}
.register {
float: right;
}
}
.fs-icon {
color: rgba(0, 0, 0, 0.45);
margin-right: 4px;
}
.fs-icon {
color: rgba(0, 0, 0, 0.45);
margin-right: 4px;
}
.ant-input-affix-wrapper {
line-height: 1.8 !important;
font-size: 14px !important;
.ant-input-affix-wrapper {
line-height: 1.8 !important;
font-size: 14px !important;
>* {
line-height: 1.8 !important;
font-size: 14px !important;
}
}
}
> * {
line-height: 1.8 !important;
font-size: 14px !important;
}
}
}
}
</style>