Commit 7f292850 by fanx

封装搜索历史记录

1 parent cf032fd7
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
.icon-shtyxydm { width: 54px; height: 54px; background-position: -2180px -1598px; } .icon-shtyxydm { width: 54px; height: 54px; background-position: -2180px -1598px; }
.icon-tel { width: 36px; height: 36px; background-position: -1288px -670px; } .icon-tel { width: 36px; height: 36px; background-position: -1288px -670px; }
.icon-time-update { width: 45px; height: 45px; background-position: -2458px -1598px; } .icon-time-update { width: 45px; height: 45px; background-position: -2458px -1598px; }
.icon-trash { width: 50px; height: 50px; background-position: -2324px -1598px; }
.icon-user-question { width: 32px; height: 36px; background-position: -1456px -670px; } .icon-user-question { width: 32px; height: 36px; background-position: -1456px -670px; }
.icon-user { width: 36px; height: 36px; background-position: -1344px -670px; } .icon-user { width: 36px; height: 36px; background-position: -1344px -670px; }
.icon-verification { width: 36px; height: 36px; background-position: -1400px -670px; } .icon-verification { width: 36px; height: 36px; background-position: -1400px -670px; }
.icon-wechat { width: 80px; height: 78px; background-position: -2080px -1598px; } .icon-wechat { width: 80px; height: 78px; background-position: -2080px -1598px; }
\ No newline at end of file \ No newline at end of file
.icon-trash { width: 50px; height: 50px; background-position: -2324px -1598px; }
\ No newline at end of file \ No newline at end of file
<template>
<div class="history">
<div class="history_title" v-if="list.length">
<span>搜索历史</span>
<img :src="require('@/assets/icon/trash.png')" @click="handleClear">
</div>
<div class="historyList" v-if="list.length">
<ul>
<li v-for="(item,index) in list" :key="index" @jump="jumItem(item)">{{item}}</li>
</ul>
</div>
<div class="noData" v-else>
暂无历史记录
</div>
</div>
</template>
<script>
export default {
name: 'SearchHistory',
props: {
list: {
type: Array,
default: () => []
}
},
methods: {
jumItem(val) {
this.$emit('jumpPage', val)
},
handleClear() {
this.$emit('clear')
}
}
}
</script>
<style lang="less" scoped>
.history {
display: flex;
flex-direction: column;
padding: 20px 15px;
background-color: #fafafa;
height: 100vh;
.history_title {
display: flex;
justify-content: space-between;
span {
color: #666;
font-size: 11px;
}
img {
width: 25px;
height: 25px;
}
}
}
.historyList {
ul {
display: flex;
flex-wrap: wrap;
li {
display: flex;
justify-content: center;
padding: 7px 15px;
background-color: #fff;
border-radius: 15px;
margin-right: 10px;
margin-top: 10px;
min-width: 80px;
font-size: 12px;
color: #161818;
word-break: break-all;
}
}
}
.noData {
text-align: center;
color: #666;
}
</style>
\ No newline at end of file \ No newline at end of file
...@@ -6,20 +6,19 @@ ...@@ -6,20 +6,19 @@
</template> </template>
</NafmHeader> </NafmHeader>
<div class="resIssue_search_content"> <div class="resIssue_search_content">
<div class="history_title" v-if="list.length"> <SearchHistory :list="list" @jumpPage="jumpDetail" @clear="handleClear" />
<span>搜索历史</span>
<img :src="require('@/assets/icon/trash.png')">
</div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import SearchInput from '@/components/SearchInput.vue' import SearchInput from '@/components/SearchInput.vue'
import SearchHistory from '@/components/SearchHistory'
import { setLocalStorage, getLocalStorage, removeLocalStorage } from '@/utils/LocalStorage' import { setLocalStorage, getLocalStorage, removeLocalStorage } from '@/utils/LocalStorage'
export default { export default {
name: 'ResIssueSearch', name: 'ResIssueSearch',
components: { components: {
SearchInput SearchInput,
SearchHistory
}, },
data() { data() {
return { return {
...@@ -32,42 +31,23 @@ export default { ...@@ -32,42 +31,23 @@ export default {
}, },
methods: { methods: {
handleSearch(val) { handleSearch(val) {
const list = getLocalStorage('resIssucessData') || [] if (this.list.indexOf(val) === -1) {
const length = list.legnth this.list.unshift(val)
const newList = [] if (this.list.length > 10) {
this.list.pop()
if (list.indexOf(val) === -1) {
list.unshift(val)
if (length >= 10) {
list.pop()
} }
newList.push(val) setLocalStorage('resIssucessData', this.list)
setLocalStorage('resIssucessData', newList)
this.list = newList
} }
},
jumpDetail(val) {
},
handleClear() {
this.list = []
removeLocalStorage('resIssucessData')
} }
} }
// console.log(val);
} }
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.resIssue_search_content {
display: flex;
flex-direction: column;
padding: 20px 15px;
.history_title {
display: flex;
justify-content: space-between;
span {
color: #666;
font-size: 11px;
}
img {
width: 25px;
height: 25px;
}
}
}
</style> </style>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!