refactor:重构请求配置

This commit is contained in:
liyuanhu 2025-04-17 14:12:49 +08:00
parent 064973aaf0
commit 9f09e8ba61
11 changed files with 41 additions and 25 deletions

1
.env
View File

@ -4,3 +4,4 @@ NODE_SECRET="aHVnZSBjb21wYW55IHBob25lIHdlc3QgcGxhY2Ugc2VtaW5hciBtaXJhY2xlIGxlbmQ
IS_DEBUG="true"
ACCOUNT_NAME="de1"
VITE_BASE_URL="http://10.66.66.234:6060"
VITE_BLOCK_URL="http://localhost:3001"

View File

@ -4,7 +4,7 @@ import { api } from "@/utils/api";
// 区块链api 类
export class BlockChainApi {
public coreConfig: CoreConfig;
public baseUrl = "http://localhost:3000/api";
public baseUrl = import.meta.env.VITE_BLOCK_URL;
constructor() {
this.coreConfig = {} as CoreConfig;

View File

@ -4,24 +4,24 @@ const baseUrl = import.meta.env.VITE_BASE_URL;
// 通行认证
export const getPassAuthentication = async () => {
return await api.get(`${baseUrl}/step/pass_authentication`);
return (await api.get(`${baseUrl}/step/pass_authentication`)).data;
};
// 流量混淆
export const getTrafficObfuscation = async () => {
return await api.get(`${baseUrl}/step/traffic_obfuscation`);
}
return (await api.get(`${baseUrl}/step/traffic_obfuscation`)).data;
};
// 嵌套加密
export const getNestedEncryption = async () => {
return await api.get(`${baseUrl}/step/nested_encryption`);
}
return (await api.get(`${baseUrl}/step/nested_encryption`)).data;
};
// 动态路由生成
export const getDynamicRouteGeneration = async () => {
return await api.get(`${baseUrl}/step/dynamic_route_generator`);
}
return (await api.get(`${baseUrl}/step/dynamic_route_generator`)).data;
};
// 应用分流
export const getApplicationDiversion = async () => {
return await api.get(`${baseUrl}/step/app_diversion`);
}
return (await api.get(`${baseUrl}/step/app_diversion`)).data;
};

View File

@ -2,7 +2,7 @@
export const TRAFFIC_OBFUSCATION = {
type: "NESTED_ENCRYPTION",
name: "流量混淆",
code: "BR",
code: "ZA",
data: [
{
country_code: "gl",
@ -404,6 +404,8 @@ export const APP_DIVERSION = [
export const PASS_AUTHENTICATION = {
type: "PASS_AUTHENTICATION",
name: "通行认证",
startPoint: "GL",
endPoint: "CA",
authenticationPoint: [
[-103.346771, 54.130366],
[-120.346771, 52.130366],
@ -444,4 +446,4 @@ export const PASS_AUTHENTICATION = {
},
],
isLine: true,
};
}

View File

@ -100,13 +100,13 @@ const NodeForm = ({ form }: { form: FormInstance }) => {
{/* <Form.Item name="uid" className="hidden">
<div className="hidden">uid</div>
</Form.Item> */}
<Form.Item name="nodePublicKey" label="节点身份公钥">
<Form.Item name="public_key" label="节点身份公钥">
<Input
className="link_name_input placeholder:text-base placeholder:text-zinc-400 text-[16px]"
placeholder="节点身份公钥*"
/>
</Form.Item>
<Form.Item name="nodeMetadata" label="节点元数据">
<Form.Item name="private_key" label="节点元数据">
<Input
className="link_name_input placeholder:text-base placeholder:text-zinc-400 text-[16px]"
placeholder="请输入TLS Pubkey*"

View File

@ -73,6 +73,7 @@ const DecentralizedElasticNetwork = () => {
await form.validateFields();
const formValue: any = form.getFieldsValue();
if (type.title === DIALOGTYPE.ADDNode.title) {
console.log(formValue,"formValue")
setOpen(false);
} else {
const { inbound, outbound } = formValue || {};

View File

@ -168,7 +168,6 @@ export const WorldGeo = memo(
// 定位自定义提示框 - 优化版本
const positionCustomTooltip = () => {
if (!customTooltipRef.current || !proxyGeoRef.current) return;
console.log(dataInfo.nestedEncryption?.[0]?.code, "sssss");
// 找到US点
const coords = geoCoordMap[dataInfo.nestedEncryption?.[0]?.code ?? "GL"];
if (!coords) return;
@ -1159,7 +1158,6 @@ export const WorldGeo = memo(
};
}, []);
useEffect(() => {
console.log(tooltipClosed, "tooltipClosedtooltipClosed");
if (tooltipClosed) {
createCustomTooltip();
createCustomTooltip2();

View File

@ -22,7 +22,6 @@ import type { AppDispatch, RootState } from "@/store";
import "./index.scss";
import { DialogConfig, FormAlertDialog } from "./components/FormAlertDialog";
import { ClearNodeDialog } from "./components/ClearNodeDialog";
import { blockChainApi } from "@/api/block";
import {
getPassAuthentication,
getTrafficObfuscation,
@ -30,6 +29,7 @@ import {
getDynamicRouteGeneration,
getApplicationDiversion,
} from "@/api/flying-line";
import { blockChainApi } from "@/api/block";
export const DIALOGTYPE = {
ADDNode: {
@ -58,7 +58,7 @@ export const NODEDIALOGTYPE = {
};
const NewHome = () => {
const dispatch = useDispatch<AppDispatch>();
const { web3List, web3List2, } = useSelector(
const { web3List, web3List2 } = useSelector(
(state: RootState) => state.web3Reducer
);
@ -242,10 +242,9 @@ const NewHome = () => {
});
};
useEffect(() => {
// blockChainApi.getLatestBlock().then((res) => {
// console.log("res", res);
// setBlockChain(res);
// });
blockChainApi.getLatestBlock().then((res) => {
console.log("res", res);
});
initData();
}, []);

View File

@ -15,7 +15,7 @@ export const router = createBrowserRouter([
children: [
{
index: true, // 默认路由
element: <Navigate to="/home" replace />, // 重定向到 /home
element: <Navigate to="/new-home" replace />, // 重定向到 /home
},
{
path: '/new-home',

View File

@ -16,9 +16,15 @@ class FetchApi {
...config,
});
if (result.ok) {
return await result.json();
return {
success: true,
data: await result.json(),
};
} else {
return null;
return {
success: false,
data: await result.text(),
};
}
}

9
src/vite-env.d.ts vendored
View File

@ -1,2 +1,11 @@
/// <reference types="vite/client" />
/// <reference types="vite-plugin-svgr/client" />
interface ImportMetaEnv {
// 定义你的环境变量,例如:
readonly VITE_BASE_URL: string
readonly VITE_BLOCK_URL: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}