| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- const n = `<template>
- <a-select
- :value="value"
- :disabled="disabled"
- :mode="multiple ? 'multiple' : undefined"
- :allow-clear="!required"
- :placeholder="placeholder"
- show-search
- :filter-option="filterOption"
- @change="handleSelect"
- v-bind="attrs"
- :style="{ minWidth: minWidth + 'px' }"
- >
- <a-select-option :value="item" v-for="item in iconList" :key="item">
- <s-icon :name="item" color=""></s-icon>
- <span style="margin-left: 8px">{{ item }}</span>
- </a-select-option>
- </a-select>
- </template>
- <script setup>
- import { useAttrs } from 'vue'
- import { filterIcons } from './icon-groups'
- const attrs = useAttrs()
- defineProps({
- // 选中图标名,支持 v-model:value
- value: {
- type: String,
- default: ''
- },
- // 占位文案
- placeholder: {
- type: String,
- default() {
- return window.$l('请选择图标')
- }
- },
- // 是否多选
- multiple: {
- type: Boolean,
- default: false
- },
- // 是否禁用
- disabled: {
- type: Boolean,
- default: false
- },
- // 是否必填(表单校验用)
- required: {
- type: Boolean,
- default: false
- },
- // 下拉面板最小宽度,单位 px
- minWidth: {
- type: Number,
- default: 240
- }
- })
- const emits = defineEmits(['update:value', 'change'])
- const handleSelect = (v) => {
- emits('update:value', v)
- emits('change', v)
- }
- // 图标名固定,列表只需算一次;搜索交给 a-select 的 filter-option(虚拟滚动只渲染可见项)
- const iconList = filterIcons('all', '')
- // 按图标名做不区分大小写的包含匹配,默认的 value 匹配对 Pascal 名同样适用但区分大小写
- const filterOption = (input, option) =>
- String(option?.value ?? '')
- .toLowerCase()
- .includes(String(input ?? '').trim().toLowerCase())
- <\/script>
- `;
- export {
- n as default
- };
|