feat: support search on Marketplace (#350)

This commit is contained in:
Fine0830 2023-11-30 23:30:01 +08:00 committed by GitHub
parent a1c7a00a83
commit b2ab93926d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 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' : ''"
@ -54,15 +63,35 @@ limitations under the License. -->
import { ref } from "vue"; import { ref } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import type { MenuOptions } from "@/types/app"; import type { MenuOptions, SubItem } from "@/types/app";
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) =>
(te(item.i18nKey) ? t(item.i18nKey) : item.title).toLowerCase().includes(searchText.value.toLowerCase()) ||
!!item.subItems.find((subItem: SubItem) =>
(te(subItem.i18nKey) ? t(subItem.i18nKey) : item.title)
.toLowerCase()
.includes(searchText.value.toLowerCase()),
),
);
currentItems.value = menus.value[0] || {};
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.menus { .menus {
@ -111,6 +140,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);