修复部分浏览器判定为app的bug

This commit is contained in:
qaq
2025-08-21 21:52:04 +08:00
parent 07a0b9e3fa
commit 365387576f
13 changed files with 183 additions and 168 deletions
+3 -12
View File
@@ -1,15 +1,6 @@
import axios, { AxiosResponse } from 'axios';
import { getPanelAddresses} from '@/utils/panel';
// 检测是否在WebView中运行
const isWebView = (): boolean => {
if((window as any).JsInterface !== undefined) {
return true;
}else if((window as any).webkit && (window as any).webkit.messageHandlers) {
return true;
}else {
return false;
}
};
import { getPanelAddresses, isWebViewFunc} from '@/utils/panel';
interface PanelAddress {
name: string;
@@ -34,7 +25,7 @@ function getWebViewPanelAddress() {
let baseURL: string = '';
export const reinitializeBaseURL = () => {
if (isWebView()) {
if (isWebViewFunc()) {
getWebViewPanelAddress();
} else {
baseURL = import.meta.env.VITE_API_BASE ? `${import.meta.env.VITE_API_BASE}/api/v1/` : '/api/v1/';
+2 -7
View File
@@ -5,6 +5,7 @@ import {
NavbarBrand,
NavbarContent,
} from "@heroui/navbar";
import { isWebViewFunc } from '@/utils/panel';
import { useNavigate } from "react-router-dom";
import { Logo } from "@/components/icons";
@@ -18,13 +19,7 @@ export const Navbar = () => {
// 检测是否在WebView中运行
useEffect(() => {
if((window as any).JsInterface !== undefined) {
setIsWebView(true);
}else if((window as any).webkit && (window as any).webkit.messageHandlers) {
setIsWebView(true);
}else {
setIsWebView(false);
}
setIsWebView(isWebViewFunc());
}, []);
+1 -1
View File
@@ -4,7 +4,7 @@ export type SiteConfig = typeof siteConfig;
// 缓存相关常量
const CACHE_PREFIX = 'vite_config_';
const VERSION = "1.3.1";
const VERSION = "1.3.2";
const APP_VERSION = "1.0.1";
const getInitialConfig = () => {
-11
View File
@@ -1,5 +1,3 @@
import { Link } from "@heroui/link";
import { Navbar } from "@/components/navbar";
export default function DefaultLayout({
@@ -13,15 +11,6 @@ export default function DefaultLayout({
<main className="container mx-auto max-w-7xl px-4 sm:px-6 flex-grow pt-4 sm:pt-16">
{children}
</main>
<footer className="w-full flex items-center justify-center py-3">
<Link
isExternal
className="flex items-center gap-1 text-current"
href="https://heroui.com"
title="heroui.com homepage"
>
</Link>
</footer>
</div>
);
}
+1 -1
View File
@@ -109,7 +109,7 @@ export default function ChangePasswordPage() {
return (
<DefaultLayout>
<section className="flex flex-col items-center justify-center gap-4 py-8 md:py-10 min-h-[calc(100vh-200px)]">
<section className="flex flex-col items-center justify-center gap-4 py-8 md:py-10 min-h-[calc(100dvh-200px)]">
<div className="w-full max-w-lg">
<Card className="w-full">
<CardHeader className="pb-0 pt-6 px-6 flex-col items-center">
+1 -1
View File
@@ -105,7 +105,7 @@ const CONFIG_ITEMS: ConfigItem[] = [
const getInitialConfigs = (): Record<string, string> => {
if (typeof window === 'undefined') return {};
const configKeys = ['app_name', 'captcha_enabled', 'captcha_type'];
const configKeys = ['app_name', 'captcha_enabled', 'captcha_type', 'ip'];
const initialConfigs: Record<string, string> = {};
try {
+4 -12
View File
@@ -5,7 +5,7 @@ import { useState, useEffect, useRef } from "react";
import { useNavigate } from "react-router-dom";
import toast from 'react-hot-toast';
import axios from 'axios';
import { isWebViewFunc } from '@/utils/panel';
import { siteConfig } from '@/config/site';
import { title } from "@/components/primitives";
import DefaultLayout from "@/layouts/default";
@@ -65,13 +65,7 @@ export default function IndexPage() {
}, []);
// 检测是否在WebView中运行
useEffect(() => {
if((window as any).JsInterface !== undefined) {
setIsWebView(true);
}else if((window as any).webkit && (window as any).webkit.messageHandlers) {
setIsWebView(true);
}else {
setIsWebView(false);
}
setIsWebView(isWebViewFunc());
}, []);
// 验证表单
const validateForm = (): boolean => {
@@ -259,7 +253,7 @@ export default function IndexPage() {
return (
<DefaultLayout>
<section className="flex flex-col items-center justify-center gap-4 py-4 sm:py-8 md:py-10 pb-20 min-h-[calc(100vh-120px)] sm:min-h-[calc(100vh-200px)]">
<section className="flex flex-col items-center justify-center gap-4 py-4 sm:py-8 md:py-10 pb-20 min-h-[calc(100dvh-120px)] sm:min-h-[calc(100dvh-200px)]">
<div className="w-full max-w-md px-4 sm:px-0">
<Card className="w-full">
<CardHeader className="pb-0 pt-6 px-6 flex-col items-center">
@@ -311,7 +305,6 @@ export default function IndexPage() {
{/* 版权信息 - 固定在底部,不占据布局空间 */}
{isWebView && (
<div className="fixed inset-x-0 bottom-4 text-center py-4">
<p className="text-xs text-gray-400 dark:text-gray-500">
Powered by{' '}
@@ -325,10 +318,9 @@ export default function IndexPage() {
</a>
</p>
<p className="text-xs text-gray-400 dark:text-gray-500 mt-1">
v{siteConfig.app_version}
v{ isWebView ? siteConfig.app_version : siteConfig.version}
</p>
</div>
)}
+23 -2
View File
@@ -5,10 +5,10 @@ import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, useDisclosure
import { Input } from "@heroui/input";
import { toast } from 'react-hot-toast';
import { useNavigate } from 'react-router-dom';
import { isWebViewFunc } from '@/utils/panel';
import { siteConfig } from '@/config/site';
import { updatePassword } from '@/api';
import { safeLogout } from '@/utils/logout';
interface PasswordForm {
newUsername: string;
currentPassword: string;
@@ -16,6 +16,7 @@ interface PasswordForm {
confirmPassword: string;
}
interface MenuItem {
path: string;
label: string;
@@ -237,9 +238,29 @@ export default function ProfilePage() {
</CardBody>
</Card>
<div className="fixed inset-x-0 bottom-20 text-center py-4">
<p className="text-xs text-gray-400 dark:text-gray-500">
Powered by{' '}
<a
href="https://github.com/bqlpfy/flux-panel"
target="_blank"
rel="noopener noreferrer"
className="text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors"
>
flux-panel
</a>
</p>
<p className="text-xs text-gray-400 dark:text-gray-500 mt-1">
v{ isWebViewFunc() ? siteConfig.app_version : siteConfig.version}
</p>
</div>
</div>
{/* 修改密码弹窗 */}
<Modal
isOpen={isOpen}
+2 -2
View File
@@ -77,9 +77,9 @@ export const SettingsPage = () => {
}, []);
return (
<div className="min-h-screen bg-gray-50 dark:bg-gray-900">
<div className="min-h-screen bg-gray-50 dark:bg-black">
{/* 顶部导航 */}
<div className="bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700">
<div className="bg-white dark:bg-black border-b border-gray-200 dark:border-gray-700">
<div className="max-w-4xl mx-auto px-4 py-4">
<div className="flex items-center gap-3">
<Button
+10
View File
@@ -38,6 +38,16 @@ export async function deletePanelAddress(name: string){
}
}
export function isWebViewFunc(){
if((window as any).JsInterface !== undefined && (window as any).JsInterface.getPanelAddresses !== undefined) {
return true;
}else if((window as any).webkit && (window as any).webkit.messageHandlers && (window as any).webkit.messageHandlers.getPanelAddresses !== undefined) {
return true;
}else {
return false;
}
}
// 验证面板地址格式
export function validatePanelAddress(address: string): boolean {
try {