feat: 订单模块基本完成

This commit is contained in:
2025-09-16 14:34:11 +08:00
parent 4a00c7f1d8
commit a045b39580
13 changed files with 799 additions and 288 deletions

View File

@@ -5,3 +5,5 @@ export * from "./processImage";
export * from "./timeUtils";
export * from "./tokenManager";
export * from "./order.pay";
export * from './orderActions';
export * from './routeUtil';

68
src/utils/orderActions.ts Normal file
View File

@@ -0,0 +1,68 @@
import { OrderStatus, CancelType } from "@/services/orderService";
export function getOrderStatus(orderData) {
const { order_status, cancel_type } = orderData
const unPay = order_status === OrderStatus.PENDING && cancel_type === CancelType.NONE;
const expired =
order_status === OrderStatus.FINISHED ||
[CancelType.TIMEOUT, CancelType.USER].includes(cancel_type);
return unPay ? 'unpay' : expired ? 'expired' : 'progress'
}
// scene: list、detail
export function generateOrderActions(orderData, actions, scene) {
const { handleDeleteOrder, handleCancelOrder, handleQuit, handlePayNow, handleViewGame } = actions
const deleteOrder = {
text: '删除订单',
className: 'cancelOrder',
action: handleDeleteOrder.bind(null, orderData),
}
const cancelOrder = {
text: '取消订单',
className: 'cancelOrder',
action: handleCancelOrder.bind(null, orderData),
}
const quitGame = {
text: '退出活动',
className: 'cancelOrder',
action: handleQuit.bind(null, orderData),
}
const payNow = {
text: '立即支付',
className: 'payNow',
action: handlePayNow.bind(null, orderData),
}
const gameDetail = {
text: '球局详情',
className: 'gameDetail',
action: handleViewGame.bind(null, orderData.game_info.id),
}
const key = getOrderStatus(orderData)
if (scene === 'list') {
const actionMap = new Map([
['expired', [deleteOrder, gameDetail]],
['progress', [quitGame, gameDetail]],
['unpay', [cancelOrder, payNow]]
])
return actionMap.get(key)
}
if (scene === 'detail') {
const actionMap = new Map([
['expired', [gameDetail, deleteOrder]],
['progress', [gameDetail, quitGame]],
['unpay', [cancelOrder]]
])
return actionMap.get(key)
}
}

23
src/utils/routeUtil.ts Normal file
View File

@@ -0,0 +1,23 @@
import Taro from "@tarojs/taro";
export function getCurrentFullPath(): string {
const pages = Taro.getCurrentPages();
const currentPage = pages.at(-1);
if (currentPage) {
console.log(currentPage, "currentPage get");
const route = currentPage.route;
const options = currentPage.options || {};
const query = Object.keys(options)
.map((key) => `${key}=${options[key]}`)
.join("&");
return query ? `/${route}?${query}` : `/${route}`;
}
return "";
}
export function reloadPage() {
Taro.reLaunch({ url: getCurrentFullPath() })
}