index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //引入vue和vuex
  2. import Vue from 'vue'
  3. import Vuex from 'vuex'
  4. Vue.use(Vuex)
  5. const store = new Vuex.Store({ // 全局变量定义
  6. state: {
  7. mainColor: '#ff6e3e', // 主色
  8. customStyle: { // 底部悬浮按钮样式
  9. height: '40px',
  10. backgroundColor: '#ff6e3e'
  11. },
  12. handleCustomStyle: { // 卡片主要操作按钮样式
  13. backgroundColor: '#ff6e3e',
  14. fontSize: '11px',
  15. padding: '0 15px'
  16. },
  17. handleDefaultCustomStyle: { // 卡片普通操作按钮样式
  18. color: '#ff6e3e',
  19. fontSize: '11px',
  20. padding: '0 15px',
  21. borderColor: '#ff6e3e',
  22. },
  23. },
  24. mutations: {
  25. // 登录
  26. login(state, provider) {
  27. state.userLoginFlag = true;
  28. state.userInfo = provider
  29. uni.setStorage({ // 异步缓存用户信息
  30. key: "userinfo",
  31. data: provider
  32. })
  33. console.log(state.userInfo)
  34. },
  35. // 退出
  36. logout(state) {
  37. state.userLoginFlag = false;
  38. state.userInfo = {};
  39. uni.removeStorage({ // 清除用户信息
  40. key: "userinfo"
  41. })
  42. }
  43. },
  44. getters: {
  45. mainColor: state => {
  46. return state.mainColor
  47. },
  48. customStyle: state => {
  49. return state.customStyle
  50. },
  51. handleCustomStyle: state => {
  52. return state.handleCustomStyle
  53. },
  54. handleDefaultCustomStyle: state => {
  55. return state.handleDefaultCustomStyle
  56. },
  57. }
  58. })
  59. export default store