antd vue图标选择器

目前antd vue还没有图标选择器,但是由于需求所需所以自定义了一个iconPicker一、效果展示二、使用1、自定义组件iconPicker.vue,支持’click’, ‘hover’, ‘focus’ 三种触发方式,默认click触发<template> <a-popover :trigger="trigger" v-model:visible="visible" > <template #title
摘要由CSDN通过智能技术生成

目前antd vue还没有图标选择器,但是由于需求所需所以自定义了一个iconPicker

一、效果展示

在这里插入图片描述

二、使用

1、自定义组件iconPicker.vue,支持’click’, ‘hover’, ‘focus’ 三种触发方式,默认click触发

<template>
    <a-popover
        :trigger="trigger"
        v-model:visible="visible"
    >
      <template #title>
        <a-input-search
            v-model:value="searchValue"
            placeholder="输入英文关键词进行搜索"
            @change="filterIcon"
        />
      </template>

      <template #content>
        <div class="icon-box">
          <div
              v-for="(item,index) in iconArr"
              :key="index"
              @click="handleClick(item)"
              class="icon-content"
              :style="{ background: icon === item ? '#268961' : ''}"
          >
            <component :is="$antIcons[item]" />
          </div>
        </div>
      </template>
      <slot name="iconSelect" ></slot>
    </a-popover>
</template>

<script lang="ts">
  import {
   defineComponent,ref,watch} from 'vue'
  import icons from '../utils/icons.json'
export default defineComponent({
   
  name: "IconPicker",
  props:{
   
    icon:{
   
      type:String,
      required:true
    },
    //自定义触发方式
    trigger:{
   
      type:String,
      default: 'click',
      validator: function(value) {
   
        return ['click', 'hover', 'focus'].indexOf(value) !== -1
      }
    }
  },
  setup(props,context){
   
    const iconArr = ref<string[]>(icons)
    const visible = ref<boolean>(false)
    const searchValue = ref('')

    const handleClick = (icon)=>{
   
      context.emit('update:icon',icon)
      visible.value = false;
    }

    /**
     * 进行搜索过滤
     */
    const filterIcon = ()=>{
   
      if (searchValue.value){
   
        iconArr.value = icons.filter(item =>  item.toLowerCase().includes(searchValue.value.toLowerCase()) )
      }else{
   
        iconArr.value = icons;
      }
    }

    watch(visible,()=>{
   
      searchValue.value = ''
      iconArr.value = icons;
    })

    return{
   
      visible,
      iconArr,
      handleClick,
      searchValue,
      filterIcon
    }
  }
})
</script>

<style scoped>
  .icon-box{
   
    overflow: auto;
    font-size: 20px;
    width: 250px;
    height: 230px;
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    align-content: flex-start;
    justify-content: center;
  }

  .icon-content{
   
    width: 45px;
    height: 40px;
    margin:  5px;
    cursor: pointer;
    text-align: center;
    border-radius: 6px;
    border: 1px solid #ccc
  }

  .icon-content:hover{
   
    background: #1890ff;
  }
</style>

2、引入icons.json文件

[
  "AccountBookFilled",
  "AccountBookOutlined",
  "AccountBookTwoTone",
  "AimOutlined",
  "AlertFilled",
  "AlertOutlined",
  "AlertTwoTone",
  "AlibabaOutlined",
  "AlignCenterOutlined",
  "AlignLeftOutlined",
  "AlignRightOutlined",
  "AlipayCircleFilled",
  "AlipayCircleOutlined",
  "AlipayOutlined",
  "AlipaySquareFilled",
  "AliwangwangFilled",
  "AliwangwangOutlined",
  "AliyunOutlined",
  "AmazonCircleFilled",
  "AmazonOutlined",
  "AmazonSquareFilled",
  "AndroidFilled",
  "AndroidOutlined",
  "AntCloudOutlined",
  "AntDesignOutlined",
  "ApartmentOutlined",
  "ApiFilled",
  "ApiOutlined",
  "ApiTwoTone",
  "AppleFilled",
  "AppleOutlined",
  "AppstoreAddOutlined",
  "AppstoreFilled",
  "AppstoreOutlined",
  "AppstoreTwoTone",
  "AreaChartOutlined",
  "ArrowDownOutlined",
  "ArrowLeftOutlined",
  "ArrowRightOutlined",
  "ArrowUpOutlined",
  "ArrowsAltOutlined",
  "AudioFilled",
  "AudioMutedOutlined",
  "AudioOutlined"
  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值