Commit 89461806 authored by Damon's avatar Damon

refactor: 搜索

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