// 该文件用来存储localStorage 本地缓存的方法
|
/**
|
* 操作登录信息
|
*/
|
|
export function setLoginData(value) {
|
try {
|
let newValue = JSON.stringify(value);
|
uni.setStorageSync('loginData', newValue);
|
console.log('存储登录信息成功');
|
} catch (e) {
|
return;
|
}
|
}
|
export function getLoginData() {
|
let loginData = uni.getStorageSync('loginData');
|
return JSON.parse(loginData);
|
}
|
export function removeLoginData(){
|
uni.removeStorageSync('loginData');
|
}
|
/**
|
* 操作用户code
|
*/
|
export function setCode(value) {
|
uni.setStorageSync('code', value);
|
console.log('存储用户code成功');
|
}
|
export function getCode() {
|
let code = uni.getStorageSync('code');
|
return code;
|
}
|
/**
|
* 操作用户openId
|
*/
|
export function setOpenId(value) {
|
uni.setStorageSync('openId', value);
|
console.log('存储用户openId成功');
|
}
|
export function getOpenId() {
|
let openId = uni.getStorageSync('openId');
|
return openId;
|
}
|
export function removeOpenId() {
|
uni.removeStorageSync('openId');
|
}
|
|
/**
|
* 操作用户token
|
*/
|
export function setToken(value) {
|
uni.setStorageSync('token', value);
|
console.log('存储用户信息成功');
|
}
|
export function getToken() {
|
let token = uni.getStorageSync('token');
|
return token;
|
}
|
export function removeToken() {
|
uni.removeStorageSync('token');
|
}
|
/**
|
* 操作用户信息
|
*/
|
|
export function setUserInfo(value) {
|
try {
|
let newValue = JSON.stringify(value);
|
uni.setStorageSync('userinfo', newValue);
|
console.log('存储用户信息成功');
|
} catch (e) {
|
return;
|
}
|
}
|
export function getUserInfo() {
|
let userinfo = uni.getStorageSync('userinfo');
|
//console.log('userinfo', userinfo)
|
if (userinfo) {
|
return JSON.parse(userinfo);
|
}
|
}
|
export function removeUserInfo(){
|
uni.removeStorageSync('userinfo');
|
}
|
|
// 存储用户地址
|
export function setAddress(value) {
|
try {
|
let newValue = JSON.stringify(value);
|
uni.setStorageSync('address', newValue);
|
console.log('存储地址信息成功', newValue);
|
} catch (e) {
|
return;
|
}
|
}
|
export function getAddress() {
|
let address = uni.getStorageSync('address');
|
|
if (address) {
|
return JSON.parse(address);
|
}
|
}
|
export function removeAddress() {
|
uni.removeStorageSync('address');
|
}
|
export function setlocation(value){ //存储位置信息
|
try {
|
let newValue = JSON.stringify(value);
|
uni.setStorageSync('location', newValue);
|
console.log('存储地址信息成功', newValue);
|
} catch (e) {
|
return;
|
}
|
}
|
export function getlocation() { //获取位置信息
|
let location = uni.getStorageSync('location');
|
if (location) {
|
return JSON.parse(location);
|
}
|
}
|