From e22e85ed81c9a5dfa8cab208fe284ebceefbc7e3 Mon Sep 17 00:00:00 2001 From: gzezFISHER Date: Fri, 14 Aug 2020 10:21:31 +0800 Subject: [PATCH] fix search --- src/StringPrototype.js | 8 +++++--- src/components/lib/AjaxTable.vue | 14 ++++++++++---- src/components/problem/list.vue | 16 +++++++--------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/StringPrototype.js b/src/StringPrototype.js index f2bbf596..b19540b0 100644 --- a/src/StringPrototype.js +++ b/src/StringPrototype.js @@ -22,6 +22,8 @@ if (String.prototype.replaceAll === undefined) { }; } -String.prototype.trim = function () { - return this.replace(/(^\s*)|(\s*$)/g, ''); -}; \ No newline at end of file +if (String.prototype.trim === undefined) { + String.prototype.trim = function () { + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + }; +} \ No newline at end of file diff --git a/src/components/lib/AjaxTable.vue b/src/components/lib/AjaxTable.vue index 17066e09..c5153036 100644 --- a/src/components/lib/AjaxTable.vue +++ b/src/components/lib/AjaxTable.vue @@ -22,7 +22,7 @@ layout="prev, pager, next, jumper" @current-change="this.onPageChange" class="pagination" - :total="this.total" + :total="this.own_total" /> @@ -36,14 +36,20 @@ export default { tableData: null, offset: 0, pageId: 1, + own_total: this.total, }; }, watch: { limit() { this.onPageChange(this.pageId); + console.log(this.limit); }, - costumData() { - this.load_data(); + costumData(new_val, old_val) { + let json_new_val = JSON.stringify(new_val); + let json_old_val = JSON.stringify(old_val); + if (json_new_val != json_old_val) { + this.onPageChange(1); + } } }, methods: { @@ -65,7 +71,7 @@ export default { }) .then(res => { if (limit === this.limit) { - this.total = res.data.count; + this.own_total = res.data.count; this.tableData = res.data.res.map(this.process); this.loading = false; } diff --git a/src/components/problem/list.vue b/src/components/problem/list.vue index ede428b3..83d51ac4 100644 --- a/src/components/problem/list.vue +++ b/src/components/problem/list.vue @@ -10,10 +10,8 @@ v-model="searchTitle" class="input-with-select" style="margin-top: 9px;" - @clear="search" clearable > - @@ -59,7 +57,7 @@ :total="data_count" :process="process" :default_sort="{prop: 'pid', order: 'ascending'}" - :costumData="{title:this.title}" + :costumData="{title:title}" /> @@ -79,7 +77,6 @@ export default { ajax_url: apiurl('/problem/list'), limit: 50, searchTitle: '', - title: null, showTags: this.$store.state.tags.displayTags, columns: [{ name: 'score', @@ -114,7 +111,12 @@ export default { }, limit(val) { this.set_column(val); - } + }, + }, + computed: { + title() { + return this.searchTitle.trim(); + }, }, methods: { get_list_lenth() { @@ -174,10 +176,6 @@ export default { return x; }, - search() { - this.searchTitle = this.searchTitle.trim(); - this.title = this.searchTitle; - } }, components: { AjaxTable,