diff --git a/pages/home/index.vue b/pages/home/index.vue index 938a6cb..9df4813 100644 --- a/pages/home/index.vue +++ b/pages/home/index.vue @@ -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,56 +438,67 @@ export default { this.getLocationData() })) }, - async getLocationData() { + getLocationData() { this.isLocating = true - const mapData = await getLocationPromise() - if (mapData.errMsg) { - const { latitude, longitude } = mapData - const address = await getCurAddress(latitude, longitude) - this.cityName = address[1].data.result.ad_info.city - this.isLocating = false + getLocationPromise().then(mapData => { + if (mapData.errMsg) { + const { latitude, longitude } = mapData + 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() - } else { - this.isLocating = false - } + }) }, 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 - _this.bastLeftList = [] - _this.bastRightList = [] - _this.lotteryCanDraw = data.lotteryCanDraw - for (let i = 0; i < data.bastList.length; i++) { - if (i % 2 === 0) { - // 店铺排名 - if (i === 4 && data.hotelList.length > 0) { - _this.bastLeftList.push({ - type: 'hotel', - list: data.hotelList - }) + 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 || false + if (data.bastList) { + for (let i = 0; i < data.bastList.length; i++) { + if (i % 2 === 0) { + // 店铺排名 + if (i === 4 && data.hotelList.length > 0) { + _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()