committed by
trae-solo-agent
co-authored by
Kimi-K3.1-Pro
parent
d731fc1da3
commit
a45a3d7a86
@@ -0,0 +1,63 @@
|
||||
// 小程序各端对 new Date('YYYY-MM-DD') 的解析并不一致,纯日期统一按本地年月日构造。
|
||||
function parseDate(value) {
|
||||
if (value instanceof Date) {
|
||||
return Number.isNaN(value.getTime()) ? null : value
|
||||
}
|
||||
if (!value) return null
|
||||
|
||||
const text = String(value)
|
||||
const dateOnly = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text)
|
||||
if (dateOnly) {
|
||||
const year = Number(dateOnly[1])
|
||||
const month = Number(dateOnly[2])
|
||||
const day = Number(dateOnly[3])
|
||||
const date = new Date(year, month - 1, day)
|
||||
if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
|
||||
return null
|
||||
}
|
||||
return date
|
||||
}
|
||||
|
||||
const date = new Date(text)
|
||||
return Number.isNaN(date.getTime()) ? null : date
|
||||
}
|
||||
|
||||
function pad(value) {
|
||||
return String(value).padStart(2, '0')
|
||||
}
|
||||
|
||||
function formatDate(value, fallback = '') {
|
||||
const date = parseDate(value)
|
||||
if (!date) return fallback
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
|
||||
}
|
||||
|
||||
function formatDateTime(value, fallback = '') {
|
||||
const date = parseDate(value)
|
||||
if (!date) return fallback
|
||||
return `${formatDate(date)} ${pad(date.getHours())}:${pad(date.getMinutes())}`
|
||||
}
|
||||
|
||||
function calcAge(value) {
|
||||
const birth = parseDate(value)
|
||||
if (!birth) return 0
|
||||
|
||||
const today = new Date()
|
||||
let age = today.getFullYear() - birth.getFullYear()
|
||||
const monthDelta = today.getMonth() - birth.getMonth()
|
||||
if (monthDelta < 0 || (monthDelta === 0 && today.getDate() < birth.getDate())) age--
|
||||
return age > 0 && age <= 120 ? age : 0
|
||||
}
|
||||
|
||||
function toISOString(value) {
|
||||
const date = parseDate(value)
|
||||
return date ? date.toISOString() : null
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
parseDate,
|
||||
formatDate,
|
||||
formatDateTime,
|
||||
calcAge,
|
||||
toISOString
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 使用微信原生返回拦截,导航栏返回和手势返回都不会静默丢失未保存内容。
|
||||
function setUnsavedGuard(enabled) {
|
||||
if (enabled && wx.canIUse('enableAlertBeforeUnload')) {
|
||||
wx.enableAlertBeforeUnload({
|
||||
message: '当前修改尚未保存,确定要离开吗?'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!enabled && wx.canIUse('disableAlertBeforeUnload')) {
|
||||
wx.disableAlertBeforeUnload()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setUnsavedGuard
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// 订单与支付状态的唯一前端映射,列表和详情只按展示需要读取不同扩展字段。
|
||||
const STATUS_MAP = {
|
||||
pending: { text: '待确认', color: '#0F766E', bg: '#ECF7F4', border: '#C7E5DF', desc: '订单已提交,等待陪诊师确认;确认前可取消' },
|
||||
confirmed: { text: '已确认', color: '#0F766E', bg: '#ECF7F4', border: '#C7E5DF', desc: '订单已确认,陪诊师将准时为您服务' },
|
||||
in_progress: { text: '进行中', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2', desc: '陪诊服务正在进行中' },
|
||||
completed: { text: '已完成', color: '#1F7A4D', bg: '#EAF6EE', border: '#CDE9D7', desc: '陪诊服务已完成,感谢您的使用' },
|
||||
cancelled: { text: '已取消', color: '#B4231A', bg: '#FCF0EE', border: '#F2D6D1', desc: '该订单已取消' }
|
||||
}
|
||||
|
||||
const PAYMENT_STATUS_MAP = {
|
||||
unpaid: { text: '未支付', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2', hint: '请联系客服完成支付' },
|
||||
partial: { text: '部分支付', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2', hint: '请联系客服补齐剩余费用' },
|
||||
paid: { text: '已支付', color: '#1F7A4D', bg: '#EAF6EE', border: '#CDE9D7' },
|
||||
refunding: { text: '退款中', color: '#B8520A', bg: '#FFF4E8', border: '#FFE0C2', hint: '退款处理中,如需了解进度请联系客服' },
|
||||
refunded: { text: '已退款', color: '#6F655C', bg: 'transparent', border: '#E5DACC' }
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
STATUS_MAP,
|
||||
PAYMENT_STATUS_MAP
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
function maskIdNumber(value) {
|
||||
const text = String(value || '').trim()
|
||||
if (!text) return ''
|
||||
if (text.length <= 8) return '********'
|
||||
return `${text.slice(0, 4)}********${text.slice(-4)}`
|
||||
}
|
||||
|
||||
function maskOrderId(value) {
|
||||
const text = String(value || '').trim()
|
||||
return text ? `****${text.slice(-8).toUpperCase()}` : '--'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
maskIdNumber,
|
||||
maskOrderId
|
||||
}
|
||||
Reference in New Issue
Block a user