user.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. let state = {
  2. userInfo: {}, //用户信息
  3. address:'...',
  4. orderInfo: {
  5. complete_count: 0, //完成
  6. received_count: 0, //待收货
  7. unshipped_count: 0, //待发货
  8. order_count: 0, //订单总数
  9. unpaid_count: 0 //待付款
  10. }, //订单信息
  11. hasLogin: false, //是否登录
  12. lang: 'zh-cn'
  13. }
  14. let mutations = {
  15. // 登录
  16. login(state) {
  17. state.hasLogin = true;
  18. },
  19. // 退出登录
  20. logout(state, provider) {
  21. state.hasLogin = false;
  22. // 清空基础信息
  23. state.userInfo = {};
  24. state.orderInfo = {
  25. complete_count: 0, //完成
  26. received_count: 0, //待收货
  27. unshipped_count: 0, //待发货
  28. order_count: 0, //订单总数
  29. unpaid_count: 0 //待付款
  30. };
  31. // 清除缓存用户信息
  32. uni.removeStorage({
  33. key: 'userInfo'
  34. })
  35. // 清除缓存token
  36. uni.removeStorage({
  37. key: 'token'
  38. })
  39. },
  40. // 保存用户信息
  41. setUserInfo(state, provider) {
  42. state.userInfo = provider;
  43. uni.setStorage({ //缓存用户登陆状态
  44. key: 'userInfo',
  45. data: provider
  46. })
  47. },
  48. // 保存订单信息
  49. setOrderInfo(state, provider) {
  50. state.orderInfo = provider;
  51. },
  52. setAddress(state, provider) {
  53. state.address = provider;
  54. uni.setStorage({ //缓存地址
  55. key: 'address',
  56. data: provider
  57. })
  58. console.log(state.address,provider,'vuex')
  59. },
  60. setLang(state,provider) {
  61. state.lang = provider;
  62. }
  63. }
  64. let getters = {}
  65. export default {
  66. namespaced: true,
  67. state,
  68. mutations,
  69. getters
  70. }