user.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. address: {
  12. latitude: '',
  13. longitude: '',
  14. }
  15. }
  16. let mutations = {
  17. // 登录
  18. login(state) {
  19. state.hasLogin = true;
  20. },
  21. // 退出登录
  22. logout(state, provider) {
  23. state.hasLogin = false;
  24. // 清空基础信息
  25. state.userInfo = {};
  26. state.orderInfo = {
  27. complete_count: 0, //完成
  28. received_count: 0, //待收货
  29. unshipped_count: 0, //待发货
  30. order_count: 0, //订单总数
  31. unpaid_count: 0 //待付款
  32. };
  33. // 清除缓存用户信息
  34. uni.removeStorage({
  35. key: 'userInfo'
  36. })
  37. // 清除缓存token
  38. uni.removeStorage({
  39. key: 'token'
  40. })
  41. },
  42. // 保存用户信息
  43. setUserInfo(state, provider) {
  44. state.userInfo = provider;
  45. uni.setStorage({ //缓存用户登陆状态
  46. key: 'userInfo',
  47. data: provider
  48. })
  49. },
  50. // 保存订单信息
  51. setOrderInfo(state, provider) {
  52. state.orderInfo = provider;
  53. },
  54. // 保存当前用户所在位置
  55. setAddress(state, provider) {
  56. state.address = provider;
  57. }
  58. }
  59. let getters = {}
  60. export default {
  61. namespaced: true,
  62. state,
  63. mutations,
  64. getters
  65. }