评论需要添加功能,提交订单有问题

This commit is contained in:
bobobobo
2025-12-26 02:15:32 +08:00
parent 1aab94bbc3
commit bb02cb22c0
32 changed files with 2844 additions and 117 deletions

View File

@@ -4,12 +4,28 @@
* @returns
*/
export const formatRMB = amount => {
const formatted = new Intl.NumberFormat('zh-CN', {
style: 'currency',
currency: 'CNY',
minimumFractionDigits: 2,
maximumFractionDigits: 2
}).format(amount)
// 处理 null、undefined 或非数字输入
if (amount == null || amount === '') {
return '0.00'
}
return formatted.replace(/^[¥\s]+/, '') // 移除开头的 ¥ 和可能的空格
// 转为数字
let num = Number(amount)
if (isNaN(num)) {
return '0.00'
}
// 保留两位小数(四舍五入)
num = Math.round(num * 100) / 100
// 转为固定两位小数字符串
let str = num.toFixed(2)
// 分离整数和小数部分
const [integer, decimal] = str.split('.')
// 添加千分位分隔符(从右往左每三位加逗号)
const formattedInteger = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
return `${formattedInteger}.${decimal}`
}

View File

@@ -48,12 +48,26 @@ const showToast = (message, type = 'none', duration = 2000) => {
})
}
// 导出响应式状态和方法
/** 对话框带确认取消按钮 */
const showDialog = (title, content) => {
return new Promise(resolve => {
uni.showModal({
title,
content,
confirmText: '确定',
cancelText: '取消',
success: res => resolve(res.confirm)
})
})
}
/** 导出响应式状态和方法 */
export const useUI = () => {
return {
isLoading: isLoading, // 可用于模板中 v-if="isLoading"
showLoading,
hideLoading,
showToast
showToast,
showDialog
}
}

View File

@@ -1,7 +1,7 @@
// 正则
/** 手机号正则(中国大陆) */
const PHONE_REGEX = /^1[3-9]\d{9}$/
export const PHONE_REGEX = /^1[3-9]\d{9}$/
/** 邮箱正则 */
const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/