app.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2024 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) || null,
  23. uuid: uni.getStorageSync('uuid') || "",
  24. backgroundColor: "#fff",
  25. userInfo: null,
  26. uid: Cache.get(UID) || null,
  27. globalData: uni.getStorageSync('GLOBAL_DATA') || {},
  28. homeActive: false,
  29. copyPwd: null,
  30. pageFooter:uni.getStorageSync('pageFoot') || {},
  31. keyColor: Cache.get('KEY_COLOR') || '_default',
  32. viewColor: Cache.get('VIEW_COLOR') || '--view-theme: #E93323;--view-assist:#FF7612;--view-priceColor:#E93323;--view-bgColor:rgba(255, 118, 18,.1);--view-minorColor:rgba(233, 51, 35,.1);--view-bntColor11:#FDA923;--view-bntColor12:#FD6523;--view-bntColor21:#F11B09;--view-bntColor22:#F67A38;',
  33. };
  34. const mutations = {
  35. LOGIN(state, opt) {
  36. state.token = opt.token;
  37. Cache.set(LOGIN_STATUS, opt.token, opt.time);
  38. uni.removeStorageSync('auth_token');
  39. },
  40. SETUID(state,val){
  41. state.uid = val;
  42. Cache.set(UID, val);
  43. },
  44. SETUUID(state,val){
  45. state.uuid = val;
  46. uni.setStorageSync('uuid', val)
  47. },
  48. UPDATE_LOGIN(state, token) {
  49. state.token = token;
  50. },
  51. LOGOUT(state) {
  52. state.token = null;
  53. state.uid = null
  54. Cache.clear(LOGIN_STATUS);
  55. Cache.clear(UID);
  56. },
  57. BACKGROUND_COLOR(state, color) {
  58. state.color = color;
  59. document.body.style.backgroundColor = color;
  60. },
  61. UPDATE_USERINFO(state, userInfo) {
  62. userInfo.isNew && Cache.set('is_new_user', '1')
  63. state.userInfo = userInfo;
  64. },
  65. OPEN_HOME(state) {
  66. state.homeActive = true;
  67. },
  68. CLOSE_HOME(state) {
  69. state.homeActive = false;
  70. },
  71. PARSE_PWD(state, pwd) {
  72. state.copyPwd = pwd;
  73. },
  74. VIEW_COLOR(state, color) {
  75. Cache.set('VIEW_COLOR', color)
  76. state.viewColor = color;
  77. },
  78. KEY_COLOR(state, key) {
  79. Cache.set('KEY_COLOR', key)
  80. state.keyColor = key;
  81. },
  82. GLOBAL_DATA(state, key) {
  83. uni.setStorageSync('GLOBAL_DATA', key);
  84. state.globalData = key;
  85. },
  86. FOOT_UPLOAD(state,data){
  87. state.pageFooter = data
  88. }
  89. };
  90. const actions = {
  91. USERINFO({
  92. state,
  93. commit
  94. }, force) {
  95. if (state.userInfo !== null && !force)
  96. return Promise.resolve(state.userInfo);
  97. else
  98. return new Promise(reslove => {
  99. getUserInfo().then(res => {
  100. commit("UPDATE_USERINFO", res.data);
  101. Cache.set(USER_INFO, res.data);
  102. reslove(res.data);
  103. });
  104. }).catch(() => {
  105. });
  106. }
  107. };
  108. export default {
  109. state,
  110. mutations,
  111. actions
  112. };