js 常用公共类封装

/**

* @用户信息缓存,公共js封装

* @Author maguangbo

* @Date 2019-07-18

* @Email [email protected]

* **/

export default (function() {

var com = {};

com.setCurrentUserInfo = function(userInfo) {

return uni.setStorageSync('userInfo', userInfo);

}

com.getCurrentuserInfo = function() {

return uni.getStorageSync('userInfo');

}

com.getToken = function(){

return uni.getStorageSync('tokens');

}

com.setToken = function(content){

return uni.setStorageSync('tokens',content);

}

var tokenInfos ={

"token": "",

"expiredTime": ""

}

com.getTokens = function(){

if(uni.getStorageSync('tokens')){

var tInfos = uni.getStorageSync('tokens');

tInfos.token && (tokenInfos.token = tInfos.token);

tInfos.expiredTime && (tokenInfos.expiredTime = tInfos.expiredTime);

}

return tokenInfos;

}

var userInfo = {

"id": '',

"userName": '',

"nickName": '',

"email": '',

"phone": '',

"identity": '',

"roleId": '',

"apiUserId": '',

"apiKey": '',

"createDate": ''

}

com.getUserInfos =function(){

if(uni.getStorageSync('userInfo')){

var infos = uni.getStorageSync('userInfo');

infos.id && (userInfo.id = infos.id);

infos.userName && (userInfo.userName = infos.userName);

infos.nickName && (userInfo.nickName = infos.nickName);

infos.email && (userInfo.email = infos.email);

infos.phone && (userInfo.phone = infos.phone);

infos.apiUserId && (userInfo.apiUserId = infos.apiUserId);

infos.apiKey && (userInfo.apiKey = infos.apiKey);

infos.createDate && (userInfo.createDate = infos.createDate);

return userInfo;

}

return false;

}

com.toast = (title, duration=1500, mask=false, icon='none')=>{

if(Boolean(title) === false){

return;

}

uni.showToast({

title,

duration,

mask,

icon

});

}

return com;

}())


这是一个常用的公共用户信息封装实体类,个人感觉很方便,如果有更好的的欢迎大佬指教!

你可能感兴趣的:(js 常用公共类封装)