系统组件
# 1. 常用组件
# 1.1 Editor 富文本组件
基于 wangEditor (opens new window) 封装
- Editor 组件:位于 src/components/Editor (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/components/editor.html (opens new window)
- 实战案例:src/views/system/notice/NoticeForm.vue (opens new window)

# 1.2 Dialog 弹窗组件
对 Element Plus 的 Dialog 组件进行封装,支持最大化、最大高度等特性
- Dialog 组件:位于 src/components/Dialog (opens new window) 内
- 实战案例:src/views/system/dept/DeptForm.vue (opens new window)
默认行为如下:
- 宽度:未传
width时使用 Element Plus 默认的50% - 位置:默认垂直居中;传入
top时按 Element Plus 默认位置显示,也可以显式传入align-center控制 - 默认开启拖拽
draggable、关闭后销毁destroy-on-close;点击遮罩不关闭(closeOnClickModal��认false) - 标题栏带最大化按钮(
fullscreen默认true),defaultFullscreen控制打开时是否最大化 scroll为true时,内容区包裹在滚动容器中,容器高度固定为maxHeight(默认400px,最大化时为窗口可用高度),内容超出时滚动;内容较少时也会占满这个高度loading为true时,默认插槽的内容会被卸载(v-if),只显示加载区;loading变回false后重新创建。所以,内容里的表单等组件内部状态(如未绑定到外部数据的输入、el-form的校验状态)会丢失,需要保留的数据请放在父组件的响应式数据中;只想遮挡内容时,可以不传loading,改用v-loading指令- 拖拽、关闭后销毁等默认值可以被传入的同名属性覆盖;其它属性和事件(如
append-to-body、@closed)原样传给el-dialog;支持title、footer插槽
<Dialog v-model="dialogVisible" :title="dialogTitle" width="600px">
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px">
<!-- ... -->
</el-form>
<template #footer>
<el-button type="primary" :disabled="formLoading" @click="submitForm">确 定</el-button>
<el-button @click="dialogVisible = false">取 消</el-button>
</template>
</Dialog>
另外,同目录的 ResizeDialog 组件在 Dialog 的基础上支持拖拽边缘调整大小,width 默认为 40%,可通过 minResizeWidth、minResizeHeight 限制最小尺寸。

# 1.3 ContentWrap 包裹组件
对 Element Plus 的 ElCard 组件进行封装,自带标题、边距
- ContentWrap 组件:位于 src/components/ContentWrap (opens new window) 内
- 实战案例:src/views/system/post/index.vue (opens new window)
内容区默认 10px 内边距,卡片之间保留 15px 下边距。title 设置标题,message 会在标题旁显示提示图标,bodyStyle 可覆盖内容区样式;设置 title 后,还可以通过 header 插槽在标题右侧追加按钮等内容。
<ContentWrap title="基本信息" message="展示客户的基础资料">
<!-- 内容 -->
</ContentWrap>

详情页怎么写?
详情页统一使用 ContentWrap 包裹 Element Plus 原生的 Descriptions 描述列表 (opens new window),字典字段使用 <dict-tag /> 展示。可参考 src/views/crm/clue/detail/ClueDetailsInfo.vue (opens new window)。
# 1.4 Pagination 分页组件
对 Element Plus 的 Pagination (opens new window) 组件进行封装
- Pagination 组件:位于 src/components/Pagination (opens new window) 内
- 实战案例:src/views/system/post/index.vue (opens new window)

# 1.5 UploadFile 上传文件组件
对 Element Plus 的 Upload (opens new window) 组件进行封装,上传文件到文件服务
- UploadFile 组件:位于 src/components/UploadFile/src/UploadFile.vue (opens new window) 内
- 实战案例:src/views/crm/followup/FollowUpRecordForm.vue (opens new window)
# 1.6 UploadImg 上传图片组件
对 Element Plus 的 Upload (opens new window) 组件进行封装,上传图片到文件服务
- UploadImg 组件:位于 src/components/UploadFile/src/UploadImg.vue (opens new window) 内
- 实战案例:src/views/system/oauth2/client/ClientForm.vue (opens new window)

# 2. 不常用组件
# 2.1 EChart 图表组件
基于 Apache ECharts (opens new window) 封装,自适应窗口大小
- EChart 组件:位于 src/components/EChart (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/components/echart.html (opens new window)
- 实战案例:src/views/mp/statistics/index.vue (opens new window)

# 2.2 InputPassword 密码输入框
对 Element Plus 的 Input 组件进行封装
- InputPassword 组件:位于 src/components/InputPassword (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/components/input-password.html (opens new window)
- 实战案例:src/views/Profile/components/ResetPwd.vue (opens new window)
# 2.3 ImageViewer 图片预览组件
将 Element Plus 的 ImageViewer (opens new window) 组件函数��,通过函数方便创建组件
- ImageViewer 组件:位于 src/components/ImageViewer (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/components/image-viewer.html (opens new window)
- 实战案例:暂无
# 2.4 Qrcode 二维码组件
基于 qrcode (opens new window) 封装
- Qrcode 组件:位于 src/components/Qrcode (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/components/qrcode.html (opens new window)
- 实战案例:暂无

# 2.5 Highlight 高亮组件
- Highlight 组件:位于 src/components/Highlight (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/components/highlight.html (opens new window)
- 实战案例:暂无

# 2.6 Error 缺省组件
用于各种占位图组件,如 404、403、500 等错误页面。
- Error ��件:位于 src/components/Error (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/components/error.html (opens new window)
- 实战案例:403.vue (opens new window)、404.vue (opens new window)、500.vue (opens new window)
# 2.7 Sticky 黏性组件
- Sticky 组件:位于 src/components/Sticky (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/components/sticky.html (opens new window)
- 实战案例:暂无

# 2.8 CountTo 数字动画组件
- CountTo 组件:位于 src/components/CountTo (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/components/count-to.html (opens new window)
- 实战案例:暂无
# 2.9 useWatermark 水印组件
为元素设置水印
- useWatermark 组件:位于 src/hooks/web/useWatermark.ts (opens new window) 内
- 详细文档:vue-element-plus-admin-doc/hooks/useWatermark.html (opens new window)
- 实战案例:暂无

# 2.10 form-create 动态表单生成器
详细文档:http://www.form-create.com/ (opens new window)
① 实战案例 - 表单设计:src/views/infra/build/index.vue (opens new window)

② 实战案例 - 表单展示:src/views/bpm/processInstance/detail/index.vue (opens new window)

# 2.11 bpmn-js 工作流组件
核心是基于 bpmn-js (opens new window) 封装
# 2.11.1 MyProcessDesigner 流程设计组件
- MyProcessDesigner 组件:位于 src/components/bpmnProcessDesigner/package/designer/index.ts (opens new window) 内,基于 https://gitee.com/MiyueSC/bpmn-process-designer (opens new window) 项目适配
- 实战案例:src/views/bpm/model/form/editor/index.vue (opens new window)

# 2.11.2 MyProcessViewer 流程展示组件
- MyProcessViewer 组件:位于 src/components/bpmnProcessDesigner/package/designer/index2.ts (opens new window) 内
- 实战案例:src/views/bpm/processInstance/detail/ProcessInstanceBpmnViewer.vue (opens new window)

# 3. 组件注册
友情提示:
该小节,基于 《vue element plus admin —— 组件注册 》 (opens new window) 的内容修改。
组件注册可以分成两种类型:自动按需引入、全局注册。
# 3.1 自动按需引入
项目通过 unplugin-vue-components (opens new window) 自动按需引入组件,配置在 build/vite/index.ts (opens new window) 中:
- Element Plus 组件:通过
ElementPlusResolver解析,如<el-table />、<el-dialog /> - 项目组件:扫描
src/components/**下的.vue文件,按文件名注册,如<ContentWrap />、<Dialog />、<DictTag />
因此,在 .vue 文件的模板里可以直接使用这些组件,无需手动 import:
<template>
<ContentWrap>
<el-table :data="list">
<el-table-column label="状态" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
</el-table>
</ContentWrap>
</template>
注意:tsx 文件不会自动引入组件,需要手动 import 后使用。
# 3.2 全局注册
如果需要全局注册,在 src/components/index.ts (opens new window) 中添加。目前全局注册了 Icon 与 Permission 组件:
import type { App } from 'vue'
import { Icon } from './Icon'
import { Permission } from './Permission'
export { Icon, registerIcons } from './Icon'
export type { IconRegistry } from './Icon'
export const setupGlobCom = (app: App<Element>): void => {
app.component('Icon', Icon)
app.component('Permission', Permission)
}
Element Plus 需要全局安装的插件,在 src/plugins/elementPlus/index.ts (opens new window) 中添加。目前只安装了 ElLoading(提供 v-loading 指令),其它 Element Plus 组件都走自动按需引入:
import type { App } from 'vue'
import { ElLoading } from 'element-plus'
export const setupElementPlus = (app: App<Element>) => {
app.use(ElLoading)
}