app.js 2.1 KB

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