mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 01:04:25 +08:00
code refactor
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import utils from './utils.js'
|
||||
|
||||
const tokenLocalStorageKey = 'lab_user_token';
|
||||
const userInfoLocalStorageKey = 'lab_user_info';
|
||||
|
||||
@@ -15,19 +17,19 @@ function isUserLogined() {
|
||||
}
|
||||
|
||||
function updateToken(token) {
|
||||
if (typeof(token) === 'string') {
|
||||
if (utils.isString(token)) {
|
||||
localStorage.setItem(tokenLocalStorageKey, token);
|
||||
}
|
||||
}
|
||||
|
||||
function updateUserInfo(user) {
|
||||
if (typeof(user) === 'object') {
|
||||
if (utils.isObject(user)) {
|
||||
localStorage.setItem(userInfoLocalStorageKey, JSON.stringify(user));
|
||||
}
|
||||
}
|
||||
|
||||
function updateTokenAndUserInfo(item) {
|
||||
if (typeof(item) === 'object') {
|
||||
if (utils.isObject(item)) {
|
||||
if (item.token) {
|
||||
updateToken(item.token);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
function isFunction(val) {
|
||||
return typeof(val) === 'function';
|
||||
}
|
||||
|
||||
function isObject(val) {
|
||||
return val != null && typeof(val) === 'object';
|
||||
}
|
||||
|
||||
function isArray(val) {
|
||||
if (isFunction(Array.isArray)) {
|
||||
return Array.isArray(val);
|
||||
}
|
||||
|
||||
return Object.prototype.toString.call(val) === '[object Array]';
|
||||
}
|
||||
|
||||
function isString(val) {
|
||||
return typeof(val) === 'string';
|
||||
}
|
||||
|
||||
function isNumber(val) {
|
||||
return typeof(val) === 'number';
|
||||
}
|
||||
|
||||
function isBoolean(val) {
|
||||
return typeof(val) === 'boolean';
|
||||
}
|
||||
|
||||
export default {
|
||||
isFunction,
|
||||
isObject,
|
||||
isArray,
|
||||
isString,
|
||||
isNumber,
|
||||
isBoolean,
|
||||
};
|
||||
Reference in New Issue
Block a user