feat: add search

This commit is contained in:
Fine 2023-11-30 13:37:02 +08:00
parent a1c7a00a83
commit 97beb6467a
2 changed files with 25 additions and 3 deletions

2
src/types/app.d.ts vendored
View File

@ -59,7 +59,7 @@ export interface SubItem {
icon: string; icon: string;
title: string; title: string;
activate: boolean; activate: boolean;
name?: string; name: string;
path?: string; path?: string;
notShow?: boolean; notShow?: boolean;
id?: string; id?: string;

View File

@ -14,11 +14,20 @@ See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<div class="menus flex-v"> <div class="menus flex-v">
<div>
<el-input v-model="searchText" placeholder="Please input name" class="input-with-search" @change="searchMenus">
<template #append>
<el-button size="small">
<Icon size="sm" iconName="search" />
</el-button>
</template>
</el-input>
</div>
<div class="category-body flex-h"> <div class="category-body flex-h">
<div class="mr-20 mt-10 flex-h category"> <div class="mr-20 mt-10 flex-h category">
<el-card <el-card
class="item" class="item"
v-for="(menu, index) in appStore.allMenus" v-for="(menu, index) in menus"
:key="index" :key="index"
@click="handleItems(menu)" @click="handleItems(menu)"
:class="currentItems.name === menu.name ? 'active' : ''" :class="currentItems.name === menu.name ? 'active' : ''"
@ -59,10 +68,20 @@ limitations under the License. -->
const { t, te } = useI18n(); const { t, te } = useI18n();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const currentItems = ref<MenuOptions>(appStore.allMenus[0] || {}); const currentItems = ref<MenuOptions>(appStore.allMenus[0] || {});
const searchText = ref<string>("");
const menus = ref<MenuOptions[]>(appStore.allMenus || []);
function handleItems(item: MenuOptions) { function handleItems(item: MenuOptions) {
currentItems.value = item; currentItems.value = item;
} }
function searchMenus() {
if (!searchText.value) {
menus.value = appStore.allMenus;
return;
}
menus.value = appStore.allMenus.filter((item: MenuOptions) => item.name.includes(searchText.value));
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.menus { .menus {
@ -75,7 +94,6 @@ limitations under the License. -->
.category-body { .category-body {
padding-left: 20px 30px; padding-left: 20px 30px;
width: 100%; width: 100%;
height: 100%;
justify-content: space-between; justify-content: space-between;
} }
@ -111,6 +129,10 @@ limitations under the License. -->
cursor: pointer; cursor: pointer;
} }
.input-with-search {
width: 300px;
}
.category { .category {
flex-wrap: wrap; flex-wrap: wrap;
border-right: 1px solid var(--sw-marketplace-border); border-right: 1px solid var(--sw-marketplace-border);