|
|
|
|
|
/*
|
|
|
|
|
|
* 公共方法
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
import { ROOTPATH } from "@/common/config.js"
|
|
|
|
|
|
const base = {
|
|
|
|
|
|
toast : (msg, time, callback) => {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
icon: "none",
|
|
|
|
|
|
title: msg,
|
|
|
|
|
|
duration: time || 2000,
|
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
if (callback && typeof(callback) == 'function') {
|
|
|
|
|
|
console.log(callback)
|
|
|
|
|
|
callback()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
// 验证是否为空
|
|
|
|
|
|
isNull : (p) => {
|
|
|
|
|
|
return p == '' || p == undefined || p == null || p == 'undefined' || p == 'null';
|
|
|
|
|
|
},
|
|
|
|
|
|
getAgeFromId(idNumber) {
|
|
|
|
|
|
if (!idNumber || idNumber.length !== 18) {
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const today = new Date();
|
|
|
|
|
|
const birthDate = new Date(idNumber.substring(6, 10), idNumber.substring(10, 12) - 1, idNumber.substring(12, 14));
|
|
|
|
|
|
|
|
|
|
|
|
let age = today.getFullYear() - birthDate.getFullYear();
|
|
|
|
|
|
const m = today.getMonth() - birthDate.getMonth();
|
|
|
|
|
|
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
|
|
|
|
|
|
age--;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return age + '岁';
|
|
|
|
|
|
},
|
|
|
|
|
|
// 格式化中国日期,兼容iOS
|
|
|
|
|
|
formatChinaDate : (dateStr) => {
|
|
|
|
|
|
if (!dateStr) return '';
|
|
|
|
|
|
|
|
|
|
|
|
// 处理iOS不支持的日期格式
|
|
|
|
|
|
let processedDateStr = dateStr;
|
|
|
|
|
|
if (typeof dateStr === 'string') {
|
|
|
|
|
|
// 将 "2025-06-25 01:31:10" 格式转换为 "2025-06-25T01:31:10"
|
|
|
|
|
|
if (dateStr.includes('-') && dateStr.includes(' ') && dateStr.includes(':')) {
|
|
|
|
|
|
processedDateStr = dateStr.replace(' ', 'T');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const date = new Date(processedDateStr);
|
|
|
|
|
|
|
|
|
|
|
|
// 检查日期是否有效
|
|
|
|
|
|
if (isNaN(date.getTime())) {
|
|
|
|
|
|
console.warn('Invalid date format:', dateStr);
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const y = date.getFullYear();
|
|
|
|
|
|
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
|
|
|
|
const d = String(date.getDate()).padStart(2, '0');
|
|
|
|
|
|
return `${y}-${m}-${d}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
|
base
|
|
|
|
|
|
}
|