From edea795c22c1410b5aa6ee03aa4c796d4c960b6f Mon Sep 17 00:00:00 2001 From: Hakadao Date: Fri, 17 Nov 2023 18:41:47 +0800 Subject: [PATCH] feat: update home settings --- src/components/Settings/components/Home.vue | 106 +++++++++++++------- 1 file changed, 70 insertions(+), 36 deletions(-) diff --git a/src/components/Settings/components/Home.vue b/src/components/Settings/components/Home.vue index a55242c1..90bdc506 100644 --- a/src/components/Settings/components/Home.vue +++ b/src/components/Settings/components/Home.vue @@ -10,10 +10,21 @@ const { t } = useI18n() const authorizeBtn = ref() as Ref const showSearchPageModeSharedSettings = ref(false) +const showQRCodeDialog = ref(false) const loginQRCodeUrl = ref() +const pollLoginQRCodeInterval = ref(null) +const authCode = ref('') const preventCloseSettings = inject('preventCloseSettings') as Ref +onDeactivated(() => { + clearInterval(pollLoginQRCodeInterval.value) +}) + +onBeforeUnmount(() => { + clearInterval(pollLoginQRCodeInterval.value) +}) + function handleAuthorize() { grantAccessKey(t, authorizeBtn.value) } @@ -22,44 +33,52 @@ function handleRevoke() { revokeAccessKey() } +async function handleOpenLoginQRCode() { + try { + await setLoginQRCode() + pollLoginQRCode() + } + catch (error) { + console.error(error) + } +} + async function setLoginQRCode() { const res = await getTVLoginQRCode() if (res.code === 0) { loginQRCodeUrl.value = res.data.url - - let isSuccess = false - setInterval(interval, 5000) - - async function interval() { - if (isSuccess) - return - - const pollRes = await pollTVLoginQRCode(res.data.auth_code) - - // 0:成功 - // -3:API校验密匙错误 - // -400:请求错误 - // -404:啥都木有 - // 86038:二维码已失效 - // 86039:二维码尚未确认 - // 86090:二维码已扫码未确认 - - if (pollRes.code === 0) { - isSuccess = true - accessKey.value = pollRes.data.access_token - console.log(pollRes.data, accessKey.value) - } - else if (pollRes.code === 86038) { - await setLoginQRCode() - } - else if (pollRes.code === -3 || pollRes.code === -400 || pollRes.code === -404) { - // eslint-disable-next-line no-alert - alert(pollRes.message) - } - } + authCode.value = res.data.auth_code } } +function pollLoginQRCode() { + clearInterval(pollLoginQRCodeInterval.value) + + pollLoginQRCodeInterval.value = setInterval(async () => { + const pollRes = await pollTVLoginQRCode(authCode.value) + + // 0:成功 + // -3:API校验密匙错误 + // -400:请求错误 + // -404:啥都木有 + // 86038:二维码已失效 + // 86039:二维码尚未确认 + // 86090:二维码已扫码未确认 + + if (pollRes.code === 0) { + accessKey.value = pollRes.data.access_token + clearInterval(pollLoginQRCodeInterval.value) + } + else if (pollRes.code === 86038) { + await setLoginQRCode() + } + else if (pollRes.code === -3 || pollRes.code === -400 || pollRes.code === -404) { + // eslint-disable-next-line no-alert + alert(pollRes.message) + } + }, 5000) +} + function handleOpenSearchPageModeSharedSettings() { showSearchPageModeSharedSettings.value = true preventCloseSettings.value = true @@ -115,7 +134,7 @@ function handleCloseSearchPageModeSharedSettings() {
-
- - - - + + + +
+
+ +
+
+ +
+
+
+