user.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. export default{
  2. //开启命名空间
  3. namespaced:true,
  4. //数据
  5. state:()=>({
  6. userName:"ST [渔夺]",
  7. avatarUrl:"../../static/avator/1.jpg",
  8. address:JSON.parse(uni.getStorageSync('address')||'{}'),
  9. token:uni.getStorageSync('token')||'',
  10. //用户的信息对象
  11. userinfo:JSON.parse(uni.getStorageSync('userinfo')||'{}'),
  12. //重定向Object对象
  13. redirectInfo:null,
  14. level:"Lv1 青铜",
  15. levelRate:0
  16. }),
  17. //方法
  18. mutations:{
  19. //更新收货地址
  20. updateAddress(state,address){
  21. state.address=address
  22. this.commit('m_user/saveAddressToStorage')
  23. },
  24. updateAvatarUrl(state,avatarUrl){
  25. state.avatarUrl=avatarUrl
  26. },
  27. updateUserName(state,userName){
  28. state.userName=userName
  29. },
  30. //持久化储存address
  31. saveAddressToStorage(state){
  32. uni.setStorageSync('address',JSON.stringify(state.address))
  33. },
  34. updateUserInfo(state,userinfo){
  35. state.userinfo=userinfo
  36. console.log('更新User数据');
  37. this.commit('m_user/saveUserInfoToStorage')
  38. },
  39. saveUserInfoToStorage(state){
  40. uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
  41. console.log('还没错哦');
  42. },
  43. updateToken(state,token){
  44. state.token=token
  45. this.commit('m_user/saveTokenToStorage')
  46. },
  47. saveTokenToStorage(state){
  48. uni.setStorageSync('token',state.token)
  49. },
  50. updateRedirectInfo(state,info){
  51. state.redirectInfo=info
  52. console.log(state.redirectInfo);
  53. },
  54. addLevelRate(state,num){//待完成
  55. if(判断升段)//
  56. {
  57. commit('m_user/addLevel')
  58. }
  59. },
  60. addLevel(state){//待完成
  61. }
  62. },
  63. getters:{
  64. //收货地址
  65. getUserName(state){
  66. return state.userName
  67. },
  68. addstr(state){
  69. if(!state.address.provinceName) return ''
  70. return state.address.provinceName+state.address.cityName+state.address.countyName+state.address.detailInfo
  71. },
  72. getAvatarUrl(state){
  73. return state.avatarUrl
  74. }
  75. }
  76. }