Fix(首页):未校验返回数据的合法性导致界面渲染错误

This commit is contained in:
lifizer
2024-11-29 15:32:14 +08:00
parent 5813924548
commit e48762c783
+26 -16
View File
@@ -427,8 +427,7 @@ export default {
getShareImage().then(({ data }) => this.shareAppImg = data)
sharpBannar().then(res => {
const { data } = res
this.bannerList = data.banner
this.getPageData()
this.bannerList = data.banner || []
})
this.getLocationData()
},
@@ -439,36 +438,45 @@ export default {
this.getLocationData()
}))
},
async getLocationData() {
getLocationData() {
this.isLocating = true
const mapData = await getLocationPromise()
getLocationPromise().then(mapData => {
if (mapData.errMsg) {
const { latitude, longitude } = mapData
const address = await getCurAddress(latitude, longitude)
getCurAddress(latitude, longitude).then(address => {
this.cityName = address[1].data.result.ad_info.city
this.isLocating = false
this.getPageData()
}).catch(() => {
this.getPageData()
})
} else {
this.isLocating = false
this.getPageData()
}
}).catch(() => {
this.getPageData()
})
},
getPageData() {
const _this = this
uni.showLoading({ title: '加载中' })
getHomeData({ cityName: this.cityName }).then(res => {
const { data } = res
_this.$set(_this, 'banner', data.banner)
_this.$set(_this, 'menus', data.menus)
_this.$set(_this, 'landmarkGoodsImage', data.landmarkGoodsImage)
_this.$set(_this, 'countyFamousImage', data.countyFamousImage)
_this.$set(_this, 'oldUserPopup', data.oldUserPopup)
_this.$set(_this, 'contentHomestay', data.contentHomestayV2)
_this.$set(_this, 'contentFestival', data.contentFestivalV2)
_this.$set(_this, 'newZone', data.newGoods)
_this.indexVideo = data.indexVideo.videoUrl
const { success, data } = res
if (success && data) {
_this.$set(_this, 'banner', data.banner || [])
_this.$set(_this, 'menus', data.menus || [])
_this.$set(_this, 'landmarkGoodsImage', data.landmarkGoodsImage || {})
_this.$set(_this, 'countyFamousImage', data.countyFamousImage || {})
_this.$set(_this, 'oldUserPopup', data.oldUserPopup || {})
_this.$set(_this, 'contentHomestay', data.contentHomestayV2 || [])
_this.$set(_this, 'contentFestival', data.contentFestivalV2 || [])
_this.$set(_this, 'newZone', data.newGoods || [])
_this.indexVideo = data.indexVideo ? data.indexVideo.videoUrl : ''
_this.bastLeftList = []
_this.bastRightList = []
_this.lotteryCanDraw = data.lotteryCanDraw
_this.lotteryCanDraw = data.lotteryCanDraw || false
if (data.bastList) {
for (let i = 0; i < data.bastList.length; i++) {
if (i % 2 === 0) {
// 店铺排名
@@ -491,6 +499,8 @@ export default {
_this.bastRightList.push(data.bastList[i])
}
}
}
}
uni.hideLoading()
}).catch(() => {
uni.hideLoading()