Skip to content

Commit eeffd81

Browse files
committed
fix: 完善图标搜索
1 parent f93377d commit eeffd81

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/views/icon/index.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div class="search">
1212
<el-input
1313
v-model="state.skey"
14-
placeholder="请输入图标(类型、名称"
14+
placeholder="请输入类型、名称、图标名"
1515
class="input-with-select"
1616
>
1717
<template #append>
@@ -36,7 +36,7 @@
3636
v-model:currentPage="state.currentPage"
3737
:page-size="49"
3838
layout="total, prev, pager, next"
39-
:total="state.skey ? state.list.length : icons.length"
39+
:total="state.searchFlag ? state.searchList.length : icons.length"
4040
>
4141
</el-pagination>
4242
</div>
@@ -67,9 +67,11 @@
6767
const state = reactive({
6868
icon: {},
6969
list: [],
70+
searchList: [],
7071
currentPage: 1,
7172
currTotal: 49,
7273
skey: '',
74+
searchFlag: false,
7375
});
7476
7577
onBeforeMount(async () => {
@@ -95,20 +97,30 @@
9597
state.currentPage = val;
9698
const start = val * 49 - 49;
9799
const end = val * 49;
98-
const iconArr = state.skey ? state.list : icons;
100+
const iconArr = state.skey ? state.searchList : icons;
99101
state.list = iconArr.slice(start, end);
100102
};
101103
102104
const handleSearchIcon = () => {
103-
if (!state.skey) state.list = icons.slice(0, 49);
104-
else {
105+
state.currentPage = 1;
106+
state.currTotal = 49;
107+
if (!state.skey) {
108+
state.searchFlag = false;
109+
state.list = icons.slice(0, 49);
110+
} else {
111+
state.searchFlag = true;
105112
let list = [];
106113
icons.map((item) => {
107-
if (item.title.indexOf(state.skey) !== -1 || item.name.indexOf(state.skey) !== -1) {
114+
if (
115+
item.title.indexOf(state.skey) !== -1 ||
116+
item.name.indexOf(state.skey) !== -1 ||
117+
item.categoryCN.indexOf(state.skey) !== -1
118+
) {
108119
list.push(item);
109120
}
110121
});
111-
state.list = list;
122+
state.searchList = list;
123+
state.list = state.searchList.slice(state.currentPage - 1, state.currTotal);
112124
}
113125
};
114126
</script>

0 commit comments

Comments
 (0)