Basic Concepts β
The entire project has been refactored. We will now introduce some fundamental concepts to help you better understand the documentation. Please make sure to read this section carefully first.
TIP
Everything discussed below pertains to the structure within ./web
under the project's root directory.
Overall Project Architecture β
This project adopts a modern front-end development architecture, built on Vue 3 + TypeScript + Vite, implementing a modular and plugin-based development model.
Global Type System β
Since the new version is written in TypeScript
, all global type definitions are stored in the ./types
directory, where you can find relevant data type structures.
Type File Organization Structure β
./types/
βββ api.d.ts # API-related type definitions
βββ components.d.ts # Component type definitions
βββ global.d.ts # Global type definitions
βββ modules.d.ts # Module type definitions
βββ utils.d.ts # Utility function type definitions
2
3
4
5
6
Usage Example β
In the project, types can be quickly imported using the alias #
:
// Import API types
import type { ApiResponse, UserInfo } from '#/api'
// Import global types
import type { MenuConfig, RouteConfig } from '#/global'
// Usage in components
interface ComponentProps {
userInfo: UserInfo
menuConfig: MenuConfig[]
}
2
3
4
5
6
7
8
9
10
11
Type Definition Best Practices β
- Naming Convention: Use PascalCase for interface and type names
- File Organization: Organize type files by functional modules
- Type Export: Use
export type
to export type definitions - Generic Support: Use generics appropriately to improve type reusability
Modular Architecture β
The new version adopts a modular structure, with the directory located at ./src/modules
. Each module manages its own business api
, types
, locales
, and view files
, achieving complete isolation and independent management of business logic.
Module Structure Design β
Standard Module Directory Structure β
./src/modules/[Module Name]/
βββ api/ # API Interface Definitions
β βββ user.ts # User-related Interfaces
β βββ menu.ts # Menu-related Interfaces
β βββ index.ts # Unified Interface Exports
βββ components/ # Module-specific Components
β βββ UserForm.vue # User Form Component
β βββ MenuTree.vue # Menu Tree Component
βββ locales/ # Module Internationalization Files
β βββ zh_CN.yaml # Chinese Language Pack
β βββ en.yaml # English Language Pack
β βββ index.ts # Language Pack Exports
βββ views/ # View Pages
β βββ user/ # User Management Pages
β β βββ index.vue # User List Page
β β βββ detail.vue # User Detail Page
β βββ dashboard/ # Dashboard Pages
β βββ index.vue
βββ index.ts # Unified Module Exports
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Module Development Process β
- Create Module Directory: Create a new module folder under
./src/modules/
- Define Module Structure: Create corresponding directories and files according to the standard structure
- Configure Routes: Define route configurations within the module
- Develop Business Logic: Write APIs, components, and views
- Add Internationalization: Configure multi-language support
- Module Export: Export module contents uniformly via index.ts
Inter-Module Communication β
Module Usage Example β
// Using base module APIs in other modules
import { userApi, menuApi } from '~/base/api'
import type { UserInfo } from '~/base/types'
// Using module functionality in components
export default defineComponent({
async setup() {
// Call user API
const userList = await userApi.getUsers()
// Call menu API
const menuTree = await menuApi.getMenuTree()
return {
userList,
menuTree
}
}
})
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Alias System β
Path aliases are defined in the vite.config.ts
file to simplify file import paths, improving development efficiency and code maintainability.
Alias Configuration β
// vite.config.ts
export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'#': path.resolve(__dirname, 'types'),
'$': path.resolve(__dirname, 'src/plugins'),
'~': path.resolve(__dirname, 'src/modules'),
},
},
})
2
3
4
5
6
7
8
9
10
11
Alias Mapping Table β
Alias | Directory Path | Description | Usage Scenarios |
---|---|---|---|
@ | ./src | Source Root Directory | Importing components, utility functions, styles, etc. |
# | ./types | Global Type Definitions | Importing TypeScript type definitions |
$ | ./src/plugins | Plugin Directory | Importing files and components within plugins |
~ | ./src/modules | Module Directory | Importing module APIs, components, views |
Alias Usage Examples β
1. Base Path Alias (@) β
// β Using relative paths (not recommended)
import Utils from '../../../utils/common'
import Button from '../../../components/Button.vue'
// β
Using aliases (recommended)
import Utils from '@/utils/common'
import Button from '@/components/Button.vue'
2
3
4
5
6
7
2. Type Definition Alias (#) β
// Import global types
import type {
ApiResponse,
UserInfo,
MenuConfig
} from '#/global'
// Import API types
import type { LoginParams } from '#/api'
// Usage in interfaces
interface ComponentProps {
userInfo: UserInfo
menuList: MenuConfig[]
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
3. Plugin Alias ($) β
// Import chart plugin
import ChartPlugin from '$/charts'
import { useChart } from '$/charts/hooks'
// Import editor plugin
import EditorPlugin from '$/editor'
import EditorComponent from '$/editor/components/RichEditor.vue'
2
3
4
5
6
7
4. Module Alias (~) β
// Import base module APIs
import { userApi, menuApi } from '~/base/api'
// Import user module components
import UserForm from '~/user/components/UserForm.vue'
import UserList from '~/user/views/UserList.vue'
// Import module types
import type { UserModuleState } from '~/user/types'
2
3
4
5
6
7
8
9
Alias System Architecture Diagram β
Alias Configuration Best Practices β
1. IDE Support Configuration β
To enable better IDE intellisense and path navigation, configure tsconfig.json
:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
"#/*": ["types/*"],
"$/*": ["src/plugins/*"],
"~/*": ["src/modules/*"]
}
}
}
2
3
4
5
6
7
8
9
10
11
2. Usage Standards β
- Consistency: Use aliases uniformly within the team, avoid mixing with relative paths
- Readability: Aliases should be semantically clear and easy to understand
- Hierarchy Control: Avoid deep path hierarchies, use aliases appropriately to simplify paths
- Type Safety: Ensure type safety in path references with TypeScript
3. Common Usage Patterns β
// Comprehensive usage example in components
<script setup lang="ts">
// Global types
import type { UserInfo, ApiResponse } from '#/global'
// Global utilities
import { formatDate, validateForm } from '@/utils/common'
// Module APIs
import { userApi } from '~/base/api'
// Plugin functionality
import { useChart } from '$/charts/hooks'
// Global components
import MaButton from '@/components/MaButton.vue'
// Module components
import UserForm from '~/user/components/UserForm.vue'
</script>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Alias System Advantages β
- Simplified Paths: Avoid complex relative path references
- Improved Maintainability: No need to modify numerous import paths when moving files
- Enhanced Readability: Quickly identify file ownership through aliases
- Unified Standards: Maintain consistent reference styles in team development
- IDE Friendly: Better development experience with TypeScript and IDE support
Summary β
Through the introduction of these basic concepts, we have understood the core architectural design of the project:
Architectural Features β
- Modular Design: Business functions are divided by modules, achieving high cohesion and low coupling
- Plugin Architecture: Supports hot-plugging and extension of features
- Type Safety: Provides complete type support based on TypeScript
- Path Optimization: Simplifies file references through the alias system
Development Process β
Next Steps β
After mastering these basic concepts, it is recommended to study in the following order:
- Getting Started - Environment setup and project launch
- Configuration Guide - Detailed configuration options
- Routing & Menu - Route and menu configuration
- Module Development - In-depth modular development
- Plugin Development - Detailed plugin system explanation
Through systematic learning and practice, you will be able to efficiently develop front-end applications based on this architecture.