From 9d86e82907fbc1d4a8c764e006e5ab56a424b625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=B2=AB=E8=8A=B1=E7=81=ABzzz=F0=9F=8C=99?= Date: Sat, 7 Sep 2024 08:54:53 +0800 Subject: [PATCH] Fix RealName pay request --- src/App.vue | 18 +++++++++--------- src/api/base.ts | 2 -- src/api/v2/realperson/pay.ts | 5 +++-- src/router/index.js | 36 +++++++++++++----------------------- src/utils/clipboard.js | 2 +- src/views/Login.vue | 2 +- src/views/RealName.vue | 3 ++- 7 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/App.vue b/src/App.vue index 04029e8..6cff0f8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -37,10 +37,10 @@ import hljs from 'highlight.js/lib/core' import ini from 'highlight.js/lib/languages/ini' import nginx from 'highlight.js/lib/languages/nginx' import api from '@/api' -import { sendWarningMessage, sendErrorMessage } from '@/utils/message' +import { sendWarningMessage } from '@/utils/message' import { logout } from '@/utils/profile' // import { init_ws, SetOnMessageFunction } from "@/utils/websocket.js"; -import { sendInfoNotification } from '@/utils/notification' +// import { sendInfoNotification } from '@/utils/notification' const osThemeRef = useOsTheme() const theme = computed(() => (osThemeRef.value === 'dark' ? darkTheme : null)) @@ -49,13 +49,13 @@ let inited = false hljs.registerLanguage('ini', ini) hljs.registerLanguage('nginx', nginx) -function getMessage(e) { - const rs = JSON.parse(e.data) - // 通知 - if (rs.type === 'notice') { - sendInfoNotification(rs.message) - } -} +// function getMessage(e) { +// const rs = JSON.parse(e.data) +// // 通知 +// if (rs.type === 'notice') { +// sendInfoNotification(rs.message) +// } +// } // 初始化websocket if (inited === false) { diff --git a/src/api/base.ts b/src/api/base.ts index b345cf1..475ec6c 100644 --- a/src/api/base.ts +++ b/src/api/base.ts @@ -1,5 +1,3 @@ -import logger from '@/utils/logger' - const base = { api_v1_url: 'https://api.locyanfrp.cn', api_v2_url: 'https://api-v2.locyanfrp.cn/api/v2', diff --git a/src/api/v2/realperson/pay.ts b/src/api/v2/realperson/pay.ts index c2dd1bf..0656a0a 100644 --- a/src/api/v2/realperson/pay.ts +++ b/src/api/v2/realperson/pay.ts @@ -2,10 +2,11 @@ import base from '@/api/base' //@ts-ignore import { get } from '@/utils/request' -const pay = async (username: string, notify_url: string) => { +const pay = async (username: string, notify_url: string, redirect_url: string) => { const rs = get(`${base.api_v2_url}/realperson/pay`, { username: username, - notify_url: notify_url + notify_url: notify_url, + redirect_url: redirect_url }) return base.buildResponse(await rs) } diff --git a/src/router/index.js b/src/router/index.js index 4040237..345fffd 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,6 +5,7 @@ import { changeMainSideBarShow } from '../components/MainNav.vue' import { changeShowGuestSideBar } from '../components/GuestNav.vue' import { setSideBarActiveKey } from '../components/MainSideBar.vue' import { setGuestSideBarActiveKey } from '../components/GuestSideBar.vue' +import logger from '@/utils/logger' const routes = [ { @@ -155,32 +156,21 @@ const router = createRouter({ routes }) -// 检查本地存储是否存在token,若存在则直接使用 -if (localStorage.getItem('token')) { - store.commit('set_token', localStorage.getItem('token')) -} +// // 检查本地存储是否存在token,若存在则直接使用 +// if (localStorage.getItem('token')) { +// store.commit('set_token', localStorage.getItem('token')) +// } + +// 检测到已登录之后自动跳转 /dashboard 的界面 +const _autoRedirectLogined = ['Login', 'Register', 'ResetPassword'] router.beforeEach((to, from, next) => { startLoadingBar() - if (to.name === 'Login') { - if (store.getters.get_token) { - next({ name: 'Dashboard' }) - } - next() - return - } - if (to.name === 'Register') { - if (store.getters.get_token) { - next({ name: 'Dashboard' }) - } - next() - return - } - if (to.name === 'ResetPassword') { - if (store.getters.get_token) { - next({ name: 'Dashboard' }) - } - next() + if (_autoRedirectLogined.includes(to.name)) { + const hasToken = store.getters.get_token != '' + logger.info(`Has token: ${hasToken}${hasToken ? ` ${store.getters.get_token}` : ''}`) + if (hasToken) next({ name: 'Dashboard' }) + else next() return } if (to.name === 'MainPage') { diff --git a/src/utils/clipboard.js b/src/utils/clipboard.js index dcf4579..d798abf 100644 --- a/src/utils/clipboard.js +++ b/src/utils/clipboard.js @@ -11,7 +11,7 @@ function clipboardError(msg) { } export default function handleClipboard(text, event, msg) { - logger.info('Writing clipboard: ' + text) + logger.info(`Writing clipboard [${event.target}]: ${text}`) const clipboard = new Clipboard(event.target, { text: () => text }) diff --git a/src/views/Login.vue b/src/views/Login.vue index 5c8e8ec..c74f04f 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -81,7 +81,7 @@ const model = ref([ // 检查是否存在redirect值 const redirect = getUrlKey('redirect') if (redirect !== null) { - logger.info('登录后返回' + redirect) + logger.info('Redirect after login: ' + redirect) } // 检查是否存在第三方登录返回值 diff --git a/src/views/RealName.vue b/src/views/RealName.vue index f5fb808..5d3d038 100644 --- a/src/views/RealName.vue +++ b/src/views/RealName.vue @@ -325,7 +325,8 @@ async function realPersonPay() { try { rs = await api.v2.realperson.pay( store.getters.get_username, - 'https://api-v2.locyanfrp.cn/api/v2/realperson/notify&redirect_url=https://dashboard.locyanfrp.cn/realname' + 'https://api-v2.locyanfrp.cn/api/v2/realperson/notify', + 'https://dashboard.locyanfrp.cn/realname' ) } catch (e) { sendErrorMessage('请求失败: ' + e)