You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.0 KiB
46 lines
1.0 KiB
/*
|
|
* 公共方法
|
|
*
|
|
*/
|
|
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 + '岁';
|
|
}
|
|
|
|
}
|
|
|
|
export {
|
|
base
|
|
} |