user.js 1.2 KB

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