功能完善
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// 小程序更新检测
|
||||
|
||||
export function mpUpdate() {
|
||||
const updateManager = uni.getUpdateManager();
|
||||
updateManager.onCheckForUpdate((res) => {
|
||||
@@ -27,11 +28,25 @@ export function mpUpdate() {
|
||||
});
|
||||
}
|
||||
|
||||
export function showToast(title: string, icon: 'none' | 'success' | 'loading' | 'error' | 'fail' | 'exception' | undefined = 'none', duration: number = 2000) {
|
||||
interface ToastOption {
|
||||
icon?: 'none' | 'success' | 'loading' | 'error' | 'fail' | 'exception' | undefined,
|
||||
duration?: number,
|
||||
complete?: Function
|
||||
}
|
||||
|
||||
export function showToast(title: string, { icon, duration, complete }: ToastOption = {}) {
|
||||
const defaultDuration = 1500;
|
||||
uni.showToast({
|
||||
title,
|
||||
icon,
|
||||
duration
|
||||
title: title,
|
||||
icon: icon || 'none',
|
||||
duration: duration || defaultDuration,
|
||||
complete(result) {
|
||||
setTimeout(() => {
|
||||
if(complete != undefined) {
|
||||
complete();
|
||||
}
|
||||
}, duration || defaultDuration);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
58
src/utils/order/index.ts
Normal file
58
src/utils/order/index.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { OrderBean } from '@/api/order/types';
|
||||
import dayjs from 'dayjs';
|
||||
import { showToast } from '@/utils';
|
||||
|
||||
/**
|
||||
* 获取订单支付过期时间
|
||||
* @param order
|
||||
*/
|
||||
export function getOrderDeadline(order: OrderBean) {
|
||||
// return dayjs(order?.createTime).add(30, 'minute').toDate().getTime();
|
||||
return dayjs(order?.createTime).add(10, 'day').toDate().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单已过期
|
||||
* @param item
|
||||
*/
|
||||
export const isExpired = (item: OrderBean) => {
|
||||
return item?.payStatus == 1 && getOrderDeadline(item) < Date.now();
|
||||
};
|
||||
|
||||
/**
|
||||
* 订单待支付
|
||||
* @param item
|
||||
*/
|
||||
export const isPending = (item: OrderBean | undefined) => {
|
||||
return item?.payStatus == 1 && getOrderDeadline(item) > Date.now();
|
||||
};
|
||||
|
||||
export const handlePayResult = (orderId: string | undefined, e: any, { onSuccess, onFailure }: any) => {
|
||||
const payDetail = e.detail;
|
||||
let url = payDetail.url;
|
||||
const str = url.split('?')[1];
|
||||
const resultObj = JSON.parse(str.replaceAll('result=', ''));
|
||||
|
||||
if(resultObj?.is_success === true) {
|
||||
if(onSuccess) {
|
||||
onSuccess();
|
||||
} else {
|
||||
showToast('支付成功', {
|
||||
icon: 'success',
|
||||
complete: () => {
|
||||
uni.navigateBack();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if(onFailure) {
|
||||
onFailure();
|
||||
}
|
||||
const msg = resultObj?.error_message || '支付失败';
|
||||
showToast(msg, {
|
||||
complete: () => {
|
||||
uni.navigateBack();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user