{{ file.filename }}
{{ formatFileSize(file.filesize || 0) }}
{{ getStatusText(file.status) }}
{{ file.progress.percent || 0 }}%
({{ file.progress.speedText }})
{{ file.error }}
```
--------------------------------
### Create Form Example
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/advanced/useForm.md
Use this snippet to create a new form for a specific resource. It handles form state, submission, and reset, with callbacks for success and error.
```javascript
import { useForm } from '@duxweb/dvha-core'
import { ref } from 'vue'
const { form, isLoading, onSubmit, onReset } = useForm({
path: 'users',
form: {
name: '',
email: '',
role: 'user'
},
action: 'create',
onSuccess: (data) => {
console.log('用户创建成功:', data)
// 可以进行页面跳转、显示成功提示等
},
onError: (error) => {
console.error('创建失败:', error)
}
})
function handleSubmit() {
onSubmit()
}
function handleReset() {
onReset()
}
```
--------------------------------
### Dux Configuration Example
Source: https://github.com/duxweb/dvha/blob/main/apps/cdn/README.md
This TypeScript snippet shows the basic configuration for the Dux framework, including API URL, default management settings, and component mappings.
```typescript
const config: IConfig = {
apiUrl: 'your-api-url',
defaultManage: 'admin',
manages: [
{
name: 'admin',
title: '管理系统标题',
routePrefix: '/admin',
components: {
authLayout: () => import('./pages/layout.vue'),
notFound: () => import('./pages/404.vue'),
},
menus: [
// 菜单配置
]
}
],
simpleDataProvider,
simpleAuthProvider,
}
```
--------------------------------
### Multi-Provider Form Example
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/advanced/useForm.md
Illustrates using the useForm hook with different data providers for distinct resources. Each useForm instance manages its own form state and submission logic.
```javascript
import { useForm } from '@duxweb/dvha-core'
// 使用默认数据提供者创建用户
const { form: userForm, onSubmit: submitUser } = useForm({
path: 'users',
action: 'create',
form: { name: '', email: '' }
})
// 使用分析服务创建报告
const { form: reportForm, onSubmit: submitReport } = useForm({
path: 'reports',
action: 'create',
providerName: 'analytics',
form: { title: '', type: 'monthly' }
})
// 使用支付服务创建订单
const { form: orderForm, onSubmit: submitOrder } = useForm({
path: 'orders',
action: 'create',
providerName: 'payment',
form: { amount: 0, currency: 'CNY' }
})
```
--------------------------------
### useMenu Hook Usage
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/router/useMenu.md
Demonstrates how to import and use the useMenu hook for managing application menus. It shows examples for both single-level and double-level menu modes.
```APIDOC
## useMenu Hook
### Description
The `useMenu` hook is designed to manage the application's menu system, supporting both single-level and double-level menu structures.
### Method
`useMenu(options?: { doubleMenu?: boolean })`
### Parameters
#### Query Parameters
- **doubleMenu** (boolean) - Optional - Whether to enable double-level menu mode. Defaults to `false`.
### Return Values
- **data** (Ref
): The complete menu tree data (only visible items).
- **originalData** (Ref): The original menu tree data (including hidden items).
- **getMenu** (Function): A function to retrieve menu data.
- **mainMenu** (Ref): Main menu data.
- **subMenu** (Ref): Sub-menu data.
- **isSubMenu** (Ref): Whether the sub-menu is displayed.
- **crumbs** (Ref): Breadcrumb path.
- **active** (Ref): The currently active menu item.
- **appActive** (Ref): The currently active main menu item.
- **subActive** (Ref): The currently active sub-menu item.
### Usage Example
```js
import { useMenu } from '@duxweb/dvha-core'
// Single-level menu mode
const { data, mainMenu, subMenu, crumbs, active } = useMenu()
// Double-level menu mode
const menuData = useMenu({ doubleMenu: true })
```
### Single-level Menu Example
```js
import { useMenu } from '@duxweb/dvha-core'
const {
mainMenu, // Main menu (excluding sub-levels)
subMenu, // Sub-menus of the current main menu
active, // Currently active menu
appActive, // Currently active main menu
subActive // Currently active sub-menu
} = useMenu()
console.log('Menu Status:', {
CurrentMainMenu: appActive.value,
CurrentSubMenu: subActive.value,
CurrentActive: active.value
})
```
```
--------------------------------
### Single Admin Panel Menu Configuration
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/router/menu.md
Example of configuring menus for a single administration panel. This includes defining dashboard, user management, system settings, and external links.
```javascript
import { createDux } from '@duxweb/dvha-core'
const app = createDux({
defaultManage: 'admin',
manages: [
{
name: 'admin',
title: '管理后台',
menus: [
// 仪表盘
{
name: 'dashboard',
label: '仪表盘',
path: 'dashboard',
icon: 'dashboard',
sort: 1,
component: () => import('./pages/Dashboard.vue')
},
// 用户管理
{
name: 'users',
label: '用户管理',
icon: 'users',
sort: 2
},
{
name: 'users.list',
label: '用户列表',
path: 'users',
parent: 'users',
sort: 1,
component: () => import('./pages/users/List.vue')
},
{
name: 'users.detail',
label: '用户详情',
path: 'users/:id',
parent: 'users',
hidden: true, // 隐藏在菜单中
component: () => import('./pages/users/Detail.vue')
},
// 系统管理
{
name: 'system',
label: '系统管理',
icon: 'system',
sort: 3
},
{
name: 'system.settings',
label: '系统设置',
path: 'system/settings',
parent: 'system',
sort: 1,
component: () => import('./pages/system/Settings.vue'),
meta: {
permissions: ['system.admin']
}
},
// 外部链接
{
name: 'docs',
label: '帮助文档',
loader: 'iframe',
path: 'https://docs.example.com',
icon: 'help',
sort: 4
}
]
}
]
})
```
--------------------------------
### Multiple Admin Panel Menu Configuration
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/router/menu.md
Example of configuring menus for multiple distinct management interfaces. This allows for separate navigation structures for different user roles or application sections.
```javascript
const app = createDux({
defaultManage: 'admin',
manages: [
// 系统管理端
{
name: 'admin',
title: '系统管理',
menus: [
{
name: 'dashboard',
label: '系统概览',
path: 'dashboard',
icon: 'dashboard',
component: () => import('./admin/Dashboard.vue')
},
{
name: 'users',
label: '用户管理',
path: 'users',
icon: 'users',
component: () => import('./admin/Users.vue')
}
]
},
// 用户中心
{
name: 'user',
title: '用户中心',
menus: [
{
name: 'profile',
label: '个人资料',
path: 'profile',
icon: 'profile',
component: () => import('./user/Profile.vue')
},
{
name: 'settings',
label: '账户设置',
path: 'settings',
icon: 'settings',
component: () => import('./user/Settings.vue')
}
]
}
]
})
```
--------------------------------
### Build Production Version
Source: https://github.com/duxweb/dvha/blob/main/apps/cdn/README.md
Execute this command to create a production-ready build of your application.
```bash
npm run build
```
--------------------------------
### Initialize Project with Specified Name
Source: https://github.com/duxweb/dvha/blob/main/packages/template/README.md
Specify a custom project name during initialization using bunx or npx.
```bash
bunx @duxweb/dvha-template init my-awesome-project
```
```bash
npx @duxweb/dvha-template init my-awesome-project
```
--------------------------------
### Basic File Upload Example with useUpload
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/advanced/useUpload.md
Demonstrates how to use the useUpload hook for basic file uploads. Configure upload path, file size and count limits, and control upload behavior with autoUpload set to false. Includes functions for selecting files, triggering uploads, and handling success/error callbacks. Also shows how to monitor overall upload progress.
```javascript
import { useUpload } from '@duxweb/dvha-core'
const { uploadFiles, open, trigger, isUploading, progress } = useUpload({
path: 'upload',
maxFileSize: 5 * 1024 * 1024, // 5MB
maxFileCount: 3,
multiple: true,
autoUpload: false, // 手动控制上传
onSuccess: (data) => {
console.log('文件上传成功:', data)
},
onError: (error) => {
console.error('上传失败:', error.message)
}
})
// 选择文件
function selectFiles() {
open()
}
// 开始上传
function startUpload() {
if (uploadFiles.value.length === 0) {
alert('请先选择文件')
return
}
trigger()
}
// 监听进度
watchEffect(() => {
const progress = overallProgress.value
console.log(`进度: ${progress.totalPercent}% (${progress.index}/${progress.totalFiles})`)
})
```
--------------------------------
### Install DVHA Pro Dependency
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/pro/installation.md
Install the DVHA Pro package using pnpm. This package includes dependencies for DVHA Core and DVHA NaiveUI.
```bash
pnpm add @duxweb/dvha-pro
```
--------------------------------
### Custom Floating Component Example
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/system/useOverlay.md
An example of a custom floating component that can be used with overlay functionalities. It includes customizable props for position, size, shape, animation, and mask behavior.
```vue
```
--------------------------------
### Full Form Example with Vue Template
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/advanced/useForm.md
A comprehensive example integrating the useForm hook within a Vue.js component, including template markup for input fields, select options, and submission buttons.
```vue
```
--------------------------------
### Basic Usage
Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/advanced/useUpload.md
Demonstrates the basic import and initialization of the useUpload hook.
```APIDOC
## Basic Usage
```js
import { useUpload } from '@duxweb/dvha-core'
const { uploadFiles, open, trigger, progress } = useUpload({
path: 'upload',
maxFileCount: 5,
autoUpload: true
})
```
```