feat: support admin create address && add ENABLE_USER_CREATE_EMAIL config (#175)

This commit is contained in:
Dream Hunter
2024-04-29 00:09:53 +08:00
committed by GitHub
parent 6ce7e2e7f6
commit 23d1709ca1
16 changed files with 306 additions and 153 deletions

View File

@@ -277,7 +277,7 @@ onMounted(async () => {
<n-modal v-model:show="showDelteAccount" preset="dialog" :title="t('delteAccount')">
<p>{{ t('deleteTip') }}</p>
<template #action>
<n-button :loading="loading" @click="deleteEmail" size="small" tertiary round type="error">
<n-button :loading="loading" @click="deleteEmail" size="small" tertiary type="error">
{{ t('delteAccount') }}
</n-button>
</template>

View File

@@ -0,0 +1,117 @@
<script setup>
import { onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../../store'
import { api } from '../../api'
const {
localeCache, loading, openSettings,
} = useGlobalState()
const message = useMessage()
const { t } = useI18n({
locale: localeCache.value || 'zh',
messages: {
en: {
address: 'Address',
enablePrefix: 'If enable Prefix',
creatNewEmail: 'Get New Email',
fillInAllFields: 'Please fill in all fields',
successTip: 'Success Created',
password: 'Password',
},
zh: {
address: '地址',
enablePrefix: '是否启用前缀',
creatNewEmail: '创建新邮箱',
fillInAllFields: '请填写完整信息',
successTip: '创建成功',
password: '密码',
}
}
});
const enablePrefix = ref(true)
const emailName = ref("")
const emailDomain = ref("")
const showReultModal = ref(false)
const result = ref("")
const newEmail = async () => {
if (!emailName.value || !emailDomain.value) {
message.error(t('fillInAllFields'))
return
}
try {
const res = await api.fetch(`/admin/new_address`, {
method: 'POST',
body: JSON.stringify({
enablePrefix: enablePrefix.value,
name: emailName.value,
domain: emailDomain.value,
})
})
result.value = res["jwt"];
message.success(t('successTip'))
showReultModal.value = true
} catch (error) {
message.error(error.message || "error");
}
}
onMounted(async () => {
if (openSettings.prefix) {
enablePrefix.value = true
}
emailDomain.value = openSettings.value.domains?.[0]?.value || ""
})
</script>
<template>
<div class="center">
<n-modal v-model:show="showReultModal" preset="dialog" :title="t('password')">
<p>{{ t('password') }}</p>
<n-card>
<b>{{ result }}</b>
</n-card>
</n-modal>
<n-card style="max-width: 600px;">
<n-form-item-row v-if="openSettings.prefix" :label="t('enablePrefix')">
<n-checkbox v-model:checked="enablePrefix" />
</n-form-item-row>
<n-form-item-row :label="t('address')">
<n-input-group>
<n-input-group-label v-if="enablePrefix && openSettings.prefix">
{{ openSettings.prefix }}
</n-input-group-label>
<n-input v-model:value="emailName" />
<n-input-group-label>@</n-input-group-label>
<n-select v-model:value="emailDomain" :consistent-menu-width="false"
:options="openSettings.domains" />
</n-input-group>
</n-form-item-row>
<div class="right">
<n-button @click="newEmail" type="primary" :loading="loading">
{{ t('creatNewEmail') }}
</n-button>
</div>
</n-card>
</div>
</template>
<style scoped>
.center {
display: flex;
text-align: left;
place-items: center;
justify-content: center;
margin: 20px;
}
.right {
text-align: right;
place-items: right;
justify-content: right;
}
</style>

View File

@@ -163,7 +163,7 @@ onMounted(async () => {
<n-input-number v-model:value="senderBalance" :min="0" :max="1000" />
</n-form-item>
<template #action>
<n-button :loading="loading" @click="updateData()" size="small" tertiary round type="primary">
<n-button :loading="loading" @click="updateData()" size="small" tertiary type="primary">
{{ t('ok') }}
</n-button>
</template>