从 xghmall(云闪付版湘工游)迁移民票模块,改造为微信公众号 H5: - 技术栈沿用 uni-app + Vue2 + uView(含定制版日历组件) - 登录/支付独立成层(common/auth.js、common/pay.js): 一期假登录(测试手机号)+ 模拟支付,后端微信接口就绪后只换这两处 - 登录页重写:短信验证码 + 公众号网页授权(code 换用户信息)预留 - 门票列表页为入口页(进页必须登录),加订单悬浮按钮 - 支付成功页接通:查看订单/继续逛逛 + 订单状态轮询 - 详情页定位导航改用 uni.openLocation + 高德网页兜底 - 出行人页:身份证 18 位格式校验,删除死的删除按钮,修正证件类型回显笔误 - 清理云闪付 SDK、支付宝授权、死页面引用等残留 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
// padStart 的 polyfill,因为某些机型或情况,还无法支持es7的padStart,比如电脑版的微信小程序
|
|
// 所以这里做一个兼容polyfill的兼容处理
|
|
if (!String.prototype.padStart) {
|
|
// 为了方便表示这里 fillString 用了ES6 的默认参数,不影响理解
|
|
String.prototype.padStart = function(maxLength, fillString = ' ') {
|
|
if (Object.prototype.toString.call(fillString) !== "[object String]") throw new TypeError(
|
|
'fillString must be String')
|
|
let str = this
|
|
// 返回 String(str) 这里是为了使返回的值是字符串字面量,在控制台中更符合直觉
|
|
if (str.length >= maxLength) return String(str)
|
|
|
|
let fillLength = maxLength - str.length,
|
|
times = Math.ceil(fillLength / fillString.length)
|
|
while (times >>= 1) {
|
|
fillString += fillString
|
|
if (times === 1) {
|
|
fillString += fillString
|
|
}
|
|
}
|
|
return fillString.slice(0, fillLength) + str;
|
|
}
|
|
}
|
|
|
|
// 其他更多是格式化有如下:
|
|
// yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合
|
|
function timeFormat(dateTime = null, fmt = 'yyyy-mm-dd') {
|
|
// 如果为null,则格式化当前时间
|
|
if (!dateTime) dateTime = Number(new Date());
|
|
// 如果dateTime长度为10或者13,则为秒和毫秒的时间戳,如果超过13位,则为其他的时间格式
|
|
if (dateTime.toString().length == 10) dateTime *= 1000;
|
|
let date = new Date(dateTime);
|
|
let ret;
|
|
let opt = {
|
|
"y+": date.getFullYear().toString(), // 年
|
|
"m+": (date.getMonth() + 1).toString(), // 月
|
|
"d+": date.getDate().toString(), // 日
|
|
"h+": date.getHours().toString(), // 时
|
|
"M+": date.getMinutes().toString(), // 分
|
|
"s+": date.getSeconds().toString() // 秒
|
|
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
|
};
|
|
for (let k in opt) {
|
|
ret = new RegExp("(" + k + ")").exec(fmt);
|
|
if (ret) {
|
|
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
|
|
};
|
|
};
|
|
return fmt;
|
|
}
|
|
|
|
export default timeFormat
|