app.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import {
  11. getUserInfo
  12. } from "../../api/user.js";
  13. import {
  14. LOGIN_STATUS,
  15. NON_WIFI_AUTOPLAY,
  16. UID
  17. } from '../../config/cache';
  18. import Cache from '../../utils/cache';
  19. import {
  20. USER_INFO
  21. } from '../../config/cache';
  22. const state = {
  23. token: Cache.get(LOGIN_STATUS) || false,
  24. backgroundColor: "#fff",
  25. userInfo: Cache.get(USER_INFO) || {},
  26. uid: Cache.get(UID) || 0,
  27. homeActive: false,
  28. phoneStatus:true,
  29. pageFooter:uni.getStorageSync('pageFoot') || {},
  30. autoplay: Cache.get(NON_WIFI_AUTOPLAY) || false,
  31. nearbyStore: 0
  32. };
  33. const mutations = {
  34. SETPHONESTATUS(state,val){
  35. state.phoneStatus = val;
  36. },
  37. LOGIN(state, opt) {
  38. state.token = opt.token;
  39. Cache.set(LOGIN_STATUS, opt.token, opt.time);
  40. },
  41. SETUID(state,val){
  42. state.uid = val;
  43. Cache.set(UID, val);
  44. },
  45. UPDATE_LOGIN(state, token) {
  46. state.token = token;
  47. },
  48. LOGOUT(state) {
  49. state.token = undefined;
  50. state.uid = undefined
  51. state.userInfo = {}
  52. Cache.clear(LOGIN_STATUS);
  53. Cache.clear(UID);
  54. Cache.clear(USER_INFO);
  55. Cache.clear('newcomerGift');
  56. },
  57. BACKGROUND_COLOR(state, color) {
  58. state.color = color;
  59. document.body.style.backgroundColor = color;
  60. },
  61. UPDATE_USERINFO(state, userInfo) {
  62. state.userInfo = userInfo;
  63. Cache.set(USER_INFO, userInfo);
  64. },
  65. OPEN_HOME(state) {
  66. state.homeActive = true;
  67. },
  68. CLOSE_HOME(state) {
  69. state.homeActive = false;
  70. },
  71. FOOT_UPLOAD(state,data){
  72. state.pageFooter = data
  73. },
  74. SET_AUTOPLAY(state,data){
  75. state.autoplay = data
  76. Cache.set(NON_WIFI_AUTOPLAY, data)
  77. },
  78. SET_NEARBY(state,data){
  79. state.nearbyStore = data
  80. }
  81. };
  82. const actions = {
  83. USERINFO({
  84. state,
  85. commit
  86. }, force) {
  87. if (state.userInfo !== null && !force)
  88. return Promise.resolve(state.userInfo);
  89. else
  90. return new Promise(reslove => {
  91. getUserInfo().then(res => {
  92. commit("UPDATE_USERINFO", res.data);
  93. Cache.set(USER_INFO, res.data);
  94. reslove(res.data);
  95. });
  96. }).catch(() => {
  97. });
  98. }
  99. };
  100. export default {
  101. state,
  102. mutations,
  103. actions
  104. };