完善功能

This commit is contained in:
wangxiaowei
2025-11-29 20:50:19 +08:00
parent 67c8e8e016
commit d38d4419d9
20 changed files with 403 additions and 98 deletions

View File

@ -197,7 +197,7 @@
money.value = Number(res.details.order_amount)
// 一键续订价格
renewPrice.value = Number(res.details.renew_dtime.renew_price) || 0
renewPrice.value = Number(res.details?.renew_dtime?.renew_price) || 0
},
/**

View File

@ -1,5 +1,6 @@
<!-- 使用 type="home" 属性设置首页其他页面不需要设置默认为page -->
<route lang="jsonc" type="page">{
"needLogin": true,
"layout": "tabbar",
"style": {
// 'custom' 表示开启自定义导航栏,默认 'default'
@ -21,7 +22,7 @@
<view class="mt-40rpx">
<view class="bg-[#F8F9FA] rounded-28rpx w-162rpx h-56rpx text-[#606266] flex items-center justify-center">
<wd-img width="28rpx" height="28rpx" :src="`${OSS}icon/icon_location2.png`"></wd-img>
<view class="text-26rpx text-[#606266] leading-36rpx">上海市</view>
<view class="text-26rpx text-[#606266] leading-36rpx">{{ city || LOCATION_DEFAULT_CITY }}</view>
</view>
</view>
</view>
@ -29,7 +30,10 @@
<view class="mt-50rpx mx-30rpx">
<view class="text-[#333] leading-42rpx text-30rpx font-bold">已开通城市</view>
<view class="mt-40rpx grid grid-cols-4 gap-20rpx w-full">
<view class="bg-[#F8F9FA] rounded-28rpx h-56rpx text-[#606266] flex items-center justify-center" v-for="(item, index) in openCityList" :key="index">
<view class="bg-[#F8F9FA] rounded-28rpx h-56rpx text-[#606266] flex items-center justify-center"
v-for="(item, index) in openCityList" :key="index"
@click="City.handleChooseCity(item)"
>
<wd-img width="28rpx" height="28rpx" :src="`${OSS}icon/icon_location2.png`"></wd-img>
<view class="text-26rpx text-[#606266] leading-36rpx">{{ item.name }}</view>
</view>
@ -41,12 +45,14 @@
<script lang="ts" setup>
import { router } from '@/utils/tools'
import { getOpenCityList } from '@/api/tea-room'
import { LOCATION_CITY_KEY, LOCATION_LAT_KEY, LOCATION_LNG_KEY } from '@/hooks/useLocation'
const OSS = inject('OSS')
// 经纬度
const latitude = ref<number>(0)
const longitude = ref<number>(0)
const city = ref<string>('')
// 已开通城市列表
const openCityList = ref<Array<any>>([])
@ -62,8 +68,27 @@
const City = {
handleInit: async () => {
city.value = uni.getStorageSync(LOCATION_CITY_KEY)
const res = await getOpenCityList()
openCityList.value = res.list
},
/**
* 选择城市
*/
handleChooseCity: (item: any) => {
const params = {
latitude: item.latitude,
longitude: item.longitude,
city: item.name
}
uni.$emit('locationUpdate', params)
uni.setStorageSync(LOCATION_LAT_KEY, item.latitude)
uni.setStorageSync(LOCATION_LNG_KEY, item.longitude)
uni.setStorageSync(LOCATION_CITY_KEY, item.name)
router.navigateBack()
}
}

View File

@ -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>