Skip to content

Commit f2b9be1

Browse files
committed
feat: add layer update eslint FormItem (#24)
* feat: update FormItem * feat: add layer update eslint * feat: update dark-mode style
1 parent dc07367 commit f2b9be1

File tree

14 files changed

+76
-40
lines changed

14 files changed

+76
-40
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"typescript.tsdk": "node_modules/typescript/lib",
33
"cSpell.words": [
44
"attributify",
5+
"cssinjs",
56
"cssnano",
67
"datetime",
78
"ianvs",

eslint.config.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,24 @@ import tailwind from "eslint-plugin-tailwindcss";
33

44
export default antfu(
55
{
6-
formatters: false,
6+
formatters: {
7+
/**
8+
* Format CSS, LESS, SCSS files, also the `<style>` blocks in Vue
9+
* By default uses Prettier
10+
*/
11+
css: true,
12+
/**
13+
* Format HTML files
14+
* By default uses Prettier
15+
*/
16+
html: true,
17+
/**
18+
* Format Markdown files
19+
* Supports Prettier and dprint
20+
* By default uses Prettier
21+
*/
22+
markdown: "prettier"
23+
},
724
react: true,
825
ignores: ["**/*.md"],
926
typescript: {

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"prepare": "husky install"
2222
},
2323
"dependencies": {
24+
"@ant-design/cssinjs": "^2.0.1",
2425
"@ant-design/icons": "^6.1.0",
2526
"@babel/runtime": "^7.24.0",
2627
"@wanp/use-swr-data": "^1.0.6",
@@ -58,9 +59,9 @@
5859
"dotenv": "^16.4.5",
5960
"eslint": "^9.39.1",
6061
"eslint-plugin-format": "^1.0.2",
61-
"eslint-plugin-react-hooks": "^5.2.0",
62-
"eslint-plugin-react-refresh": "^0.4.20",
63-
"eslint-plugin-tailwindcss": "^3.18.0",
62+
"eslint-plugin-react-hooks": "^7.0.1",
63+
"eslint-plugin-react-refresh": "^0.4.24",
64+
"eslint-plugin-tailwindcss": "^3.18.2",
6465
"html-webpack-plugin": "^5.6.0",
6566
"husky": "^8.0.3",
6667
"less": "^4.2.0",

src/assets/css/init.css

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
@tailwind base;
1+
@layer tailwind-base, antd;
2+
3+
@layer tailwind-base {
4+
@tailwind base;
5+
}
6+
27
@tailwind components;
38
@tailwind utilities;
49

@@ -8,17 +13,3 @@ body,
813
height: 100%;
914
width: 100%;
1015
}
11-
12-
body,
13-
ul,
14-
li {
15-
margin: 0;
16-
padding: 0;
17-
}
18-
19-
*,
20-
::before,
21-
::after {
22-
border-width: 0;
23-
border-style: solid;
24-
}

src/components/FormList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { FormInstance, FormProps } from "antd";
22
import type { ReactElement } from "react";
33
import { Button, Form } from "antd";
4-
import { memo, useEffect, useMemo } from "react";
4+
import { Fragment, memo, useEffect, useMemo } from "react";
55

66
import { getFormElement } from "../tools";
77

@@ -111,7 +111,7 @@ function FormList(props: FormListProps) {
111111
}
112112

113113
if (e.type === "blockNode") {
114-
return <span key={key}>{e.label}</span>;
114+
return <Fragment key={key}>{e.label}</Fragment>;
115115
}
116116

117117
return (

src/components/FormModal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function FormModal(props: FormModalProps) {
5050
footer={noFooter ? null : undefined}
5151
classNames={classNames || {
5252
body: "pt-6",
53-
header: "border-b border-black/10 border-solid pb-3",
53+
header: "border-b border-black/10 border-solid pb-3 dark:border-white/20",
5454
}}
5555
afterClose={() => {
5656
formInstance.current && formInstance.current.resetFields();

src/components/LazyLoadSelect.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default function LazyLoadSelect<P extends AnyObject, R extends ResponseLi
3535
return;
3636

3737
if (data?.pageNum > 1) {
38+
// eslint-disable-next-line react-hooks/set-state-in-effect
3839
setList(draft => [...draft, ...data.list]);
3940
}
4041
else {

src/components/tools.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export function getFormElement(type: FormItem["type"], info: FormItem): ReactNod
1919
case "checkbox":
2020
return <Checkbox.Group style={{ width: "100%" }} options={info.options || []} {...info.otherOptions} />;
2121

22-
case "node":
23-
return info.rightNode;
22+
case "inputNode":
23+
return info.inputNode;
2424

2525
case "switch":
2626
return <Switch size="small" disabled={info.disable} {...info.otherOptions} />;

src/formIten.d.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@ declare interface FormItem {
88
visible?: boolean;
99
disable?: boolean;
1010
extra?: string | React.ReactNode;
11-
type: "input" | "numberInput" | "select" | "treeSelect" | "datePick" | "rangePick" | "radio" | "checkbox" | "textArea" | "switch" | "blockNode" | "node";
11+
type:
12+
"input"
13+
| "textArea"
14+
| "numberInput"
15+
| "select"
16+
| "treeSelect"
17+
| "radio"
18+
| "switch"
19+
| "checkbox"
20+
| "datePick"
21+
| "rangePick"
22+
// 特有属性
23+
| "blockNode"
24+
| "inputNode";
1225
valuePropName?: import("antd").FormItemProps["valuePropName"];
1326
formItemProps?: import("antd").FormItemProps;
1427
// 特有属性
15-
rightNode?: React.ReactNode; // node
28+
inputNode?: React.ReactNode; // 输入组件
1629
options?: { label: string | React.ReactNode; value: any }[];
1730
otherOptions?: Record<string, any>; // 组件额外属性
1831
}

src/layout/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import BreadCrumb from "&src/components/BreadCrumb";
22
import { COLOR_PRIMARY, SPLIT_FLAG } from "&src/config";
33
import useRootStore, { useGetRouterConfig } from "&src/store";
44
import { ConfigProvider, Layout, theme } from "antd";
5-
import { useMemo } from "react";
5+
import { useLayoutEffect, useMemo } from "react";
66
import { Link, useLocation } from "react-router-dom";
77
import MenuHeader from "./header";
88
import SiderCom from "./sider";
@@ -88,9 +88,19 @@ function AppLayout({ children }: { children: React.ReactNode }) {
8888
token: { colorPrimary: COLOR_PRIMARY },
8989
};
9090

91+
// 设置 body 的 className 以应用暗黑模式样式
92+
useLayoutEffect(() => {
93+
if (darkMode) {
94+
document.body.className = "dark";
95+
}
96+
else {
97+
document.body.className = "";
98+
}
99+
}, [darkMode]);
100+
91101
return (
92102
<ConfigProvider theme={currentThem}>
93-
<Layout className={darkMode ? "dark" : ""}>
103+
<Layout>
94104
<MenuHeader tabId={tabId} tabList={routerMenu} />
95105

96106
<Layout className="h-[calc(100vh-3.5rem)] overflow-hidden">

0 commit comments

Comments
 (0)