### Install Dependencies and Start Project Source: https://github.com/duxweb/dvha/blob/main/apps/docs/pro/getting-started.md After initializing the project, run these commands to install dependencies and start the development server. This will launch a basic, runnable Pro backend project. ```bash pnpm install pnpm dev ``` -------------------------------- ### Minimal DVHA Core Setup Example Source: https://github.com/duxweb/dvha/blob/main/README.md This example demonstrates the basic setup for DVHA Core, including defining manages, routes, menus, and configuring data and authentication providers. Ensure you have Vue and TypeScript set up. ```typescript import type { IConfig } from '@duxweb/dvha-core' import { createDux, simpleAuthProvider, simpleDataProvider } from '@duxweb/dvha-core' import { createApp } from 'vue' import App from './App.vue' const app = createApp(App) const config: IConfig = { defaultManage: 'admin', manages: [ { name: 'admin', title: 'DVHA 后台管理系统', routePrefix: '/admin', routes: [ { name: 'admin.login', path: 'login', component: () => import('./pages/login.vue'), meta: { authorization: false }, }, ], menus: [ { name: 'home', path: 'index', icon: 'i-tabler:home', label: '首页', component: () => import('./pages/home.vue'), }, ], }, ], dataProvider: simpleDataProvider({ apiUrl: 'https://api.example.com', }), authProvider: simpleAuthProvider(), } app.use(createDux(config)) app.mount('#app') ``` -------------------------------- ### Development Setup and Testing Source: https://github.com/duxweb/dvha/blob/main/packages/template/README.md Commands for installing dependencies, running local tests, and using npm for development. ```bash # 安装依赖 bun install # 本地测试 bun run bin/index.js init test-project # 或者使用 npm npm install node bin/index.js init test-project ``` -------------------------------- ### Global Installation and Usage Source: https://github.com/duxweb/dvha/blob/main/packages/template/README.md Install the template globally and then use the command directly to initialize a project. ```bash # 安装到全局 npm install -g @duxweb/dvha-template # 然后可以直接使用 duxweb-dvha init my-project ``` -------------------------------- ### Basic Redirect Example Source: https://github.com/duxweb/dvha/blob/main/apps/docs/router/redirect.md Use `useRouter` and `useManage` to push a new route with a management prefix. Ensure `@duxweb/dvha-core` is installed. ```typescript import { useRouter } from 'vue-router' import { useManage } from '@duxweb/dvha-core' const router = useRouter() const manage = useManage() router.push(manage.getRoutePath('users')) ``` -------------------------------- ### Get Manage Configuration with Examples Source: https://github.com/duxweb/dvha/blob/main/apps/docs/guide/config.md Shows how to use `useManage` to get current manage settings, including feature flags like `register` and `forgotPassword`, and display the manage title. ```typescript // 获取当前管理端配置 import { useManage } from '@duxweb/dvha-core' const manage = useManage() // 根据功能开关显示/隐藏按钮 const showRegister = manage.register // false const showForgotPassword = manage.forgotPassword // true // 显示管理端标题 console.log(manage.title) // '管理后台' ``` -------------------------------- ### Get Theme Configuration with Examples Source: https://github.com/duxweb/dvha/blob/main/apps/docs/guide/config.md Illustrates fetching theme configuration, specifically the logo, using the `useTheme` hook. ```typescript // 获取主题配置 import { useTheme } from '@duxweb/dvha-core' const theme = useTheme() // 获取当前主题的 Logo console.log(theme.logo) // '/images/logo.png' ``` -------------------------------- ### Install Dependencies Source: https://github.com/duxweb/dvha/blob/main/apps/cdn/README.md Run this command in your terminal to install all necessary project dependencies. ```bash npm install ``` -------------------------------- ### Get Global Configuration with Examples Source: https://github.com/duxweb/dvha/blob/main/apps/docs/guide/config.md Demonstrates how to fetch global configuration using `useConfig` and access specific properties like `title` and `extends.analytics.enabled`. ```typescript // 获取全局配置 import { useConfig } from '@duxweb/dvha-core' const config = useConfig() // 在模板中显示应用标题 console.log(config.title) // '我的管理系统' // 获取扩展配置 console.log(config.extends?.analytics?.enabled) // true ``` -------------------------------- ### GET Request Example Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/system/useClient.md An example of how to perform a GET request using the `request` function obtained from the `useClient` hook to fetch statistical data. ```APIDOC ## GET Request Example ### Description This example demonstrates how to use the `request` function to perform a GET request to retrieve statistical data. It includes basic error handling. ### Method GET ### Endpoint `/api/statistics` ### Query Parameters - **period** (string) - Required - The time period for the statistics (e.g., 'month'). - **category** (string) - Required - The category of statistics to retrieve (e.g., 'sales'). ### Request Example ```js import { useClient } from '@duxweb/dvha-core' const { request } = useClient() // GET Request const fetchData = async () => { try { const response = await request({ path: '/api/statistics', method: 'GET', query: { period: 'month', category: 'sales' } }) console.log('Statistics data:', response.data) return response.data } catch (error) { console.error('Request failed:', error) throw error } } ``` ### Response #### Success Response (200) - **data** (any) - The statistical data returned from the server. ``` -------------------------------- ### Basic Single Manage Configuration Example Source: https://github.com/duxweb/dvha/blob/main/apps/docs/guide/config.md Provides a comprehensive example of setting up a single manage configuration, including title, default manage, feature flags, components, menus, extended configurations, data providers, and i18n. ```typescript import { i18nProvider } from '@duxweb/dvha-core' import enUS from './locales/en-US.json' import zhCN from './locales/zh-CN.json' // 创建数据提供者 const dataProvider = simpleDataProvider({ apiUrl: 'https://api.example.com' }) const config: IConfig = { title: '企业管理系统', defaultManage: 'admin', manages: [ { name: 'admin', title: '管理后台', routePrefix: '/admin', // 功能开关 - 供组件调用 forgotPassword: true, updatePassword: true, components: { authLayout: () => import('./layouts/AdminLayout.vue'), notFound: () => import('./pages/404.vue'), }, menus: [ { name: 'dashboard', label: '仪表板', path: 'index', icon: 'i-tabler:dashboard', component: () => import('./pages/Dashboard.vue'), }, { name: 'users', label: '用户管理', path: 'users', icon: 'i-tabler:users', component: () => import('./pages/Users.vue'), }, ] } ], // 扩展配置 - 供组件调用 extends: { analytics: { enabled: true, trackingId: 'GA-XXXXXXXX', }, }, dataProvider, authProvider: simpleAuthProvider(), // 全局国际化配置 i18nProvider: i18nProvider({ locale: 'zh-CN', fallbackLocale: 'en-US', messages: { 'zh-CN': zhCN, 'en-US': enUS } }), } ``` -------------------------------- ### Start Development Server Source: https://github.com/duxweb/dvha/blob/main/apps/cdn/README.md Use this command to launch the local development server for testing and development. ```bash npm run dev ``` -------------------------------- ### Basic Upload Example Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/advanced/useUpload.md A practical example demonstrating how to use the useUpload hook for basic file uploads with manual control. ```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, // Manual upload control onSuccess: (data) => { console.log('File upload successful:', data) }, onError: (error) => { console.error('Upload failed:', error.message) } }) // Function to select files function selectFiles() { open() } // Function to start the upload function startUpload() { if (uploadFiles.value.length === 0) { alert('Please select files first') return } trigger() } // Watch for progress updates watchEffect(() => { const progress = overallProgress.value console.log(`Progress: ${progress.totalPercent}% (${progress.index}/${progress.totalFiles})`) }) ``` -------------------------------- ### Install DVHA Core Package Source: https://github.com/duxweb/dvha/blob/main/README.md Use npm, yarn, or pnpm to install the `@duxweb/dvha-core` package. ```bash # npm npm install @duxweb/dvha-core # yarn yarn add @duxweb/dvha-core # pnpm pnpm add @duxweb/dvha-core ``` -------------------------------- ### Complete Application Example with useJson Source: https://github.com/duxweb/dvha/blob/main/apps/docs/hooks/advanced/useJson.md This example demonstrates a complete application built with the useJson hook. It includes state management, business logic, event handlers, and dynamic schema generation for the UI. Ensure all necessary Naive UI components and Vue reactivity functions are imported. ```vue