| | |
| | | # React + TypeScript + Vite |
| | | # admin2-components |
| | | |
| | | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. |
| | | PC 端管理系统公共组件库,基于 React + TypeScript + Ant Design 构建。 |
| | | |
| | | Currently, two official plugins are available: |
| | | ## 项目定位 |
| | | |
| | | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs) |
| | | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) |
| | | 本项目是一套 PC 端管理系统的公共组件库,提供: |
| | | - **框架组件** - 管理系统页面主结构(侧边栏、顶部栏、多页签等) |
| | | - **表单组件** - 处理用户输入(日期选择、级联选择、文件上传等) |
| | | - **高级组件** - 复杂功能(表格、图表、弹窗、编辑器等) |
| | | |
| | | ## React Compiler |
| | | ## 技术栈 |
| | | |
| | | The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation). |
| | | - React 19 |
| | | - TypeScript 5.9 |
| | | - Vite 8 |
| | | - Ant Design 6.3.5 |
| | | - ESLint 9 (Flat Config) |
| | | |
| | | ## Expanding the ESLint configuration |
| | | ## 引用方式 |
| | | |
| | | If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules: |
| | | 作为 git 子模块挂载到业务项目根目录: |
| | | |
| | | ```js |
| | | export default defineConfig([ |
| | | globalIgnores(['dist']), |
| | | { |
| | | files: ['**/*.{ts,tsx}'], |
| | | extends: [ |
| | | // Other configs... |
| | | ```bash |
| | | # 添加子模块到项目根目录 |
| | | git submodule add <repository-url> components |
| | | |
| | | // Remove tseslint.configs.recommended and replace with this |
| | | tseslint.configs.recommendedTypeChecked, |
| | | // Alternatively, use this for stricter rules |
| | | tseslint.configs.strictTypeChecked, |
| | | // Optionally, add this for stylistic rules |
| | | tseslint.configs.stylisticTypeChecked, |
| | | |
| | | // Other configs... |
| | | ], |
| | | languageOptions: { |
| | | parserOptions: { |
| | | project: ['./tsconfig.node.json', './tsconfig.app.json'], |
| | | tsconfigRootDir: import.meta.dirname, |
| | | }, |
| | | // other options... |
| | | }, |
| | | }, |
| | | ]) |
| | | # 更新子模块 |
| | | git submodule update --init --recursive |
| | | ``` |
| | | |
| | | You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules: |
| | | 业务项目需配置别名 `@components` 指向 `components/src` 目录。组件引用示例: |
| | | |
| | | ```js |
| | | // eslint.config.js |
| | | import reactX from 'eslint-plugin-react-x' |
| | | import reactDom from 'eslint-plugin-react-dom' |
| | | |
| | | export default defineConfig([ |
| | | globalIgnores(['dist']), |
| | | { |
| | | files: ['**/*.{ts,tsx}'], |
| | | extends: [ |
| | | // Other configs... |
| | | // Enable lint rules for React |
| | | reactX.configs['recommended-typescript'], |
| | | // Enable lint rules for React DOM |
| | | reactDom.configs.recommended, |
| | | ], |
| | | languageOptions: { |
| | | parserOptions: { |
| | | project: ['./tsconfig.node.json', './tsconfig.app.json'], |
| | | tsconfigRootDir: import.meta.dirname, |
| | | }, |
| | | // other options... |
| | | }, |
| | | }, |
| | | ]) |
| | | ```tsx |
| | | import { CSideMenu } from '@components/framework/sideMenu/CSideMenu'; |
| | | ``` |
| | | |
| | | ## 组件分类 |
| | | |
| | | | 分类 | 说明 | |
| | | |------|------| |
| | | | `framework` | 框架组件 - 页面主结构 | |
| | | | `forms` | 表单组件 - 用户输入 | |
| | | | `fragments` | 页面片段 - 布局元素 | |
| | | | `plugins` | 高级组件 - 复杂功能 | |
| | | | `bases` | 业务组件 - 领域特定 | |
| | | |
| | | 详细目录结构说明见 [STRUCTURE.md](./STRUCTURE.md) |
| | | |
| | | ## 可用脚本 |
| | | |
| | | ```bash |
| | | pnpm dev # 启动开发服务器 |
| | | pnpm build # 构建生产版本 |
| | | pnpm preview # 预览生产版本 |
| | | pnpm lint # 运行 ESLint |
| | | ``` |
| | | |
| | | ## 开发规范 |
| | | |
| | | - 使用 TypeScript 严格模式 |
| | | - ESLint 配置了类型检查规则,提交前需通过 lint |
| | | - 组件开发遵循函数式组件 + Hooks 模式 |
| | | - 组件文件以 `C` 开头(如 `CButton.tsx`) |
| | | - 样式文件与组件同目录,使用 `c` 开头(如 `cButton.scss`) |