---
url: /ecosystem/eslint-config.md
---
# @plus-pro-components/eslint-config
[](https://www.npmjs.org/package/@plus-pro-components/eslint-config)
## 简介
`@plus-pro-components/eslint-config` 是 `plus-pro-components` 内置的 eslint 配置集合,集成了常用的 `vue`、`ts`、`import`插件,为快速配置 eslint 提供保障。
## 使用
* 安装
```sh
pnpm i @plus-pro-components/eslint-config
```
* 配置
```js {4}
// .eslintrc.js
module.exports = {
root: true,
extends: ['@plus-pro-components/eslint-config']
}
```
---
---
url: /ecosystem/resolver.md
---
# @plus-pro-components/resolver
[](https://www.npmjs.org/package/@plus-pro-components/resolver)
## 简介
`@plus-pro-components/resolver` 是[plus-pro-components](https://plus-pro-components.com/)为 [unplugin-vue-components](https://github.com/unplugin/unplugin-vue-components) 提供的官方解析器,可以按需自动导入`plus-pro-components`的组件及其样式文件。
## 使用
* 安装
```sh
pnpm i @plus-pro-components/resolver
```
* 配置
```ts {5,11}
// vite.config.ts
import { defineConfig } from 'vite'
import Components from 'unplugin-vue-components/vite'
import { PlusProComponentsResolver } from '@plus-pro-components/resolver'
export default defineConfig({
// ...
plugins: [
Components({
resolvers: [PlusProComponentsResolver({ importStyle: 'css' })]
})
]
})
```
## 配置参数说明
| 参数名称 | 说明 | 类型 | 默认值 | 是否必须 |
| -------------------- | ------------------------ | ----------------------------------------------------- | ------- | -------- |
| `ssr` | 是否是 ssr | `boolean` | `false` | 否 |
| `importStyle` | 导入的样式文件类型 | `string` | `css` | 否 |
| `exclude` | 不需要加载的组件名称正则 | `RegExp` | | 否 |
| `noStylesComponents` | 不需要加载样式的组件名称 | `array` | | 否 |
---
---
url: /api/utils.md
---
# @plus-pro-components/utils
[](https://www.npmjs.org/package/@plus-pro-components/utils)
## 简介
`@plus-pro-components/utils` 提供了 web 开发常用的工具库,它具有以下特点:
* 和`plus-pro-components`解耦,独立的 npm 包,可选安装。
* 安装后结合 plus-pro-components 使用会非常方便。
* 它提供了基于 ES Module 的开箱即用的 [Tree Shaking](https://webpack.js.org/guides/tree-shaking/) 功能,无需担心引入会导致打包体积增大。
* 使用 TypeScript 编写,提供 d.ts,使用起来安全便捷。
有新的工具需求 👉 欢迎 [issues](https://github.com/plus-pro-components/plus-pro-components/issues)
## 独立安装
::: code-group
```sh [pnpm]
pnpm install @plus-pro-components/utils
```
```sh [npm]
npm install @plus-pro-components/utils --save
```
```sh [yarn]
yarn add @plus-pro-components/utils
```
:::
## 使用示例
```ts
import { formatMoney } from '@plus-pro-components/utils'
formatMoney('100') // ¥100.00
```
---
---
url: /guide/installation.md
---
# 安装
## 环境支持
| [](http://godban.github.io/browsers-support-badges/) | [](http://godban.github.io/browsers-support-badges/) | [](http://godban.github.io/browsers-support-badges/) | [](http://godban.github.io/browsers-support-badges/) |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Edge | last 2 versions | last 2 versions | last 2 versions |
### 版本
`PlusProComponents` 目前处于功能稳定阶段。
[](https://www.npmjs.org/package/plus-pro-components)
## 使用包管理器 推荐
::: warning 注意
`plus-pro-components`大于等于 `0.0.11` 版本,`element-plus`不再作为`plus-pro-components`的依赖,需要单独安装。
:::
**建议您使用包管理器 ([pnpm](https://pnpm.io/)推荐 , [yarn](https://classic.yarnpkg.com/lang/en/),[npm](https://www.npmjs.com/)) 安装 plus-pro-components**。
::: code-group
```sh [pnpm]
pnpm install plus-pro-components
```
```sh [yarn]
yarn add plus-pro-components
```
```sh [npm]
npm install plus-pro-components --save
```
:::
## 浏览器直接引入
直接通过浏览器的 HTML 标签导入 plus-pro-components,然后就可以使用全局变量 `PlusProComponents` 了。
根据不同的 CDN 提供商有不同的引入方式, 我们在这里以[unpkg](https://unpkg.com) 和 [jsDelivr](https://jsdelivr.com) 举例。 你也可以使用其它的 CDN 供应商。
### unpkg
```html{10,12}
```
### jsDelivr
```html{10,12}
```
::: warning 注意
默认使用最新版本,使用时建议加上版本号 如使用`0.0.1`版本,防止因版本导致应用出现问题。
:::
---
---
url: /guide/dark-mode.md
---
# 暗黑模式
支持 element-plus 的暗黑模式,点击本网站右上角 **切换暗黑模式** 按钮,去[组件](/components/layout.html)页面即可体验。
[element-plus 暗黑模式文档](https://element-plus.org/zh-CN/guide/dark-mode.html)。
---
---
url: /guide/upgrade.md
---
# 版本升级
本记录只记录影响较大变更,对于一般[新功能、性能提升和问题修复](/guide/changelog.html)不在此记录。
## 从 v0.1.18 升级到 v0.1.19
* [PlusLayout](/components/layout.html) 布局样式发生变化,注意适配。
## 从 v0.1.14 升级到 v0.1.15
* [PlusSearch](/components/search.html#search-attributes) 新增了折叠动画
默认开启,不需要的话,设置 `collapseTransition` 为 `false`即可。
```html
```
* [PlusColumn](/components/config.html) 中对 `options` 新增了 `optionsMap`,可以对 `options` 中的字段显示进行自定义。 [参考](/components/config.html)
* [PlusColumn](/components/config.html) 中 `tooltip` 新增了计算属性支持。 [参考](/components/config.html)
## 从 v0.1.13 升级到 v0.1.14
* [PlusPage](/components/page.html) Exposes 变更 [参考](/components/page.html#page-exposes)
`handleRest` 方法已废弃(未来会在 v0.2.0 版本中移除),请使用 `handleReset `代替。 [参考](/components/page.html#page-exposes)
## 从 v0.1.8 升级到 v0.1.11
* 提升了组件 TS 类型兼容性
在 v0.1.8 版本的基础上,提升了组件的 TS 类型兼容性,不存在的类型不再会提示类型错误。
## 从 v0.1.7 升级到 v0.1.8
* [PlusColumn](/components/config.html) 中的 `formItemProps` 中的 `labelWidth` 开始生效,原来[PlusColumn](/components/config.html) 中的配置 `labelWidth` 不再生效。
```ts
import type { PlusColumn } from 'plus-pro-components'
const columns: PlusColumn[] = [
{
label: 'test',
prop: 'test',
labelWidth: '100px', // [!code --]
formItemProps: {
labelWidth: '100px' // [!code ++]
}
}
]
```
* 组件 TS 类型更加严格
组件的 TS 类型更加严格了,提示性更好了,兼容性降低了,不影响功能,但是会提示类型错误。
## 从 v0.1.4 升级到 v0.1.6
### [PlusDrawerForm](/components/drawer-form.html)
* 废弃了 `drawer` props,el-drawer 的 props 直接在 [PlusDrawerForm](/components/drawer-form.html) 上写。
## v0.1.0
### 更加友好
* 重构了 [PlusFormItem](/components/form-item.html) 和重 [PlusDisplay](/components/display-item.html) 组件,对新功能扩展更加友好。
* 重构了 d.ts 生成工具,ts 提示由原来的 `80%` 提升至 `100%`,对用户使用更加友好。
### 体积更小
* 整包体积由原来的 `39.5MB` 优化至 `9.5MB`,体积减少了 `76%`。
* CSS 体积由原来的 `17.7kB` 优化至 `12.8KB`,体积减少了 `28%`。
### 更高的单元测试覆盖率
* 单元测试覆盖率由原来的 `90%` 提升至 `92.5%`。
## 从 v0.0.9 升级到 v0.0.10
### PlusDrawerForm 抽屉表单 事件修改
* [PlusDrawerForm](/components/drawer-form.html#drawerform-events) 的事件`submit` 已废弃,请使用`confirm` 代替。[ 参考 DrawerForm-events](/components/drawer-form.html#drawerform-events)
## 从 v0.0.7 升级到 v0.0.8
### 国际化文件导入方式修改
* 导入文件报错
```sh
ERROR failed to resolve import "plus-pro-components/locale/zh-cn.mjs"
ERROR failed to resolve import "plus-pro-components/locale/en.mjs"
```
* 解决方案
```js
import plusZhCn from 'plus-pro-components/locale/zh-cn.mjs' // [!code --]
import plusZhCn from 'plus-pro-components/locale/zh-cn' // [!code ++]
import plusEn from 'plus-pro-components/locale/en.mjs' // [!code --]
import plusEn from 'plus-pro-components/locale/en' // [!code ++]
```
或者
```js
import plusZhCn from 'plus-pro-components/locale/zh-cn.mjs' // [!code --]
import plusZhCn from 'plus-pro-components/es/locale/lang/zh-cn' // [!code ++]
import plusEn from 'plus-pro-components/locale/en.mjs' // [!code --]
import plusEn from 'plus-pro-components/es/locale/lang/en' // [!code ++]
```
## 从 v0.0.4 升级到 v0.0.5
### PlusSearch 搜索组件
* 搜索按钮现在默认靠右,要恢复以前的顺序排布可使用以下代码
```css
.plus-search .plus-search__button__wrapper.el-form-item {
flex: none;
}
```
## 从 v0.0.3 升级到 v0.0.4
### PlusFormItem 表单单项组件
* 表单单项组件 移除了 `valueType === 'date-picker'`时,`el-date-picker` 组件的默认属性 `format` 和`value-format`,原来的默认值都为 `YYYY-MM-DD HH:mm:ss`。
* 受影响的组件 [PlusForm](/components/form.html), [PlusDialogForm](/components/dialog-form.html),[PlusDrawerForm ](/components/drawer-form.html), [PlusStepsForm ](/components/steps-form.html),[PlusSearch ](/components/search.html),[PlusDisplayItem ](/components/display-item.html),[PlusTable ](/components/table.html),[PlusPage ](/components/page.html)
## 从 v0.0.2 升级到 v0.0.3
### 高级组件通用配置 columns
* `headerFilter`参数已废弃,请使用 `disabledHeaderFilter`代替。[ 参考 columns](/components/config.html)
---
---
url: /guide/dev.md
---
# 本地开发指南
## 开发环境
| 类型 | 名称 | 版本 |
| ------------- | ----------------- | -------------- |
| 操作系统 | Windows 11 专业版 | 22000.1098 |
| 开发工具 | Microsoft VS Code | 1.79.0 |
| 调试工具 | Google Chrome | 104.0.5112.102 |
| 代码版本控制 | git | 2.37.0 |
| 语言环境 | node | 18.19.0 |
| 包管理器 | npm | 8.19.2 |
| 包管理器 | yarn | 1.22.19 |
| 包管理器 | pnpm | 8.15.7 |
| node 版本管理 | nvm | 1.1.7 |
| npm 源管理 | nrm | 1.2.5 |
## 项目结构
```sh
├── CHANGELOG.md #changelog文件
├── commitlint.config.js #commitlint配置
├── docs #文档所在目录
| ├── .vitepress #vitepress配置
| ├── components #组件文档
| ├── examples #组件文档对应的vue示例
| ├── deploy.sh #文档部署脚本
| ├── guide #快速开始文档
| ├── index.md #文档首页
| ├── package.json
| ├── public
| └── utils
├── global.d.ts #全局组件ts提示
├── LICENSE #LICENSE 文件
├── package.json
├── packages #包文件夹
| ├── components #主组件
| ├── constants #固定变量
| ├── eslint-config #eslint配置独立
| ├── hooks #hooks
| ├── locale #国际化
| ├── play #组件实时预览
| ├── plus-pro-components #主包入口
| ├── utils #工具
| ├── theme-chalk #样式
| └── types #公共TS类型
├── pnpm-lock.yaml
├── pnpm-workspace.yaml #工作空间配置
├── README.md #项目介绍
├── scripts #脚本
| ├── build #主包打包
| ├── changelog #changelog
| ├── create-component #新增组件
| ├── release #整包release
| ├── utils #公共打包工具
| ├── commit.sh #代码提交
| └── publish.sh #整包发布
├── tsconfig.base.json #tsconfig配置
├── tsconfig.json
├── tsconfig.node.json
├── tsconfig.vitest.json
├── tsconfig.web.json
├── typings #全局d.ts
| └── env.d.ts
└── vitest.config.ts #vitest配置
```
## 克隆仓库
```sh
git clone https://github.com/plus-pro-components/plus-pro-components.git
```
如果 GitHub 克隆速度较慢,你也可以直接克隆 plus-pro-components 在 gitee 上的[镜像仓库](https://gitee.com/plus-pro-components/plus-pro-components.git),同步可能会存在时差。
```bash
git clone https://gitee.com/plus-pro-components/plus-pro-components.git
```
## 启动项目
```sh
pnpm i
```
## 文档网站预览
```sh
pnpm docs:dev
```
## 本地开发
```sh
pnpm dev
```
## 添加新的组件步骤
例如现在需要新增一个新的组件 组件名叫 `table` 对应的 vue 组件名称叫 `PlusTable`(所有组件名字以`Plus` 开头,组件的基本代码全部会自动生成。)
### 1. 组件创建
* 执行创建组件脚本
```sh
pnpm run new table
```
* 确定
```
Confirm create table component? yes
```
* 此时 packages/components/table 文件夹已经生成并且有了如下目录
```sh
├── index.ts #主文件
├── src
| └── index.vue #组件实际代码
├── style
| ├── index.ts #组件按需加载 scss 样式,包含自身样式和外部样式
| └── css.ts #组件按需加载 css 样式,包含自身样式和外部样式
└── __tests__
└── table.test.tsx #单元测试代码 主要测试组件中的 props、event、slots、样式、CSS class 名、生命周期钩子,和其他相关的问题。
```
然后添加组件实际代码和对应的单元测试
* 导出组件
packages/components/index.ts 新增
```ts
export * from './table'
```
* 在 packages/plus-pro-components/component.ts 添加新增的组件 `PlusTable`
```js
import { PlusTable } from '@plus-pro-components/components/table'
const plugins: Component[] = [PlusDialog, PlusPagination, PlusTable]
```
* 在 `global.d.ts` 添加类型
```ts{3}
declare module '@vue/runtime-core' {
export interface GlobalComponents {
PlusTable: typeof import('plus-pro-components')['PlusTable']
}
}
```
### 2. 预览组件
* 执行下面的命令
```sh
pnpm run dev
```
* 打开 packages/play/src/views/table.vue(文件自动生成) 里面新增如下代码
```html
```
* 打开终端地址即可预览组件
### 3. 组件的测试 单元测试 写完之后 执行
```sh
pnpm run test
```
查看测试覆盖率
```sh
pnpm run test:coverage
```
### 4. 文档的添加
* 执行打包命令
```sh
pnpm run build
```
* 在 docs/components 文件下, 新建文件 table.md 内容写法参考之前的
* 在 docs/文件夹下执行 `pnpm run start` 后的地址即可预览已打包的本地组件
* 在 docs/文件夹下执行 `pnpm run debug` 后的地址即可实时预览正在开发的本地组件
## 代码提交
```sh
pnpm run commit # 全部提交
```
::: tip 提示
**如果需要分次提交** 可以先执行 `git add ./x/x `,再执行`pnpm run gitcz`,最后执行 `git push origin dev`(或者其他分支)。
:::
## 打包组件
```sh
pnpm run build
```
---
---
url: /components/QA.md
---
# 常见问题
## 组件 TypeScript 类型不兼容或错误 ?
借用[Ant Design Pro](https://pro.ant.design/zh-CN/docs/type-script/#ts-ignore)官网的一句话:
`TypeScript 毕竟是一个标注语言,在需要使用 any 的时候不必吝于使用 any,在遇到【动态性比较强的代码】时,不妨使用 as unknown as XXX, 可以节省很多时间。`
`@ts-ignore` `@vue-ignore`
有些时候类型错误是组件的,但是看起来非常难受。会一直编译报错,这里就可以使用 `@ts-ignore` 来暂时忽略它,在模板中还可以使用`@vue-ignore`
> \*.vue
```html
```
## 表格的 columns 使用 ref 定义类型报错
[详见 issues/195](https://github.com/plus-pro-components/plus-pro-components/issues/195)
```ts
import type { Ref } from 'vue'
import type { PlusColumn } from 'plus-pro-components'
// const columns = ref([]) 类型替换为下面的写法
const columns: Ref = ref([])
```
## 是否兼容element-plus@2.6.0 ?
是, [详见 issues/79](https://github.com/plus-pro-components/plus-pro-components/issues/79),[详见 issues/105](https://github.com/plus-pro-components/plus-pro-components/issues/105)
## 按钮,placeholder,标题文本显示异常?


问题原因:未配置 `plus-pro-components` 的国际化。
解决方案:[配置国际化](/guide/i18n.html)
## 国际化配置了不起效果?
[详见](/guide/i18n.html#国际化不起效果)
## 表单字段改变后怎么根据改变字段的值通过接口获取另一个字段的 options?
[详见 issues/99](https://github.com/plus-pro-components/plus-pro-components/issues/99)
## PlusTable 和 PlusForm 复用 PlusColumn 问题?
[详见 issues/94](https://github.com/plus-pro-components/plus-pro-components/issues/94)
## 单个组件的事件在哪里配置?
[参考](/components/attrs.html)
## PlusTable 表格操作栏如何居中显示?
小于v0.1.7
```css
.plus-table .plus-table-action-bar .cell {
justify-content: center;
}
```
大于等于v0.1.7
```html
```
## PlusTable 表格操作栏如何做权限控制?
小于v0.1.7
可使用 [ActionBarButtonsRow](/components/type.html#actionbarbuttonsrow) 中的 `show` 字段控制。 [示例](/components/table.html#自定义操作栏)
大于等于v0.1.7
可使用 [ActionBarButtonsRow](/components/type.html#actionbarbuttonsrow) 中的 `directives`指令字段控制。[示例](/components/table.html#权限控制)
## 搜索表单如何改变重置、搜索按钮的顺序?
[参考 flex 布局 order ](https://www.w3school.com.cn/tiy/t.asp?f=cssref_order)
[详见 issues/54](https://github.com/plus-pro-components/plus-pro-components/issues/54)
```css
.plus-search__button__wrapper .el-button {
order: 2;
}
.plus-search__button__wrapper .el-button--primary {
order: 1;
margin-left: 0;
margin-right: 20px;
}
.plus-search__button__wrapper .el-link {
order: 3;
}
```
## PlusForm 里面的表单元素,想单独占一行,但是宽度是`{colProps: {span: 8}}` 怎么配置?
```ts
import type { PlusColumn } from 'plus-pro-components'
const columns: PlusColumn[] = [
{
label: 'test',
prop: 'test',
colProps: {
span: 8, // 实际宽度是 33.3%
// @ts-ignore
style: { marginRight: '67%' }
}
}
]
```
## 表单中的某项如何添加 ref 获取实例,使用实例的方法?
```vue {15,50-52}
```
## PlusTable 设置了 adaptive 属性,在搜索栏没有展开表格内容是可以自适应的 展开后表格高度还是之前的怎么办?
在 [PlusSearch](/components/search.html#search-events) 的事件 [collapse](/components/search.html#search-events) 中主动触发 [PlusTable](/components/table.html) 的 `resize` 方法
```vue {2,127-132}
```
---
---
url: /guide/changelog.md
---
# 更新日志
在这个页面上,你只能看到我们最近更新的 30 条 更新日志。
## 版本发布策略
| 发布者 | 阶段 | 发布策略 | 备注 |
| ---------------------- | ------------------------------------- | -------- | ------------------------------------------------------------------- |
| PlusProComponents 团队 | 快速开发迭代阶段 | 每周 | 关键的 bug 修复将需要热修复,所以实际发布版本可能每周超过 1 次 |
| PlusProComponents 团队 | 功能稳定阶段 current | 1-6 个月 | 关键的 bug 修复将需要热修复,所以实际发布版本可能每 6 个月超过 1 次 |
## 推荐版本
推荐选择[release](https://github.com/plus-pro-components/plus-pro-components/releases)版本,功能稳定。参考[release 版本列表](https://github.com/plus-pro-components/plus-pro-components/releases)。
---
---
url: /guide/contribution.md
---
# 贡献指南
### 介绍
感谢您使用 PlusProComponents。
以下是关于向 PlusProComponents 提交反馈或代码的指南。在向 PlusProComponents 提交 issue 或者 PR 之前,请先花几分钟时间阅读以下内容。
### Issue 规范
* 遇到问题时,请先确认这个问题是否已经在 issue 中有记录或者已被修复。
* 提 issue 时,请用简短的语言描述遇到的问题,并添加出现问题时的**环境** 和复现步骤,必要时需提供可复现问题最小代码仓库。
#### 环境包含
* `浏览器` 版本
* `操作系统` 版本
* `node` 版本
* `vite`/ `webpack` / `Rollup` / `Vue CLI` 构建工具版本, 是否使用 `CDN`
* `vue` 版本
* `element-plus` 版本
* `plus-pro-components` 版本
## 参与开发
### [参考本地开发](/guide/dev.html)
### 代码规范
在编写代码时,请注意:
* 确保代码可以通过仓库的 ESLint 校验。
* 确保代码格式是规范的,使用 prettier 进行代码格式化。
* 确保没有使用超出兼容性范围的 API.
## 提交 Pull Request
### 参考指南
如果你是第一次在 GitHub 上提 Pull Request ,可以阅读下面这两篇文章来学习:
* [第一次参与开源](https://github.com/firstcontributions/first-contributions/blob/main/translations/README.zh-cn.md)
* [如何优雅地在 GitHub 上贡献代码](https://segmentfault.com/a/1190000000736629)
### Pull Request 规范
在提交 Pull Request 时,请注意:
* 保持你的 PR 足够小,一个 PR 只解决单个问题或添加单个功能。
* 当新增组件或者修改原有组件时,记得增加或者修改对应的单元测试,保证代码的稳定。
* 在 PR 中请添加合适的描述,并关联相关的 Issue。
### Pull Request 流程
1. fork 主仓库,如果已经 fork 过,请同步主仓库的最新代码。
2. 基于 fork 后仓库的 dev 分支新建一个分支,比如 `feature/docs`。
3. 在新分支上进行开发,开发完成后,提 Pull Request 到主仓库的 dev 分支。
4. Pull Request 会在 Review 通过后被合并到主仓库。
5. 等待 PlusProComponents 发布新版本,一般是每周一次。
### Pull Request 标题格式
Pull Request 的标题应该遵循以下格式:
```bash
type(ComponentName?):commit message
```
示例:
* docs: fix typo in quickstart
* build: optimize build speed
* fix(component\[form-item]): incorrect style
* feat(component\[table]): add color prop
可选的类型:
* feat
* fix
* build
* docs
* test
* style
* ci
* refactor
* perf
* chore
* revert
### 同步最新代码
提 Pull Request 前,请依照下面的流程同步主仓库的最新代码:
```bash
# 添加主仓库到 remote
git remote add upstream https://github.com/plus-pro-components/plus-pro-components.git
# 拉取主仓库最新代码
git fetch upstream
# 切换至 dev 分支
git checkout dev
# 合并主仓库代码
git merge upstream/dev
```
---
---
url: /guide/i18n.md
---
# 国际化
PlusProComponents 组件的国际化完全兼容 Element Plus 的国际化,和 Element Plus 一样默认使用英语,如果需要配置国际化,只需要在 Element Plus 语言包的基础上合并 PlusProComponents 的语言包即可。
## 示例
:::demo
locale/basic
:::
## 全局配置
在 Element Plus 的配置上合并语言包。
```typescript
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
// import en from 'element-plus/es/locale/lang/en'
import plusZhCn from 'plus-pro-components/es/locale/lang/zh-cn'
// import plusEn from 'plus-pro-components/es/locale/lang/en'
app.use(ElementPlus, {
locale: { ...zhCn, ...plusZhCn }
})
```
## ConfigProvider 推荐
在 Element Plus 的 ConfigProvider 合并语言包。
```html
***
```
## CDN 用法
::: tip 提示
PlusProComponents 的所有语言包全局名称都是以`PlusProComponentsLocale` 开头 然后加上语言包文件名称的驼峰命名。
Element Plus 的所有语言包全局名称都是以 `ElementPlusLocale` 开头 然后加上语言包文件名称的驼峰命名。
:::
在 CDN 上合并语言包
```html
```
[支持的语言列表](https://github.com/plus-pro-components/plus-pro-components/tree/dev/packages/locale/lang)
* 简体中文(zh-cn)
* American English (en)
* 日语 (ja) v0.1.4 感谢 [@maojunkun](https://github.com/plus-pro-components/plus-pro-components/commit/8888ce5eb411ac47f2de796529181662022566c1) 贡献
* 繁体中文 (zh-tw) v0.1.14 感谢 [@xiaoxian521](https://github.com/plus-pro-components/plus-pro-components/commit/213f67233b8bb51b00e9854f3ea74be95607eee1) 贡献
* 韩语 (ko) v0.1.14 感谢 [@xiaoxian521](https://github.com/plus-pro-components/plus-pro-components/commit/25a0ddd7e2e687583c54ef1798e4156c0670fffa) 贡献
* 繁体中文 (zh-hk) v0.1.31 感谢 [@bryqiu](https://github.com/plus-pro-components/plus-pro-components/commit/5f6f613dbc23cd13b5b710d197cf9717e6be1ad7) 贡献
如果你需要使用其他的语言,欢迎贡献 [PR](https://github.com/plus-pro-components/plus-pro-components/pulls),只需在[这里](https://github.com/plus-pro-components/plus-pro-components/tree/dev/packages/locale/lang)添加一个语言配置文件即可。
## 国际化不起效果?
[issues/125](https://github.com/plus-pro-components/plus-pro-components/issues/125)
`plus-pro-components` 小于 `0.0.11` 版本,使用 `npm` 安装依赖,导致`element-plus`版本不一致,进而导致国际化失效,解决方案:
* 方案一:使用 `npm` 升级`element-plus`到最新版本即可。
* 方案二: 移除`node_modules` 文件夹,移除`package-lock.json`,然后使用`pnpm i ` 重新安装依赖即可。
---
---
url: /components/type.md
---
# 基础 Ts 类型
::: tip 提示
本页面类型会互相引用,请注意上下文!
:::
## ElementRefType
ref 绑定的元素类型
```ts
/**
* ref 绑定的元素类型
*/
export type ElementRefType = HTMLElement | null
```
## Timeout
setTimeout 类型
```ts
/**
* setTimeout 类型
*/
export type Timeout = ReturnType
```
## Interval
setInterval 类型
```ts
/**
* setInterval 类型
*/
export type Interval = ReturnType
```
## RecordType
普通的对象的泛型
```ts
/**
* 普通的对象的类型
*/
export type RecordType = {
[index: string]: any
}
```
## Nullable
允许 null 的泛型
```ts
/**
* 允许null的泛型
*/
export type Nullable = T | null
```
## Mutable
去除只读状态
```ts
/**
* 去除只读状态
*/
export type Mutable> = {
-readonly [K in keyof T]: T[K]
}
```
## PageInfo
分页参数
```ts
/**
* 分页参数
*/
export interface PageInfo {
/**
* 默认为1
*/
page: number
/**
* 默认为10
*/
pageSize: number
}
```
## ActionBarButtonsRow
表格操作栏按钮配置项的值的类型
```ts
import type { ElMessageBoxOptions } from 'element-plus'
import type { Component, Ref, ComputedRef, AppContext, DirectiveArguments } from 'vue'
import type { RecordType, ButtonsCallBackParams } from 'plus-pro-components'
/**
* 按钮属性的类型
*/
export type ButtonRowProps = Partial<
Mutable
>
/**
* 表格操作栏按钮配置项的值的类型
*/
export interface ActionBarButtonsRow {
/**
* 操作文本
* @version v0.0.8 新增函数类型
*/
text:
| string
| Ref
| ComputedRef
| ((
row: any,
index: number,
button: ActionBarButtonsRow
) => string | Ref | ComputedRef)
/**
* 操作按钮唯一code,可用来判断按钮类型
*/
code?: string | number
/**
* `@element-plus/icons-vue` 的图标名称,对ElButton,ElLink 和ElIcon 组件同时生效
*/
icon?: Component
/**
* ElButton,ElLink和ElIcon 组件对应的props
* @version v0.1.16 新增函数类型和计算属性
*/
props?:
| ButtonRowProps
| ((row: any, index: number, button: ActionBarButtonsRow) => ButtonRowProps)
| ComputedRef
/**
* ElTooltip组件的props, type 为icon 时生效
*/
tooltipProps?: Partial
/**
* 按钮显示的逻辑 默认 true 显示, 不需要显示给 false
*
* 可以用来控制权限
*/
show?:
| boolean
| Ref
| ComputedRef
| ((
row: any,
index: number,
button: ActionBarButtonsRow
) => boolean | Ref | ComputedRef)
/**
* 操作是不是需要二次确认 默认值为 `false`
*/
confirm?:
| boolean
| {
/**
* ElMessageBox.confirm 的title 默认 `提示`
*/
title?: string | ((data: ButtonsCallBackParams) => string)
/**
* ElMessageBox.confirm 的message 默认 `确定执行本次操作`
*
* @version v0.1.17 新增 当ActionBarProps.confirmType为 `popconfirm` 时 , 版本中 message 会作为 ElPopconfirm 的title
*/
message?: string | ((data: ButtonsCallBackParams) => string)
/**
* ElMessageBox.confirm 的options
*/
options?: ElMessageBoxOptions
/**
* ElPopconfirm的props
*
* 当ActionBarProps.confirmType为 `popconfirm` 时生效
* @version v0.1.17
* @see https://element-plus.org/zh-CN/component/popconfirm.html#attributes
*/
popconfirmProps?: Partial>
/**
* ElMessageBox.confirm 的appContext
*/
appContext?: AppContext | null
}
/**
* 指令,可以用来控制权限,数据类型是二维数组
* @version v0.1.7
* @see https://cn.vuejs.org/guide/extras/render-function.html#custom-directives
*
*/
directives?: DirectiveArguments
/**
* 点击当前按钮时触发,可与PlusTable的事件 `clickAction` 同时触发;
* 操作需要二次确认时:PlusTable的事件 `clickAction`会在确认时触发,而当前的onClick是在点击时触发;
* @version v0.1.8
* @param params
* @returns
*/
onClick?: (params: ButtonsCallBackParams) => void
/**
* 操作需要二次确认时,点击确认时触发
* @version v0.1.8
* @param params
* @returns
*/
onConfirm?: (params: ButtonsCallBackParams) => void
/**
* 操作需要二次确认时,点击取消时触发, 可与PlusTable的事件 `clickActionConfirmCancel` 同时触发
* @version v0.1.8
* @param params
* @returns
*/
onCancel?: (params: ButtonsCallBackParams) => void
}
```
## ActionBarProps
表格操作栏数据类型
```ts
import type { ComputedRef } from 'vue'
import type { ActionBarButtonsRow } from 'plus-pro-components'
/**
* 表格操作栏数据类型
*/
export interface ActionBarProps {
/**
* 操作栏名称 默认值为 `'操作栏'`
*
* @version v0.1.0 类型新增ComputedRef
*/
label?: string | ComputedRef
/**
* 操作栏固定 默认值为 `'right'`
*/
fixed?: string
/**
* 显示出来的按钮个数 默认值为 `3`
* @version 0.1.23 新增函数类型
* @default 3
*/
showNumber?: number | ((row: RecordType, index: number) => number)
/**
* 更多按钮展示策略
* true时,showNumber限制的包括更多按钮在内,即包括更多按钮在内,总按钮个数为showNumber
* false时,showNumber限制的不包括更多按钮在内,即总按钮个数为showNumber+1,+1是因为'更多'按钮不在showNumber的限制内
* @default false
* @version v0.1.20
*/
showLimitIncludeMore?: boolean
/**
* 操作按钮的类型 默认值为 `'link'`
*/
type?: 'icon' | 'button' | 'link'
/**
* 操作按钮集合 默认值为 `[]`
*/
buttons?: ActionBarButtonsRow[]
/**
* 表格操作栏 el-table-column 的其width 默认值为 `200`
*/
width?: string | number
/**
* 表格操作栏 el-table-column 的其他props 默认值为 `{}`
*/
actionBarTableColumnProps?: Partial
/**
* 表格操作栏 需要二次确认的类型,默认是 messageBox
* @version v0.1.17
*/
confirmType?: 'messageBox' | 'popconfirm'
/**
* 更多按钮的显示类型,text 显示文字和图标,icon 只显示图标
* @default 'text'
* @version v0.1.28
*/
moreType?: 'text' | 'icon'
}
```
## TableFormRefRow
表格可编辑表单的行 form 的参数类型
```ts
import { ElForm, ElFormItem } from 'element-plus'
import type { Ref } from 'vue'
/**
* 表格可编辑表单的行form 的参数类型
*/
export interface TableFormRefRow {
/**
* 单元格的表单实例
*/
formInstance: Ref>
/**
* 表格的行索引
*/
index: number
/**
* 表格的行索引, 同 index
* @version 0.1.20
*/
rowIndex: number
/**
* 单元格的列索引
* @version 0.1.20
*/
cellIndex: number
/**
* 表格的列字段
*/
prop: string
/**
* 单元格的表单开启编辑
* @returns
*/
startCellEdit: () => void
/**
* 单元格的表单停止编辑
* @returns
*/
stopCellEdit: () => void
/**
* 当前单元格是否可编辑
* @version v0.1.8
*/
isEdit: Ref
}
```
## TableCellParams
表格单元格回调参数
```ts
import type { RecordType } from 'plus-pro-components'
/**
* 表格单元格回调参数
*/
export type TableCellParams = {
/**
* 表格行数据
*/
row: RecordType
/**
* 表格行索引
*/
index: number
/**
* 表格列数据
*/
column?: RecordType
/**
* 表格行索引 同 index
* @version v0.1.7
*/
rowIndex: number
/**
* 表格列索引
* @version v0.1.7
*/
cellIndex: number
/**
* 表格store
* @version v0.1.7
*/
store: RecordType
/**
* 表格 expanded
* @version v0.1.7
*/
expanded: boolean
/**
* 表格 _self
* @version v0.1.7
*/
_self: RecordType
}
```
## ButtonsCallBackParams
表格点击按钮回调的参数的类型
```ts
import type { TableFormRefRow, TableCellParams, ActionBarButtonsRow } from 'plus-pro-components'
/**
* 点击按钮回调的参数的类型
*/
export interface ButtonsCallBackParams extends TableCellParams {
/**
* 点击按钮数据
*/
buttonRow: ActionBarButtonsRow
/**
* 解析后的按钮数据中的text
* @version v0.1.17
*/
text: string
/**
* 按钮点击事件数据
*/
e: MouseEvent
/**
* 可编辑表单的行form
*/
formRefs?: TableFormRefRow[]
}
```
## FormChangeCallBackParams
表格表单回调参数
```ts
import type { FieldValueType, TableCellParams } from 'plus-pro-components'
/**
* formChange回调的参数的类型
*/
export interface FormChangeCallBackParams extends TableCellParams {
/**
* 表单的值
*/
value: FieldValueType
/**
* 当前单元格的prop
*/
prop: string
}
```
## TableValueType
所有表格列显示的类型 默认是 `undefined`
```ts
/**
* 所有表格列显示的类型 默认是 `undefined`
*/
export type TableValueType =
| 'img'
| 'link'
| 'money'
| 'tag'
| 'progress'
| 'copy'
| 'code'
// v0.1.0 新增
| 'divider'
// v0.1.0 新增
| 'avatar'
| ''
```
## FormItemValueType
所有表单的类型 默认是 `input` (`undefined`)
```ts
/**
* 所有表单的类型 默认是 `input` (`undefined`)
*/
export type FormItemValueType =
| 'autocomplete'
| 'cascader'
| 'checkbox'
| 'color-picker'
| 'date-picker'
| 'input-number'
| 'radio'
| 'rate'
| 'select'
| 'slider'
| 'switch'
| 'time-picker'
| 'time-select'
| 'textarea'
| 'input'
| 'text'
| 'plus-radio'
| 'plus-date-picker'
| 'plus-input-tag'
/**
* @version 0.1.1 新增
*/
| 'transfer'
/**
* @version 0.1.1 新增
*/
| 'tree-select'
/**
* @version 0.1.21 新增
*/
| 'select-v2'
| undefined
```
## FieldValueType
单个表单值的类型
```ts
import type { RecordType } from 'plus-pro-components'
/**
* 单个表单值的类型
*/
export type FieldValueType =
| string
| number
| boolean
| null
| undefined
| Date
| string[]
| number[]
| boolean[]
| Date[]
| [Date, Date]
| [number, number]
| [string, string]
// v0.1.7 新增
| RecordType
```
## FieldValues
整体表单值的类型
```ts
import type { FieldValueType } from 'plus-pro-components'
/**
* 整体表单值的类型
*/
export type FieldValues = Record
```
## PropsItemType
自定义 props 类型
```ts
import type { ComputedRef } from 'vue'
import type { FieldValueType } from 'plus-pro-components'
/**
* 自定义props类型 值支持对象 object,computed,函数和 Promise。
*/
export type PropsItemType = any> =
| Partial
| ComputedRef>
| ((
value: FieldValueType,
data: {
row: Record
index: number
}
) => Partial | Promise>)
| Promise>
```
## OptionsRow
选择框类型
```ts
import type { PropsItemType, RecordType } from 'plus-pro-components'
import type { ButtonType } from 'element-plus'
import type { VNode } from 'vue'
/**
* 选择框类型
*/
export interface OptionsRow {
/**
* @version v0.1.15 新增索引类型,用来支持optionsMap @see /components/config.html
*/
[index: keyof any]: any
/**
* @version v0.1.15 变更为可选,用来支持optionsMap @see /components/config.html
*/
label?: number | string
/**
* @version v0.1.7 新增 RecordType 类型
* @version v0.1.15 变更为可选,用来支持optionsMap @see /components/config.html
*/
value?: Exclude
/**
* 小圆点背景色,仅在表格和描述列表中生效
* color 优先级 高于 type
*/
color?: string
/**
* 小圆点颜色类型,仅在表格和描述列表中生效
* type 优先级 低于 color,
* 只支持 'success' | 'warning' | 'info' | 'primary' | 'danger'
*/
type?: Exclude
/**
* 表单子项的props 如 el-checkbox-group下的el-checkbox的props
* @version v0.1.25 新增函数类型支持 ((item: OptionsRow) => RecordType)
*/
fieldItemProps?: RecordType | ((item: OptionsRow) => RecordType)
/**
* el-checkbox-group下的,每一项el-checkbox的各自插槽(即el-checkbox的default插槽)。
* el-radio-group下的,每一项el-checkbox的内容各自插槽(即el-radio的default插槽)。
* el-select下的,每一项el-option的内容整体插槽(即el-option的default插槽)。
*
* @see https://element-plus.org/zh-CN/component/checkbox.html#checkbox-slots
* @see https://element-plus.org/zh-CN/component/radio.html#radio-slots
*/
fieldSlot?: (option?: OptionsRow) => RenderTypes
/**
* 子选项,仅valueType 为 `cascader` 时生效
*/
children?: OptionsRow[]
/**
* @version 0.1.28 当 valueType 为 select 时,将选项进行分组显示
*/
options?: OptionsRow[]
}
```
## OptionsType
选择类型
```ts
import type { OptionsRow } from 'plus-pro-components'
/**
* 选择类型 支持数组,computed,函数和Promise
*/
*/
export type OptionsType =
| OptionsRow[]
| ComputedRef
| ((props?: PlusColumn) => OptionsRow[] | Promise)
| Promise
```
## PlusFormGroupRow
分步表单配置项
```ts
import type { Component, ComputedRef } from 'vue'
import type { PlusColumn, Mutable } from 'plus-pro-components'
import type { CardProps } from from 'element-plus'
/**
* 分组表单配置项
*/
export interface PlusFormGroupRow {
/**
* @version v0.1.17 新增 ComputedRef 类型
*/
title: string | ComputedRef
/**
* @version v0.1.25 新增,用于自动生成分步内容插槽
*/
name?: string
icon?: Component
/**
* @desc 分组表单el-card的props,优先级高于整体的cardProps
* @version v0.1.1
*/
cardProps?: Partial>
hideInGroup?: boolean | ComputedRef
/**
* @version v0.1.25 调整为可选
*/
columns?: PlusColumn[]
}
```
## PlusStepFromRow
v0.1.8
分步表单配置项
```ts
import type { Component } from 'vue'
import type { PlusFormProps } from 'plus-pro-components'
/**
* 分步表单配置项
*/
export interface PlusStepFromRow {
title: string
/**
* @version 0.1.22 变更为可选
*/
form: PlusFormProps
description?: string
icon?: string | Component
status?: '' | 'wait' | 'process' | 'finish' | 'error' | 'success'
}
```
## TitleBar
表格标题栏
```ts
import type { Options as SortableOptions } from 'sortablejs'
import type { LinkProps } from 'element-plus'
import type { Mutable } from 'element-plus/es/utils'
export type ColumnSetting = {
dragSort?: boolean | Partial
/**
* 列设置是否需要重置按钮,当值为对象时是el-link按钮的props
* @version v0.1.20
* @default true
*/
reset?: boolean | Partial>
/**
* 列设置popover的宽度
* @version v0.1.23
* @default 100
*/
popoverWidth?: number | string
/**
* 列设置 checkbox label 隐藏的长度
* @version v0.1.23
* @default 6
*/
overflowLabelLength?: number
}
/**
* 标题栏
*/
export type TitleBar = {
/**
* 标题 使用title插槽则此配置不生效
*/
title?: string
/**
* 是否需要刷新 默认false
*/
refresh?: boolean
/**
* 是否需要密度控制 默认true
*/
density?: boolean
/**
* 是否需要列设置 默认true
*/
columnSetting?: boolean | ColumnSetting
/**
* 工具栏 icon 的大小和颜色配置
*/
icon?: {
/**
* icon 的大小 默认 18
*/
size?: string
/**
* icon 的颜色 默认 #606266
*/
color?: string
}
}
```
## PlusRouteRecordRaw
扩展的路由类型
```ts
import type { RouteRecordRaw } from 'vue-router'
import type { VNode, Component } from 'vue'
/**
* 路由配置类型
*
* @description 继承自 vue-router 的 RouteRecordRaw,无侵入,仅仅只扩展 meta,meta除了扩展的属性外,同时支持添加任意自定义属性,
* 外链的话 path给 '/'+链接 例: `/https://element-plus.org`
*
*/
export type PlusRouteRecordRaw = Partial> & {
/**
* meta除了扩展的属性外,同时支持添加任意自定义属性
*
*/
meta?: {
/**
* 页面标题 标题存在面包屑和菜单名称显示标题 不存在显示路由的 name name不存在显示路由的 path
*/
title?: string
/**
* 图标
*/
icon?: Component | VNode | ((route: PlusRouteRecordRaw) => VNode)
/**
* 排序,默认为0 只对第一级有效
*/
sort?: number
/**
* 在侧边栏菜单中隐藏,默认false 不隐藏
*/
hideInMenu?: boolean
/**
* 隐藏面包屑,默认false 不隐藏
*/
hideInBreadcrumb?: boolean
/**
* 菜单是否禁用
* @see https://element-plus.org/zh-CN/component/menu.html#menu-item-attributes
*/
disabled?: boolean
}
children?: PlusRouteRecordRaw[]
}
```
---
---
url: /guide.md
---
# 简介
**PlusProComponents 灵感来自于[AntDesign ProComponents](https://procomponents.ant.design/)。PlusProComponents 是基于 element-plus 而开发的模板组件,它提供了更高级别的抽象支持,开箱即用。可以显著的提升制作 CRUD 页面的效率,更加专注于页面。**
## 组件列表
* [PlusLayout](/components/layout.html) 页面布局组件,解决布局的问题,提供开箱即用的菜单和面包屑功能。
* [PlusPage](/components/page.html) 页面模板组件,抽象网络请求和表格格式化。
* [PlusTable](/components/table.html) 表格模板组件。
* [PlusSearch](/components/search.html) 搜索模板组件。
* [PlusForm](/components/form.html) 表单模板组件,预设常见布局和行为。
* [PlusDialogForm ](/components/dialog-form.html) 弹窗表单模板组件,预设常见布局和行为。
* [PlusDrawerForm ](/components/drawer-form.html) 抽屉表单模板组件,预设常见布局和行为。
* [PlusDescriptions](/components/descriptions.html) 定义列表模板组件。
## 组件特性
* 🔥 功能强大:`PlusProComponents` 的组件不仅提供了基本的 UI 展示功能,还具备了复杂的数据操作和业务逻辑处理能力,能够快速构建出功能强大的企业应用。
* 💡 易于使用:`PlusProComponents` 提供了简单易用的 API 和完善的文档,使得开发者能够快速上手并使用其中的组件。
* 📦 高度可定制:`PlusProComponents` 的组件支持多种配置和样式自定义,能够满足不同项目的需求。
* ✅ 兼容 element-plus:`PlusProComponents` 100%兼容和 element-plus 同名的组件,包括属性,事件,方法,插槽等。
* 🛠️ 丰富的组件库:`PlusProComponents` 基于 element-plus 提供了大量的 UI 组件,包括表格、表单、布局等,能够满足大多数企业应用的需求。
* ➕ 使用 TypeScript:`PlusProComponents` 全量使用 TypeScript 编写,和你的 TypeScript 项目无缝衔接。
* 🌐 国际化:`PlusProComponents`提供完备的国际化,与 element-plus 体系打通,无需多余配置。
* 🐋 预设: PlusProComponents 预设基本的样式,与 element-plus 样式一脉相承。 PlusProComponents 预设基本的行为,更少的代码具备更多的功能。
* 🎄 可摇树:开箱即用的 Tree Shaking,只对引入的代码进行打包。
* 🍭 代码零侵入:保持 element-plus 组件兼容的同时,提供更灵活的配置和更强大的功能。
* ✅ 测试:单元测试覆盖率超过 90%,提供稳定性保障。
## 组件缺点
`PlusProComponents` 是一个基于` Vue` 和 `element-plus` 的组件库,它提供了很多常用的 UI 组件和业务组件,可以方便地帮助开发者快速搭建前端页面。虽然 `PlusProComponents` 具有很多优点,但是也有以下一些缺点:
* 学习成本较高:`PlusProComponents` 的组件库比较复杂,学习所有组件可能需要花费较长时间。因此,对于新手开发者来说,学习成本可能会比较高。
* 高度可定制有限:`PlusProComponents` 的组件支持高度可定制,但是仍然不可能保证组件 100%完全自定义,定制需求非常高的项目谨慎使用。
---
---
url: /guide/quickstart.md
---
# 快速开始
本节将介绍如何在项目中使用 `PlusProComponents`。
::: warning 注意
以下使用步骤完成后,请配置[国际化](/guide/i18n.html),否则可能导致文本显示异常。
:::
## 使用之前
在开始使用` PlusProComponents` 之前,有必要先了解以下基础知识,我们假设您已经写过 `Vue 3`,并掌握了下面的内容。
* [ES6+](https://es6.ruanyifeng.com/)
* [Vue 组件](https://cn.vuejs.org/guide/essentials/component-basics.html)
* [单文件组件](https://cn.vuejs.org/guide/scaling-up/sfc.html)
* [渲染函数](https://cn.vuejs.org/guide/extras/render-function.html)
* [透传 Attributes](https://cn.vuejs.org/guide/components/attrs.html)
* [TypeScript](https://www.typescriptlang.org/) (非必须,但是有 TypeScript 基础,使用起来会更加方便。)
# 用法
**`plus-pro-components` 和`element-plus` 导入方式需要保持一致。**
## 完整引入
如果你对打包后的文件大小不是很在乎,那么使用完整导入会更方便。
> main.ts
```typescript{8,9,16}
import { createApp } from 'vue'
// 导入element-plus 及其样式
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 导入plus-pro-components 及其样式
import PlusProComponents from 'plus-pro-components'
import 'plus-pro-components/index.css'
import App from './App.vue'
const app = createApp(App)
app.use(ElementPlus)
// 使用
app.use(PlusProComponents)
app.mount('#app')
```
### Vue - Official (Volar)支持
如果您使用 Vue - Official (Volar),请在 tsconfig.json 中通过 compilerOptions.type 指定全局组件类型。
```json
// tsconfig.json
{
"compilerOptions": {
// ...
"types": ["plus-pro-components/global"]
}
}
```
## 自动按需导入 推荐
`PlusProComponents` 提供了基于`ES Module` 的开箱即用的 [Tree Shaking](https://webpack.js.org/guides/tree-shaking/) 功能。
* 1. 安装插件
```sh
pnpm install -D unplugin-vue-components unplugin-auto-import @plus-pro-components/resolver
```
* 2. 配置 `vite.config.ts` 或者配置 `webpack(vue).config.js`
[@plus-pro-components/resolver 文档](/ecosystem/resolver.html)
::: code-group
```ts {6,16} [vite.config.ts]
// vite.config.ts
import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { PlusProComponentsResolver } from '@plus-pro-components/resolver'
export default defineConfig({
// ...
plugins: [
// ...
AutoImport({
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [ElementPlusResolver(), PlusProComponentsResolver()]
})
]
})
```
```js {5,15} [webpack.config.js]
// webpack.config.js
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const { PlusProComponentsResolver } = require('@plus-pro-components/resolver')
module.exports = {
// ...
plugins: [
// ...
AutoImport({
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [PlusProComponentsResolver(), ElementPlusResolver()]
})
]
}
```
```js {6,17} [vue.config.js]
// vue.config.js
const { defineConfig } = require('@vue/cli-service')
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const { PlusProComponentsResolver } = require('@plus-pro-components/resolver')
module.exports = defineConfig({
// ...
configureWebpack: {
plugins: [
// ...
AutoImport({
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [PlusProComponentsResolver(), ElementPlusResolver()]
})
]
}
})
```
:::
* 3. 使用组件
> App.vue
```html{3}
```
### 自动按需导入示例工程
如果你需要新建一个项目,我们推荐使用 Vite。
以下是 plus-pro-components 官方提供的一些示例项目,你可以克隆该项目,并直接拷贝代码来使用。
* [vite-project](https://github.com/plus-pro-components/plus-pro-components-demos/tree/main/vite-project):使用 Vue 3、Vite 、element-plus、plus-pro-components 搭建应用。
* [vue-cli-project](https://github.com/plus-pro-components/plus-pro-components-demos/tree/main/vue-cli-project):使用 Vue 3、vue-cli@5 、element-plus、plus-pro-components 搭建应用。
## 手动导入
手动导入需要导入组件和其对应的样式文件。如下示例:
```html
```
## CDN
示例
::: warning 注意
使用 CDN 时,在 HTML 中所有的组件都是小写中划线隔开的形式,不支持单标签。
例如:
```html
```
需要写成
```html
```
:::
---
---
url: /components/attrs.md
---
# 事件和样式透传
## 事件透传
### vue3 的事件透传原则如下
**`以 on 开头,并跟着大写字母的 props 会被当作事件监听器。`**
**比如,onClick 与模板中的 @click 等价,onVisibleChange 与模板中的 @visible-change 等价**
参考 vue 官方文档 **[透传 Attributes](https://cn.vuejs.org/guide/components/attrs.html)**
参考 vue 官方文档 **[渲染函数 & JSX](https://cn.vuejs.org/guide/extras/render-function.html)**
### `PlusProComponents` 组件的事件透传
具备以下条件的都支持事件透传
* **[columns](/components/config.html) 配置中的`*Props`字段**
* **其他组件中的`*Props`字段**
* **文档中说明这个字段是组件的 props 的字段**
### `fieldProps` 事件示例
[columns](/components/config.html) 配置中的`fieldProps`字段表示的是 传递给具体表单项和表格显示的配置,如 el-input,el-select,el-tag,el-image 的 props ,同时还支持事件透传
```js
const columns = [
{
label: '状态',
prop: 'status',
// 对应的element-plus 的组件el-select
valueType: 'select',
options: [],
fieldProps: {
// https://element-plus.org/zh-CN/component/select.html#select-events
// el-select 的事件 `change`,对应的配置就是 `onChange`
onChange: () => {
console.log('onChange')
},
// el-select 的事件 `visible-change`,对应的配置就是 `onVisibleChange`
onVisibleChange: () => {
console.log('visibleChange')
},
// el-select 的事件 `remove-tag`,对应的配置就是 `onRemoveTag`
onRemoveTag: () => {
console.log('onRemoveTag')
}
}
},
{
label: '名称',
prop: 'name',
// 对应的element-plus 的组件el-input
valueType: 'input',
fieldProps: {
// https://element-plus.org/zh-CN/component/input.html#input-events
// el-input 的事件 `blur`,对应的配置就是 `onBlur`
onBlur: () => {
console.log('onBlur')
},
// el-input 的事件 `focus`,对应的配置就是 `onFocus`
onFocus: () => {
console.log('onFocus')
},
// el-input 的事件 `change`,对应的配置就是 `onChange`
onChange: () => {
console.log('onChange')
},
// el-input 的事件 `input`,对应的配置就是 `onInput`
onInput: () => {
console.log('onInput')
},
// el-input 的事件 `clear`,对应的配置就是 `onClear`
onClear: () => {
console.log('onClear')
}
}
}
]
```
### 需要 `事件修饰符` 和 `按键修饰符`的事件写法示例
[参考 Vue 官方写法](https://cn.vuejs.org/guide/extras/render-function.html#event-modifiers)
* 对于 `.passive`、`.capture` 和 `.once` 事件修饰符,可以使用驼峰写法将他们拼接在事件名后面。
示例
```ts
import type { PlusColumn } from 'plus-pro-components'
const columns: PlusColumn[] = [
{
label: '文本',
prop: 'text',
valueType: 'text',
fieldProps: {
onClickCapture() {
/* 捕捉模式中的监听器 */
},
onKeyupOnce() {
/* 只触发一次 */
},
onMouseoverOnceCapture() {
/* 单次 + 捕捉 */
}
}
}
]
```
* 其他`修饰符`写法,需要使用`withKeys`、[withModifiers](https://cn.vuejs.org/api/render-function.html#withmodifiers)
以`fieldProps`为例,支持点击阻止事件冒泡, 按下 Enter 键提交搜索等。
```html
```
[vue 官方建议使用 withModifiers,为什么使用 withKeys?](https://github.com/vuejs/babel-plugin-jsx/issues/269)
### PlusLayout 子组件事件写法示例
[PlusLayout](/components/layout.html) 的 `sidebarProps` 和`headerProps`表示的就是子组件的 props。
如 [PlusSidebar ](/components/sidebar.html) 的事件 `toggleCollapse`和 [PlusHeader ](/components/header.html)的事件`clickDropdownItem`。
示例:
> 模板中
```html
```
> setup 中
```ts
const handleClickDropdownItem = (dropdownItem: { label: string; value: string }) => {
console.log(dropdownItem)
}
const handleToggleCollapse = (collapse: boolean) => {
console.log(collapse)
}
```
### 其他\*Props 和高级组件事件写法参考上面示例
## 样式透传
支持事件透传的一般都支持样式透传
### `fieldProps` 样式透传示例
```js
const columns = [
{
label: '状态',
prop: 'status',
// 对应的element-plus 的组件el-select
valueType: 'select',
options: [],
fieldProps: {
// 对应的 el-select 的样式
style: {
width: '100%'
}
}
}
]
```
### `colProps` 样式透传示例
```js
const columns = [
{
label: '名称',
prop: 'name',
colProps: {
// 对应的 el-col 的样式
style: {
marginLeft: '10px'
}
}
}
]
```
### 其他参考上面示例
---
---
url: /components/config.md
---
# 通用配置
::: tip 提示
文中的一些类型来自 基础 Ts 类型 章节,建议先阅读。
:::
高级组件中除了布局组件[Layout](/components/layout.html)和多选卡片[CheckCardGroup ](/components/check-card-group.html)之外的组件通用配置。
配置的核心字段是`valueType`,渲染的 key 是`prop`(所以需要保证唯一)。
## columns 配置
TS 类型 `PlusColumn`
| 名称 | 说明 | 类型 | 默认值 | 是否必须 |
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | ---------------------------------------- |
| `prop` (**不可重复**) | 表格对应列内容的字段名 ;在 form/search 中是 el-input 等所有表单项的双向绑定的值;在 descriptions 是 el-descriptions-item 的值对应的字段; **支持`x.y.z`形式的多(无限)级数据形式**; 表单中v0.1.7版本开始支持多级 | `string` | | 是 |
| `label` | 表格表头显示的标题 ;在 form 中是 [ el-form-item](https://element-plus.org/zh-CN/component/form.html#formitem-attributes) 的 label;在 descriptions 是 el-descriptions-item 的 label;v0.1.0 版本开始支持计算属性,可用于实现国际化。 | `string`|`ComputedRef`(v0.1.0新增) | | 否 (小于v0.0.10是必须 ) |
| `width` | 表格列宽 | `string`| `number` | | 否 |
| `minWidth` | 表格列最小宽 | `string`| `number` | | 否 |
| **`valueType`** | 值的类型 | `string`([TableValueType](/components/type.html#tablevaluetype) / [FormItemValueType](/components/type.html#formitemvaluetype) ) | | 否 |
| `editable` | 当值为`true`时,表格中整列显示的是`valueType`取值对应的可编辑的表单,`valueType`取值为 [FormItemValueType](/components/type.html#formitemvaluetype) | `boolean` | `false` | 否 |
| `headerFilter` deprecated v0.0.3 | 表格列设置中禁止表格当前列的表头过滤,已废弃,请使用`disabledHeaderFilter`代替 | `boolean` | `false` | 否 |
| `disabledHeaderFilter` v0.0.3 | 表格列设置中禁止表格当前列的表头过滤 | `boolean` | `false` | 否 |
| `headerIsChecked` v0.1.22 | 表格列设置中当前表格项是否勾选,默认勾选 | `boolean` | `true` | 否 |
| `tableColumnProps` | 表格 column,支持所有[el-table-column 属性](https://element-plus.org/zh-CN/component/table.html#table-column-%E5%B1%9E%E6%80%A7) (不包含 `label,prop,width,minWidth,formatter`),[支持事件透传](/components/attrs.html) | `object` [ElTableColumnProps](https://element-plus.org/zh-CN/component/table.html#table-column-%E5%B1%9E%E6%80%A7) | | 否 |
| `preview` | 表格列图片预览,仅当 valueType 等于 img 时生效;[ el-image](https://element-plus.org/zh-CN/component/image.html) 图片预览 默认开启 给 false 关闭 | `boolean` | | 否 |
| `linkText` | 表格列 link 文字,valueType 等于 link 时生效;有值时则表格的整列都会显示这个值,默认取得是 prop 对应的表格数据 | `string` | | 否 |
| `descriptionsItemProps` | 描述行,[el-descriptions-item](https://element-plus.org/zh-CN/component/descriptions.html#descriptionsitem-attributes) 的 props ,[支持事件透传](/components/attrs.html) | `object` [DescriptionsItemProps](https://element-plus.org/zh-CN/component/descriptions.html#descriptionsitem-attributes) | | 否 |
| `renderDescriptionsItem`v0.0.2 | 自定义[PlusDescriptions ](/components/descriptions.html) 单行显示内容,在[PlusDescriptions ](/components/descriptions.html)组件中优先级最高,高于 render,renderHTML | `function` | | 否 |
| `renderDescriptionsLabel`v0.0.2 | 自定义[PlusDescriptions ](/components/descriptions.html) 单行 label 显示内容 | `function` | | 否 |
| `options` | `valueType` 为 `select`|`radio`|`checkbox`|`plus-radio` 时的选项 ,支持数组,computed,函数,和 Promise | `array`|`function`|`promise`[OptionsType](/components/type.html#optionstype) | | 否 |
| `optionsMap`v0.1.15 | 对 options 进行映射,仅对`valueType` 为 `select`|`radio`|`checkbox`|`plus-radio` 时生效 | `object` | `{ label: 'label',value: 'value'}` | 否 |
| `customGetStatus` | 自定义 options 的显示逻辑,需要返回一个[OptionsRow](/components/type.html#optionsrow)对象。 | `function` | | 否 |
| `tooltip` | 展示一个 icon,hover 时展示一些提示信息,v0.1.15新增了计算属性 ComputedRef 类型 | `string` |`ComputedRef`v0.1.15 | ( `object`|`ComputedRef