user.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // 清除缓存用户信息
  30. uni.removeStorage({
  31. key: 'userInfo'
  32. })
  33. // 清除缓存token
  34. uni.removeStorage({
  35. key: 'token'
  36. })
  37. },
  38. // 保存用户信息
  39. setUserInfo(state, provider) {
  40. state.userInfo = provider;
  41. uni.setStorage({ //缓存用户登陆状态
  42. key: 'userInfo',
  43. data: provider
  44. })
  45. },
  46. // 保存订单信息
  47. setOrderInfo(state, provider) {
  48. state.orderInfo = provider;
  49. }
  50. }
  51. let getters = {}
  52. export default {
  53. namespaced: true,
  54. state,
  55. mutations,
  56. getters
  57. }