mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-09 03:13:09 +02:00
Refactor admin/email-settings to use Composition API (#8656)
* refactor(client): refactor admin/email-settings to use Composition API * Update packages/client/src/pages/admin/email-settings.vue Co-authored-by: Johann150 <johann@qwertqwefsday.eu> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp> Co-authored-by: Johann150 <johann@qwertqwefsday.eu>
This commit is contained in:
parent
577f63c4f4
commit
3f9b7e8b1d
1 changed files with 73 additions and 88 deletions
|
@ -3,37 +3,37 @@
|
||||||
<FormSuspense :p="init">
|
<FormSuspense :p="init">
|
||||||
<div class="_formRoot">
|
<div class="_formRoot">
|
||||||
<FormSwitch v-model="enableEmail" class="_formBlock">
|
<FormSwitch v-model="enableEmail" class="_formBlock">
|
||||||
<template #label>{{ $ts.enableEmail }}</template>
|
<template #label>{{ i18n.ts.enableEmail }}</template>
|
||||||
<template #caption>{{ $ts.emailConfigInfo }}</template>
|
<template #caption>{{ i18n.ts.emailConfigInfo }}</template>
|
||||||
</FormSwitch>
|
</FormSwitch>
|
||||||
|
|
||||||
<template v-if="enableEmail">
|
<template v-if="enableEmail">
|
||||||
<FormInput v-model="email" type="email" class="_formBlock">
|
<FormInput v-model="email" type="email" class="_formBlock">
|
||||||
<template #label>{{ $ts.emailAddress }}</template>
|
<template #label>{{ i18n.ts.emailAddress }}</template>
|
||||||
</FormInput>
|
</FormInput>
|
||||||
|
|
||||||
<FormSection>
|
<FormSection>
|
||||||
<template #label>{{ $ts.smtpConfig }}</template>
|
<template #label>{{ i18n.ts.smtpConfig }}</template>
|
||||||
<FormSplit :min-width="280">
|
<FormSplit :min-width="280">
|
||||||
<FormInput v-model="smtpHost" class="_formBlock">
|
<FormInput v-model="smtpHost" class="_formBlock">
|
||||||
<template #label>{{ $ts.smtpHost }}</template>
|
<template #label>{{ i18n.ts.smtpHost }}</template>
|
||||||
</FormInput>
|
</FormInput>
|
||||||
<FormInput v-model="smtpPort" type="number" class="_formBlock">
|
<FormInput v-model="smtpPort" type="number" class="_formBlock">
|
||||||
<template #label>{{ $ts.smtpPort }}</template>
|
<template #label>{{ i18n.ts.smtpPort }}</template>
|
||||||
</FormInput>
|
</FormInput>
|
||||||
</FormSplit>
|
</FormSplit>
|
||||||
<FormSplit :min-width="280">
|
<FormSplit :min-width="280">
|
||||||
<FormInput v-model="smtpUser" class="_formBlock">
|
<FormInput v-model="smtpUser" class="_formBlock">
|
||||||
<template #label>{{ $ts.smtpUser }}</template>
|
<template #label>{{ i18n.ts.smtpUser }}</template>
|
||||||
</FormInput>
|
</FormInput>
|
||||||
<FormInput v-model="smtpPass" type="password" class="_formBlock">
|
<FormInput v-model="smtpPass" type="password" class="_formBlock">
|
||||||
<template #label>{{ $ts.smtpPass }}</template>
|
<template #label>{{ i18n.ts.smtpPass }}</template>
|
||||||
</FormInput>
|
</FormInput>
|
||||||
</FormSplit>
|
</FormSplit>
|
||||||
<FormInfo class="_formBlock">{{ $ts.emptyToDisableSmtpAuth }}</FormInfo>
|
<FormInfo class="_formBlock">{{ i18n.ts.emptyToDisableSmtpAuth }}</FormInfo>
|
||||||
<FormSwitch v-model="smtpSecure" class="_formBlock">
|
<FormSwitch v-model="smtpSecure" class="_formBlock">
|
||||||
<template #label>{{ $ts.smtpSecure }}</template>
|
<template #label>{{ i18n.ts.smtpSecure }}</template>
|
||||||
<template #caption>{{ $ts.smtpSecureInfo }}</template>
|
<template #caption>{{ i18n.ts.smtpSecureInfo }}</template>
|
||||||
</FormSwitch>
|
</FormSwitch>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
</template>
|
</template>
|
||||||
|
@ -42,8 +42,8 @@
|
||||||
</MkSpacer>
|
</MkSpacer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from 'vue';
|
import { } from 'vue';
|
||||||
import FormSwitch from '@/components/form/switch.vue';
|
import FormSwitch from '@/components/form/switch.vue';
|
||||||
import FormInput from '@/components/form/input.vue';
|
import FormInput from '@/components/form/input.vue';
|
||||||
import FormInfo from '@/components/ui/info.vue';
|
import FormInfo from '@/components/ui/info.vue';
|
||||||
|
@ -52,86 +52,71 @@ import FormSplit from '@/components/form/split.vue';
|
||||||
import FormSection from '@/components/form/section.vue';
|
import FormSection from '@/components/form/section.vue';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import * as symbols from '@/symbols';
|
import * as symbols from '@/symbols';
|
||||||
import { fetchInstance } from '@/instance';
|
import { fetchInstance, instance } from '@/instance';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
export default defineComponent({
|
let enableEmail: boolean = $ref(false);
|
||||||
components: {
|
let email: any = $ref(null);
|
||||||
FormSwitch,
|
let smtpSecure: boolean = $ref(false);
|
||||||
FormInput,
|
let smtpHost: string = $ref('');
|
||||||
FormSplit,
|
let smtpPort: number = $ref(0);
|
||||||
FormSection,
|
let smtpUser: string = $ref('');
|
||||||
FormInfo,
|
let smtpPass: string = $ref('');
|
||||||
FormSuspense,
|
|
||||||
},
|
|
||||||
|
|
||||||
emits: ['info'],
|
async function init() {
|
||||||
|
const meta = await os.api('admin/meta');
|
||||||
|
enableEmail = meta.enableEmail;
|
||||||
|
email = meta.email;
|
||||||
|
smtpSecure = meta.smtpSecure;
|
||||||
|
smtpHost = meta.smtpHost;
|
||||||
|
smtpPort = meta.smtpPort;
|
||||||
|
smtpUser = meta.smtpUser;
|
||||||
|
smtpPass = meta.smtpPass;
|
||||||
|
}
|
||||||
|
|
||||||
data() {
|
async function testEmail() {
|
||||||
return {
|
const { canceled, result: destination } = await os.inputText({
|
||||||
[symbols.PAGE_INFO]: {
|
title: i18n.ts.destination,
|
||||||
title: this.$ts.emailServer,
|
type: 'email',
|
||||||
icon: 'fas fa-envelope',
|
placeholder: instance.maintainerEmail
|
||||||
bg: 'var(--bg)',
|
});
|
||||||
actions: [{
|
if (canceled) return;
|
||||||
asFullButton: true,
|
os.apiWithDialog('admin/send-email', {
|
||||||
text: this.$ts.testEmail,
|
to: destination,
|
||||||
handler: this.testEmail,
|
subject: 'Test email',
|
||||||
}, {
|
text: 'Yo'
|
||||||
asFullButton: true,
|
});
|
||||||
icon: 'fas fa-check',
|
}
|
||||||
text: this.$ts.save,
|
|
||||||
handler: this.save,
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
enableEmail: false,
|
|
||||||
email: null,
|
|
||||||
smtpSecure: false,
|
|
||||||
smtpHost: '',
|
|
||||||
smtpPort: 0,
|
|
||||||
smtpUser: '',
|
|
||||||
smtpPass: '',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
function save() {
|
||||||
async init() {
|
os.apiWithDialog('admin/update-meta', {
|
||||||
const meta = await os.api('admin/meta');
|
enableEmail,
|
||||||
this.enableEmail = meta.enableEmail;
|
email,
|
||||||
this.email = meta.email;
|
smtpSecure,
|
||||||
this.smtpSecure = meta.smtpSecure;
|
smtpHost,
|
||||||
this.smtpHost = meta.smtpHost;
|
smtpPort,
|
||||||
this.smtpPort = meta.smtpPort;
|
smtpUser,
|
||||||
this.smtpUser = meta.smtpUser;
|
smtpPass,
|
||||||
this.smtpPass = meta.smtpPass;
|
}).then(() => {
|
||||||
},
|
fetchInstance();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async testEmail() {
|
defineExpose({
|
||||||
const { canceled, result: destination } = await os.inputText({
|
[symbols.PAGE_INFO]: {
|
||||||
title: this.$ts.destination,
|
title: i18n.ts.emailServer,
|
||||||
type: 'email',
|
icon: 'fas fa-envelope',
|
||||||
placeholder: this.$instance.maintainerEmail
|
bg: 'var(--bg)',
|
||||||
});
|
actions: [{
|
||||||
if (canceled) return;
|
asFullButton: true,
|
||||||
os.apiWithDialog('admin/send-email', {
|
text: i18n.ts.testEmail,
|
||||||
to: destination,
|
handler: testEmail,
|
||||||
subject: 'Test email',
|
}, {
|
||||||
text: 'Yo'
|
asFullButton: true,
|
||||||
});
|
icon: 'fas fa-check',
|
||||||
},
|
text: i18n.ts.save,
|
||||||
|
handler: save,
|
||||||
save() {
|
}],
|
||||||
os.apiWithDialog('admin/update-meta', {
|
|
||||||
enableEmail: this.enableEmail,
|
|
||||||
email: this.email,
|
|
||||||
smtpSecure: this.smtpSecure,
|
|
||||||
smtpHost: this.smtpHost,
|
|
||||||
smtpPort: this.smtpPort,
|
|
||||||
smtpUser: this.smtpUser,
|
|
||||||
smtpPass: this.smtpPass,
|
|
||||||
}).then(() => {
|
|
||||||
fetchInstance();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue