user.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. information: {} //申请后获取信息
  12. }
  13. let mutations = {
  14. // 登录
  15. login(state) {
  16. console.log('登录完成');
  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. // 申请获取信息
  53. setInformation(state, provider) {
  54. state.information = provider;
  55. }
  56. }
  57. let getters = {}
  58. export default {
  59. namespaced: true,
  60. state,
  61. mutations,
  62. getters
  63. }