Skip to content

通用组件

本文档介绍 Antdv Next Admin 项目中除 Pro 组件外的其他常用组件。

目录


IconPicker 图标选择器

用于选择图标的弹出式组件,支持搜索和分类浏览。

位置

src/components/IconPicker/

基础用法

vue
<template>
  <IconPicker v-model:value="iconName" />
</template>

<script setup>
import { ref } from 'vue'
import IconPicker from '@/components/IconPicker/index.vue'

const iconName = ref('HomeOutlined')
</script>

Props

属性类型默认值说明
valuestring-当前选中的图标名
placeholderstring'请选择图标'占位文字
readonlybooleanfalse是否只读

事件

事件名参数说明
changeicon: string选择图标时触发

Captcha 验证码

提供多种验证码类型:滑块、拼图、旋转、点选。

位置

src/components/Captcha/

滑块验证码

vue
<template>
  <SliderCaptcha
    v-model:visible="visible"
    @success="handleSuccess"
    @fail="handleFail"
  />
</template>

<script setup>
import { ref } from 'vue'
import SliderCaptcha from '@/components/Captcha/SliderCaptcha.vue'

const visible = ref(false)

const handleSuccess = () => {
  message.success('验证通过')
  // 执行登录等操作
}

const handleFail = () => {
  message.error('验证失败,请重试')
}
</script>

属性

属性类型默认值说明
visiblebooleanfalse是否显示
widthnumber300宽度
heightnumber200高度

Editor 富文本编辑器

基于 TipTap 的富文本编辑器组件。

位置

src/components/Editor/

基础用法

vue
<template>
  <Editor v-model="content" :height="400" />
</template>

<script setup>
import { ref } from 'vue'
import Editor from '@/components/Editor/index.vue'

const content = ref('<p>初始内容</p>')
</script>

Props

属性类型默认值说明
modelValuestring''编辑器内容(HTML)
heightnumber300编辑器高度
placeholderstring'请输入内容...'占位文字
disabledbooleanfalse是否禁用
toolbarstring[]全部显示的工具栏按钮

工具栏配置

vue
<Editor
  v-model="content"
  :toolbar="['bold', 'italic', 'heading', 'link', 'image', 'code']"
/>

可用工具:

  • bold - 粗体
  • italic - 斜体
  • heading - 标题
  • link - 链接
  • image - 图片
  • code - 代码块
  • blockquote - 引用
  • bulletList - 无序列表
  • orderedList - 有序列表

Watermark 水印组件

用于在页面上添加防篡改水印。

位置

src/components/Watermark/

基础用法

vue
<template>
  <Watermark content="内部资料" :fullscreen="true" />
</template>

<script setup>
import Watermark from '@/components/Watermark/index.vue'
</script>

属性

属性类型默认值说明
contentstring-水印文字
fullscreenbooleanfalse是否全屏显示
opacitynumber0.15透明度
fontSizenumber14字体大小
colorstring'#000'字体颜色
rotatenumber-30旋转角度
gapnumber[][100, 100]水印间距

使用 Store 管理

项目中可通过 useWatermarkStore 管理水印:

typescript
import { useWatermarkStore } from '@/stores/watermark'

const watermarkStore = useWatermarkStore()

// 设置水印
watermarkStore.setWatermark({
  content: `${userStore.userInfo?.username} - ${formatDate(new Date())}`,
})

// 清除水印
watermarkStore.clearWatermark()

PermissionButton 权限按钮

封装了权限检查的按钮组件。

位置

src/components/Permission/PermissionButton.vue

基础用法

vue
<template>
  <PermissionButton permission="user.create">
    新增用户
  </PermissionButton>
  
  <PermissionButton :permission="['user.edit', 'user.admin']">
    编辑
  </PermissionButton>
</template>

<script setup>
import PermissionButton from '@/components/Permission/PermissionButton.vue'
</script>

Props

属性类型默认值说明
permissionstring | string[]-所需权限
allbooleanfalse是否需要全部权限

使用建议

1. 按需引入

这些组件在需要时引入,不需要全局注册:

typescript
import IconPicker from '@/components/IconPicker/index.vue'

2. 与 Pro 组件配合

在 ProForm 中使用这些组件:

typescript
const formItems = [
  {
    name: 'icon',
    label: '图标',
    type: 'custom',
    render: () => h(IconPicker),
  },
]

3. 权限控制

结合权限系统使用:

vue
<PermissionButton permission="user.export">
  <ExportOutlined />
  导出数据
</PermissionButton>

下一步

基于 MIT 许可发布