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ライセンスの下で公開されています