进一步整合js工具
This commit is contained in:
@@ -306,6 +306,51 @@ const $calcAge = (code) => {
|
|||||||
}
|
}
|
||||||
return Math.ceil($dayjs.duration($dayjs().unix() - $dayjs(birthday).unix(), 's').asYears())
|
return Math.ceil($dayjs.duration($dayjs().unix() - $dayjs(birthday).unix(), 's').asYears())
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 获取code
|
||||||
|
* @returns {Promise<unknown>}
|
||||||
|
*/
|
||||||
|
const $getLoginCode = () => {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
uni.login({
|
||||||
|
success: function (res) {
|
||||||
|
if (res.code) {
|
||||||
|
resolve(res);
|
||||||
|
} else {
|
||||||
|
reject(res);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: function () {
|
||||||
|
reject(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const $autoLogin = (params, store) => {
|
||||||
|
params = params ? params : {};
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
$getLoginCode().then((res) => {
|
||||||
|
let body = {...params, code: res.code};
|
||||||
|
store.commit('getToken', {
|
||||||
|
...body,
|
||||||
|
then: (v1) => {
|
||||||
|
if (v1) {
|
||||||
|
store.commit('getUserInfo', (v2) => {
|
||||||
|
if (v2) {
|
||||||
|
resolve(v2);
|
||||||
|
} else {
|
||||||
|
reject(v2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
reject(v1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
export default {
|
export default {
|
||||||
$toast,
|
$toast,
|
||||||
$loading,
|
$loading,
|
||||||
@@ -318,5 +363,7 @@ export default {
|
|||||||
$idCardNoUtil: idCardNoUtil,
|
$idCardNoUtil: idCardNoUtil,
|
||||||
$calcAge,
|
$calcAge,
|
||||||
$dayjs,
|
$dayjs,
|
||||||
$dict
|
$dict,
|
||||||
|
$getLoginCode,
|
||||||
|
$autoLogin
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user