diff --git a/src/api/user.ts b/src/api/user.ts index a07f221..3e7c61d 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -82,6 +82,7 @@ export function userAddressDetails(data: IUserAddressDetailsParams) { export interface IGetCouponsParams { id: number numbers: number + type_id: number } export function getCoupons(data: IGetCouponsParams) { @@ -93,6 +94,7 @@ export function getCoupons(data: IGetCouponsParams) { */ export interface IGetMyCouponsParams { status: number + type_id: number } export function getMyCoupons(data: IGetMyCouponsParams) { return http.Post('/api/UserCoupon/orderCoupinList', data) diff --git a/src/bundle/coupon/coupon.vue b/src/bundle/coupon/coupon.vue index bcf9786..c1ee66a 100644 --- a/src/bundle/coupon/coupon.vue +++ b/src/bundle/coupon/coupon.vue @@ -100,7 +100,7 @@ const Coupons = { // 初始化优惠券列表 handleInit: async (id: number, numbers: number) => { - const res = await getCoupons({id, numbers}) + const res = await getCoupons({id, numbers, type_id: 1}) couponList.value = res }, diff --git a/src/bundle/coupon/my-coupon.vue b/src/bundle/coupon/my-coupon.vue index d400672..67b9fb3 100644 --- a/src/bundle/coupon/my-coupon.vue +++ b/src/bundle/coupon/my-coupon.vue @@ -52,9 +52,7 @@ import {ref} from 'vue' import Coupon from '@/components/coupon/Coupon.vue' import { getMyCoupons } from '@/api/user' -import List from '@/pages/address/list.vue' - // const tab = ref(0) const tag = ref>([ {label: '全部', value: 0 }, @@ -84,7 +82,7 @@ import List from '@/pages/address/list.vue' const MyCoupon = { handleInit: async () => { - const res: any = await getMyCoupons({status: currentTag.value}) + const res: any = await getMyCoupons({status: currentTag.value, type_id: 1}) if (Array.isArray(res)) { res.map((res) => { diff --git a/src/bundle/order/tea-specialist/order-list.vue b/src/bundle/order/tea-specialist/order-list.vue index 098e673..2909041 100644 --- a/src/bundle/order/tea-specialist/order-list.vue +++ b/src/bundle/order/tea-specialist/order-list.vue @@ -18,7 +18,7 @@ - + @@ -31,35 +31,35 @@ - + - + - + - + - + @@ -109,7 +109,7 @@ uni.$off('refreshOrderList') }) - const orderList = { + const OrderList = { // 上拉加载的回调: 其中num:当前页 从1开始, size:每页数据条数,默认10 upCallback: (mescroll) => { const filter = { diff --git a/src/hooks/usePay.ts b/src/hooks/usePay.ts new file mode 100644 index 0000000..32b746c --- /dev/null +++ b/src/hooks/usePay.ts @@ -0,0 +1,37 @@ +export function wxpay(opt) { + return new Promise((resolve, reject) => { + let params; + // #ifdef MP-WEIXIN + params = { + timeStamp: opt.timeStamp, + // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符 + nonceStr: opt.nonceStr, + // 支付签名随机串,不长于 32 位 + package: opt.package, + // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***) + signType: opt.signType, + // 签名方式,默认为'SHA1',使用新版支付需传入'MD5' + paySign: opt.paySign, + } + // #endif + // #ifdef APP-PLUS + params = { + orderInfo: opt + } + // #endif + console.log(params) + uni.requestPayment({ + provider: 'wxpay', + ...params, + success: res => { + resolve('success'); + }, + cancel: res => { + resolve('fail'); + }, + fail: res => { + resolve('fail'); + } + }); + }); +} diff --git a/src/hooks/useWeiXin.ts b/src/hooks/useWeiXin.ts index bf7a33d..17397b4 100644 --- a/src/hooks/useWeiXin.ts +++ b/src/hooks/useWeiXin.ts @@ -27,7 +27,7 @@ export const getUrlCode = (): { [key: string]: string | undefined } => { */ export async function snsapiBaseAuthorize() { // TODO 测试代码 - wxSnsapiBaseLogin({code: '081kkz0w3wXuX53Hf83w3l4oy30kkz0z'}).then((res: IUserInfoVo) => { + wxSnsapiBaseLogin({code: '011ganGa10NGEK0reKGa1l3rpS2ganGX'}).then((res: IUserInfoVo) => { console.log("登录成功 ~ snsapiBaseAuthorize ~ res:", res) // 映射 IUserLogin 到 IUserInfoVo useUserStore().setUserInfo(res) diff --git a/src/pages/index/detail.vue b/src/pages/index/detail.vue index f09b469..11cb222 100644 --- a/src/pages/index/detail.vue +++ b/src/pages/index/detail.vue @@ -356,14 +356,12 @@ userInfo.value = userStore.userInfo id.value = args.id || 0 - latitude.value = args.lat || 0 - longitude.value = args.lng || 0 // 获取茶艺师详情 const res = await getTeaSpecialistDetails({ id: args.id, - latitude: latitude.value, - longitude: longitude.value, + latitude: uni.getStorageSync('latitude'), + longitude: uni.getStorageSync('longitude'), user_id: userInfo.value.id || 0 }) // 将返回的数据合并到 reactive 对象中 diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index ddeb5aa..a8b285a 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -182,7 +182,9 @@ // 经纬度缓存过期处理(1小时) const LOCATION_EXPIRE_KEY = 'location_expire_time' - const LOCATION_EXPIRE_MS = 60 * 60 * 1000 // 1小时 + const LOCATION_EXPIRE_MS = 30 * 24 * 60 * 60 * 1000 // 1个月 + const LOCATION_DENY_KEY = 'location_deny_time' + const LOCATION_DENY_INTERVAL = 60 * 1000 // 1分钟 const defaultCity = ref(import.meta.env.VITE_DEFAULT_ADDRESS) // 默认城市 const list = ref>([]) // 茶艺师列表 const teaSpecialistName = ref('') // 茶艺师名称 @@ -190,30 +192,54 @@ const cityValue = ref('') onLoad(async () => { + // 获取茶艺师等级tab + getTeaSpecialistLevels().then((res:Array) => { + TeaSpecialistLevels.push(...res) + }) + // 检查缓存是否过期,超时则重新授权 await Index.handleEnsureLocationAuth() - // 获取城市列表 - getCity({latitude: latitude.value, longitude: longitude.value}).then((res: any) => { - cityColumns.value = res.area_list.map(item => { - return { - label: item.getArea[0].name, - value: item.getArea[0].lat + ',' + item.getArea[0].lng - } - }) - }) // getDecorate({id: 1}).then((res: any) => { // const data = JSON.parse(res.data) // console.log('装修数据:', data) // }) - - // 等待授权完成后再加载数据 - getTeaSpecialistLevels().then((res:Array) => { - TeaSpecialistLevels.push(...res) - }) }) const Index = { + // 上拉加载的回调: 其中num:当前页 从1开始, size:每页数据条数,默认10 + upCallback: (mescroll) => { + const filter = { + level_id: selectedLevel.value.join(',') || '0', + page: mescroll.num, + size: mescroll.size, + latitude: latitude.value, + longitude: longitude.value, + search: teaSpecialistName.value + } + + getTeaSpecialist(filter).then((res: IIndexListResult) => { + 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() // 请求失败, 结束加载 + }) + }, + + // 获取城市列表 + handleGetCityList: () => { + getCity({latitude: latitude.value, longitude: longitude.value}).then((res: any) => { + cityColumns.value = res.area_list.map(item => { + return { + label: item.getArea[0].name, + value: item.getArea[0].lat + ',' + item.getArea[0].lng + } + }) + }) + }, + // 设置经纬度缓存 handleSetLocationCache: (lat: number, lng: number) => { uni.setStorageSync('latitude', lat) @@ -235,14 +261,10 @@ // 初始化经纬度 handleEnsureLocationAuth: async () => { + // 检查缓存是否过期 if (!Index.handleCheckLocationCache()) { // 超时,重新获取授权 - await wxGetLocation((res) => { - latitude.value = res.latitude - longitude.value = res.longitude - Index.handleSetLocationCache(latitude.value, longitude.value) - Index.handleSearch() - }) + await Index.handleRequestLocationAuth() } else { const lat = uni.getStorageSync('latitude') const lng = uni.getStorageSync('longitude') @@ -250,16 +272,38 @@ latitude.value = lat longitude.value = lng } else { - await wxGetLocation((res) => { - latitude.value = res.latitude - longitude.value = res.longitude - Index.handleSetLocationCache(latitude.value, longitude.value) - Index.handleSearch() - }) + await Index.handleRequestLocationAuth() } } }, + // 定位授权弹窗逻辑 + handleRequestLocationAuth: async () => { + // 检查上次弹窗时间,1分钟内不再弹 + const lastDeny = uni.getStorageSync(LOCATION_DENY_KEY) + if (lastDeny && Date.now() - lastDeny < LOCATION_DENY_INTERVAL) { + return + } + try { + await wxGetLocation((res) => { + latitude.value = res.latitude + longitude.value = res.longitude + Index.handleSetLocationCache(latitude.value, longitude.value) + Index.handleSearch() + Index.handleGetCityList() + }) + } catch (e) { + // 用户拒绝授权,记录弹窗时间 + uni.setStorageSync(LOCATION_DENY_KEY, Date.now()) + // 可选:弹窗提示 + uni.showModal({ + title: '提示', + content: '需要获取您的地理位置以提供更好的服务,请在授权弹窗中允许定位。', + showCancel: false + }) + } + }, + // 选择城市 handleSelectCity: (e: any) => { cityValue.value = e.value @@ -277,28 +321,6 @@ getMescroll().resetUpScroll() }, - // 上拉加载的回调: 其中num:当前页 从1开始, size:每页数据条数,默认10 - upCallback: (mescroll) => { - const filter = { - level_id: selectedLevel.value.join(',') || '0', - page: mescroll.num, - size: mescroll.size, - latitude: latitude.value, - longitude: longitude.value, - search: teaSpecialistName.value - } - console.log('filter:', filter) - - getTeaSpecialist(filter).then((res: IIndexListResult) => { - 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() // 请求失败, 结束加载 - }) - }, - handleClick: (item: any) => { // 处理点击事件 console.log('Clicked item:', item) @@ -306,7 +328,7 @@ // 跳转到预约茶艺师页面 handleToReserveTeaSpecialist: (id: number = 1) => { - router.navigateTo(`/pages/index/detail?id=${id}&lat=${latitude.value}&lng=${longitude.value}`) + router.navigateTo(`/pages/index/detail?id=${id}`) }, // 选择茶艺师等级 diff --git a/src/utils/jwexin.ts b/src/utils/jwexin.ts index 78d66c7..60d69fe 100644 --- a/src/utils/jwexin.ts +++ b/src/utils/jwexin.ts @@ -57,15 +57,20 @@ export async function wxGetLocation(callback: (res: any) => void ) { wx.getLocation({ type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' success: function(res) { - // console.log(res); + uni.removeStorageSync('location_deny_time') callback(res) + console.log('授权成功:' + res) }, fail: function(res) { - console.log('经纬度:' + res) + console.log('授权失败:' + res) }, - // complete:function(res){ - // console.log(res) - // } + complete:function(res){ + console.log(res) + if (res.errMsg === 'getLocation:cancel') { + // 用户拒绝授权 + uni.setStorageSync('location_deny_time', Date.now()) + } + } }); }); }