Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mayi-mp-shop
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
程默
mayi-mp-shop
Commits
3a787cd4
Commit
3a787cd4
authored
Mar 09, 2022
by
柳士祥
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
首页商品列表分页懒加载
parent
33daa5fb
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
247 additions
and
13 deletions
+247
-13
src/components/basicTool/transverse-label/index.vue
+29
-1
src/pages/home/index.vue
+36
-3
static/nativeComponents/GoodsList/GoodsItem/index.wxml
+10
-0
static/nativeComponents/GoodsList/index.js
+164
-6
static/nativeComponents/GoodsList/index.wxml
+8
-3
No files found.
src/components/basicTool/transverse-label/index.vue
View file @
3a787cd4
...
@@ -69,7 +69,10 @@
...
@@ -69,7 +69,10 @@
<banner
:datas=
"item1"
></banner>
<banner
:datas=
"item1"
></banner>
</div>
</div>
<div
v-else-if=
"item1.componentCode=='goods-list' && item1.componentInfo.visible == 1"
style=
"height:100%;"
>
<div
v-else-if=
"item1.componentCode=='goods-list' && item1.componentInfo.visible == 1"
style=
"height:100%;"
>
<goods-list
class=
"goodsListItem"
:datas=
"item1"
></goods-list>
<!--
<goods-list
class=
"goodsListItem"
:datas=
"item1"
></goods-list>
-->
<goods-list
:class=
"['goodsListItemIndex'+index,'transverse-label-goodsListItem']"
:datas=
"item1"
:datasIndex=
"active"
:goodsListIndex=
"index"
></goods-list>
</div>
</div>
<div
v-else-if=
"item1.componentCode == 'area-navigation' && item1.componentInfo.visible == 1"
>
<div
v-else-if=
"item1.componentCode == 'area-navigation' && item1.componentInfo.visible == 1"
>
<area-navigation
:datas=
"item1"
:changeLocation=
"changeLocation"
></area-navigation>
<area-navigation
:datas=
"item1"
:changeLocation=
"changeLocation"
></area-navigation>
...
@@ -215,6 +218,28 @@ export default {
...
@@ -215,6 +218,28 @@ export default {
computed
:
{
computed
:
{
tabList
:
{
tabList
:
{
get
()
{
get
()
{
let
pageGoodsList
=
[]
let
storageDatasList
=
[]
let
loadingFlag
=
[]
let
ids
=
[]
let
pageNumList
=
[]
this
.
datas
.
componentData
.
tabList
.
forEach
(
v
=>
{
v
.
contentList
.
forEach
(
vc
=>
{
if
(
vc
.
componentCode
==
'goods-list'
)
{
pageGoodsList
.
push
([])
storageDatasList
.
push
([])
ids
.
push
([])
pageNumList
.
push
(
1
)
loadingFlag
.
push
(
false
)
}
})
})
console
.
log
(
pageGoodsList
,
storageDatasList
,
ids
,
loadingFlag
,
pageNumList
,
'newVal'
);
wx
.
setStorageSync
(
"pageGoodsList"
,
pageGoodsList
)
wx
.
setStorageSync
(
"storageDatasList"
,
storageDatasList
)
wx
.
setStorageSync
(
"ids"
,
ids
)
wx
.
setStorageSync
(
"loadingFlag"
,
loadingFlag
)
wx
.
setStorageSync
(
"pageNumList"
,
pageNumList
)
return
this
.
datas
.
componentData
.
tabList
.
filter
(
return
this
.
datas
.
componentData
.
tabList
.
filter
(
(
item
)
=>
item
.
visible
==
undefined
||
item
.
visible
==
1
(
item
)
=>
item
.
visible
==
undefined
||
item
.
visible
==
1
);
);
...
@@ -421,6 +446,9 @@ export default {
...
@@ -421,6 +446,9 @@ export default {
item
.
getScroll
()
item
.
getScroll
()
})
})
}
}
if
(
this
.
$parent
.
$mp
.
page
.
selectAllComponents
(
'.goodsListItem'
)){
this
.
$parent
.
$mp
.
page
.
selectAllComponents
(
'.transverse-label-goodsListItem'
)
}
this
.
active
=
res
.
target
.
index
;
this
.
active
=
res
.
target
.
index
;
},
},
timeOutInitTabs
(
notGetAllTabWidth
)
{
timeOutInitTabs
(
notGetAllTabWidth
)
{
...
...
src/pages/home/index.vue
View file @
3a787cd4
...
@@ -157,6 +157,7 @@ import { setTabBarActive, checkTabbarPage,themeColor, checkShowConditionIds } fr
...
@@ -157,6 +157,7 @@ import { setTabBarActive, checkTabbarPage,themeColor, checkShowConditionIds } fr
import
indexApi
from
"@/api/index.js"
;
import
indexApi
from
"@/api/index.js"
;
import
{
throttle
,
concatUrl
}
from
"../../utils/index.js"
import
{
throttle
,
concatUrl
}
from
"../../utils/index.js"
import
mpvueCropper
from
'@/components/mpvue-cropper'
import
mpvueCropper
from
'@/components/mpvue-cropper'
import
tool
from
'../../utils/tool.js'
const
app
=
getApp
();
const
app
=
getApp
();
const
{
log
}
=
app
;
const
{
log
}
=
app
;
export
default
{
export
default
{
...
@@ -387,6 +388,26 @@ export default {
...
@@ -387,6 +388,26 @@ export default {
// 新人有礼弹窗
// 新人有礼弹窗
this
.
newUserFun
();
this
.
newUserFun
();
}
}
//清除懒加载缓存
wx
.
removeStorage
({
key
:
'pageGoodsList'
})
wx
.
removeStorage
({
key
:
'storageDatasList'
})
wx
.
removeStorage
({
key
:
'datasIndex'
})
wx
.
removeStorage
({
key
:
'loadingFlag'
})
wx
.
removeStorage
({
key
:
'pageNumList'
})
console
.
log
(
'storageGoodsList---detory'
);
},
},
onShow
()
{
onShow
()
{
// 设置显示条件
// 设置显示条件
...
@@ -408,10 +429,16 @@ export default {
...
@@ -408,10 +429,16 @@ export default {
this
.
active
=
checkTabbarPage
(
'/'
)
this
.
active
=
checkTabbarPage
(
'/'
)
}
}
this
.
$mp
.
page
.
onPageScroll
=
(
el
)
=>
{
//
this.$mp.page.onPageScroll= (el)=>{
throttle
(
this
.
scrolls
(
el
),
100
)
//
throttle(this.scrolls(el),100)
};
//
};
},
},
// 滚动节流方法
onPageScroll
:
tool
.
throttle
(
function
(
el
)
{
// console.log(el);
this
.
scrolls
(
el
)
},
200
),
methods
:
{
methods
:
{
async
setVisible
(
pageList
,
cb
)
{
async
setVisible
(
pageList
,
cb
)
{
// 首页显示条件
// 首页显示条件
...
@@ -673,6 +700,12 @@ export default {
...
@@ -673,6 +700,12 @@ export default {
if
(
this
.
$mp
.
page
&&
this
.
$mp
.
page
.
selectComponent
(
".goodsListItem"
)){
if
(
this
.
$mp
.
page
&&
this
.
$mp
.
page
.
selectComponent
(
".goodsListItem"
)){
this
.
$mp
.
page
.
selectComponent
(
".goodsListItem"
).
getScroll
(
el
);
this
.
$mp
.
page
.
selectComponent
(
".goodsListItem"
).
getScroll
(
el
);
}
}
if
(
this
.
$mp
.
page
&&
this
.
$mp
.
page
.
selectAllComponents
(
".transverse-label-goodsListItem"
)){
this
.
$mp
.
page
.
selectAllComponents
(
".transverse-label-goodsListItem"
).
forEach
(
item
=>
{
console
.
log
(
item
,
'-this.$mp.page.selectComponent(".goodsListItem")'
)
item
.
getScroll
(
el
)
})
}
},
},
setFooterShow
(
el
){
setFooterShow
(
el
){
// return
// return
...
...
static/nativeComponents/GoodsList/GoodsItem/index.wxml
View file @
3a787cd4
<!-- 商品列表item -->
<!-- 商品列表item -->
<!-- {{items.loadState}}--{{items.loadProductImgUrl}}--{{items.productImgUrl}} -->
<!-- <view wx:if="{{items && datas.componentData['style'] == 'list' && items.loadState == false}}">
<view class="skeleton-animate">
<view class="skeleton-bg skeleton-img"></view>
<view class="skeleton-bg skeleton-title"></view>
<view class="skeleton-bg skeleton-detail"></view>
<view class="skeleton-bg skeleton-price"></view>
</view>
</view> -->
<view
<view
class="goodsItem {{datas.componentData.style==='rowList'?'goodsRowList':''}} {{datas.componentData.style==='heap'?'goodsRowList goodsHeapItem':''}}"
class="goodsItem {{datas.componentData.style==='rowList'?'goodsRowList':''}} {{datas.componentData.style==='heap'?'goodsRowList goodsHeapItem':''}}"
style="--proGap2:{{datas.componentData.proGap*2}}rpx;"
style="--proGap2:{{datas.componentData.proGap*2}}rpx;"
...
...
static/nativeComponents/GoodsList/index.js
View file @
3a787cd4
...
@@ -9,6 +9,12 @@ const componentOptions = {
...
@@ -9,6 +9,12 @@ const componentOptions = {
properties
:
{
properties
:
{
datas
:
{
datas
:
{
type
:
Object
type
:
Object
},
datasIndex
:{
type
:
Number
},
goodsListIndex
:{
type
:
Number
}
}
},
},
// 组件数据
// 组件数据
...
@@ -21,6 +27,12 @@ const componentOptions = {
...
@@ -21,6 +27,12 @@ const componentOptions = {
loading
:
false
,
loading
:
false
,
finished
:
false
,
finished
:
false
,
goodsList
:[],
goodsList
:[],
storageGoodsList
:[],
storageDatasList
:[],
pageSize
:
10
,
pageNum
:
1
,
pageGoodsList
:[],
loadingFlag
:[],
},
},
// 数据监听器
// 数据监听器
observers
:
{},
observers
:
{},
...
@@ -61,6 +73,11 @@ const componentOptions = {
...
@@ -61,6 +73,11 @@ const componentOptions = {
},
},
// 组件方法
// 组件方法
methods
:
{
methods
:
{
// setPageDatas(active){
// this.pageGoodsList = wx.getStorageSync('pageGoodsList')
// console.log(this.pageGoodsList,active,'active');
// },
init
()
{
init
()
{
let
{
let
{
goodsType
,
goodsType
,
...
@@ -183,11 +200,39 @@ const componentOptions = {
...
@@ -183,11 +200,39 @@ const componentOptions = {
let
goodsList
=
this
.
render
?
res
.
data
.
list
:
res
.
data
.
data
.
list
;
let
goodsList
=
this
.
render
?
res
.
data
.
list
:
res
.
data
.
data
.
list
;
return
element
.
terminalProductId
;
return
element
.
terminalProductId
;
});
});
this
.
moreProduct
(
ids
);
let
storageIds
=
wx
.
getStorageSync
(
'ids'
)
storageIds
[
this
.
data
.
goodsListIndex
]
=
ids
wx
.
setStorageSync
(
'ids'
,
storageIds
)
let
storageDatasList
=
wx
.
getStorageSync
(
'storageDatasList'
)
storageDatasList
[
this
.
data
.
goodsListIndex
]
=
this
.
data
.
datas
.
componentData
wx
.
setStorageSync
(
'storageDatasList'
,
storageDatasList
)
this
.
moreProduct
(
true
);
}
}
});
});
},
},
async
moreProduct
(
terminalProductIds
)
{
async
moreProduct
(
flag
)
{
// 没有数据了就不再请求了,直接return
if
(
this
.
data
.
pageGoodsList
.
length
!=
0
&&
this
.
data
.
pageGoodsList
[
this
.
data
.
datasIndex
].
length
==
wx
.
getStorageSync
(
'ids'
)[
this
.
data
.
datasIndex
].
length
)
return
let
terminalProductIds
=
[]
console
.
log
(
pageNum
,
'page-----'
);
let
pageNumList
=
wx
.
getStorageSync
(
'pageNumList'
)
let
pageNum
=
null
if
(
flag
)
{
pageNum
=
pageNumList
[
this
.
data
.
goodsListIndex
]
terminalProductIds
=
wx
.
getStorageSync
(
'ids'
)[
this
.
data
.
goodsListIndex
].
slice
((
pageNum
-
1
)
*
this
.
data
.
pageSize
,
pageNum
*
this
.
data
.
pageSize
)
pageNum
+=
1
pageNumList
[
this
.
data
.
goodsListIndex
]
=
pageNum
}
else
{
pageNum
=
pageNumList
[
this
.
data
.
datasIndex
]
terminalProductIds
=
wx
.
getStorageSync
(
'ids'
)[
this
.
data
.
datasIndex
].
slice
((
pageNum
-
1
)
*
this
.
data
.
pageSize
,
pageNum
*
this
.
data
.
pageSize
)
pageNum
+=
1
pageNumList
[
this
.
data
.
datasIndex
]
=
pageNum
}
wx
.
setStorageSync
(
'pageNumList'
,
pageNumList
)
let
{
let
{
vipPrice
,
vipPrice
,
marketingTag
,
marketingTag
,
...
@@ -207,11 +252,11 @@ const componentOptions = {
...
@@ -207,11 +252,11 @@ const componentOptions = {
goodsApi
.
queryMoreProductInfo
(
moreQuery
).
then
(
res
=>
{
goodsApi
.
queryMoreProductInfo
(
moreQuery
).
then
(
res
=>
{
if
(
res
.
data
.
code
==
200
)
{
if
(
res
.
data
.
code
==
200
)
{
goodsList
=
res
.
data
.
data
;
goodsList
=
res
.
data
.
data
;
this
.
goodsListVal
(
goodsList
,
1
);
this
.
goodsListVal
(
goodsList
,
1
,
flag
);
}
}
});
});
},
},
goodsListVal
(
goodsList
,
type
)
{
goodsListVal
(
goodsList
,
type
,
flag
)
{
console
.
log
(
goodsList
,
"------------goodsListVal"
);
console
.
log
(
goodsList
,
"------------goodsListVal"
);
goodsList
.
forEach
((
item
,
index
)
=>
{
goodsList
.
forEach
((
item
,
index
)
=>
{
item
.
marketingTag
=
item
.
defaultTags
item
.
marketingTag
=
item
.
defaultTags
...
@@ -221,6 +266,7 @@ const componentOptions = {
...
@@ -221,6 +266,7 @@ const componentOptions = {
)
)
:
[];
:
[];
item
.
shopLogoUrl
=
DFSImg
(
item
.
shopLogoUrl
);
item
.
shopLogoUrl
=
DFSImg
(
item
.
shopLogoUrl
);
item
.
loadState
=
false
item
.
coverImage
=
DFSImg
(
item
.
coverImage
,
400
,
400
,
1
);
item
.
coverImage
=
DFSImg
(
item
.
coverImage
,
400
,
400
,
1
);
item
.
productImgUrl
=
DFSImg
(
item
.
productImgUrl
,
400
,
400
,
1
);
item
.
productImgUrl
=
DFSImg
(
item
.
productImgUrl
,
400
,
400
,
1
);
item
.
minPrice
=
Number
(
item
.
minPrice
).
toFixed
(
2
);
item
.
minPrice
=
Number
(
item
.
minPrice
).
toFixed
(
2
);
...
@@ -243,10 +289,47 @@ const componentOptions = {
...
@@ -243,10 +289,47 @@ const componentOptions = {
item
.
getSaleTime
=
this
.
getSaleTime
(
item
.
saleTime
);
item
.
getSaleTime
=
this
.
getSaleTime
(
item
.
saleTime
);
}
}
});
});
var
that
=
this
let
pageGoodsList
=
wx
.
getStorageSync
(
'pageGoodsList'
)
||
[]
if
(
flag
)
{
pageGoodsList
[
that
.
data
.
goodsListIndex
].
push
(...
goodsList
)
}
else
{
pageGoodsList
[
that
.
data
.
datasIndex
].
push
(...
goodsList
)
console
.
log
(
pageGoodsList
[
that
.
data
.
datasIndex
],
'--pageGoodsList[that.data.datasIndex]'
)
}
wx
.
setStorageSync
(
'pageGoodsList'
,
pageGoodsList
);
// 获取是否要开启请求拦截
let
loadingFlag
=
wx
.
getStorageSync
(
'loadingFlag'
)
loadingFlag
[
that
.
data
.
datasIndex
]
=
false
wx
.
setStorageSync
(
'loadingFlag'
,
loadingFlag
);
that
.
setData
({
pageGoodsList
,
})
this
.
setData
({
this
.
setData
({
"datas.componentData.goodsList"
:
goodsList
,
"datas.componentData.goodsList"
:
goodsList
,
goodsList
// goodsList
});
loadingFlag
},
function
()
{
// that.lazyloading();
// 节点布局方案在组件嵌套层级过深测试无效
// let goodsList = this.data.goodsList // 获取原数据
// goodsList.forEach((item,index)=>{
// wx.createIntersectionObserver().relativeToViewport({bottom: 20}).observe(`.goodsItemIndex${index}`, (ret) => {
// // if (ret.intersectionRatio > 0){
// // group[i].show = true
// // }
// // this.setData({ // 更新数据
// // group
// // })
// console.log('1111');
// })
// })
})
if
(
type
==
1
)
{
if
(
type
==
1
)
{
// 初始化
// 初始化
if
(
this
.
selectComponent
(
"#waterfallFlow"
))
{
if
(
this
.
selectComponent
(
"#waterfallFlow"
))
{
...
@@ -259,6 +342,77 @@ const componentOptions = {
...
@@ -259,6 +342,77 @@ const componentOptions = {
}
}
}
}
},
},
// 触发图片加载
lazyloading
(){
var
that
=
this
console
.
log
(
that
.
data
.
datasIndex
,
that
.
data
.
goodsListIndex
,
'datasIndex'
);
console
.
log
(
that
.
data
.
pageGoodsList
[
that
.
data
.
datasIndex
]);
let
storageDatasList
=
wx
.
getStorageSync
(
'storageDatasList'
)
||
[]
let
{
style
}
=
storageDatasList
[
that
.
data
.
datasIndex
];
let
type
=
''
if
(
style
==
'list'
){
type
=
'goods-item'
}
else
{
console
.
log
(
"不是goods-item"
);
return
}
let
windowHeight
=
wx
.
getSystemInfoSync
().
windowHeight
let
pageGoodsList
=
wx
.
getStorageSync
(
'pageGoodsList'
)
||
[]
console
.
log
(
that
.
data
.
pageGoodsList
,
pageGoodsList
,
that
.
data
.
datasIndex
,
'pageGoodsList--loading'
);
let
loadingFlag
=
wx
.
getStorageSync
(
'loadingFlag'
)
// 如果所有的商品都加载完成直接return
if
(
loadingFlag
[
that
.
data
.
datasIndex
])
{
console
.
log
(
"如果所有的商品都加载完成直接return"
);
return
}
let
ids
=
wx
.
getStorageSync
(
'ids'
)[
that
.
data
.
datasIndex
]
if
(
ids
.
length
==
that
.
data
.
pageGoodsList
[
that
.
data
.
datasIndex
].
length
&&
that
.
data
.
pageGoodsList
[
that
.
data
.
datasIndex
][
that
.
data
.
pageGoodsList
[
that
.
data
.
datasIndex
].
length
-
1
].
loadState
==
true
)
{
return
}
wx
.
createSelectorQuery
().
selectAll
(
`.goodsListItemIndex
${
that
.
data
.
datasIndex
}
>>>.
${
type
}
`
).
boundingClientRect
(
function
(
rects
){
for
(
let
index
=
0
;
index
<
rects
.
length
;
index
++
)
{
if
(
rects
[
index
].
top
==
0
&&
rects
[
index
].
bottom
==
0
&&
rects
[
index
].
left
==
0
&&
rects
[
index
].
right
==
0
)
{
break
}
if
(
rects
[
index
].
top
<
windowHeight
)
{
pageGoodsList
[
that
.
data
.
datasIndex
][
index
].
loadState
=
true
}
}
that
.
setData
({
pageGoodsList
,
})
// that.pageGoodsList = pageGoodsList
console
.
log
(
rects
,
pageGoodsList
[
that
.
data
.
goodsListIndex
],
pageGoodsList
[
that
.
data
.
datasIndex
],
'fff'
);
wx
.
setStorageSync
(
'pageGoodsList'
,
pageGoodsList
)
// 如果当前分页倒数第一张加载完成直接 打开loadingFlag开关并加载下一页数据
if
(
that
.
data
.
pageGoodsList
[
that
.
data
.
datasIndex
][
that
.
data
.
pageGoodsList
[
that
.
data
.
datasIndex
].
length
-
1
].
loadState
==
true
)
{
loadingFlag
[
that
.
data
.
datasIndex
]
=
true
that
.
setData
({
loadingFlag
})
wx
.
setStorageSync
(
'loadingFlag'
,
loadingFlag
)
that
.
moreProduct
(
false
)
console
.
log
(
'load--ok'
);
}
}).
exec
();
},
getSaleTime
(
val
)
{
getSaleTime
(
val
)
{
return
new
Date
(
val
.
replace
(
/-/g
,
"/"
)).
getTime
()
-
new
Date
().
getTime
();
return
new
Date
(
val
.
replace
(
/-/g
,
"/"
)).
getTime
()
-
new
Date
().
getTime
();
},
},
...
@@ -326,8 +480,12 @@ const componentOptions = {
...
@@ -326,8 +480,12 @@ const componentOptions = {
return
showFlag
;
return
showFlag
;
},
},
getScroll
(
el
)
{
getScroll
(
el
)
{
//! 如果不是当前tab页return不执行滚动加载
if
(
this
.
data
.
datasIndex
!=
this
.
data
.
goodsListIndex
)
return
;
// 是指定分类且不显示查看更多的瀑布流组件滚动加载
// 是指定分类且不显示查看更多的瀑布流组件滚动加载
let
{
goodsSource
,
moreShow
,
style
}
=
this
.
data
.
datas
.
componentData
;
let
{
goodsSource
,
moreShow
,
style
}
=
this
.
data
.
datas
.
componentData
;
console
.
log
(
'goodsSource, moreShow, style'
,
goodsSource
,
moreShow
,
style
);
this
.
lazyloading
()
if
(
if
(
goodsSource
==
"classify"
&&
goodsSource
==
"classify"
&&
moreShow
==
false
&&
moreShow
==
false
&&
...
...
static/nativeComponents/GoodsList/index.wxml
View file @
3a787cd4
...
@@ -25,15 +25,20 @@
...
@@ -25,15 +25,20 @@
style="margin-left:{{-datas.componentData.proGap*2}}rpx;"
style="margin-left:{{-datas.componentData.proGap*2}}rpx;"
>
>
<view
<view
wx:for="{{
goodsList
}}"
wx:for="{{
pageGoodsList[datasIndex]
}}"
wx:key="index"
wx:key="index"
class="goods-item"
class="goods-item
{{'goodsItemIndex'+index}}
"
style="width:{{100/datas.componentData.columnNum}}%;padding-left:{{datas.componentData.proGap*2}}rpx"
style="width:{{100/datas.componentData.columnNum}}%;padding-left:{{datas.componentData.proGap*2}}rpx"
>
>
<goods-item
<
!-- <
goods-item
datas="{{datas}}"
datas="{{datas}}"
items="{{goodsList[index]}}"
items="{{goodsList[index]}}"
indexs="{{index}}"
indexs="{{index}}"
></goods-item> -->
<goods-item
items="{{item}}"
datas="{{datas}}"
indexs="{{index}}"
></goods-item>
></goods-item>
</view>
</view>
</view>
</view>
...
...
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