feat(payment): 集成PingPong支付SDK并实现支付功能
- 添加PingPong支付SDK动态加载逻辑 - 实现支付组件与SDK的初始化配置 - 配置支付容器自适应不同屏幕尺寸 - 添加支付token校验和错误提示 - 集成Element Plus消息组件显示支付状态 - 配置SDK基础样式和按钮样式参数 - 添加支付页面路由和基本布局结构 - 实现支付结果页面跳转逻辑 - 添加订单状态管理和响应码常量定义 - 集成工具函数支持金额格式化和日期处理 - 配置开发环境变量支持沙箱模式切换 - 添加防抖节流等常用工具函数实现 - 实现订单号生成和状态文本映射逻辑 - 添加表单验证函数支持邮箱和手机校验
This commit is contained in:
123
src/utils/helpers.js
Normal file
123
src/utils/helpers.js
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* 工具函数
|
||||
*/
|
||||
|
||||
/**
|
||||
* 格式化金额
|
||||
*/
|
||||
export function formatAmount(amount, currency = 'USD') {
|
||||
if (!amount) return '0.00'
|
||||
return parseFloat(amount).toFixed(2)
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期时间
|
||||
*/
|
||||
export function formatDateTime(dateTime, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||
if (!dateTime) return ''
|
||||
|
||||
const date = new Date(dateTime)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0')
|
||||
|
||||
return format
|
||||
.replace('YYYY', year)
|
||||
.replace('MM', month)
|
||||
.replace('DD', day)
|
||||
.replace('HH', hours)
|
||||
.replace('mm', minutes)
|
||||
.replace('ss', seconds)
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单号
|
||||
*/
|
||||
export function generateOrderId() {
|
||||
const timestamp = Date.now()
|
||||
const random = Math.floor(Math.random() * 10000)
|
||||
return `MTN${timestamp}${random.toString().padStart(4, '0')}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单状态标签类型
|
||||
*/
|
||||
export function getStatusTagType(status) {
|
||||
if (!status) return 'info'
|
||||
const statusUpper = status.toUpperCase()
|
||||
if (statusUpper === 'SUCCESS' || statusUpper === 'SUCCESSFUL') {
|
||||
return 'success'
|
||||
} else if (statusUpper === 'FAILED' || statusUpper === 'FAILURE') {
|
||||
return 'danger'
|
||||
} else if (statusUpper === 'REVIEW') {
|
||||
return 'warning'
|
||||
}
|
||||
return 'info'
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单状态文本
|
||||
*/
|
||||
export function getStatusText(status) {
|
||||
if (!status) return '未知'
|
||||
const statusMap = {
|
||||
'PENDING': '待支付',
|
||||
'SUCCESS': '支付成功',
|
||||
'SUCCESSFUL': '支付成功',
|
||||
'FAILED': '支付失败',
|
||||
'FAILURE': '支付失败',
|
||||
'REVIEW': '审核中',
|
||||
'CANCELLED': '已取消',
|
||||
'CANCEL': '已取消'
|
||||
}
|
||||
return statusMap[status.toUpperCase()] || status
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证邮箱
|
||||
*/
|
||||
export function validateEmail(email) {
|
||||
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||
return re.test(email)
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证手机号(简单验证)
|
||||
*/
|
||||
export function validatePhone(phone) {
|
||||
const re = /^1[3-9]\d{9}$/
|
||||
return re.test(phone)
|
||||
}
|
||||
|
||||
/**
|
||||
* 防抖函数
|
||||
*/
|
||||
export function debounce(func, wait) {
|
||||
let timeout
|
||||
return function executedFunction(...args) {
|
||||
const later = () => {
|
||||
clearTimeout(timeout)
|
||||
func(...args)
|
||||
}
|
||||
clearTimeout(timeout)
|
||||
timeout = setTimeout(later, wait)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 节流函数
|
||||
*/
|
||||
export function throttle(func, limit) {
|
||||
let inThrottle
|
||||
return function(...args) {
|
||||
if (!inThrottle) {
|
||||
func.apply(this, args)
|
||||
inThrottle = true
|
||||
setTimeout(() => inThrottle = false, limit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user