|
@@ -115,29 +115,63 @@ export default {
|
|
loaded: false,
|
|
loaded: false,
|
|
loading: false,
|
|
loading: false,
|
|
pageNum: 1,
|
|
pageNum: 1,
|
|
|
|
+ total: 0,
|
|
list: []
|
|
list: []
|
|
}
|
|
}
|
|
Object.assign(this.listState, state)
|
|
Object.assign(this.listState, state)
|
|
},
|
|
},
|
|
- doSearch (search) {
|
|
|
|
|
|
+ setUrlQuery: function () {
|
|
|
|
+ const arr = []
|
|
|
|
+ for (const key in this.searchQuery) {
|
|
|
|
+ arr.push(this.searchQuery[key] === this.$route.query[key])
|
|
|
|
+ }
|
|
|
|
+ // 如果当前url和设置的url完全相同或者搜索值为空时候,则直接返回
|
|
|
|
+ // 是否所有元素都为true
|
|
|
|
+ const isSame = arr.every(item => item)
|
|
|
|
+ if (isSame || !this.searchQuery.text) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ this.$router.replace({
|
|
|
|
+ name: 'search',
|
|
|
|
+ query: {
|
|
|
|
+ type: this.searchQuery.type,
|
|
|
|
+ text: this.searchQuery.text
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ getSearchState: function (search) {
|
|
if (search) {
|
|
if (search) {
|
|
Object.assign(this.searchQuery, search)
|
|
Object.assign(this.searchQuery, search)
|
|
} else {
|
|
} else {
|
|
this.searchQuery.type = this.$refs.search.type
|
|
this.searchQuery.type = this.$refs.search.type
|
|
- this.searchQuery.text = this.$refs.search.input
|
|
|
|
|
|
+ this.searchQuery.text = this.$refs.search.input.trim().replace(/\s+/g, ' ')
|
|
}
|
|
}
|
|
- this.getList()
|
|
|
|
},
|
|
},
|
|
- async getList () {
|
|
|
|
- if (!this.searchQuery.text) return
|
|
|
|
|
|
+ doSearch (search) {
|
|
|
|
+ this.getSearchState(search)
|
|
|
|
+ if (!this.searchQuery.text) {
|
|
|
|
+ if (search.events === 'onSubmit') {
|
|
|
|
+ this.$router.push('/')
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ this.resetListState()
|
|
|
|
+ this.getList(search)
|
|
|
|
+ },
|
|
|
|
+ async getList (search) {
|
|
const query = {
|
|
const query = {
|
|
- keyWord: this.searchQuery.text,
|
|
|
|
|
|
+ keyWord: this.searchQuery.text.trim().replace(/\s+/g, ' '),
|
|
tag: this.searchQuery.type === '全部' ? '' : this.searchQuery.type,
|
|
tag: this.searchQuery.type === '全部' ? '' : this.searchQuery.type,
|
|
sort: this.activeSortList.type,
|
|
sort: this.activeSortList.type,
|
|
num: this.listState.pageNum,
|
|
num: this.listState.pageNum,
|
|
size: this.listState.pageSize
|
|
size: this.listState.pageSize
|
|
}
|
|
}
|
|
|
|
+
|
|
console.log(query)
|
|
console.log(query)
|
|
|
|
+ // 设置url
|
|
|
|
+ this.setUrlQuery()
|
|
|
|
+ // 搜索内容去多余的空格并设置
|
|
|
|
+ this.$refs.search.setSearchContent(query.keyWord)
|
|
|
|
|
|
this.listState.loading = true
|
|
this.listState.loading = true
|
|
this.listState.loaded = false
|
|
this.listState.loaded = false
|
|
@@ -149,6 +183,9 @@ export default {
|
|
if (res.error_code === 0) {
|
|
if (res.error_code === 0) {
|
|
this.listState.total = res.data.total
|
|
this.listState.total = res.data.total
|
|
this.listState.list = res.data.list || []
|
|
this.listState.list = res.data.list || []
|
|
|
|
+ } else {
|
|
|
|
+ this.listState.total = 0
|
|
|
|
+ this.listState.list = []
|
|
}
|
|
}
|
|
},
|
|
},
|
|
sortAndSearch (item, index) {
|
|
sortAndSearch (item, index) {
|
|
@@ -161,7 +198,6 @@ export default {
|
|
})
|
|
})
|
|
item.active = true
|
|
item.active = true
|
|
}
|
|
}
|
|
- this.resetListState()
|
|
|
|
this.doSearch()
|
|
this.doSearch()
|
|
},
|
|
},
|
|
toDocDetail (item) {
|
|
toDocDetail (item) {
|
|
@@ -174,7 +210,7 @@ export default {
|
|
},
|
|
},
|
|
onPageChange (p) {
|
|
onPageChange (p) {
|
|
this.listState.pageNum = p
|
|
this.listState.pageNum = p
|
|
- this.doSearch()
|
|
|
|
|
|
+ this.getList()
|
|
},
|
|
},
|
|
calcSubInfo (item) {
|
|
calcSubInfo (item) {
|
|
const { docFileSize: size, downTimes, uploadDate, docPageSize } = item
|
|
const { docFileSize: size, downTimes, uploadDate, docPageSize } = item
|