feat(新工具类): 优化重新获取请求头的工具类
This commit is contained in:
parent
1f00654a14
commit
510d527531
@ -11,14 +11,26 @@ import {
|
|||||||
isAppConnected,
|
isAppConnected,
|
||||||
getAppHeaderInfo,
|
getAppHeaderInfo,
|
||||||
} from '@/utils/appConnectionManager.js'
|
} 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连接工具函数
|
* 统一的APP连接工具函数
|
||||||
* @param {Function} onConnected - 连接成功回调
|
* @param {Function} onConnected - 连接成功回调
|
||||||
* @param {Function} onFailed - 连接失败回调
|
* @param {Function} onFailed - 连接失败回调(可选,默认使用通用处理)
|
||||||
* @returns {Promise<Object>} 连接结果
|
* @returns {Promise<Object>} 连接结果
|
||||||
*/
|
*/
|
||||||
export const connectToApp = async (onConnected, onFailed) => {
|
export const connectToApp = async (onConnected, onFailed = defaultOnFailed) => {
|
||||||
console.group('🔗 APP Connection Process')
|
console.group('🔗 APP Connection Process')
|
||||||
console.debug('🚀 Starting APP connection...')
|
console.debug('🚀 Starting APP connection...')
|
||||||
|
|
||||||
|
|||||||
@ -601,18 +601,10 @@ const initData = () => {
|
|||||||
|
|
||||||
// 使用工具函数连接APP
|
// 使用工具函数连接APP
|
||||||
const connectToAppHandler = async () => {
|
const connectToAppHandler = async () => {
|
||||||
await connectToApp(
|
await connectToApp(() => {
|
||||||
() => {
|
// 连接成功回调
|
||||||
// 连接成功回调
|
initData()
|
||||||
initData()
|
})
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
// 连接失败回调
|
|
||||||
if (error.message && error.message.includes('parse access')) {
|
|
||||||
router.push({ path: '/not_app', query: { message: error.message } })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user