### Full Usage Example with PForm and PGrid
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
A complete Vue 3 example showcasing the integration of PForm and PGrid components. It includes component setup, global configuration using `setup`, data binding, event handling, and dynamic configuration of form and grid settings.
```vue
```
--------------------------------
### Main Application Setup
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.zh.md
Example of setting up the Vue application with Ant Design Vue and Vue UI Kit, including adding a custom formatter.
```typescript
/*main.ts*/
import { createApp } from 'vue';
import App from './App.vue';
import Antd from 'ant-design-vue';
import UIKit from '@vue-ui-kit/ant';
import '@vue-ui-kit/ant/scss';
/*创建渲染器(推荐使用tsx配置)*/
import { setupKit } from './setup/kit.tsx';
/*创建格式化*/
UIKit.addFormatter({
test: ({ row, column, cellValue }) => 'test:...' + 'field:' + column.field + '...v:' + cellvalue,
});
createApp(App).use(Antd).use(UIKit).mount('#app');
```
--------------------------------
### PGrid Basic Example
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.zh.md
Vue component script setup for configuring and using the PGrid enhanced data table, including columns, form configuration, and proxy settings for data fetching.
```vue
```
--------------------------------
### Install Vue UI Kit
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.zh.md
Commands to install the Vue UI Kit package using npm, yarn, or pnpm.
```bash
npm install @vue-ui-kit/ant
# or
yarn add @vue-ui-kit/ant
# or
pnpm add @vue-ui-kit/ant
```
--------------------------------
### Installation
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Install the Vue UI Kit using npm, yarn, or pnpm package managers.
```bash
npm install @vue-ui-kit/ant
# or
yarn add @vue-ui-kit/ant
# or
pnpm add @vue-ui-kit/ant
```
--------------------------------
### Vue Form Group Basic Example
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.zh.md
Demonstrates the basic setup of a PFormGroup component in Vue.js, including defining project data, configuring form settings with validation rules, and handling save operations.
```vue
保存所有项目
```
--------------------------------
### Basic Vue Form Example with TypeScript
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Demonstrates a standard form setup using Vue.js and TypeScript. It defines form data structure, configures form items with validation and input types, and includes a submit handler.
```vue
```
--------------------------------
### Responsive Layout Tools Comprehensive Example
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Presents a comprehensive example integrating multiple responsive layout utilities, including `defaultItemResponsive`, `labelColDict`, and `getButtonResponsive`. It illustrates creating a dynamic form layout calculator that assigns responsive column properties to form items and calculates button area layout.
```typescript
import { getButtonResponsive, defaultItemResponsive, labelColDict } from '@vue-ui-kit/ant';
// 创建一个动态表单布局计算器
function createFormLayout(items: Array<{ title: string }>) {
return {
// 表单项布局
items: items.map((item) => ({
...item,
col: defaultItemResponsive, // 使用默认响应式布局
labelCol: labelColDict[item.title.length] || labelColDict[4], // 根据标题长度选择
})),
// 按钮区域布局
buttonCol: getButtonResponsive(items.length),
};
}
// 使用示例
const layout = createFormLayout([{ title: '姓名' }, { title: '邮箱地址' }, { title: '手机号码' }]);
console.log('按钮布局:', layout.buttonCol);
// 自动计算最后一行剩余空间给按钮使用
```
--------------------------------
### Vue Component Usage Example
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Provides a complete Vue component example demonstrating the practical application of the library's utilities. It shows how to dynamically render form items with responsive layouts and calculate button area layout using `getButtonResponsive`, `defaultItemResponsive`, and `labelColDict`.
```vue
提交重置
```
--------------------------------
### Vue FormGroup Basic Usage Example
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Demonstrates the basic setup of the FormGroup component, binding data using v-model, and configuring form settings via computed properties. Includes a save button that triggers validation of all form instances.
```vue
Save All Projects
```
--------------------------------
### Configure Global Defaults
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Customize global default settings for form and grid components using the `setup` function provided by the library.
```typescript
/*main.ts*/
import { createApp } from 'vue';
import App from './App.vue';
import Antd from 'ant-design-vue';
import UIKit, { setup } from '@vue-ui-kit/ant';
import '@vue-ui-kit/ant/style.scss';
// Configure global defaults
setup({
form: {
labelCol: { span: 8 }, // Modify form label column width
wrapperCol: { span: 14 }, // Modify form input column width
},
grid: {
align: 'center', // Set default table alignment
lazyReset: true, // Don't auto-submit after reset
fitHeight: 200, // Set adaptive height
},
});
createApp(App).use(Antd).use(UIKit).mount('#app');
```
--------------------------------
### getButtonResponsive Usage Example
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Provides examples for using the `getButtonResponsive` utility. This function helps calculate responsive layout configurations for buttons, either automatically based on the number of form items or by accepting custom responsive arrays.
```typescript
import { getButtonResponsive, defaultItemResponsive } from '@vue-ui-kit/ant';
// 方式1: 根据表单项数量自动计算按钮响应式布局
const buttonSpan1 = getButtonResponsive(3); // 3个表单项
console.log(buttonSpan1);
// 结果: { xs: 24, sm: 24, md: 24, lg: 0, xl: 0, xxl: 6 }
// 方式2: 传入自定义响应式配置数组
const customResponsive = [
{ xs: 24, sm: 12, md: 8, lg: 6, xl: 6, xxl: 6 },
{ xs: 24, sm: 12, md: 8, lg: 6, xl: 6, xxl: 6 },
];
const buttonSpan2 = getButtonResponsive(customResponsive);
console.log(buttonSpan2);
// 计算剩余空间作为按钮区域
```
--------------------------------
### Importing Utility Functions
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Shows how to import various utility functions from the @vue-ui-kit/ant npm package. These utilities cover responsive layout calculations, table column cleaning, and configuration setup.
```typescript
import {
// 响应式布局工具
getButtonResponsive,
defaultItemResponsive,
defaultLabelCol,
labelColDict,
get24rest,
// 表格工具
cleanCol,
// 其他工具
UIKitConfig,
setup,
} from '@vue-ui-kit/ant';
```
--------------------------------
### labelColDict Usage Example
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Demonstrates the usage of `labelColDict`, a utility that maps the character count of a label to appropriate responsive column configurations. It shows how to retrieve configurations and apply them directly within form item settings.
```typescript
import { labelColDict } from '@vue-ui-kit/ant';
// 根据标签字符数获取合适的labelCol配置
const labelCol = labelColDict[4]; // 4个字符的标签
console.log(labelCol);
// 结果: { xs: 12, sm: 4, md: 6, lg: 9, xl: 7, xxl: 6 }
// 在表单配置中使用
const formSetting = computed(() => ({
items: [
{
field: 'username',
title: '用户名称', // 4个字符
labelCol: labelColDict[4],
itemRender: {
name: '$input',
props: { placeholder: '请输入用户名称' },
},
},
],
}));
```
--------------------------------
### Vue PForm Basic Example with TypeScript
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.zh.md
Demonstrates creating a dynamic form using the PForm component with TypeScript. It defines form data structure, settings with validation rules, and a submit handler.
```vue
```
--------------------------------
### Common Import Errors
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Illustrates incorrect ways to import from the @vue-ui-kit/ant library. These examples highlight common mistakes such as importing from incorrect subpaths or attempting invalid import syntax.
```typescript
// ❌ 错误:这样无法导入组件
import { PForm, PGrid } from '@vue-ui-kit/ant/components';
// ❌ 错误:组件不能从utils路径导入
import { PForm } from '@vue-ui-kit/ant/utils';
// ❌ 错误:混合默认导入和组件导入
import UIKit, PForm from '@vue-ui-kit/ant'; // 语法错误
// ✅ 正确:从主包路径导入所有内容
import {
PForm,
PGrid,
getButtonResponsive,
labelColDict
} from '@vue-ui-kit/ant';
```
--------------------------------
### PGrid Component Basic Usage
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Example of configuring and using the PGrid component for displaying data in a table. It includes setting up columns, defining a search form, and configuring data fetching via AJAX.
```vue
```
--------------------------------
### PForm component configuration with TypeScript types
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Example of configuring `PForm` using `PFormProps` and `PFormItemProps` for defining form fields, validation rules, and input renderers. Includes type definitions for form data.
```ts
import { ref, computed } from 'vue';
import { PFormProps, PFormItemProps } from '@vue-ui-kit/ant';
// Define form data type
interface UserForm {
name: string;
email: string;
age?: number;
gender: string;
}
const formData = ref({
name: '',
email: '',
age: undefined,
gender: '',
});
// Use PFormProps type
const formSetting = computed>(() => ({
items: [
{
field: 'name',
title: '姓名',
rule: [{ required: true, message: '请输入姓名' }],
itemRender: {
name: '$input',
props: { placeholder: '请输入姓名' },
},
},
{
field: 'email',
title: '邮箱',
rule: [
{ required: true, message: '请输入邮箱' },
{ type: 'email', message: '邮箱格式不正确' },
],
itemRender: {
name: '$input',
props: { placeholder: '请输入邮箱' },
},
},
] as PFormItemProps[],
}));
```
--------------------------------
### Register custom cell formatters for PGrid
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Shows how to register custom cell formatters for the `PGrid` component using `UIKit.addFormatter`. Provides examples for formatting currency and percentages.
```ts
UIKit.addFormatter({
currency: ({ cellValue }) => `$${cellValue?.toLocaleString() || '0'}`,
percentage: ({ cellValue }) => `${(cellValue * 100).toFixed(2)}%`
});
```
--------------------------------
### Custom Renderer Setup
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.zh.md
TypeScript code for setting up custom cell and form renderers using Vue UI Kit, specifically for a paragraph and a switch component.
```tsx
/*kit.tsx*/
import UIKit from '@vue-ui-kit/ant';
import { TypographyParagraph, Switch } from 'ant-design-vue';
export const setupKit = () => {
/*注册$paragraph作为单元格渲染器*/
UIKit.addRender('$paragraph', {
renderDefault({ props = {} }: RenderOptions, { row, field }: RenderTableParams) {
const content = props.getContent?.({ row, field }) ?? (valued(field) ? row[field!] : '');
return valued(field) ? (
) : null;
},
});
/*注册$switch 作为表单渲染器*/
UIKit.addRender('$switch', {
renderItemContent(
{ props = {}, events = {} }: RenderOptions,
{ data, field }: RenderFormParams,
) {
return valued(field) ? (
{
events.change?.({ data, field }, ...arg);
}}
/>
) : null;
},
});
};
/*
* 已内置了渲染器
*
$input: Input,
AInput: Input,
$textarea: Textarea,
Textarea: Textarea,
$number: InputNumber,
AInputNumber: InputNumber,
$select: Select,
ASelect: Select,
$date: DatePicker,
ADatePicker: DatePicker,
$range: RangePicker,
ARangePicker: RangePicker,
AAutoComplete: AutoComplete,
$Cascader: Cascader,
ACascader: Cascader,
ACheckbox: Checkbox,
AMentions: Mentions,
ARate: Rate,
ASlider: Slider,
$time: TimePicker,
ATimePicker: TimePicker,
ATreeSelect: TreeSelect,
*
* */
```
--------------------------------
### PGrid component configuration with TypeScript types
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Example of configuring `PGrid` using `PGridProps` for defining columns, form configurations, and AJAX proxy settings. Includes type definitions for data and query interfaces.
```ts
import { computed } from 'vue';
import { PGridProps } from '@vue-ui-kit/ant';
// Define data type
interface Student {
id: number;
name: string;
email: string;
age: number;
}
// Define query form type
interface StudentQuery {
keyword?: string;
age?: number;
}
// Use PGridProps type
const gridSetting = computed>(() => ({
columns: [
{ field: 'name', title: '姓名', width: 200 },
{ field: 'email', title: '邮箱', width: 200 },
{ field: 'age', title: '年龄', width: 100 },
],
formConfig: {
items: [
{
field: 'keyword',
title: '关键字',
itemRender: {
name: '$input',
props: { placeholder: '请输入关键字' },
},
},
],
},
proxyConfig: {
ajax: {
query: ({ form, page }) => api.getStudents({ ...form, ...page }),
},
},
}));
```
--------------------------------
### Advanced Vue Form Example with Custom Slots (TSX)
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Illustrates using custom slots for rendering form fields, specifically showing how to integrate Ant Design's Switch component (`a-switch`) directly within a form item using TSX syntax.
```vue
```
--------------------------------
### Vue Form Group Custom Menu Example
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.zh.md
Illustrates how to add custom menus to a PFormGroup component, enabling actions like copy, delete, export, and archive based on item data and visibility rules.
```vue
```
--------------------------------
### Vue PForm Custom Slot Example with TSX
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.zh.md
Illustrates how to use custom slots within the PForm component for advanced UI rendering, specifically for a custom switch input.
```vue
```
--------------------------------
### Webpack Configuration for SCSS
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Configure Webpack (or Vue CLI's webpack setup) to process SCSS files by adding the library's SCSS path to `additionalData` in `webpack.config.js` or `vue.config.js`.
```javascript
// webpack.config.js or vue.config.js
module.exports = {
css: {
loaderOptions: {
sass: {
additionalData: `@import '@vue-ui-kit/ant/dist/style.scss';`,
},
},
},
};
```
--------------------------------
### Register custom form field renderers
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Demonstrates how to register custom renderers for form fields using `UIKit.addRender`. Includes an example for a `$switch` renderer, showing how to bind values and handle events.
```tsx
import UIKit from '@vue-ui-kit/ant';
import { Switch } from 'ant-design-vue';
UIKit.addRender('$switch', {
renderItemContent({ props = {}, events = {} }, { data, field }) {
return (
{
events.change?.({ data, field }, ...args);
}}
/>
);
},
});
```
--------------------------------
### Alternative Style Import Methods
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Provides various methods for importing the library's styles, including direct SCSS/CSS imports, SCSS @use syntax, and integration within Vue single-file components.
```scss
// In your main.scss file
@import '@vue-ui-kit/ant/dist/style.scss';
```
```typescript
import '@vue-ui-kit/ant/dist/style.scss';
// or
import '@vue-ui-kit/ant/dist/style.css';
```
```scss
@use '@vue-ui-kit/ant/style.scss';
// or use full path
@use '@vue-ui-kit/ant/dist/style.scss';
```
```vue
```
--------------------------------
### Correct Import Methods
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Demonstrates the recommended way to import components, types, and utility functions from the @vue-ui-kit/ant library. It shows both separate imports for specific items and default imports combined with named imports.
```typescript
// 方式1: 分别导入 (推荐)
import {
// 组件
PForm,
PGrid,
PFormGroup,
PGroupBlock,
PromisePicker,
// 类型
PGridProps,
PFormProps,
PFormItemProps,
ColumnProps,
UIKitConfig,
// 工具方法
getButtonResponsive,
labelColDict,
defaultItemResponsive,
get24rest,
cleanCol,
// 配置方法
setup,
addFormatter,
addRender,
} from '@vue-ui-kit/ant';
// 方式2: 默认导入 + 命名导入
import UIKit, { PForm, PGrid, setup } from '@vue-ui-kit/ant';
```
--------------------------------
### Pre-defined label column configurations
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Provides pre-defined label column configurations for different text lengths using `labelColDict`. Demonstrates usage within form items for dynamic label sizing based on content length.
```ts
import { labelColDict } from '@vue-ui-kit/ant';
// Usage in form items
{
field: 'shortField',
title: 'Name', // 2 characters
labelCol: labelColDict[2],
}
{
field: 'longerField',
title: 'Description', // 4+ characters
labelCol: labelColDict[4],
}
```
--------------------------------
### Component Instance Types
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Demonstrates how to obtain and utilize instances of PGrid and PForm components. It shows how to reference component instances using `ref` and call their methods for actions like reloading data or resetting form fields.
```typescript
import { ref } from 'vue';
import { PGridInstance, PFormInstance } from '@vue-ui-kit/ant';
// PGrid 组件实例
const gridRef = ref>();
// 调用实例方法
gridRef.value?.commitProxy.reload();
gridRef.value?.resizeTable();
// PForm 组件实例
const formRef = ref();
// 调用实例方法
formRef.value?.reset();
formRef.value?.$form.validateFields();
```
--------------------------------
### Vue FormGroup Advanced Usage with Custom Menus
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Illustrates advanced configuration of the FormGroup component, including custom menu items for each entry and a custom function to create new items. It also shows how to handle menu actions and provides a placeholder for form settings.
```vue
```
--------------------------------
### Advanced TypeScript type usage for PGrid and Toolbar
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Demonstrates advanced type usage for `PGrid` columns with custom formatters and slots, `ToolbarConfig` for defining buttons and tools, and `UIKitConfig` for global UI settings.
```ts
// 1. Custom column type
import { ColumnProps } from '@vue-ui-kit/ant';
interface Student { id: number; name: string; email: string; age: number; }
const customColumns: ColumnProps[] = [
{
field: 'name',
title: '姓名',
formatter: (arg) => arg.cellValue?.toUpperCase(),
},
{
field: 'actions',
title: '操作',
slots: {
default: ({ row, rowIndex }) => (
),
},
},
];
// 2. Toolbar configuration type
import { ToolbarConfig } from '@vue-ui-kit/ant';
const toolbarConfig: ToolbarConfig = {
buttons: [
{
code: 'add',
content: '新增',
type: 'primary',
icon: 'PlusOutlined',
},
],
tools: [
{
code: 'refresh',
icon: 'ReloadOutlined',
},
],
};
// 3. Setup configuration type
import { UIKitConfig } from '@vue-ui-kit/ant';
const kitConfig: UIKitConfig = {
form: {
labelCol: { span: 8 },
wrapperCol: { span: 14 },
},
grid: {
align: 'center',
lazyReset: true,
fitHeight: 200,
},
};
```
--------------------------------
### Vue UI Kit Ant - TypeScript Type Definitions
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.zh.md
Highlights the comprehensive TypeScript support provided by the library, listing key type definitions available for components like PForm, PGrid, and their items.
```ts
import type {
PFormProps,
PFormItemProps,
PFormGroupProps,
PGridProps,
ColumnProps
} from '@vue-ui-kit/ant';
```
--------------------------------
### Basic Usage
Source: https://github.com/vue-ui-kit/ant/blob/main/packages/ui-kit/README.md
Integrate the Vue UI Kit into your Vue 3 application by importing necessary modules and styles in your main entry file (e.g., main.ts).
```typescript
/*main.ts*/
import { createApp } from 'vue';
import App from './App.vue';
import Antd from 'ant-design-vue';
import UIKit from '@vue-ui-kit/ant';
// Import styles - choose one of the following methods:
// Method 1: Import SCSS source files (recommended, allows variable override)
import '@vue-ui-kit/ant/style.scss';
// Method 2: Import compiled CSS file
// import '@vue-ui-kit/ant/style.css';
createApp(App).use(Antd).use(UIKit).mount('#app');
```