feat: support random param and default config (#50)

This commit is contained in:
ReaJason
2025-04-06 13:55:17 +08:00
parent fa206e8acc
commit 0f798b367f
35 changed files with 251 additions and 116 deletions
+2 -3
View File
@@ -1,13 +1,12 @@
import { LanguageSwitcher } from "@/components/language-switcher";
import { ModeToggle } from "@/components/mode-toggle.tsx";
import { ThemeProvider } from "@/components/theme-provider.tsx";
import { Button } from "@/components/ui/button";
import { Toaster } from "@/components/ui/sonner";
import VersionBadge from "@/components/version-badge";
import { GitHubIcon } from "@/icon";
import { Button } from "@/components/ui/button";
import { Outlet } from "react-router-dom";
export default function RootLayout() {
return (
<ThemeProvider defaultTheme="system" storageKey="vite-ui-theme">
@@ -39,4 +38,4 @@ export default function RootLayout() {
</div>
</ThemeProvider>
);
}
}
+37 -13
View File
@@ -19,7 +19,7 @@ import {
WaypointsIcon,
ZapIcon,
} from "lucide-react";
import { JSX, useState } from "react";
import { JSX, useEffect, useState } from "react";
import { FormProvider, UseFormReturn } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { AntSwordTabContent } from "./tools/antsword-tab";
@@ -65,20 +65,45 @@ export function MainConfigCard({
const shellTool = form.watch("shellTool");
const { t } = useTranslation();
// 处理一下默认值 server 不刷新 shellType 的问题
useEffect(() => {
if (mainConfig) {
const initialServer = form.getValues("server");
if (initialServer && mainConfig[initialServer]) {
handleServerChange(initialServer);
}
}
}, [mainConfig, form]);
// 处理一下 shellTypes 由于 server 或 shellTool 变更时无法正常为 form.shellType 赋值的问题
useEffect(() => {
if (shellTypes.length > 0) {
form.setValue("shellType", shellTypes[0]);
}
}, [shellTypes, form]);
const handleServerChange = (value: string) => {
if (mainConfig) {
const newShellToolMap = mainConfig[value];
setShellToolMap(newShellToolMap);
const newShellTools = Object.keys(newShellToolMap);
setShellTools([...newShellTools.map((tool) => tool as ShellToolType), ShellToolType.Custom]);
if (newShellTools.length > 0) {
const firstTool = newShellTools[0];
setShellTypes(newShellToolMap[firstTool]);
form.setValue("shellTool", firstTool);
} else {
setShellTypes([]);
}
const currentShellTool = form.getValues("shellTool");
const firstTool = newShellTools[0];
let currentShellTypes = null;
if (!newShellToolMap[currentShellTool]) {
form.setValue("shellTool", firstTool);
currentShellTypes = newShellToolMap[firstTool];
} else {
currentShellTypes = newShellToolMap[currentShellTool];
}
setShellTypes(currentShellTypes);
// 特殊环境的 JDK 版本
if (
(value === "SpringWebFlux" || value === "XXLJOB") &&
Number.parseInt(form.getValues("targetJdkVersion") as string) < 52
@@ -88,8 +113,6 @@ export function MainConfigCard({
form.resetField("targetJdkVersion");
}
form.resetField("bypassJavaModule");
form.resetField("shellTool");
form.resetField("shellType");
form.resetField("urlPattern");
}
};
@@ -133,14 +156,15 @@ export function MainConfigCard({
};
if (shellToolMap) {
let currentShellTypes = null;
if (value === ShellToolType.Custom) {
setShellTypes(servers?.[form.getValues("server")] as string[]);
currentShellTypes = servers?.[form.getValues("server")] as string[];
} else {
setShellTypes(shellToolMap[value]);
currentShellTypes = shellToolMap[value];
}
setShellTypes(currentShellTypes);
form.resetField("urlPattern");
form.resetField("shellType");
form.resetField("shellClassName");
form.resetField("injectorClassName");
if (value === ShellToolType.Godzilla) {
+13 -11
View File
@@ -16,10 +16,10 @@ type Option = {
export function PackageConfigCard({
packerConfig,
form,
}: {
}: Readonly<{
packerConfig: PackerConfig | undefined;
form: UseFormReturn<FormSchema>;
}) {
}>) {
const [options, setOptions] = useState<Array<Option>>([]);
const shellType = form.watch("shellType");
@@ -39,15 +39,17 @@ export function PackageConfigCard({
}
return !name.startsWith("Agent") && !name.toLowerCase().startsWith("xxl");
});
setOptions(
filteredOptions.map((name) => {
return {
name: t(`packageConfig.packer.${name}`),
value: name,
};
}),
);
if (filteredOptions.length > 0) {
const mappedOptions = filteredOptions.map((name) => {
return {
name: t(`packageConfig.packer.${name}`),
value: name,
};
});
setOptions(mappedOptions);
const currentValue = form.getValues("packingMethod");
if (filteredOptions.length > 0 && (!currentValue || !filteredOptions.includes(currentValue))) {
form.setValue("packingMethod", filteredOptions[0]);
}
}, [form, packerConfig, server, shellType, t]);
+6 -2
View File
@@ -28,7 +28,9 @@ export function AntSwordTabContent({
name="antSwordPass"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.antSwordPass")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.antSwordPass")} {t("optional")}
</FormLabel>
<Input {...field} placeholder={t("placeholders.input")} className="h-8" />
</FormItem>
)}
@@ -49,7 +51,9 @@ export function AntSwordTabContent({
name="headerValue"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.headerValue")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.headerValue")} {t("optional")}
</FormLabel>
<Input {...field} placeholder={t("shellToolConfig.headerValue")} className="h-8" />
</FormItem>
)}
+6 -2
View File
@@ -28,7 +28,9 @@ export function BehinderTabContent({
name="behinderPass"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.behinderPass")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.behinderPass")} {t("optional")}
</FormLabel>
<Input {...field} placeholder={t("placeholders.input")} className="h-8" />
</FormItem>
)}
@@ -49,7 +51,9 @@ export function BehinderTabContent({
name="headerValue"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.headerValue")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.headerValue")} {t("optional")}
</FormLabel>
<Input {...field} placeholder={t("shellToolConfig.headerValue")} className="h-8" />
</FormItem>
)}
+3 -1
View File
@@ -28,7 +28,9 @@ export function CommandTabContent({
name="commandParamName"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.paramName")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.paramName")} {t("optional")}
</FormLabel>
<FormControl>
<Input {...field} placeholder={t("shellToolConfig.paramName")} className="h-8" />
</FormControl>
+9 -3
View File
@@ -29,7 +29,9 @@ export function GodzillaTabContent({
name="godzillaPass"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.pass")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.pass")} {t("optional")}
</FormLabel>
<Input {...field} placeholder={t("shellToolConfig.pass")} className="h-8" />
</FormItem>
)}
@@ -39,7 +41,9 @@ export function GodzillaTabContent({
name="godzillaKey"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.key")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.key")} {t("optional")}
</FormLabel>
<Input {...field} placeholder={t("shellToolConfig.key")} className="h-8" />
</FormItem>
)}
@@ -59,7 +63,9 @@ export function GodzillaTabContent({
name="headerValue"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.headerValue")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.headerValue")} {t("optional")}
</FormLabel>
<Input {...field} placeholder={t("shellToolConfig.headerValue")} className="h-8" />
</FormItem>
)}
+3 -1
View File
@@ -39,7 +39,9 @@ export function NeoRegTabContent({
name="headerValue"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.headerValue")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.headerValue")} {t("optional")}
</FormLabel>
<Input {...field} placeholder={t("shellToolConfig.headerValue")} className="h-8" />
</FormItem>
)}
+3 -1
View File
@@ -39,7 +39,9 @@ export function Suo5TabContent({
name="headerValue"
render={({ field }) => (
<FormItem className="gap-1">
<FormLabel className="h-6 flex items-center gap-1">{t("shellToolConfig.headerValue")}</FormLabel>
<FormLabel className="h-6 flex items-center gap-1">
{t("shellToolConfig.headerValue")} {t("optional")}
</FormLabel>
<Input {...field} placeholder={t("shellToolConfig.headerValue")} className="h-8" />
</FormItem>
)}