修复转发暂停问题 增加安卓apk

This commit is contained in:
qaq
2025-08-20 13:43:35 +08:00
parent 42d04da2a2
commit b1647ed309
82 changed files with 449473 additions and 291 deletions
+74 -3
View File
@@ -1,8 +1,63 @@
import axios, { AxiosResponse } from 'axios';
// 配置axios基础URL
const baseURL = import.meta.env.VITE_API_BASE ? `${import.meta.env.VITE_API_BASE}/api/v1/` : '/api/v1/';
axios.defaults.baseURL = baseURL;
// 检测是否在WebView中运行
const isWebView = (): boolean => {
try {
if (typeof (window as any).AndroidInterface !== 'undefined') {
const result = (window as any).AndroidInterface.isWebView();
return result === "true";
}
return false;
} catch (error) {
return false;
}
};
// 获取WebView中当前选中的面板地址
const getWebViewPanelAddress = (): string | null => {
try {
if (typeof (window as any).AndroidInterface !== 'undefined') {
const currentAddress = (window as any).AndroidInterface.getCurrentPanelAddress();
// 确保返回的地址不为空且已选中
if (currentAddress && currentAddress.trim()) {
return currentAddress;
}
return null;
}
return null;
} catch (error) {
return null;
}
};
// 初始化时获取基础URL
let baseURL: string = '';
// 重新初始化baseURL的函数
export const reinitializeBaseURL = () => {
if (isWebView()) {
const panelAddress = getWebViewPanelAddress();
if (panelAddress && panelAddress.trim()) {
baseURL = `${panelAddress}/api/v1/`;
axios.defaults.baseURL = baseURL;
return true;
} else {
baseURL = '';
axios.defaults.baseURL = '';
return false;
}
} else {
// 非WebView环境使用默认配置
baseURL = import.meta.env.VITE_API_BASE ? `${import.meta.env.VITE_API_BASE}/api/v1/` : '/api/v1/';
axios.defaults.baseURL = baseURL;
return true;
}
};
// 初始调用
reinitializeBaseURL();
// 在开发环境下输出API配置信息
if (import.meta.env.DEV) {
@@ -10,6 +65,10 @@ if (import.meta.env.DEV) {
console.log(' - VITE_API_BASE:', import.meta.env.VITE_API_BASE || '(undefined)');
console.log(' - Base URL:', baseURL);
console.log(' - Environment:', import.meta.env.MODE);
console.log(' - Is WebView:', isWebView());
if (isWebView()) {
console.log(' - WebView Panel Address:', getWebViewPanelAddress() || '(not set)');
}
}
interface ApiResponse<T = any> {
@@ -42,6 +101,12 @@ function isTokenExpired(response: ApiResponse) {
const Network = {
get: function<T = any>(path: string = '', data: any = {}): Promise<ApiResponse<T>> {
return new Promise(function(resolve) {
// 如果baseURL是默认值且是WebView环境,说明没有设置面板地址
if (baseURL === '') {
resolve({"code": -1, "msg": " - 请先设置面板地址", "data": null as T});
return;
}
axios.get(path, {
params: data,
timeout: 30000,
@@ -73,6 +138,12 @@ const Network = {
post: function<T = any>(path: string = '', data: any = {}): Promise<ApiResponse<T>> {
return new Promise(function(resolve) {
// 如果baseURL是默认值且是WebView环境,说明没有设置面板地址
if (baseURL === '') {
resolve({"code": -1, "msg": " - 请先设置面板地址", "data": null as T});
return;
}
axios.post(path, data, {
timeout: 30000,
headers: {