|
|
@@ -358,6 +358,7 @@ tools.setLoginData = function (data) {
|
|
|
uni.setStorageSync('tokenType', data.token_type)
|
|
|
uni.setStorageSync('refreshToken', data.access_token)
|
|
|
uni.setStorageSync('mobile', data.username)
|
|
|
+ uni.setStorageSync('userId', data.user_id)
|
|
|
tools.success('登陆成功')
|
|
|
// setTimeout(() => {
|
|
|
// if (data.status * 1 === 0) {
|
|
|
@@ -390,6 +391,31 @@ tools.delCosToken=function (data){
|
|
|
}
|
|
|
|
|
|
|
|
|
+tools.getAge=function (birthYearMonthDay) {
|
|
|
+ birthYearMonthDay=birthYearMonthDay.replace('-','/')
|
|
|
+ //birthYearMonthDay必须为"1995/6/15"这种字符串格式,不可为"2020-6-15",这种格式在Safari中会报错
|
|
|
+ const birthDate = new Date(birthYearMonthDay);
|
|
|
+ const momentDate = new Date();
|
|
|
+ momentDate.setHours(0, 0, 0, 0); //因为new Date()出来的时间是当前的时分秒。我们需要把时分秒重置为0。使后面时间比较更精确
|
|
|
+ const thisYearBirthDate = new Date(
|
|
|
+ momentDate.getFullYear(),
|
|
|
+ birthDate.getMonth(),
|
|
|
+ birthDate.getDate()
|
|
|
+ );
|
|
|
+ const aDate = thisYearBirthDate - birthDate;
|
|
|
+ const bDate = momentDate - birthDate;
|
|
|
+ let tempAge = momentDate.getFullYear() - birthDate.getFullYear();
|
|
|
+ let age = null;
|
|
|
+ if (bDate < aDate) {
|
|
|
+ tempAge = tempAge - 1;
|
|
|
+ age = tempAge < 0 ? 0 : tempAge;
|
|
|
+ } else {
|
|
|
+ age = tempAge;
|
|
|
+ }
|
|
|
+ return age;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|