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

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