完善接口

This commit is contained in:
wangxiaowei
2025-11-18 16:41:52 +08:00
parent c96aaf65eb
commit 89fcea5bb9
9 changed files with 133 additions and 71 deletions

View File

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

View File

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

View File

@ -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<number>(0)
const tag = ref<Array<any>>([
{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) => {

View File

@ -18,7 +18,7 @@
</template>
</wd-navbar>
<view class="tabs">
<wd-tabs v-model="tab" swipeable slidable="always" :lazy="false" @click="orderList.handleChangeTabs">
<wd-tabs v-model="tab" swipeable slidable="always" :lazy="false" @click="OrderList.handleChangeTabs">
<wd-tab title="全部" :name="TeaSpecialistOrderStatusText.All"></wd-tab>
<wd-tab title="待付款" :name="TeaSpecialistOrderStatusText.Pending"></wd-tab>
<wd-tab title="预约单" :name="TeaSpecialistOrderStatusText.Pay"></wd-tab>
@ -31,35 +31,35 @@
<view class="tabs mt-18rpx mx-30rpx">
<!-- 这里可以尝试下不重新刷新获取列表 -->
<!-- 全部 -->
<mescroll-body ref="mescrollItem0" @init="mescrollInit" @down="downCallback" @up="orderList.upCallback" :down="downOption" :up="upOption" v-if="tab === 'all'">
<mescroll-body ref="mescrollItem0" @init="mescrollInit" @down="downCallback" @up="OrderList.upCallback" :down="downOption" :up="upOption" v-if="tab === 'all'">
<view class="mb-20rpx" v-for="(item, index) in list" :key="index">
<combo-card :type="OrderSource.TeaSpecialist" :order="item"></combo-card>
</view>
</mescroll-body>
<!-- 待付款 -->
<mescroll-body ref="mescrollItem1" @init="mescrollInit" @down="downCallback" @up="orderList.upCallback" :down="downOption" :up="upOption" v-if="tab === OrderStatus.Pending">
<mescroll-body ref="mescrollItem1" @init="mescrollInit" @down="downCallback" @up="OrderList.upCallback" :down="downOption" :up="upOption" v-if="tab === OrderStatus.Pending">
<view class="mb-20rpx" v-for="(item, index) in list" :key="index">
<combo-card :type="OrderSource.TeaSpecialist" :order="item"></combo-card>
</view>
</mescroll-body>
<!-- 预约单 -->
<mescroll-body ref="mescrollItem2" @init="mescrollInit" @down="downCallback" @up="orderList.upCallback" :down="downOption" :up="upOption" v-if="tab === OrderStatus.Reserved">
<mescroll-body ref="mescrollItem2" @init="mescrollInit" @down="downCallback" @up="OrderList.upCallback" :down="downOption" :up="upOption" v-if="tab === OrderStatus.Reserved">
<view class="mb-20rpx" v-for="(item, index) in list" :key="index">
<combo-card :type="OrderSource.TeaSpecialist" :order="item"></combo-card>
</view>
</mescroll-body>
<!-- 待确认 -->
<mescroll-body ref="mescrollItem2" @init="mescrollInit" @down="downCallback" @up="orderList.upCallback" :down="downOption" :up="upOption" v-if="tab === OrderStatus.Confirm">
<mescroll-body ref="mescrollItem2" @init="mescrollInit" @down="downCallback" @up="OrderList.upCallback" :down="downOption" :up="upOption" v-if="tab === OrderStatus.Confirm">
<view class="mb-20rpx" v-for="(item, index) in list" :key="index">
<combo-card :type="OrderSource.TeaSpecialist" :order="item"></combo-card>
</view>
</mescroll-body>
<!-- 已完结 -->
<mescroll-body ref="mescrollItem3" @init="mescrollInit" @down="downCallback" @up="orderList.upCallback" v-if="tab === OrderStatus.Finished">
<mescroll-body ref="mescrollItem3" @init="mescrollInit" @down="downCallback" @up="OrderList.upCallback" v-if="tab === OrderStatus.Finished">
<view class="mb-20rpx" v-for="(item, index) in list" :key="index">
<combo-card :type="OrderSource.TeaSpecialist" :order="item"></combo-card>
</view>
@ -109,7 +109,7 @@
uni.$off('refreshOrderList')
})
const orderList = {
const OrderList = {
// 上拉加载的回调: 其中num:当前页 从1开始, size:每页数据条数,默认10
upCallback: (mescroll) => {
const filter = {

37
src/hooks/usePay.ts Normal file
View File

@ -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');
}
});
});
}

View File

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

View File

@ -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 对象中

View File

@ -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<string>(import.meta.env.VITE_DEFAULT_ADDRESS) // 默认城市
const list = ref<Array<any>>([]) // 茶艺师列表
const teaSpecialistName = ref<string>('') // 茶艺师名称
@ -190,30 +192,54 @@
const cityValue = ref<string>('')
onLoad(async () => {
// 获取茶艺师等级tab
getTeaSpecialistLevels().then((res:Array<any>) => {
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<any>) => {
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}`)
},
// 选择茶艺师等级

View File

@ -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())
}
}
});
});
}