完善功能
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
<wd-navbar safeAreaInsetTop :bordered="false" custom-style="background-color: transparent !important;">
|
||||
<template #left>
|
||||
<view class="flex items-center line-1 w-130rpx" @click="Index.handleToCity">
|
||||
<view class="mr-10rpx font-400 leading-44rpx text-32rpx pl-10rpx line-1">上海市</view>
|
||||
<view class="mr-10rpx font-400 leading-44rpx text-32rpx pl-10rpx line-1">{{ city || LOCATION_DEFAULT_CITY }}</view>
|
||||
<wd-img width="14rpx" height="9rpx" :src="`${OSS}icon/icon_arrow_down.png`" />
|
||||
</view>
|
||||
</template>
|
||||
@ -110,7 +110,7 @@
|
||||
import { router } from '@/utils/tools'
|
||||
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
|
||||
import useMescroll from "@/uni_modules/mescroll-uni/hooks/useMescroll.js"
|
||||
import { LOCATION_DENY_TIME_KEY, handleEnsureLocationAuthHooks } from '@/hooks/useLocation'
|
||||
import { LOCATION_DENY_TIME_KEY, handleEnsureLocationAuthHooks, LOCATION_DEFAULT_CITY, handleGetLocationCity, LOCATION_CITY_KEY } from '@/hooks/useLocation'
|
||||
import { getHomeBannerList } from '@/api/home'
|
||||
import { getHomeTeaStoreList } from '@/api/tea-room'
|
||||
import { useUserStore } from '@/store'
|
||||
@ -133,17 +133,28 @@
|
||||
}
|
||||
const latitude = ref<number>(0)
|
||||
const longitude = ref<number>(0)
|
||||
const city = ref<string>('')
|
||||
const keywords = ref<string>('')
|
||||
const list = ref<Array<any>>([])
|
||||
|
||||
onShow(async() => {
|
||||
// 等到onLoad执行完毕且获取到授权KEY后,才执行定位授权检查
|
||||
let lastLocation = { lat: 0, lng: 0 }
|
||||
onShow(async () => {
|
||||
if (uni.getStorageSync(LOCATION_DENY_TIME_KEY)) {
|
||||
const location = await checkLocationAuthWithModal()
|
||||
if (location) {
|
||||
latitude.value = location.lat
|
||||
longitude.value = location.lng
|
||||
Index.handleResetSearch()
|
||||
// 只有经纬度变化时才刷新
|
||||
if (location.lat !== lastLocation.lat || location.lng !== lastLocation.lng) {
|
||||
const loc = await handleGetLocationCity(location.lat, location.lng)
|
||||
city.value = loc.city
|
||||
|
||||
latitude.value = location.lat
|
||||
longitude.value = location.lng
|
||||
lastLocation.lat = location.lat
|
||||
lastLocation.lng = location.lng
|
||||
|
||||
console.log("🚀 ~ city.value:", 'xxxxx', city.value)
|
||||
Index.handleResetSearch()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -156,10 +167,16 @@
|
||||
const { lat, lng } = await handleEnsureLocationAuthHooks()
|
||||
latitude.value = lat
|
||||
longitude.value = lng
|
||||
Index.handleResetSearch()
|
||||
|
||||
const location = await handleGetLocationCity(lat, lng)
|
||||
city.value = location.city
|
||||
latitude.value = location.latitude
|
||||
longitude.value = location.longitude
|
||||
|
||||
Index.handleResetSearch()
|
||||
})
|
||||
|
||||
|
||||
const Index = {
|
||||
/**
|
||||
* 茶室门店列表
|
||||
@ -177,16 +194,22 @@
|
||||
search: keywords.value,
|
||||
user_id: userId
|
||||
}
|
||||
uni.showLoading({ title: '加载中...' })
|
||||
|
||||
getHomeTeaStoreList(filter).then( res => {
|
||||
console.log("🚀 ~ res:", res)
|
||||
const curPageData = res.list || [] // 当前页数据
|
||||
if(mescroll.num == 1) list.value = [] // 第一页需手动制空列表
|
||||
list.value = list.value.concat(curPageData) //追加新数据
|
||||
mescroll.endSuccess(curPageData.length, Boolean(res.more))
|
||||
}).catch(() => {
|
||||
mescroll.endErr() // 请求失败, 结束加载
|
||||
})
|
||||
try {
|
||||
getHomeTeaStoreList(filter).then( res => {
|
||||
const curPageData = res.list || [] // 当前页数据
|
||||
if(mescroll.num == 1) list.value = [] // 第一页需手动制空列表
|
||||
list.value = list.value.concat(curPageData) //追加新数据
|
||||
mescroll.endSuccess(curPageData.length, Boolean(res.more))
|
||||
}).catch(() => {
|
||||
mescroll.endErr() // 请求失败, 结束加载
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -202,6 +225,15 @@
|
||||
* 跳转城市选择
|
||||
*/
|
||||
handleToCity: () => {
|
||||
uni.$on('locationUpdate', params => {
|
||||
console.log("🚀 ~ params:", params)
|
||||
uni.$off('locationUpdate')
|
||||
|
||||
city.value = params.city
|
||||
latitude.value = params.latitude
|
||||
longitude.value = params.longitude
|
||||
Index.handleResetSearch()
|
||||
})
|
||||
router.navigateTo(`/pages/city/city?lat=${latitude.value}&lng=${longitude.value}`)
|
||||
},
|
||||
|
||||
@ -229,6 +261,8 @@
|
||||
* 重置搜索
|
||||
*/
|
||||
handleResetSearch: () => {
|
||||
console.log("🚀 ~ location:", 456)
|
||||
|
||||
list.value = []
|
||||
getMescroll().resetUpScroll()
|
||||
},
|
||||
@ -244,6 +278,23 @@
|
||||
fail: res => {
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新定位信息
|
||||
*/
|
||||
handleLocationUpdate: (params: any) => {
|
||||
console.log("🚀 ~ locationUpdate:")
|
||||
if (
|
||||
city.value !== params.city ||
|
||||
latitude.value !== params.latitude ||
|
||||
longitude.value !== params.longitude
|
||||
) {
|
||||
city.value = params.city
|
||||
latitude.value = params.latitude
|
||||
longitude.value = params.longitude
|
||||
Index.handleResetSearch()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user