feat(跳转app): 新增3个跳转方法
This commit is contained in:
parent
dbfcac8270
commit
53a73e6f26
@ -3,7 +3,7 @@
|
||||
* 用于H5页面与原生APP之间的通信
|
||||
*/
|
||||
|
||||
import {COMMON_HEADERS} from "@/utils/http.js";
|
||||
import { COMMON_HEADERS } from '@/utils/http.js'
|
||||
|
||||
/**
|
||||
* 检测是否为iOS系统
|
||||
@ -55,6 +55,39 @@ export function closePage() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 前往私聊
|
||||
*/
|
||||
export function gotoPrivateChat(userId) {
|
||||
try {
|
||||
window.FlutterPageControl.postMessage(`private_chat:${userId}`)
|
||||
} catch (error) {
|
||||
console.error('前往私聊失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看个人页面
|
||||
*/
|
||||
export function gotoUserInfo(userId) {
|
||||
try {
|
||||
window.FlutterPageControl.postMessage(`view_user_info:${userId}`)
|
||||
} catch (error) {
|
||||
console.error('查看个人页面失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 前往房间
|
||||
*/
|
||||
export function gotoRoom(roomId) {
|
||||
try {
|
||||
window.FlutterPageControl.postMessage(`go_to_room:${roomId}`)
|
||||
} catch (error) {
|
||||
console.error('前往房间失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出APP
|
||||
*/
|
||||
@ -110,14 +143,18 @@ export function connectApplication(renderFun) {
|
||||
|
||||
// 等待Flutter注入完成
|
||||
const waitForFlutterInterface = () => {
|
||||
let attempts = 0;
|
||||
const maxAttempts = 50; // 最多等待5秒
|
||||
let attempts = 0
|
||||
const maxAttempts = 50 // 最多等待5秒
|
||||
|
||||
const checkInterface = () => {
|
||||
attempts++;
|
||||
attempts++
|
||||
console.debug(`尝试第 ${attempts} 次检查Flutter接口...`)
|
||||
|
||||
if (window.app && window.app.getAccessOrigin && typeof window.app.getAccessOrigin === 'function') {
|
||||
if (
|
||||
window.app &&
|
||||
window.app.getAccessOrigin &&
|
||||
typeof window.app.getAccessOrigin === 'function'
|
||||
) {
|
||||
console.debug('Flutter接口检测成功,调用 getAccessOrigin')
|
||||
try {
|
||||
const result = window.app.getAccessOrigin()
|
||||
@ -133,10 +170,10 @@ export function connectApplication(renderFun) {
|
||||
console.error('Flutter接口注入超时,使用默认数据')
|
||||
// 使用默认的开发数据
|
||||
const mockAccess = JSON.stringify({
|
||||
'Authorization': 'Bearer FLUTTER_MOCK_TOKEN',
|
||||
Authorization: 'Bearer FLUTTER_MOCK_TOKEN',
|
||||
'Req-Lang': 'en',
|
||||
'Req-App-Intel': 'build=1.0;version=2.1;channel=flutter;Req-Imei=flutter-device',
|
||||
'Req-Sys-Origin': 'origin=LIKEI;originChild=LIKEI'
|
||||
'Req-Sys-Origin': 'origin=LIKEI;originChild=LIKEI',
|
||||
})
|
||||
renderFun(mockAccess)
|
||||
}
|
||||
@ -169,9 +206,8 @@ export function connectApplication(renderFun) {
|
||||
}
|
||||
checkApp()
|
||||
}
|
||||
}
|
||||
|
||||
/*else if (ios()) {
|
||||
} else {
|
||||
/*else if (ios()) {
|
||||
console.debug('ios access detected')
|
||||
// iOS可能需要特殊处理,这里先使用通用方法
|
||||
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.getAccessOrigin) {
|
||||
@ -180,18 +216,16 @@ export function connectApplication(renderFun) {
|
||||
renderFun(window.app.getAccessOrigin())
|
||||
}
|
||||
}*/
|
||||
|
||||
else {
|
||||
console.debug('非移动设备环境')
|
||||
// 非APP环境,可能是浏览器调试
|
||||
console.warn('Not in APP environment, using mock data for development')
|
||||
// 开发环境可以提供模拟数据
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
const mockAccess = JSON.stringify({
|
||||
'Authorization': COMMON_HEADERS.authorization,
|
||||
Authorization: COMMON_HEADERS.authorization,
|
||||
'Req-Lang': COMMON_HEADERS['req-lang'],
|
||||
'Req-App-Intel': COMMON_HEADERS['req-app-intel'],
|
||||
'Req-Sys-Origin': COMMON_HEADERS['req-sys-origin']
|
||||
'Req-Sys-Origin': COMMON_HEADERS['req-sys-origin'],
|
||||
})
|
||||
setTimeout(() => renderFun(mockAccess), 100)
|
||||
}
|
||||
@ -211,14 +245,14 @@ export function parseAccessOrigin(access) {
|
||||
const accessParam = JSON.parse(access)
|
||||
return {
|
||||
success: true,
|
||||
data: accessParam
|
||||
data: accessParam,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to parse access origin:', error)
|
||||
return {
|
||||
success: false,
|
||||
error: 'accessOrigin Error.',
|
||||
data: null
|
||||
data: null,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -266,7 +300,7 @@ export function parseHeader(head) {
|
||||
appChannel: reqAppIntelObj['channel'],
|
||||
reqImei: reqAppIntelObj['Req-Imei'],
|
||||
sysOrigin: reqSysOriginObj['origin'],
|
||||
sysOriginChild: reqSysOriginObj['child']
|
||||
sysOriginChild: reqSysOriginObj['child'],
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,13 +309,12 @@ export function parseHeader(head) {
|
||||
* @param {Object} headerInfo 解析后的头部信息
|
||||
*/
|
||||
export async function setHttpHeaders(headerInfo) {
|
||||
|
||||
try {
|
||||
const httpModule = await import('../utils/http.js')
|
||||
if (httpModule.setHeadersFromApp) {
|
||||
httpModule.setHeadersFromApp(headerInfo)
|
||||
}
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
console.error('Failed to update HTTP headers:', error)
|
||||
}
|
||||
|
||||
@ -291,6 +324,6 @@ export async function setHttpHeaders(headerInfo) {
|
||||
version: headerInfo.appVersion,
|
||||
build: headerInfo.buildVersion,
|
||||
channel: headerInfo.appChannel,
|
||||
system: headerInfo.sysOrigin
|
||||
system: headerInfo.sysOrigin,
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user