From a8e961caf4458056f7da5e6ea5f96ba235face76 Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Sun, 31 Mar 2024 16:16:15 +0800 Subject: [PATCH] feat: UI: move account releated code to header.vue (#84) --- frontend/src/api/index.js | 18 ++-- frontend/src/store/index.js | 3 + frontend/src/views/Content.vue | 121 +---------------------- frontend/src/views/Header.vue | 167 ++++++++++++++++++++++++++++---- frontend/src/views/Settings.vue | 6 +- 5 files changed, 168 insertions(+), 147 deletions(-) diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index abc94d7f..91e5bdec 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -63,14 +63,18 @@ const getOpenSettings = async (message) => { } const getSettings = async () => { - if (typeof jwt.value != 'string' || jwt.value.trim() === '' || jwt.value === 'undefined') { - return ""; + try { + if (typeof jwt.value != 'string' || jwt.value.trim() === '' || jwt.value === 'undefined') { + return ""; + } + const res = await apiFetch("/api/settings");; + settings.value = { + address: res["address"], + auto_reply: res["auto_reply"] + }; + } finally { + settings.value.fetched = true; } - const res = await apiFetch("/api/settings");; - settings.value = { - address: res["address"], - auto_reply: res["auto_reply"] - }; } const adminShowPassword = async (id) => { diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 110a9947..a12253c3 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -13,6 +13,7 @@ export const useGlobalState = createGlobalState( }] }) const settings = ref({ + fetched: false, address: '', auto_reply: { subject: '', @@ -29,6 +30,7 @@ export const useGlobalState = createGlobalState( const jwt = useStorage('jwt', ''); const localeCache = useStorage('locale', 'zhCN'); const themeSwitch = useStorage('themeSwitch', false); + const showLogin = ref(false); return { loading, settings, @@ -40,6 +42,7 @@ export const useGlobalState = createGlobalState( themeSwitch, adminAuth, showAdminAuth, + showLogin, } }, ) diff --git a/frontend/src/views/Content.vue b/frontend/src/views/Content.vue index 336fd087..2ea134f7 100644 --- a/frontend/src/views/Content.vue +++ b/frontend/src/views/Content.vue @@ -12,18 +12,13 @@ import { api } from '../api' import { CloudDownloadRound } from '@vicons/material' import { useIsMobile } from '../utils/composables' -const { toClipboard } = useClipboard() const message = useMessage() const isMobile = useIsMobile() -const { jwt, settings, openSettings, themeSwitch } = useGlobalState() +const { settings, themeSwitch } = useGlobalState() const autoRefresh = ref(false) const data = ref([]) const timer = ref(null) -const showPassword = ref(false) -const showNewEmail = ref(false) -const emailName = ref("") -const emailDomain = ref("") const count = ref(0) const page = ref(1) @@ -31,41 +26,20 @@ const pageSize = ref(20) const showAttachments = ref(false) const curAttachments = ref([]) +const curMail = ref(null); const { t } = useI18n({ locale: 'zh', messages: { en: { - yourAddress: 'Your email address is', - pleaseGetNewEmail: 'Please click "Get New Email" button to get a new email address', - getNewEmail: 'Get New Email', - getNewEmailTip1: 'Please input the email you want to use.', - getNewEmailTip2: 'Levaing it blank will generate a random email address.', - cancel: 'Cancel', - ok: 'OK', - copy: 'Copy', - showPassword: 'Show Password', autoRefresh: 'Auto Refresh', refresh: 'Refresh', - password: 'Password', - passwordTip: 'Please copy the password and you can use it to login to your email account.', attachments: 'Show Attachments', pleaseSelectMail: "Please select a mail to view." }, zh: { - yourAddress: '你的邮箱地址是', - pleaseGetNewEmail: '请点击 "获取新邮箱" 按钮来获取一个新的邮箱地址', - getNewEmail: '获取新邮箱', - getNewEmailTip1: '请输入你想要使用的邮箱地址。', - getNewEmailTip2: '留空将会生成一个随机的邮箱地址。', - cancel: '取消', - ok: '确定', - copy: '复制', - showPassword: '显示密码', autoRefresh: '自动刷新', refresh: '刷新', - password: '密码', - passwordTip: '请复制密码,你可以使用它登录你的邮箱。', attachments: '查看附件', pleaseSelectMail: "请选择一封邮件查看。" } @@ -116,33 +90,6 @@ const refresh = async () => { } }; -const copy = async () => { - try { - await toClipboard(settings.value.address) - message.success('Copied'); - } catch (e) { - message.error(e.message || "error"); - } -} - -const newEmail = async () => { - try { - const res = await api.fetch( - `/api/new_address` - + `?name=${emailName.value || ''}` - + `&domain=${emailDomain.value || ''}` - ); - jwt.value = res["jwt"]; - await api.getSettings(); - await refresh(); - showNewEmail.value = false; - showPassword.value = true; - } catch (error) { - message.error(error.message || "error"); - } -}; - -const curMail = ref(null); const clickRow = async (row) => { curMail.value = row; }; @@ -173,8 +120,6 @@ const getAttachments = async (attachment_id) => { }; onMounted(async () => { - await api.getOpenSettings(message); - emailDomain.value = openSettings.value.domains ? openSettings.value.domains[0].value : ""; await api.getSettings(); await refresh(); }); @@ -182,24 +127,7 @@ onMounted(async () => {