feat(新工具类): 优化重新获取请求头的工具类

This commit is contained in:
hzj 2025-11-03 14:25:04 +08:00
parent 1f00654a14
commit 510d527531
2 changed files with 18 additions and 14 deletions

View File

@ -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<Object>} 连接结果
*/
export const connectToApp = async (onConnected, onFailed) => {
export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
console.group('🔗 APP Connection Process')
console.debug('🚀 Starting APP connection...')

View File

@ -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(() => {