从 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>
48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
import timeFormat from '../../libs/function/timeFormat.js';
|
|
|
|
/**
|
|
* 时间戳转为多久之前
|
|
* @param String timestamp 时间戳
|
|
* @param String | Boolean format 如果为时间格式字符串,超出一定时间范围,返回固定的时间格式;
|
|
* 如果为布尔值false,无论什么时间,都返回多久以前的格式
|
|
*/
|
|
function timeFrom(dateTime = null, format = 'yyyy-mm-dd') {
|
|
// 如果为null,则格式化当前时间
|
|
if (!dateTime) dateTime = Number(new Date());
|
|
// 如果dateTime长度为10或者13,则为秒和毫秒的时间戳,如果超过13位,则为其他的时间格式
|
|
if (dateTime.toString().length == 10) dateTime *= 1000;
|
|
let timestamp = + new Date(Number(dateTime));
|
|
|
|
let timer = (Number(new Date()) - timestamp) / 1000;
|
|
// 如果小于5分钟,则返回"刚刚",其他以此类推
|
|
let tips = '';
|
|
switch (true) {
|
|
case timer < 300:
|
|
tips = '刚刚';
|
|
break;
|
|
case timer >= 300 && timer < 3600:
|
|
tips = parseInt(timer / 60) + '分钟前';
|
|
break;
|
|
case timer >= 3600 && timer < 86400:
|
|
tips = parseInt(timer / 3600) + '小时前';
|
|
break;
|
|
case timer >= 86400 && timer < 2592000:
|
|
tips = parseInt(timer / 86400) + '天前';
|
|
break;
|
|
default:
|
|
// 如果format为false,则无论什么时间戳,都显示xx之前
|
|
if(format === false) {
|
|
if(timer >= 2592000 && timer < 365 * 86400) {
|
|
tips = parseInt(timer / (86400 * 30)) + '个月前';
|
|
} else {
|
|
tips = parseInt(timer / (86400 * 365)) + '年前';
|
|
}
|
|
} else {
|
|
tips = timeFormat(timestamp, format);
|
|
}
|
|
}
|
|
return tips;
|
|
}
|
|
|
|
export default timeFrom;
|