添加收藏茶室接口和完善茶室详情

This commit is contained in:
wangxiaowei
2025-11-12 17:40:35 +08:00
parent 29bf4dae74
commit 0cad65c295
32 changed files with 1522 additions and 505 deletions

View File

@ -1,13 +1,12 @@
import { router } from '@/utils/tools'
const LOCATION_EXPIRE_MS = 30 * 24 * 60 * 60 * 1000 // 定位缓存30天
const LOCATION_DENY_INTERVAL = 60 * 60 * 1000 // 未授权定位弹窗间隔1小时
const LOCATION_EXPIRE_KEY = import.meta.env.VITE_DEFAULT_LOCATION_EXPIRE_KEY // 定位缓存KEY
const LOCATION_EXPIRE_MS = import.meta.env.VITE_DEFAULT_LOCATION_EXPIRE_MS // 30天
const LOCATION_DEFAULT_CITY = import.meta.env.VITE_DEFAULT_ADDRESS // 默认城市
const LOCATION_DEFAULT_LAT = import.meta.env.VITE_DEFAULT_LATITUDE // 上海经度
const LOCATION_DEFAULT_LNG = import.meta.env.VITE_DEFAULT_LONGITUDE // 上海纬度
const LOCATION_DENY_TIME_KEY = import.meta.env.VITE_DEFAULT_LOCATION_DENY_TIME_KEY
const LOCATION_DENY_INTERVAL = import.meta.env.VITE_DEFAULT_LOCATION_DENY_INTERVAL
export const LOCATION_EXPIRE_KEY = 'location_expire_time' // 定位缓存KEY
export const LOCATION_DEFAULT_CITY = '上海市' // 默认城市
export const LOCATION_DEFAULT_LAT = 34.757975 // 上海经度
export const LOCATION_DEFAULT_LNG = 113.665412 // 上海纬度
export const LOCATION_DENY_TIME_KEY = 'location_deny_time' // 未授权定位重新授权时间KEY
export const LOCATION_CITY_KEY = 'city' // 城市缓存KEY
// 检查过期时间
export function handleCheckLocationCacheHooks() {
@ -50,6 +49,7 @@ export async function handleEnsureLocationAuthHooks() {
},
fail() {
// 定位失败,返回默认上海
handleSetLocationCacheHooks(LOCATION_DEFAULT_LAT, LOCATION_DEFAULT_LNG)
resolve({ lat: LOCATION_DEFAULT_LAT, lng: LOCATION_DEFAULT_LNG })
}
})
@ -69,12 +69,88 @@ export async function handleEnsureLocationAuthHooks() {
})
}
// 返回默认上海
handleSetLocationCacheHooks(LOCATION_DEFAULT_LAT, LOCATION_DEFAULT_LNG)
resolve({ lat: LOCATION_DEFAULT_LAT, lng: LOCATION_DEFAULT_LNG })
}
})
})
}
/**
* 检查并弹窗授权地理位置(每小时弹一次,授权后自动获取定位)
* 返回 Promise<boolean>true 表示已授权false 表示未授权
*/
export function checkLocationAuthWithModal(): Promise<{ lat: number, lng: number } | false> {
return new Promise((resolve) => {
uni.getSetting({
success(settingRes) {
const hasAuth = settingRes.authSetting && settingRes.authSetting['scope.userLocation']
if (hasAuth) {
// 已授权,自动获取并返回经纬度
uni.getLocation({
type: 'gcj02',
success(res) {
handleSetLocationCacheHooks(res.latitude, res.longitude)
resolve({ lat: res.latitude, lng: res.longitude })
},
fail() {
resolve(false)
}
})
} else {
// 未授权,判断是否需要弹窗
const lastDeny = uni.getStorageSync(LOCATION_DENY_TIME_KEY)
if (!lastDeny || (Date.now() - lastDeny > LOCATION_DENY_INTERVAL)) {
uni.setStorageSync(LOCATION_DENY_TIME_KEY, Date.now())
uni.showModal({
title: '提示',
content: '需要获取您的地理位置,请授权定位服务',
showCancel: false,
success: () => {
uni.openSetting({
success(openRes) {
const nowAuth = openRes.authSetting && openRes.authSetting['scope.userLocation']
if (nowAuth) {
// 用户授权后,自动获取并返回经纬度
uni.getLocation({
type: 'gcj02',
success(res) {
handleSetLocationCacheHooks(res.latitude, res.longitude)
resolve({ lat: res.latitude, lng: res.longitude })
},
fail() {
resolve(false)
}
})
} else {
resolve(false)
}
}
})
}
})
} else {
resolve(false)
}
}
},
fail() {
resolve(false)
}
})
})
}
/**
* 设置城市
*/
export function setLocationCity(city: string) {
uni.setStorageSync(LOCATION_CITY_KEY, city)
}
// 检查是否需要弹授权框
function shouldShowAuthModal() {
const lastDeny = uni.getStorageSync(LOCATION_DENY_TIME_KEY)

View File

@ -0,0 +1,97 @@
import { router } from '@/utils/tools'
import { toast } from '@/utils/toast'
import { cancelTeaSpecialistOrder, deleteTeaSpecialistOrder, confirmTeaSpecialistOrder, refundTeaSpecialistOrder } from '@/api/teaSpecialist-order'
/**
* 取消订单
* @param orderId 订单ID
*/
export async function handleCancelOrderHooks(orderId: number) {
try {
const response = await cancelTeaSpecialistOrder({ id: orderId })
uni.$emit('refreshOrderList')
uni.$emit('refreshOrderDetail')
} catch (error) {
router.navigateBack()
throw error
}
}
/**
* 重新支付
* @param orderId 订单ID
* @param teaSpecialistId 茶艺师ID
* @returns
*/
export function handleToPayHooks(orderId: number, teaSpecialistId: number) {
try {
uni.$on('payment', params => {
console.log("🚀 ~ params:", params)
setTimeout(() => {
uni.$off("payment")
uni.$emit('refreshOrderList')
uni.$emit('refreshOrderDetail')
if (params.result) {
uni.redirectTo({
url: `/pages/notice/reserve?type=teaSpecialist&orderId=${params.orderId}`
})
} else {
uni.redirectTo({
url: '/bundle/order/tea-specialist/order-list'
})
}
}, 1000)
})
setTimeout(() => {
router.navigateTo(`/pages/cashier/cashier?from=order&orderId=${orderId}&teaSpecialistId=${teaSpecialistId}`)
}, 800)
} catch (error) {
toast.info('订单提交失败,请稍后重试')
return
}
}
/**
* 删除订单
*/
export async function handleDeleteOrderHooks(orderId: number) {
try {
const response = await deleteTeaSpecialistOrder({ id: orderId })
uni.$emit('refreshOrderList')
uni.$emit('refreshOrderDetail')
} catch (error) {
router.navigateBack()
throw error
}
}
/**
* 确认(完成)订单
*/
export async function handleConfirmOrderHooks(orderId: number) {
try {
const response = await confirmTeaSpecialistOrder({ id: orderId })
uni.$emit('refreshOrderList')
uni.$emit('refreshOrderDetail')
} catch (error) {
router.navigateBack()
throw error
}
}
/**
* 订单退款
* @param orderId 订单ID
* @param orderType 订单类型
*/
export async function handleRefundOrderHooks(orderId: number, orderType: string) {
try {
const response = await refundTeaSpecialistOrder({ id: orderId, order_type: orderType })
uni.$emit('refreshOrderList')
uni.$emit('refreshOrderDetail')
} catch (error) {
router.navigateBack()
throw error
}
}