Commit 89461806 authored by Damon's avatar Damon

refactor: 搜索

parent 30cd5f18
......@@ -21,9 +21,9 @@
></u-search>
</view>
<view v-if="lists.length > 0" class="results">
<view class="results" v-if="lists.length > 0">
<view class="title"
>共找到含有<text>“{{ keyword }}”</text>相关试题<text>{{ count }}</text
>共找到含有<text>“{{ keyword }}”</text>相关试题<text>{{ total }}</text
>道</view
>
<view class="result">
......@@ -87,7 +87,7 @@
</view>
</view>
<view class="u-flex default" v-if="count === 0">
<view class="u-flex default" v-if="lists.length === 0">
<view>
<image :src="defaultImg" />
</view>
......@@ -110,12 +110,6 @@ export default {
},
data() {
return {
itemStyle: {
background: '#fff',
padding: '0rpx 20rpx',
margin: '10rpx 0',
'border-radius': '30rpx 30rpx 0 0',
},
keyword: '',
lists: [],
arrIndex: '',
......@@ -123,6 +117,7 @@ export default {
pageSize: 10,
loadStatus: 'loadmore',
isLoadMore: false, //是否加载中
total: 0
}
},
onLoad(e) {
......@@ -133,9 +128,6 @@ export default {
defaultImg() {
return process.uniEnv.qn_base_url + 'no-search.png'
},
count() {
return this.lists.length
},
collectImg() {
const info = this.lists.find((v) => v.index === this.arrIndex)
const name = info?.collectionFlag ? 'collected.png' : 'collect.png'
......@@ -170,9 +162,10 @@ export default {
this.loadStatus = 'loading'
this.$u.api.searchQuestion(data).then((res) => {
uni.hideLoading()
this.total = res.total
const lists =
res?.records.length > 0
? res?.records.map((v, i) => {
? res?.records.map(v => {
const rightKey = v.answer.split(',')
const content = JSON.parse(v.content)
const answerList = content.choiceList.map((item) => {
......@@ -186,7 +179,6 @@ export default {
return {
id: v.id,
index: i,
answer: v.answer,
title: content.title,
type: v.echoMap.questionTypeId,
......@@ -200,7 +192,6 @@ export default {
: []
this.lists = this.lists.concat(lists)
if (res.records.length < this.pageSize) {
//判断接口返回数据量小于请求数据量,则表示此为最后一页
this.isLoadMore = true
......@@ -223,6 +214,7 @@ export default {
history.splice(9, 1)
}
this.$u.vuex('searchHistory', history)
this.lists = []
this.init()
}
},
......@@ -245,7 +237,7 @@ export default {
<style lang="scss" scoped>
.search {
height: 100vh;
min-height: 100vh;
flex-direction: column;
background-color: #f8fafd;
background-image: linear-gradient(to top, #f8fafd 0%, #e9f3ff 50%);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment