Commit 802a7193 by 严立

LL - 商品列表分类显示,即时更新身份认证

parent 9690d2f5
...@@ -33,10 +33,16 @@ App({ ...@@ -33,10 +33,16 @@ App({
onLaunch: function () { onLaunch: function () {
this.setUnitProportion() this.setUnitProportion()
this.login() this.login()
}, },
onShow: function () {
console.log('onShow')
if (this.globalData.token === '') return
this.queryUserStatus()
},
setUnitProportion: function () { setUnitProportion: function () {
let funcProportion = wx.getSystemInfoSync().windowWidth / 750 let funcProportion = wx.getSystemInfoSync().windowWidth / 750
wx.setStorageSync('unitProportion', funcProportion) wx.setStorageSync('unitProportion', funcProportion)
...@@ -160,7 +166,7 @@ App({ ...@@ -160,7 +166,7 @@ App({
// 防止无限刷新 token 的紧急修复手段 // 防止无限刷新 token 的紧急修复手段
if (obj && obj.error) { if (obj && obj.error) {
wx.switchTab({ wx.switchTab({
url: '/pages/home/home' url: '/pages/home/home/home'
}) })
} }
}, },
...@@ -208,7 +214,8 @@ App({ ...@@ -208,7 +214,8 @@ App({
let funcResponse = response.data let funcResponse = response.data
let funcUserInfo = wx.getStorageSync('userInfo') let funcUserInfo = wx.getStorageSync('userInfo')
let funcStatus = Number(funcResponse.state) let funcStatus = Number(funcResponse.state) // 最新的用户身份
let funcStatusRaw = funcUserInfo.status // 当前的用户身份,用于对比用户身份是否更新
let funcStatusText = '去认证' let funcStatusText = '去认证'
switch (funcStatus) { switch (funcStatus) {
...@@ -235,6 +242,12 @@ App({ ...@@ -235,6 +242,12 @@ App({
} }
wx.setStorageSync('userInfo', funcUserInfo) wx.setStorageSync('userInfo', funcUserInfo)
// 如果用户身份有更新,则自动跳转到首页
if (funcStatus !== funcStatusRaw) {
console.log('status change')
wx.switchTab({ url: '/pages/home/home/home' })
}
} }
}) })
}, },
......
...@@ -3,6 +3,7 @@ let App = getApp() ...@@ -3,6 +3,7 @@ let App = getApp()
Page({ Page({
scrollLock: false, scrollLock: false,
scrollTimer: 0, scrollTimer: 0,
sideBarIsSelection: false,
data: { data: {
imageBase: App.globalData.appImageBase, imageBase: App.globalData.appImageBase,
...@@ -23,18 +24,12 @@ Page({ ...@@ -23,18 +24,12 @@ Page({
sideBarTopPadding: 0, sideBarTopPadding: 0,
sideBarIndex: 0, sideBarIndex: 0,
commoditScroll: 0,
menuTitle: '', // 商品列表标题
commodityList: [], // 商品列表 commodityList: [], // 商品列表
commodityDetail: {}, // 商品详情 commodityDetail: {}, // 商品详情
shoppingCart: [], // 购物车列表 shoppingCart: [], // 购物车列表
shoppingCartTotal: 0, // 购物车总数 shoppingCartTotal: 0, // 购物车总数
scrollTop: 0,
winToast: false, winToast: false,
winLoading: false, winLoading: false,
winCommodityDetail: false, winCommodityDetail: false,
...@@ -193,7 +188,6 @@ Page({ ...@@ -193,7 +188,6 @@ Page({
this.setData({ this.setData({
sideBar: funcSideBar, sideBar: funcSideBar,
menuTitle: funcSideBar[0].tab
}) })
this.queryCommodity() this.queryCommodity()
...@@ -308,6 +302,7 @@ Page({ ...@@ -308,6 +302,7 @@ Page({
let funcSideBarId = this.data.sideBar let funcSideBarId = this.data.sideBar
let funcList = [] let funcList = []
// 添加商品到对应分类
for (let i = 0, l = funcSideBarId.length; i < l; i++) { for (let i = 0, l = funcSideBarId.length; i < l; i++) {
funcList.push({ funcList.push({
'id': funcSideBarId[i].id, 'id': funcSideBarId[i].id,
...@@ -323,8 +318,18 @@ Page({ ...@@ -323,8 +318,18 @@ Page({
} }
} }
// 删除没有商品的分类
for (let i = 0; i < funcList.length; i++) {
if (funcList[i].commodity.length === 0) {
funcList.splice(i, 1)
funcSideBarId.splice(i, 1)
i = i - 1
}
}
this.setData({ this.setData({
winLoading: false, winLoading: false,
sideBar: funcSideBarId,
commodityList: funcList, commodityList: funcList,
}) })
...@@ -335,14 +340,13 @@ Page({ ...@@ -335,14 +340,13 @@ Page({
let funcElement = response[0] let funcElement = response[0]
let funcSideBarHeight = [] let funcSideBarHeight = []
for (let i = 0, l = funcElement.length; i < l; i++) { for (let i = 0, l = funcElement.length; i < l; i++) {
funcSideBarHeight.push(funcElement[i].top) // 120 是分类标题元素 rpx 高度
funcSideBarHeight.push(funcElement[i].top - 120 * wx.getStorageSync('unitProportion'))
} }
this.setData({ this.setData({
sideBarHeight: funcSideBarHeight sideBarHeight: funcSideBarHeight
}) })
console.log(this.data.sideBarHeight)
}) })
}, },
...@@ -354,14 +358,45 @@ Page({ ...@@ -354,14 +358,45 @@ Page({
*/ */
onSelectionSideBar: function (event) { onSelectionSideBar: function (event) {
let funcIndex = event.currentTarget.dataset.index let funcIndex = event.currentTarget.dataset.index
let funcMenuTitle = this.data.sideBar[funcIndex].tab
this.setData({ this.setData({
sideBarIndex: funcIndex, sideBarIndex: funcIndex,
menuTitle: funcMenuTitle, commoditScroll: this.data.sideBarHeight[funcIndex]
scrollTop: 0 })
},
/**
* 商品列表滚动事件
* @function
* @param
* @returns
*/
onCommoditScroll: function (event) {
// 当滚动幅度较大时,认定为是分类点击跳转,屏蔽此事件的滚动
if (250 * wx.getStorageSync('unitProportion') < Math.abs(event.detail.deltaY)) return
// 优化滚动事件触发频率
if (this.scrollLock) return
this.scrollLock = true
let funcIndex = 0
let funcScrollHeight = event.detail.scrollTop
let funcSideBarHeight = this.data.sideBarHeight
for (let i = 0, l = funcSideBarHeight.length; i < l; i++) {
if (funcScrollHeight > funcSideBarHeight[i]) {
funcIndex = i
}
}
this.setData({
sideBarIndex: funcIndex
}) })
this.queryCommodity() // 恢复滚动事件
this.scrollTimer = setTimeout(() => {
this.scrollLock = false
clearTimeout(this.scrollTimer)
}, 10)
}, },
/** /**
...@@ -494,36 +529,4 @@ Page({ ...@@ -494,36 +529,4 @@ Page({
url: '/pages/commodity/shopping-cart/shopping-cart', url: '/pages/commodity/shopping-cart/shopping-cart',
}) })
}, },
/**
* 页面滚动事件
* @function
* @param
* @returns
*/
onPageScroll: function (event) {
// 优化滚动事件触发频率
if (this.scrollLock) return
this.scrollLock = true
console.log(event.detail.scrollTop)
let funcIndex = 0
let funcScrollHeight = event.detail.scrollTop
let funcSideBarHeight = this.data.sideBarHeight
for (let i = 0, l = funcSideBarHeight.length; i < l; i++) {
if (funcScrollHeight > funcSideBarHeight[i]) {
funcIndex = i
}
}
this.setData({
sideBarIndex: funcIndex
})
// 恢复滚动事件
this.scrollTimer = setTimeout(() => {
this.scrollLock = false
clearTimeout(this.scrollTimer)
}, 10)
},
}) })
\ No newline at end of file
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
</scroll-view> </scroll-view>
<!-- 商品列表 --> <!-- 商品列表 -->
<scroll-view class="menu-list" scroll-y bindscroll="onPageScroll"> <scroll-view class="menu-list" scroll-y scroll-top="{{commoditScroll}}" bindscroll="onCommoditScroll">
<block wx:for="{{commodityList}}" wx:for-index="index" wx:for-item="item" wx:key="index"> <block wx:for="{{commodityList}}" wx:for-index="index" wx:for-item="item" wx:key="index">
<view class="right-content-title">{{item.tab}}</view> <view class="right-content-title">{{item.tab}}</view>
......
const App = getApp() const App = getApp()
Page({ Page({
scrollLock: false,
scrollTimer: 0,
/**
* 页面的初始数据
*/
data: { data: {
// 导航栏相关属性
navigationStyle: {
normal: {
backIcon: '',
color: '#FFFFFF',
background: 'rgba(255, 255, 255, 0)'
},
change: {
backIcon: '',
color: '#000000',
background: 'rgba(255, 255, 255, 1)'
},
scroll: '400rpx',
},
navigationScroll: 0,
isCheckPermission: false, isCheckPermission: false,
imageBase: App.globalData.appImageBase, imageBase: App.globalData.appImageBase,
imageResourcesBase: App.globalData.appResourcesBase, imageResourcesBase: App.globalData.appResourcesBase,
...@@ -550,5 +565,25 @@ Page({ ...@@ -550,5 +565,25 @@ Page({
}) })
} },
onPageScroll: function (event) {
console.log(this.scrollLock)
// 优化滚动事件触发频率
if (this.scrollLock) return
this.scrollLock = true
this.setData({
navigationScroll: event.scrollTop
})
console.log(this.data.navigationScroll)
// 恢复滚动事件
this.scrollTimer = setTimeout(() => {
this.scrollLock = false
clearTimeout(this.scrollTimer)
}, 10)
},
}) })
\ No newline at end of file
<navigation class="navigation" titleText="我的" color="{{type == 1? '#FFFFFF' :''}}"></navigation> <navigation class="navigation" titleText="我的" scrollStyle="{{navigationStyle}}" scrollHeight="{{navigationScroll}}"></navigation>
<view class="container"> <view class="container">
<view class="mine" wx:if="{{type !== 1}}"> <view class="mine" wx:if="{{type !== 1}}">
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
} }
.navigation { .navigation {
z-index: 2; z-index: 1900;
} }
.background-image { .background-image {
......
<!-- 畅玩 - 活动详情 --> <navigation class="navigation" titleText="主题活动" scrollStyle="{{navigationStyle}}" scrollHeight="{{navigationScroll}}"></navigation>
<navigation class="navigation" titleText="主题活动" color="#ffffff" scrollStyle="{{navigationStyle}}" scrollHeight="{{navigationScroll}}"></navigation>
<view class="container"> <view class="container">
<view id="banner" class="banner"> <view id="banner" class="banner">
......
...@@ -572,7 +572,7 @@ Page({ ...@@ -572,7 +572,7 @@ Page({
'scoreService': funcResponse.list[i].environmentalEvaluation, // 服务评价 'scoreService': funcResponse.list[i].environmentalEvaluation, // 服务评价
'scoreCommodity': funcResponse.list[i].productEvaluation, // 商品评价 'scoreCommodity': funcResponse.list[i].productEvaluation, // 商品评价
'scoreEnvironmental': funcResponse.list[i].environmentalEvaluation, // 环境评价 'scoreEnvironmental': funcResponse.list[i].environmentalEvaluation, // 环境评价
'userName': funcResponse.list[i].name, 'userName': funcResponse.list[i].nickname,
'userAvatar': funcResponse.list[i].headImg, 'userAvatar': funcResponse.list[i].headImg,
'userType': funcResponse.list[i].userType, 'userType': funcResponse.list[i].userType,
'userAlbum': funcResponse.list[i].imgUrls, // 评论图册 'userAlbum': funcResponse.list[i].imgUrls, // 评论图册
......
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": true,
"es6": true,
"enhance": true,
"postcss": true,
"minified": true,
"newFeature": true,
"coverView": true,
"nodeModules": true,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": false,
"uploadWithSourceMap": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
}
},
"compileType": "miniprogram",
"libVersion": "2.10.0",
"appid": "wx37a9b7a3d92029f2",
"projectname": "%E4%B8%96%E8%8C%82%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%BA%8C%E6%9C%9F",
"cloudfunctionTemplateRoot": "",
"watchOptions": {
"ignore": []
},
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"plugin": {
"current": -1,
"list": []
},
"game": {
"list": []
},
"gamePlugin": {
"current": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": [
{
"id": -1,
"name": "pages/commodity/menu-food/menu-food",
"pathName": "pages/commodity/menu-food/menu-food",
"query": "",
"scene": null
},
{
"id": -1,
"name": "pages/play/home/home",
"pathName": "pages/play/home/home",
"query": "",
"scene": null
},
{
"id": -1,
"name": "pages/play/service-detail/service-detail",
"pathName": "pages/play/service-detail/service-detail",
"query": "id=1&type=4",
"scene": null
},
{
"id": -1,
"name": "pages/mine/home/home",
"pathName": "pages/mine/home/home",
"query": "",
"scene": null
}
]
}
}
}
\ No newline at end of file
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 sign in to comment