Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
study
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Damon
study
Commits
cbc3674e
Commit
cbc3674e
authored
Jul 29, 2021
by
Damon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 搜索-虚拟列表
parent
0329c8dc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
273 additions
and
309 deletions
+273
-309
index.vue
src/components/search-item/index.vue
+165
-0
uni-list.vue
src/components/uni-list/uni-list.vue
+0
-105
detail.vue
src/pages/search/detail.vue
+55
-204
list.js
src/pages/search/list.js
+1
-0
my-section.vue
src/pages/search/my-section.vue
+52
-0
No files found.
src/components/search-item/index.vue
0 → 100644
View file @
cbc3674e
<
template
>
<view
@
click
.
stop=
"itemChange(item.id)"
class=
"list-item"
>
<view
:class=
"['u-flex', 'head',
{ selected: item.id === arrIndex }]">
<view
class=
"titles"
>
<text>
{{
item
.
type
}}
</text
>
{{
item
.
title
}}
</view>
<view
class=
"u-flex arrow"
v-show=
"item.id !== arrIndex"
>
<text>
展开
</text>
<u-icon
name=
"arrow-down"
color=
"#9EA5BB"
></u-icon>
</view>
</view>
<view
class=
"u-flex subject"
v-show=
"item.id === arrIndex"
>
<view
class=
"content"
>
<answer-sheet
ref=
"answerSheet"
:answerList=
"item.answerList"
:rightKey=
"item.rightKey"
:multiple=
"item.type === 3"
:submitStatus=
"item.submitStatus"
:btnStatus=
"false"
@
change=
"answerChange"
></answer-sheet>
</view>
<view
class=
"explain"
>
<answer-explanation
:answer=
"item.answer"
:explain=
"item.explain"
></answer-explanation>
</view>
</view>
<view
class=
"u-flex opera"
v-show=
"item.id === arrIndex"
>
<view
class=
"opera-list"
@
click=
"collection(item)"
>
<u-image
:src=
"collectImg"
width=
"36"
height=
"36"
:fade=
"false"
:lazy-load=
"false"
/>
<text>
{{
collectionFlag
?
'已收藏'
:
'收藏'
}}
</text>
</view>
<view
class=
"opera-list"
@
click
.
stop=
"arrowUp(item.id)"
>
<text>
收起
</text>
<u-icon
name=
"arrow-up"
color=
"#9EA5BB"
></u-icon>
</view>
</view>
</view>
</
template
>
<
script
>
import
answerSheet
from
'@/components/answer-sheet/index.vue'
import
answerExplanation
from
'@/components/answer-explanation/index.vue'
export
default
{
components
:
{
answerSheet
,
answerExplanation
,
},
props
:
[
'item'
,
'arrIndex'
],
computed
:
{
collectImg
()
{
const
name
=
this
.
item
?.
collectionFlag
?
'collected.png'
:
'collect.png'
return
process
.
uniEnv
.
qn_base_url
+
name
},
collectionFlag
()
{
return
this
.
item
?.
collectionFlag
||
false
},
},
methods
:
{
itemChange
(
id
)
{
this
.
$emit
(
'arrowDown'
,
id
)
},
arrowUp
(
id
)
{
this
.
$emit
(
'arrowUp'
,
id
)
},
collection
(
item
)
{
this
.
$emit
(
'collection'
,
item
)
},
},
}
</
script
>
<
style
lang=
"scss"
scoped
>
.list-item
{
background
:
#fff
;
padding
:
30rpx
20rpx
;
margin
:
10rpx
0
;
border-radius
:
30rpx
30rpx
0
0
;
.head
{
width
:
100%
;
height
:
60rpx
;
overflow
:
hidden
;
.titles
{
color
:
#191c27
;
font-size
:
32rpx
;
line-height
:
50rpx
;
font-weight
:
bold
;
flex
:
1
;
height
:
60rpx
;
overflow
:
hidden
;
text
{
background
:
#9ea5bb
;
color
:
#fff
;
padding
:
8rpx
20rpx
;
margin-right
:
10rpx
;
font-size
:
20rpx
;
border-radius
:
50rpx
0
50rpx
50rpx
;
}
}
.arrow
{
padding-left
:
20rpx
;
margin-top
:
-10rpx
;
text
{
color
:
#2953ff
;
font-size
:
28rpx
;
padding-right
:
10rpx
;
}
}
}
.selected
{
height
:
auto
;
overflow
:
auto
;
.titles
{
height
:
auto
;
overflow
:
auto
;
}
}
.subject
{
flex-flow
:
column
;
.type
{
width
:
100%
;
text-align
:
left
;
padding
:
20rpx
0
;
}
.content
{
width
:
100%
;
}
.explain
,
.btn
{
width
:
100%
;
padding-top
:
50rpx
;
}
}
.opera
{
padding-top
:
30rpx
;
justify-content
:
space-between
;
color
:
#5a6073
;
font-size
:
28rpx
;
.opera-list
{
display
:
flex
;
&
:nth-of-type
(
1
)
{
text
{
padding-left
:
10rpx
;
}
}
&
:nth-of-type
(
2
)
{
text
{
padding-right
:
10rpx
;
color
:
#2953ff
;
}
}
}
}
}
</
style
>
src/components/uni-list/uni-list.vue
deleted
100644 → 0
View file @
0329c8dc
<
template
>
<!-- #ifndef APP-NVUE -->
<view
class=
"uni-list uni-border-top-bottom"
>
<view
v-if=
"border"
class=
"uni-list--border-top"
></view>
<slot
/>
<view
v-if=
"border"
class=
"uni-list--border-bottom"
></view>
</view>
<!-- #endif -->
<!-- #ifdef APP-NVUE -->
<list
class=
"uni-list"
:class=
"
{ 'uni-list--border': border }" :enableBackToTop="enableBackToTop" loadmoreoffset="15">
<slot
/></list>
<!-- #endif -->
</
template
>
<
script
>
/**
* List 列表
* @description 列表组件
* @tutorial https://ext.dcloud.net.cn/plugin?id=24
* @property {String} border = [true|false] 标题
*/
export
default
{
name
:
'uniList'
,
'mp-weixin'
:
{
options
:
{
multipleSlots
:
false
}
},
props
:
{
enableBackToTop
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
scrollY
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
border
:
{
type
:
Boolean
,
default
:
true
}
},
// provide() {
// return {
// list: this
// };
// },
created
()
{
this
.
firstChildAppend
=
false
;
},
methods
:
{
loadMore
(
e
)
{
this
.
$emit
(
'scrolltolower'
);
}
}
};
</
script
>
<
style
lang=
"scss"
>
.uni-list
{
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
position
:
relative
;
flex-direction
:
column
;
}
.uni-list--border
{
position
:
relative
;
/* #ifdef APP-NVUE */
border-top-color
:
$uni-border-color
;
border-top-style
:
solid
;
border-top-width
:
0
.5px
;
border-bottom-color
:
$uni-border-color
;
border-bottom-style
:
solid
;
border-bottom-width
:
0
.5px
;
/* #endif */
z-index
:
-1
;
}
/* #ifndef APP-NVUE */
.uni-list--border-top
{
position
:
absolute
;
top
:
0
;
right
:
0
;
left
:
0
;
height
:
1px
;
-webkit-transform
:
scaleY
(
0
.5
);
transform
:
scaleY
(
0
.5
);
background-color
:
$uni-border-color
;
z-index
:
1
;
}
.uni-list--border-bottom
{
position
:
absolute
;
bottom
:
0
;
right
:
0
;
left
:
0
;
height
:
1px
;
-webkit-transform
:
scaleY
(
0
.5
);
transform
:
scaleY
(
0
.5
);
background-color
:
$uni-border-color
;
}
/* #endif */
</
style
>
src/pages/search/detail.vue
View file @
cbc3674e
...
@@ -27,62 +27,12 @@
...
@@ -27,62 +27,12 @@
>
道
</view
>
道
</view
>
>
<view
class=
"result"
>
<view
class=
"result"
>
<uni-list
:border=
"false"
>
<my-section
<view
v-for=
"(item, index) in section"
v-for=
"item in lists"
:key=
"index"
:key=
"item.id"
:begin=
"item.begin"
@
click
.
stop=
"itemChange(item.id)"
:end=
"item.end"
class=
"list-item"
></my-section>
>
<view
:class=
"['u-flex', 'head',
{ selected: item.id === arrIndex }]"
>
<view
class=
"titles"
>
<text>
{{
item
.
type
}}
</text
>
{{
item
.
title
}}
</view>
<view
class=
"u-flex arrow"
v-show=
"item.id !== arrIndex"
>
<text>
展开
</text>
<u-icon
name=
"arrow-down"
color=
"#9EA5BB"
></u-icon>
</view>
</view>
<view
class=
"u-flex subject"
v-show=
"item.id === arrIndex"
>
<view
class=
"content"
>
<answer-sheet
ref=
"answerSheet"
:answerList=
"item.answerList"
:rightKey=
"item.rightKey"
:multiple=
"item.type === 3"
:submitStatus=
"item.submitStatus"
:btnStatus=
"false"
@
change=
"answerChange"
></answer-sheet>
</view>
<view
class=
"explain"
>
<answer-explanation
:answer=
"item.answer"
:explain=
"item.explain"
></answer-explanation>
</view>
</view>
<view
class=
"u-flex opera"
v-show=
"item.id === arrIndex"
>
<view
class=
"opera-list"
@
click=
"collection(item)"
>
<u-image
:src=
"collectImg"
width=
"36"
height=
"36"
:fade=
"false"
:lazy-load=
"false"
/>
<text>
{{
collectionFlag
?
'已收藏'
:
'收藏'
}}
</text>
</view>
<view
class=
"opera-list"
@
click
.
stop=
"arrowUp(index)"
>
<text>
收起
</text>
<u-icon
name=
"arrow-up"
color=
"#9EA5BB"
></u-icon>
</view>
</view>
</view>
</uni-list>
<u-loadmore
:status=
"loadStatus"
:margin-bottom=
"40"
/>
<u-loadmore
:status=
"loadStatus"
:margin-bottom=
"40"
/>
</view>
</view>
</view>
</view>
...
@@ -99,14 +49,11 @@
...
@@ -99,14 +49,11 @@
</
template
>
</
template
>
<
script
>
<
script
>
import
answerSheet
from
'@/components/answer-sheet/index.vue'
import
{
list
}
from
'./list.js'
import
answerExplanation
from
'@/components/answer-explanation/index.vue'
import
mySection
from
'./my-section.vue'
import
uniList
from
'@/components/uni-list/uni-list.vue'
export
default
{
export
default
{
components
:
{
components
:
{
answerSheet
,
mySection
,
answerExplanation
,
uniList
,
},
},
data
()
{
data
()
{
return
{
return
{
...
@@ -117,26 +64,21 @@ export default {
...
@@ -117,26 +64,21 @@ export default {
pageSize
:
10
,
pageSize
:
10
,
loadStatus
:
'loadmore'
,
loadStatus
:
'loadmore'
,
isLoadMore
:
false
,
//是否加载中
isLoadMore
:
false
,
//是否加载中
total
:
0
total
:
0
,
section
:
[],
}
}
},
},
onLoad
(
e
)
{
onLoad
(
e
)
{
this
.
keyword
=
e
?
decodeURIComponent
(
e
.
keyword
)
:
''
this
.
keyword
=
e
?
decodeURIComponent
(
e
.
keyword
)
:
''
this
.
lists
=
list
},
onReady
()
{
this
.
init
()
this
.
init
()
},
},
computed
:
{
computed
:
{
defaultImg
()
{
defaultImg
()
{
return
process
.
uniEnv
.
qn_base_url
+
'no-search.png'
return
process
.
uniEnv
.
qn_base_url
+
'no-search.png'
},
}
collectImg
()
{
const
info
=
this
.
lists
.
find
((
v
)
=>
v
.
index
===
this
.
arrIndex
)
const
name
=
info
?.
collectionFlag
?
'collected.png'
:
'collect.png'
return
process
.
uniEnv
.
qn_base_url
+
name
},
collectionFlag
()
{
const
info
=
this
.
lists
.
find
((
v
)
=>
v
.
index
===
this
.
arrIndex
)
return
info
?
info
.
collectionFlag
:
false
},
},
},
onReachBottom
()
{
onReachBottom
()
{
//上拉触底函数
//上拉触底函数
...
@@ -156,55 +98,56 @@ export default {
...
@@ -156,55 +98,56 @@ export default {
size
:
this
.
pageSize
,
size
:
this
.
pageSize
,
}
}
uni
.
showLoading
({
title
:
'加载中'
,
})
this
.
loadStatus
=
'loading'
this
.
loadStatus
=
'loading'
this
.
$u
.
api
.
searchQuestion
(
data
).
then
((
res
)
=>
{
this
.
$u
.
api
.
searchQuestion
(
data
).
then
((
res
)
=>
{
uni
.
hideLoading
()
this
.
total
=
res
.
total
this
.
total
=
res
.
total
const
lists
=
const
records
=
res
?.
records
||
[]
res
?.
records
.
length
>
0
if
(
records
.
length
===
0
)
{
?
res
?.
records
.
map
(
v
=>
{
this
.
loadStatus
=
'nomore'
const
rightKey
=
v
.
answer
.
split
(
','
)
return
const
content
=
JSON
.
parse
(
v
.
content
)
}
const
answerList
=
content
.
choiceList
.
map
((
item
)
=>
{
return
{
sort
:
item
.
value
,
text
:
item
.
label
,
checked
:
rightKey
.
includes
(
item
.
value
),
confirm
:
rightKey
.
includes
(
item
.
value
),
}
})
return
{
for
(
let
i
=
0
;
i
<
records
.
length
;
i
++
)
{
id
:
v
.
id
,
const
v
=
records
[
i
]
answer
:
v
.
answer
,
const
rightKey
=
v
.
answer
.
split
(
','
)
title
:
content
.
title
,
const
content
=
JSON
.
parse
(
v
.
content
)
type
:
v
.
echoMap
.
questionTypeId
,
const
answerList
=
content
.
choiceList
.
map
((
item
)
=>
{
answerList
:
answerList
,
return
{
explain
:
v
.
analysis
,
sort
:
item
.
value
,
rightKey
:
rightKey
,
text
:
item
.
label
,
collectionFlag
:
v
.
collectionFlag
,
checked
:
rightKey
.
includes
(
item
.
value
),
submitStatus
:
true
,
confirm
:
rightKey
.
includes
(
item
.
value
),
}
}
})
})
:
[]
this
.
lists
=
this
.
lists
.
concat
(
lists
)
this
.
lists
.
push
({
if
(
res
.
records
.
length
<
this
.
pageSize
)
{
id
:
v
.
id
,
answer
:
v
.
answer
,
title
:
content
.
title
,
type
:
v
.
echoMap
.
questionTypeId
,
answerList
:
answerList
,
explain
:
v
.
analysis
,
rightKey
:
rightKey
,
collectionFlag
:
v
.
collectionFlag
,
submitStatus
:
true
,
})
}
this
.
section
.
push
({
begin
:
this
.
lists
.
length
-
records
.
length
,
end
:
this
.
lists
.
length
,
})
if
(
records
.
length
<
this
.
pageSize
)
{
//判断接口返回数据量小于请求数据量,则表示此为最后一页
//判断接口返回数据量小于请求数据量,则表示此为最后一页
this
.
isLoadMore
=
true
this
.
isLoadMore
=
true
this
.
loadStatus
=
'nomore'
this
.
loadStatus
=
'nomore'
}
else
{
}
else
{
this
.
loadStatus
=
'loadmore'
this
.
isLoadMore
=
false
this
.
isLoadMore
=
false
}
}
this
.
status
=
'nomore'
})
})
},
},
itemChange
(
e
)
{
this
.
arrIndex
=
e
},
search
(
val
)
{
search
(
val
)
{
if
(
val
)
{
if
(
val
)
{
this
.
keyword
=
val
this
.
keyword
=
val
...
@@ -214,23 +157,12 @@ export default {
...
@@ -214,23 +157,12 @@ export default {
history
.
splice
(
9
,
1
)
history
.
splice
(
9
,
1
)
}
}
this
.
$u
.
vuex
(
'searchHistory'
,
history
)
this
.
$u
.
vuex
(
'searchHistory'
,
history
)
this
.
currentPage
=
1
this
.
lists
=
[]
this
.
lists
=
[]
this
.
section
=
[]
this
.
init
()
this
.
init
()
}
}
},
}
collection
(
item
)
{
const
action
=
item
.
collectionFlag
?
'removeCollection'
:
'joinCollection'
this
.
$u
.
api
[
action
]({
questionId
:
item
.
id
}).
then
((
res
)
=>
{
if
(
res
)
{
const
msg
=
item
.
collectionFlag
?
'取消收藏成功'
:
'收藏成功'
this
.
$u
.
toast
(
msg
)
item
.
collectionFlag
=
!
item
.
collectionFlag
}
})
},
arrowUp
()
{
this
.
arrIndex
=
''
},
},
},
}
}
</
script
>
</
script
>
...
@@ -264,87 +196,6 @@ export default {
...
@@ -264,87 +196,6 @@ export default {
.result
{
.result
{
margin-top
:
30rpx
;
margin-top
:
30rpx
;
width
:
100%
;
width
:
100%
;
.list-item
{
background
:
#fff
;
padding
:
30rpx
20rpx
;
margin
:
10rpx
0
;
border-radius
:
30rpx
30rpx
0
0
;
.head
{
width
:
100%
;
height
:
60rpx
;
overflow
:
hidden
;
.titles
{
color
:
#191c27
;
font-size
:
32rpx
;
line-height
:
50rpx
;
font-weight
:
bold
;
flex
:
1
;
height
:
60rpx
;
overflow
:
hidden
;
text
{
background
:
#9ea5bb
;
color
:
#fff
;
padding
:
8rpx
20rpx
;
margin-right
:
10rpx
;
font-size
:
20rpx
;
border-radius
:
50rpx
0
50rpx
50rpx
;
}
}
.arrow
{
padding-left
:
20rpx
;
margin-top
:
-10rpx
;
text
{
color
:
#2953ff
;
font-size
:
28rpx
;
padding-right
:
10rpx
;
}
}
}
.selected
{
height
:
auto
;
overflow
:
auto
;
.titles
{
height
:
auto
;
overflow
:
auto
;
}
}
.subject
{
flex-flow
:
column
;
.type
{
width
:
100%
;
text-align
:
left
;
padding
:
20rpx
0
;
}
.content
{
width
:
100%
;
}
.explain
,
.btn
{
width
:
100%
;
padding-top
:
50rpx
;
}
}
.opera
{
padding-top
:
30rpx
;
justify-content
:
space-between
;
color
:
#5a6073
;
font-size
:
28rpx
;
.opera-list
{
display
:
flex
;
&
:nth-of-type
(
1
)
{
text
{
padding-left
:
10rpx
;
}
}
&
:nth-of-type
(
2
)
{
text
{
padding-right
:
10rpx
;
color
:
#2953ff
;
}
}
}
}
}
}
}
.default
{
.default
{
flex-flow
:
column
;
flex-flow
:
column
;
...
...
src/pages/search/list.js
0 → 100644
View file @
cbc3674e
export
const
list
=
[]
\ No newline at end of file
src/pages/search/my-section.vue
0 → 100644
View file @
cbc3674e
<
template
>
<view>
<search-item
v-for=
"(item, index) in list"
:key=
"index"
:item=
"item"
:arrIndex
.
sync=
"arrIndex"
@
arrowDown=
"arrowDown"
@
arrowUp=
"arrowUp"
@
collection=
"collection($event, index)"
></search-item>
</view>
</
template
>
<
script
>
import
{
list
}
from
'./list.js'
import
searchItem
from
'@/components/search-item/index.vue'
export
default
{
components
:
{
searchItem
,
},
props
:
[
'begin'
,
'end'
],
data
()
{
return
{
list
:
[],
arrIndex
:
''
,
}
},
created
()
{
this
.
list
=
list
.
slice
(
this
.
begin
,
this
.
end
)
},
methods
:
{
arrowDown
(
e
)
{
this
.
arrIndex
=
e
},
arrowUp
()
{
this
.
arrIndex
=
''
},
collection
(
item
,
index
)
{
const
action
=
item
.
collectionFlag
?
'removeCollection'
:
'joinCollection'
this
.
$u
.
api
[
action
]({
questionId
:
item
.
id
}).
then
((
res
)
=>
{
if
(
res
)
{
const
msg
=
item
.
collectionFlag
?
'取消收藏成功'
:
'收藏成功'
this
.
$u
.
toast
(
msg
)
this
.
$set
(
this
.
list
[
index
],
'collectionFlag'
,
!
item
.
collectionFlag
)
}
})
},
},
}
</
script
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment