提交 70f10702 编写于 作者: X xinla

移动端关键词列表排序修改

上级 fa5abf3d
<template> <template>
<div> <div>
<div> <div>
<van-search <van-search v-model="keyword" placeholder="搜索活码名或关键词" shape="round" @search="onSearch" @clear="clear">
v-model="keyword"
placeholder="搜索活码名或关键词"
shape="round"
@search="onSearch"
@clear="clear"
>
</van-search> </van-search>
</div> </div>
...@@ -43,7 +37,7 @@ import { getKeywordTasks } from '@/api/community' ...@@ -43,7 +37,7 @@ import { getKeywordTasks } from '@/api/community'
export default { export default {
components: { KeywordPanel }, components: { KeywordPanel },
data () { data() {
return { return {
keyword: '', keyword: '',
storageKey: 'keywords', storageKey: 'keywords',
...@@ -55,19 +49,22 @@ export default { ...@@ -55,19 +49,22 @@ export default {
}, },
methods: { methods: {
getTasks () { getTasks() {
this.loading = true this.loading = true
getKeywordTasks(this.keyword).then((res) => { getKeywordTasks(this.keyword)
if (res.code === 200) { .then((res) => {
this.tasks = res.rows if (res.code === 200) {
} let timeStamp = (dateString) => (dateString ? +new Date(dateString.replace(/-/g, '/')) : 0)
this.loading = false this.tasks = res.rows.sort((a, b) => timeStamp(b.updateTime) - timeStamp(a.updateTime))
}).catch(() => { }
this.loading = false this.loading = false
}) })
.catch(() => {
this.loading = false
})
}, },
setHistory (keyword) { setHistory(keyword) {
if (!keyword) return if (!keyword) return
if (!this.history.includes(keyword)) { if (!this.history.includes(keyword)) {
...@@ -76,41 +73,42 @@ export default { ...@@ -76,41 +73,42 @@ export default {
} }
}, },
removeHistory (keyword) { removeHistory(keyword) {
if (this.history.includes(keyword)) { if (this.history.includes(keyword)) {
this.history.splice(this.history.indexOf(keyword), 1) this.history.splice(this.history.indexOf(keyword), 1)
localStorage.setItem(this.storageKey, JSON.stringify(this.history)) localStorage.setItem(this.storageKey, JSON.stringify(this.history))
} }
}, },
getHistory () { getHistory() {
this.history = JSON.parse(localStorage.getItem(this.storageKey)) || [] this.history = JSON.parse(localStorage.getItem(this.storageKey)) || []
}, },
onSearch () { onSearch() {
this.setHistory(this.keyword) this.setHistory(this.keyword)
this.getTasks() this.getTasks()
}, },
search (keyword) { search(keyword) {
this.keyword = keyword this.keyword = keyword
this.getTasks() this.getTasks()
}, },
clear () { clear() {
this.keyword = ''
this.getTasks() this.getTasks()
} }
}, },
computed: { computed: {
url () { url() {
return window.location.href return window.location.href
} }
}, },
created () { created() {
this.getHistory() this.getHistory()
this.getTasks() this.getTasks()
...@@ -119,25 +117,25 @@ export default { ...@@ -119,25 +117,25 @@ export default {
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.history-wrapper { .history-wrapper {
padding: 0 20px 20px; padding: 0 20px 20px;
.van-tag { .van-tag {
margin: 10px 10px 0 0; margin: 10px 10px 0 0;
}
} }
}
.bottom-line { .bottom-line {
background-color: #f2f2f2; background-color: #f2f2f2;
height: 15px; height: 15px;
} }
.overlay { .overlay {
display: flex; display: flex;
align-items: center; align-items: center;
.van-loading { .van-loading {
margin: auto; margin: auto;
}
} }
}
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册