Stabilize dashboard user search trigger
This commit is contained in:
@@ -93,9 +93,11 @@ module.exports = {
|
|||||||
pageSync: {
|
pageSync: {
|
||||||
get() { return this.$store.state.dashboard_user.page },
|
get() { return this.$store.state.dashboard_user.page },
|
||||||
set(val) {
|
set(val) {
|
||||||
if (val === this.$store.state.dashboard_user.page) return
|
let nextPage = Number(val) || 1
|
||||||
this.$store.commit('dashboard_user/update_page', val)
|
let currentPage = Number(this.$store.state.dashboard_user.page) || 1
|
||||||
this.doSearch(val)
|
if (nextPage === currentPage) return
|
||||||
|
this.$store.commit('dashboard_user/update_page', nextPage)
|
||||||
|
this.doSearch(nextPage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ export default {
|
|||||||
limit: 20,
|
limit: 20,
|
||||||
total_rows: 0,
|
total_rows: 0,
|
||||||
total_pages: 0,
|
total_pages: 0,
|
||||||
|
last_search_signature: '',
|
||||||
|
last_search_at: 0,
|
||||||
search_status: 0,
|
search_status: 0,
|
||||||
save_status: 0,
|
save_status: 0,
|
||||||
save_error_message: '',
|
save_error_message: '',
|
||||||
@@ -30,6 +32,8 @@ export default {
|
|||||||
update_limit(state, val) { state.limit = val },
|
update_limit(state, val) { state.limit = val },
|
||||||
update_total_rows(state, val) { state.total_rows = val },
|
update_total_rows(state, val) { state.total_rows = val },
|
||||||
update_total_pages(state, val) { state.total_pages = val },
|
update_total_pages(state, val) { state.total_pages = val },
|
||||||
|
update_last_search_signature(state, val) { state.last_search_signature = val },
|
||||||
|
update_last_search_at(state, val) { state.last_search_at = val },
|
||||||
update_search_status(state, val) { state.search_status = val },
|
update_search_status(state, val) { state.search_status = val },
|
||||||
update_save_status(state, val) { state.save_status = val },
|
update_save_status(state, val) { state.save_status = val },
|
||||||
update_save_error_message(state, val) { state.save_error_message = val },
|
update_save_error_message(state, val) { state.save_error_message = val },
|
||||||
@@ -38,10 +42,23 @@ export default {
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async search(context, prm) {
|
async search(context, prm) {
|
||||||
|
let normalized = {
|
||||||
|
username: (prm && prm.username ? prm.username : '').trim(),
|
||||||
|
project: (prm && prm.project ? prm.project : 'all'),
|
||||||
|
page: Number(prm && prm.page ? prm.page : context.state.page) || 1,
|
||||||
|
limit: Number(prm && prm.limit ? prm.limit : context.state.limit) || 20
|
||||||
|
}
|
||||||
|
let signature = JSON.stringify(normalized)
|
||||||
|
let now = Date.now()
|
||||||
|
if (signature === context.state.last_search_signature && (now - context.state.last_search_at) < 1000) {
|
||||||
|
return { status: 'SKIP' }
|
||||||
|
}
|
||||||
|
context.commit('update_last_search_signature', signature)
|
||||||
|
context.commit('update_last_search_at', now)
|
||||||
context.commit('update_search_status', 1)
|
context.commit('update_search_status', 1)
|
||||||
try {
|
try {
|
||||||
prm.token = one_token()
|
let payload = Object.assign({}, normalized, { token: one_token() })
|
||||||
let resp = await api.search(prm)
|
let resp = await api.search(payload)
|
||||||
if (resp.status != 'OK') {
|
if (resp.status != 'OK') {
|
||||||
context.commit('update_search_status', 3)
|
context.commit('update_search_status', 3)
|
||||||
context.commit('update_save_error_message', resp.message)
|
context.commit('update_save_error_message', resp.message)
|
||||||
|
|||||||
Reference in New Issue
Block a user