Skip to content

Commit

Permalink
feat: change request search function from back end to front end
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemonnnnnnnnnnn committed Feb 22, 2024
1 parent 7e8c12f commit ce774bc
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/lib/modules/ServiceModule/components/TypesTree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { Button, Search } from 'carbon-components-svelte';
import { confirm } from '@tauri-apps/api/dialog';
let full_list: TypesTree[] = [];
let list: TypesTree[] = [];
let searchKey = '';
Expand All @@ -16,9 +17,10 @@
});
function get_data() {
request('get_request_list', { key: searchKey })
request('get_request_list', { key: "" })
// @ts-expect-error
.then((res: SuccessResponse<TypesTree[]>) => {
full_list = sort(res.data);
list = sort(res.data);
toast.push(JSON.stringify(res.message), toastTheme.success);
})
Expand All @@ -27,6 +29,33 @@
});
}
function filter_data() {
if (searchKey === '') {
list = full_list;
return;
}
list = do_filter(full_list);
function do_filter(list: TypesTree[]) {
return list.filter((item) => {
if (item.name.includes(searchKey)) {
return true;
} else {
if (item.children.length) {
item.children = do_filter(item.children);
if (item.children.length) {
return true;
}
}
return false;
}
});
}
}
async function update_service() {
const confirmed = await confirm('操作将重新生成ts文件,是否确定?');
Expand Down Expand Up @@ -68,9 +97,9 @@
</div>
<div class="flex items-center" style="margin-top:10px;margin-bottom:10px">
<Search bind:value={searchKey} />
<Button kind="secondary" on:click={get_data}>搜索</Button>
<Button kind="secondary" on:click={filter_data}>搜索</Button>
</div>

{#each list as item}
<Node {...item} expanded={true} />
{/each}
Expand Down

0 comments on commit ce774bc

Please sign in to comment.