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

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

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