app.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. UID
  16. } from '../../config/cache';
  17. import Cache from '../../utils/cache';
  18. import {
  19. USER_INFO
  20. } from '../../config/cache';
  21. const state = {
  22. token: Cache.get(LOGIN_STATUS) || false,
  23. backgroundColor: "#fff",
  24. userInfo: Cache.get(USER_INFO) || {},
  25. uid: Cache.get(UID) || 0,
  26. homeActive: false,
  27. phoneStatus:true,
  28. pageFooter:uni.getStorageSync('pageFoot') || {}
  29. };
  30. const mutations = {
  31. SETPHONESTATUS(state,val){
  32. state.phoneStatus = val;
  33. },
  34. LOGIN(state, opt) {
  35. state.token = opt.token;
  36. Cache.set(LOGIN_STATUS, opt.token, opt.time);
  37. },
  38. SETUID(state,val){
  39. state.uid = val;
  40. Cache.set(UID, val);
  41. },
  42. UPDATE_LOGIN(state, token) {
  43. state.token = token;
  44. },
  45. LOGOUT(state) {
  46. state.token = undefined;
  47. state.uid = undefined
  48. state.userInfo = {}
  49. Cache.clear(LOGIN_STATUS);
  50. Cache.clear(UID);
  51. Cache.clear(USER_INFO);
  52. Cache.clear('newcomerGift');
  53. },
  54. BACKGROUND_COLOR(state, color) {
  55. state.color = color;
  56. document.body.style.backgroundColor = color;
  57. },
  58. UPDATE_USERINFO(state, userInfo) {
  59. state.userInfo = userInfo;
  60. Cache.set(USER_INFO, userInfo);
  61. },
  62. OPEN_HOME(state) {
  63. state.homeActive = true;
  64. },
  65. CLOSE_HOME(state) {
  66. state.homeActive = false;
  67. },
  68. FOOT_UPLOAD(state,data){
  69. state.pageFooter = data
  70. }
  71. };
  72. const actions = {
  73. USERINFO({
  74. state,
  75. commit
  76. }, force) {
  77. if (state.userInfo !== null && !force)
  78. return Promise.resolve(state.userInfo);
  79. else
  80. return new Promise(reslove => {
  81. getUserInfo().then(res => {
  82. commit("UPDATE_USERINFO", res.data);
  83. Cache.set(USER_INFO, res.data);
  84. reslove(res.data);
  85. });
  86. }).catch(() => {
  87. });
  88. }
  89. };
  90. export default {
  91. state,
  92. mutations,
  93. actions
  94. };