import Storage from '@/static/js/storage.js'
let cache_key_user="cache_key_user";

export default {
	/**
	 * 保存用户登录状态
	 */
	save(user){ 
		let cache_time = 30 * 24 * 3600;
		Storage.setEncrypt(cache_key_user,user,cache_time) 
	},
	/**
	 * 获取当前登录的用户
	 */
	get(){
		return Storage.getEncrypt(cache_key_user);
	},
	phone(){
		let user = this.get();
		return user && user.phone ? user.phone :'';
	},
	token(){
		let user = this.get();
		return user && user.authtoken ? user.authtoken :'';
	},
	/** 
	 * 退出当前登录
	 */
	loginOut(){
		this.save(null)
	},
	isLogin(){
		let user = this.get();
		return user && user.userId && user.authtoken;
	},
	setPhone(phone){ 
		let user = this.get(); 
		user.phone=phone; 
		this.save(user);
	},
	updateInfo(data){
		console.log(data)
		let user = this.get(); 
		user =Object.assign({},user,data);
		console.log(user)
		this.save(user);
	}
}