Vben Admin: A Beginner's Guide to Simple Modifications
What is Vben Admin?
Vben Admin is a comprehensive solution for developing modern admin dashboards and management systems. It is built with Vue 3.0, Vite, and TypeScript, offering a robust and scalable foundation for enterprise applications.
Key Features:
- Cutting-Edge Technology Stack: Developed using the latest front-end technologies, including Vue 3, Vite, and TypeScript.
- Ready-to-Use: Comes with a complete set of admin dashboard features right out of the box.
- Multi-UI Framework Support: Compatible with popular UI libraries such as Ant Design Vue, Element Plus, and Naive UI.
- Full Internationalization: Includes a well-designed multi-language solution for seamless localization.
System Requirements
Before starting with Vben Admin, ensure that your development environment meets the following prerequisites:
- Node.js: Version 20.15.0 or higher.
- Package Manager: Only supports pnpm.
Project Setup and Installation
Vben Admin uses a Monorepo structure for project management. For more details, refer to the concept documentation. This guide focuses on the development of the web-antd
version.
Project Directory Structure
Below is an overview of the key directories and files in the web-antd
project:
1 | apps/web-antd/src/ |
1. Clone the Project Repository
To get the project source code, run the following commands:
1 | # Clone the repository from GitHub |
2. Install Dependencies
Follow these steps to install the necessary dependencies:
1 | # Enable the project's specified pnpm version |
3. Start the Project
Run the following commands to start the development server:
1 | # Navigate to the Ant Design Vue version directory |
Modify Language Settings
Vben Admin provides a comprehensive internationalization solution, supporting multi-language switching. For more details, refer to the official documentation. Below are the steps to modify the default language settings:
Change Default Language
To set the default language, modify the file apps/web-antd/src/preferences.ts
as follows:
1 | import { defineOverridesPreferences } from '@vben/preferences'; |
Disable the Language Toggle Button
If the language toggle button is not needed, you can disable it in src/preferences.ts
:
1 | export const overridesPreferences = defineOverridesPreferences({ |
Notes
- After making changes, clear the browser cache to apply the updates.
- Language files are located in the
src/locales/langs/
directory.
API Implementation Example
In Vben Admin, API-related code is recommended to be placed in the src/api
directory and organized by functional modules (reference):
1 | src/api/ |
Below is an example implementation for the process management module:
1 | import { requestClient } from '#/api/request'; |
Usage Instructions
- All API requests are handled uniformly using
requestClient
(reference).
ProcessSearch Component Implementation Guide
The search component is implemented using the Vben Form (reference).
Implementation
The component is defined as follows:
1 | <script lang="ts" setup> |
Explanation
- Event Handling: The
search
event is emitted when the form is submitted, sending the search parameters (ProcessSearchParams
) to the parent component. - Dynamic Layout: The form uses a responsive grid system to adapt to different screen sizes, making it mobile-friendly.
- Fields:
- Process Name: An input field for entering the process name.
- Status: A dropdown to select the status (
Active
orInactive
). - Creation Date: A range picker for selecting a date range.
- Customizable Options:
- The search button text is set to “Search.”
- The form supports triggering the search using the Enter key.
- Collapsible Form: Includes an option to collapse the form for better user experience.
This implementation provides a clean, responsive, and easy-to-use search interface for process management.
src/views/process/index.vue
1 | <script lang="ts" setup> |
Key Features and Explanation:
Query Form:
- A collapsible form that includes fields for keyword, type, and date filtering.
- Triggered submission calls
onSubmit
, which reloads the data table with new filters.
Data Table:
- Configured with pagination, sorting, and dynamic data loading from a simulated API call.
- Includes action buttons for row-level operations (Edit/Delete).
Dynamic API Integration:
- Uses the
proxyConfig
feature of VxeGrid to fetch data dynamically based on pagination parameters.
- Uses the
Responsive Layout:
- The query form and table use grid-based responsive designs for optimal display across devices.
Adding a New Route for Process Management
To integrate the process management module into your Vben Admin project, you’ll need to update the routing configuration and localization files. Here’s how to do it step-by-step:
Step 1: Create a New Route
Add the following file: src/router/routes/modules/process.ts
1 | import { BasicLayout } from '#/layouts'; // Import the basic layout for the module. |
Step 2: Add Localization Keys
To ensure proper display of titles and labels, update the localization file src/locales/langs/en-US/process.json
with the following content:
1 | { |
This setup provides a clean and modular approach to adding new features to your Vben Admin project while supporting localization.