user.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. let state = {
  2. userInfo: {}, //用户信息
  3. orderInfo: {
  4. complete_count: 0, //完成
  5. received_count: 0, //待收货
  6. unshipped_count: 0, //待发货
  7. order_count: 0, //订单总数
  8. unpaid_count: 0 //待付款
  9. }, //订单信息
  10. hasLogin: false, //是否登录
  11. }
  12. let mutations = {
  13. // 登录
  14. login(state) {
  15. state.hasLogin = true;
  16. },
  17. // 退出登录
  18. logout(state, provider) {
  19. state.hasLogin = false;
  20. // 清空基础信息
  21. state.userInfo = {};
  22. state.orderInfo = {
  23. complete_count: 0, //完成
  24. received_count: 0, //待收货
  25. unshipped_count: 0, //待发货
  26. order_count: 0, //订单总数
  27. unpaid_count: 0 //待付款
  28. };
  29. uni.removeStorage({
  30. key: 'userInfo'
  31. })
  32. },
  33. // 保存用户信息
  34. setUserInfo(state, provider) {
  35. state.userInfo = provider;
  36. uni.setStorage({ //缓存用户登陆状态
  37. key: 'userInfo',
  38. data: provider
  39. })
  40. },
  41. // 保存订单信息
  42. setOrderInfo(state, provider) {
  43. state.orderInfo = provider;
  44. }
  45. }
  46. let getters = {}
  47. export default {
  48. namespaced: true,
  49. state,
  50. mutations,
  51. getters
  52. }