Merge pull request #217 from 1129921824/master

实现简易的搜索功能
This commit is contained in:
木偶 2023-08-11 10:28:43 +08:00 committed by GitHub
commit c2a23f0c6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 2 deletions

View File

@ -4,6 +4,7 @@ export default {
market: { market: {
title: 'Market', title: 'Market',
search: 'Search Plugins', search: 'Search Plugins',
searchResult: 'Search Results',
explore: 'Explore', explore: 'Explore',
efficiency: 'Efficiency', efficiency: 'Efficiency',
searchTool: 'Search Tools', searchTool: 'Search Tools',

View File

@ -4,6 +4,7 @@ export default {
market: { market: {
title: '插件市场', title: '插件市场',
search: '搜索插件', search: '搜索插件',
searchResult: '搜索结果',
explore: '探索', explore: '探索',
efficiency: '效率', efficiency: '效率',
searchTool: '搜索工具', searchTool: '搜索工具',

View File

@ -16,6 +16,7 @@ export default createStore({
state: { state: {
totalPlugins: [], totalPlugins: [],
localPlugins: [], localPlugins: [],
searchValue: '',
}, },
mutations: { mutations: {
commonUpdate(state: any, payload) { commonUpdate(state: any, payload) {
@ -23,6 +24,9 @@ export default createStore({
state[key] = payload[key]; state[key] = payload[key];
}); });
}, },
setSearchValue(state: any, payload) {
state.searchValue = payload;
},
}, },
actions: { actions: {
async init({ commit }) { async init({ commit }) {

View File

@ -0,0 +1,45 @@
<template>
<div class="result">
<PluginList
v-if="result && !!result.length"
@downloadSuccess="downloadSuccess"
:title="$t('feature.market.searchResult')"
:list="result"
/>
</div>
</template>
<script setup>
import { computed } from 'vue';
import PluginList from './plugin-list.vue';
import { useStore } from 'vuex';
const store = useStore();
const totalPlugins = computed(() => store.state.totalPlugins);
const searchValue = computed(() => store.state.searchValue);
const result = computed(() => {
if (searchValue.value.trim().length > 0) {
const pattern = new RegExp(searchValue.value);
return totalPlugins.value.filter((plugin) => {
if (plugin.pluginName.match(pattern)) {
return true;
} else {
return false;
}
});
} else {
return totalPlugins.value;
}
});
</script>
<style lang="less">
.result {
width: 100%;
height: 100vh;
overflow-x: hidden;
box-sizing: border-box;
}
</style>

View File

@ -73,6 +73,7 @@ import Worker from './components/worker.vue';
import Tools from './components/tools.vue'; import Tools from './components/tools.vue';
import Dev from './components/devlopment.vue'; import Dev from './components/devlopment.vue';
import Image from './components/image.vue'; import Image from './components/image.vue';
import Result from './components/result.vue';
const Components = { const Components = {
finder: Finder, finder: Finder,
@ -81,6 +82,7 @@ const Components = {
image: Image, image: Image,
tools: Tools, tools: Tools,
dev: Dev, dev: Dev,
result: Result,
}; };
const state = reactive({ const state = reactive({
@ -93,6 +95,11 @@ const store = useStore();
const totalPlugins = computed(() => store.state.totalPlugins); const totalPlugins = computed(() => store.state.totalPlugins);
const { searchValue, current } = toRefs(state); const { searchValue, current } = toRefs(state);
const onSearch = (searchValue: string) => {
state.current = ['result'];
store.commit('setSearchValue', searchValue);
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@ -104,9 +111,11 @@ const { searchValue, current } = toRefs(state);
width: 100%; width: 100%;
overflow: hidden; overflow: hidden;
background: var(--color-menu-bg); background: var(--color-menu-bg);
height: calc(~"100vh - 46px"); height: calc(~'100vh - 46px');
.search { .search {
:deep(.ant-btn), :deep(.ant-input), :deep(.ant-input-group-addon) { :deep(.ant-btn),
:deep(.ant-input),
:deep(.ant-input-group-addon) {
color: var(--ant-primary-color) !important; color: var(--ant-primary-color) !important;
background: var(--color-input-hover); background: var(--color-input-hover);
border-color: var(--color-border-light); border-color: var(--color-border-light);