Skip to content

Commit be3873c

Browse files
committed
feat: Optimize code (#19)
* chore: update dir * chore: Optimize dependencies * fix: fix type * 🦄 feat: update' * feat: update * feat: update * feat: code optimization * feat: code optimization * feat: 代码优化 * feat: update * feat: update build version * feat: update util * feat: update
1 parent 4a7a8af commit be3873c

File tree

10 files changed

+370
-172
lines changed

10 files changed

+370
-172
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dependencies": {
2424
"@ant-design/icons": "^5.3.4",
2525
"@babel/runtime": "^7.24.0",
26-
"@wanp/use-swr-data": "^1.0.0",
26+
"@wanp/use-swr-data": "^1.0.3",
2727
"antd": "^5.15.3",
2828
"axios": "^1.6.8",
2929
"classnames": "^2.5.1",
@@ -73,7 +73,7 @@
7373
"react-refresh": "^0.17.0",
7474
"style-loader": "^3.3.4",
7575
"tailwindcss": "^3.4.1",
76-
"typescript": "^5.8.2",
76+
"typescript": "~5.8.2",
7777
"webpack": "^5.90.3",
7878
"webpack-bundle-analyzer": "^4.10.1",
7979
"webpack-cli": "^4.10.0",

pnpm-workspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
onlyBuiltDependencies:
2+
- core-js

src/components/BreadCrumb/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,21 @@ function BreadCrumb({ routerPath }: BreadCrumbProps) {
2626
<div className="flex h-14 items-center pl-2 text-neutral-400">
2727
{currentPath.split("/").map((e, i, arr) => {
2828
const text = e.trim();
29-
const isLast = arr.length - 1 === i;
29+
const last = arr.length - 1 === i;
3030
const path = pathMap[text];
3131

3232
return (
3333
<span key={e}>
3434
<span
35-
className={classNames({
36-
"cursor-pointer text-primary": !isLast && path,
37-
})}
35+
className={classNames({ "cursor-pointer text-primary": !last && path })}
3836
onClick={() => {
3937
navigate(path);
4038
}}
4139
>
4240
{text}
4341
</span>
4442

45-
{isLast ? null : <span className="mx-2">/</span>}
43+
{last ? null : <span className="mx-2">/</span>}
4644
</span>
4745
);
4846
})}

src/components/FormFilter/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function FormFilter(props: FormFilterProps) {
3535
);
3636

3737
return (
38-
<Card classNames={{ body: className }}>
38+
<Card classNames={{ body: className || "py-4" }}>
3939
<FormList
4040
colon={false}
4141
layout="inline"

src/layout/sider.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { MenuProps } from "antd";
12
import { Layout, Menu } from "antd";
23
import { useEffect, useMemo, useState } from "react";
34

@@ -30,10 +31,10 @@ function SiderCom({ menu, selectKey }: { menu: MenuItem[]; selectKey: string | n
3031
<Sider theme="light" width={160}>
3132
<Menu
3233
mode="inline"
33-
items={menu}
34+
className="mt-5"
3435
openKeys={keys}
3536
selectedKeys={[`${currentKay}`]}
36-
className="mt-5"
37+
items={menu as MenuProps["items"]}
3738
onOpenChange={(openKeys) => {
3839
setKeys(openKeys);
3940
}}

src/pages/system/setting/company.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function Company() {
115115

116116
return (
117117
<div>
118-
<FormFilter loading={isLoading} filterInfo={filterInfo} onOk={onSearch} reset />
118+
<FormFilter reset loading={isLoading} filterInfo={filterInfo} onOk={onSearch} />
119119

120120
<Card className="mt-1">
121121
<div className="mb-2">

src/pages/system/setting/params.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
import { Card, Skeleton } from "antd";
2-
import { Link } from "react-router-dom";
1+
import { Button, Card, Skeleton } from "antd";
2+
import { useNavigate } from "react-router-dom";
33

44
function Params({ title }: RoutePageProps) {
5+
const navigate = useNavigate();
6+
57
return (
68
<Card title={title || "参数配置"}>
7-
<div>
8-
<Link to="/setting/detail">detail</Link>
9-
</div>
9+
<Button
10+
type="primary"
11+
className="mb-2"
12+
onClick={() => {
13+
navigate("/setting/detail");
14+
}}
15+
>
16+
detail
17+
</Button>
18+
1019
<Skeleton active />
1120
</Card>
1221
);

src/router/config.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const GLOBAL_ROUTERS = {
109109
NOT_FOUND_PAGE: {
110110
path: "*",
111111
redirect: "/login",
112-
} as Route
112+
} as Route,
113113
};
114114

115115
/**
@@ -200,21 +200,26 @@ export function getRoute(routers: Route[] | Route) {
200200
return list.map((e) => {
201201
const { key = nanoid(), path, title, index, redirect, component: componentPath, childrenList = [] } = e;
202202

203-
let element: ReactNode = null;
204-
if (redirect)
205-
element = <Redirect redirect={redirect}></Redirect>;
203+
let element: ReactNode = <></>;
204+
206205
if (componentPath) {
207206
const Component = getLazyLoad(componentPath);
207+
208208
element = (
209209
<Suspense fallback={<Loading full />}>
210-
<Component title={title}>{childrenList.length ? <Outlet /> : null}</Component>
210+
<Component title={title}>{childrenList.length ? <Outlet /> : undefined}</Component>
211211
</Suspense>
212212
);
213213
}
214+
else {
215+
if (redirect) {
216+
element = <Redirect redirect={redirect}></Redirect>;
217+
}
218+
}
214219

215220
const jsx = index
216221
? (
217-
<Route key={key} element={element} index></Route>
222+
<Route key={key} element={element} index />
218223
)
219224
: (
220225
<Route key={key} element={element} path={path}>

0 commit comments

Comments
 (0)