diff --git a/src/utils/appConnector.js b/src/utils/appConnector.js index 0cc7511..facd0e8 100644 --- a/src/utils/appConnector.js +++ b/src/utils/appConnector.js @@ -11,14 +11,26 @@ import { isAppConnected, getAppHeaderInfo, } from '@/utils/appConnectionManager.js' +import { useRouter } from 'vue-router' +const router = useRouter() + +/** + * 默认的连接失败处理函数 + * @param {Error} error - 错误对象 + */ +const defaultOnFailed = (error) => { + if (error.message && error.message.includes('parse access')) { + router.push({ path: '/not_app', query: { message: error.message } }) + } +} /** * 统一的APP连接工具函数 * @param {Function} onConnected - 连接成功回调 - * @param {Function} onFailed - 连接失败回调 + * @param {Function} onFailed - 连接失败回调(可选,默认使用通用处理) * @returns {Promise} 连接结果 */ -export const connectToApp = async (onConnected, onFailed) => { +export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => { console.group('🔗 APP Connection Process') console.debug('🚀 Starting APP connection...') diff --git a/src/views/Invitation/InvitationToRegister.vue b/src/views/Invitation/InvitationToRegister.vue index 12fc5b4..4873a87 100644 --- a/src/views/Invitation/InvitationToRegister.vue +++ b/src/views/Invitation/InvitationToRegister.vue @@ -601,18 +601,10 @@ const initData = () => { // 使用工具函数连接APP const connectToAppHandler = async () => { - await connectToApp( - () => { - // 连接成功回调 - initData() - }, - (error) => { - // 连接失败回调 - if (error.message && error.message.includes('parse access')) { - router.push({ path: '/not_app', query: { message: error.message } }) - } - } - ) + await connectToApp(() => { + // 连接成功回调 + initData() + }) } onMounted(() => {