Skip to content

Commit

Permalink
perf: IconPicker新增搜索功能
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong321200875 committed Oct 9, 2023
1 parent 1c51221 commit a4d1391
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/components/IconPicker/src/IconPicker.vue
Expand Up @@ -52,7 +52,7 @@ const tabChange = () => {
currentPage.value = 1
}
const pageSize = ref(63)
const pageSize = ref(49)
const currentPage = ref(1)
Expand All @@ -78,7 +78,7 @@ async function init(icon?: string) {
iconName.value = iconInfo[0]
const wrapIndex = icons.findIndex((item) => item.prefix === iconInfo[0])
// 查询当前icon的索引
const index = icons[wrapIndex].icons.findIndex((item) => item === icon)
const index = filterItemIcons(icons[wrapIndex].icons).findIndex((item) => item === icon)
// 计算当前icon的页码
await nextTick()
currentPage.value = Math.ceil((index + 1) / unref(pageSize))
Expand All @@ -91,6 +91,16 @@ const popoverShow = () => {
const iconSelect = (icon: string) => {
modelValue.value = icon
}
const search = ref('')
const filterItemIcons = (icons: string[]) => {
return icons.filter((item) => item.includes(unref(search)))
}
const inputClear = () => {
init(unref(modelValue))
}
</script>

<template>
Expand All @@ -100,7 +110,7 @@ const iconSelect = (icon: string) => {
placement="bottom"
trigger="click"
:width="450"
popper-style="box-shadow: rgb(14 18 22 / 35%) 0px 10px 38px -10px, rgb(14 18 22 / 20%) 0px 10px 20px -15px; height: 400px;"
popper-style="box-shadow: rgb(14 18 22 / 35%) 0px 10px 38px -10px, rgb(14 18 22 / 20%) 0px 10px 20px -15px; height: 380px;"
@show="popoverShow"
>
<template #reference>
Expand All @@ -109,11 +119,18 @@ const iconSelect = (icon: string) => {
</div>
</template>
<ElScrollbar class="h-[calc(100%-50px)]!">
<ElInput
v-model="search"
class="mb-20px"
clearable
placeholder="搜索图标"
@clear="inputClear"
/>
<ElTabs tab-position="left" v-model="iconName" @tab-change="tabChange">
<ElTabPane v-for="item in icons" :key="item.name" :label="item.name" :name="item.prefix">
<div class="flex flex-wrap box-border">
<div
v-for="icon in filterIcons(item.icons)"
v-for="icon in filterIcons(filterItemIcons(item.icons))"
:key="icon"
:style="{
width: iconSize,
Expand Down Expand Up @@ -149,7 +166,7 @@ const iconSelect = (icon: string) => {
small
:page-sizes="[100, 200, 300, 400]"
layout="total, prev, pager, next, jumper"
:total="icons[currentIconNameIndex].icons.length"
:total="filterItemIcons(icons[currentIconNameIndex].icons).length"
/>
</div>
</ElPopover>
Expand Down

0 comments on commit a4d1391

Please sign in to comment.