Skip to content

Commit d6c2dd1

Browse files
ice201508jiuling
andauthored
feature-admin-search-add-debounce (#1336)
* Draft MR * feature admin search add debounce --------- Co-authored-by: jiuling <[email protected]>
1 parent 8a86ddd commit d6c2dd1

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

frontend/src/components/admin_next/models/AdminModelList.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
:placeholder="$t('admin.search') + ' ' + $t('admin.name') + ' / ' + $t('admin.owner')"
1313
size="large"
1414
:prefix-icon="Search"
15-
@input="searchModels"
15+
@input="debouncedSearch"
1616
/>
1717
</div>
1818
<Table
@@ -100,7 +100,8 @@
100100

101101
<script setup>
102102
import { Container, Pagination, Table } from '../admin_component'
103-
import { ref, onMounted, inject } from 'vue'
103+
import { ref, onMounted, onUnmounted, inject } from 'vue'
104+
import { debounce } from 'lodash'
104105
import { Search } from '@element-plus/icons-vue'
105106
import { ElMessage } from 'element-plus'
106107
import useFetchApi from '../../../packs/useFetchApi'
@@ -131,6 +132,12 @@
131132
fetchModels()
132133
}
133134
135+
const debouncedSearch = debounce(searchModels, 500)
136+
137+
onUnmounted(() => {
138+
debouncedSearch.cancel()
139+
})
140+
134141
const showDetail = (path) => {
135142
window.location.href = `/admin_panel/models/${path}`
136143
}

frontend/src/components/admin_next/users/AdminUserList.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!-- search & filter -->
44
<div class="flex items-center gap-3 w-full">
55
<el-input v-model="keyword" :placeholder="$t('admin.name') + ',' + $t('admin.email') + ',' + $t('admin.phone')" size="large" :prefix-icon="Search"
6-
@input="searchUsers" />
6+
@input="debouncedSearch" />
77
</div>
88
<Table
99
:data="users"
@@ -51,7 +51,8 @@
5151

5252
<script setup>
5353
import { Container, Pagination, Table } from '../admin_component'
54-
import { ref, onMounted } from 'vue'
54+
import { ref, onMounted, onUnmounted } from 'vue'
55+
import { debounce } from 'lodash'
5556
import { Search } from '@element-plus/icons-vue'
5657
import { ElMessage } from 'element-plus'
5758
import useFetchApi from '../../../packs/useFetchApi'
@@ -77,6 +78,12 @@ const searchUsers = () => {
7778
fetchUsers()
7879
}
7980
81+
const debouncedSearch = debounce(searchUsers, 500)
82+
83+
onUnmounted(() => {
84+
debouncedSearch.cancel()
85+
})
86+
8087
const showDetail = (row) => {
8188
window.location.href = `/admin_panel/users/${row.username}`
8289
}

0 commit comments

Comments
 (0)